从0加到99时后就变回了00再加到99,不停重复00加到99,不知道为什么会突破100的额?求解啊。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar t,z,qian,bai,shi,ge;
uint i;
uchar code dulama[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void init();
void delay(uint z);
void display_1();
void display_2(uchar shi,uchar ge);
void display_3(uchar bai,uchar shi,uchar ge);
void display_4(uchar qian,uchar bai,uchar shi,uchar ge);
void main()
{
init();
while(1)
{
while(i<10)
{display_1();}
while(10<=i<100)
{display_2(shi,ge);}
while(100<=i<1000)
{display_3(bai,shi,ge);}
while(1000<=i<10000)
{display_4(qian,bai,shi,ge);}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
if(t==10)
{
t=0;
i++;
if(i==10000)
{i=0;}
}
if(10<=i<100)
{
shi=i/10;
ge=i%10;
}
if(100<=i<1000)
{
bai=i/100;
shi=i%100/10;
ge=i%10;
}
if(1000<=i<10000)
{
qian=i/1000;
bai=i%1000/100;
shi=i%1000%100/10;
ge=i%10;
}
}
void init()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display_1()
{
dula=1;
P0=dulama[i];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
}
void display_2(uchar shi,uchar ge)
{
dula=1;
P0=dulama[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=dulama[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
}
void display_3(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=dulama[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=dulama[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=dulama[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
}
void display_4(uchar qian,uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=dulama[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=dulama[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=dulama[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=dulama[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
}
------最佳解决方案--------------------
噗,这种错误我最近一周内也犯过,木有办法,只能怪自己大意了。
------其他解决方案--------------------
看不懂 一堆拼音字母
------其他解决方案--------------------