我编了个c语言程序,下载到单片机中,用信号发生器输入信号作为外部中断,只有最后一位led显示,请高手帮我看下程序哪里出错,不胜感激!!!
#include<reg52.h>#define uint unsigned int
#define uchar unsigned char
uchar qian,bai,shi,ge;
sbit dula=P2^6;
sbit wela=P2^7;
void display(uchar qian,uchar bai,uchar shi,uchar ge);
uint mm=1234;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,};
delay(uint m)
{ uint i,j;
for(i=m;i>0;i--)
for(j=60;j>0;j--);
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
dula=1;
qian=mm/1000;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
bai=mm%1000/100;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
shi=mm%1000%100/10;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
ge=mm%10;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
}
timer_init() //定时器计数器初始化函数
{
EA=1;
ET0=1;
ET1=1;
TMOD=0X51;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TH1=0;
TL1=0;
TR0=1;
TR1=1;
}
main()
{
timer_init();
P0=0; //开始数码管不显示
while(1)
{
display(qian,bai,shi,ge);
delay(600); //数码管刷新时间单位毫秒
}
}
void timer0() interrupt 1
{ TR0=0;
TR1=0;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
mm=0;
mm|=TH1;
mm=(mm<<8)|TL1;
mm-=55536;
TH1=0;
TL1=0;
TR0=1;
TR1=1;
}
void timer1() interrupt 3 //显示0000说明出错
{ TR1=0;
TR0=0;
mm=0;
TH1=0;
TL1=0;
TR1=1;
}