在使用Proteus仿真软件运行时,数码管在显示到20的时候就开始显示不全,然后显示到26左右就会清零重新开始计数,下面是我的代码,我想知道是什么情况,并给出解决办法,谢谢
#include <reg51.h>
#define uchar unsigned char
uchar code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code discode3[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x07,0xff,0xef};
uchar timer=0;
uchar second;
uchar key=0;
main()
{
P1=0xff;
P2=0xff;
P0=0xff;
TMOD=0x01;
ET0=1;
EA=1;
second=0;
P1=discode1[second/100];
P0=discode2[second/10];
P2=discode3[second%10];
while(1)
{
if((P3&0x80)==0x00)
{
key++;
switch(key)
{
case 1:
TH0=0xee;
TL0=0x00;
TR0=1;
break;
case 2:
TR0=0;
break;
case 3:
key=0;
second=0;
P1=discode1[second/100];
P0=discode2[second/10];
P2=discode3[second%10];
break;
}
while((P3&0x80)==0x00);
}
}
}
void int_T0() interrupt 1 using 0
{
TR0=0;
TH0=0xee;
timer++;
if(timer==20)
{
timer=0;
second++;
P1=discode1[second/100];
P0=discode2[second/10];
P2=discode3[second%10];
}
if(second==999)
{
TR0=0;
second=0;
key=2;
}
else
{
TR0=1;
}
}
将case3中的second=0给注释下,看是不是这里的影响!