程序是可以实现倒计时的,而且倒计时也基本正确,但是在复位后发现第一秒由9999到9998的时候,过了大约2s的时间,其他的都没问题,P0段选,P2位选。求各位大神解决#include <reg52.h>
unsigned char code shumaguan[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
unsigned char chushi[]={0x90,0x90,0x90,0x90};
unsigned int cnt=0;
unsigned char m=0;
void main()
{
unsigned int i,j=10000;
TMOD=0x01;
TH0=0xEC;
TL0=0x78;
EA=1;
ET0=1;
TR0=1;
while (1)
{
if (cnt==200)
{
cnt=0;
j--;
chushi[0]=shumaguan[j/1000%10];
chushi[1]=shumaguan[j/100%10];
chushi[2]=shumaguan[j/10%10];
chushi[3]=shumaguan[j%10];
}
}
}
void Tnterruptime0()interrupt 1
{
cnt++;
TH0=0xEC;
TL0=0x78;
switch(m)
{
case 0:P0=chushi[0];P2=~0x01;m++;break;
case 1:P0=chushi[1];P2=~0x02;m++;break;
case 2:P0=chushi[2];P2=~0x04;m++;break;
case 3: P0=chushi [3];P2=~0x08;m=0;break;
}
}
|