#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wela=P2^7;
sbit dula=P2^6;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,};
uchar bai,shi,ge,tt;
uint aa;
void init();
void delay(uint z);
void display(uchar bai,uchar shi,uchar ge);
void main()
{
init();
while(1)
{
bai=aa/100;
shi=aa%100/10;
ge=aa%10;
display(bai,shi,ge);
if(key1==0)
{
delay(5);
if(key1==0)
{
TR0=0;
}
while(!key1);
delay(5);
while(!key1);
}
else
TR0=0;
}
}
void init()
{
aa=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
tt++;
if(tt==100)
{
tt=0;
aa++;
if(aa==999)
aa=0;
}
}
void display(uchar bai,uchar shi,uchar ge)
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=table[bai];
dula=0;
delay(1);
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=table[shi];
dula=0;
delay(1);
wela=1;
P0=0xfb;
wela=0;
dula=1;
P0=table[ge];
dula=0;
delay(1);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
} |