是這樣的。我想利用定時計數器的中斷,完成一個倒計時顯示器的功能,就是每隔一秒,數碼管從10遞減逐漸減到0,減到0后跑馬燈運行。然后這個程序開始為什么會顯示5,然后10也顯示不了,就從9減到0了,哪位大佬解釋一下為啥啊,拜托了
#include "reg52.h"
unsigned char run[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char table[]={0x3f,0x6f,0x7f,0x07,0x7d,0x6d,0x66,0x4f,0x5b,0x06};
void delay(int i)
{
while(i--);
}
void show(unsigned int j)
{
if(j==0)
{
P0=table[j/10];
P2=0x04;
}
P0=table[j%10];
P2=0x00;
}
void int1() interrupt 1
{
unsigned int i,a,b;
i++;
if(i==1000)
{
i=0;
if(a>10)
{
while(1)
{
P0=0x00;
P2=run[b++];
delay(10000);
if(b==8)
b=0;
}
}
else show(a++);
}
show(a-1);
TH0=0Xfc;
TL0=0X18;
}
void main()
{
while (1)
{
TMOD=0x01;
TH0 =0xfc;
TL0 =0x18;
ET0 =1;
EA =1;
TR0 =1;
while(1);
}
} |