#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar aa,num1,num2,num3; /*num1Îaê±£¬num2Îa·Ö,num3ÎaÃë*/
uchar shi1,ge1,shi2,ge2,shi3,ge3;
void inint()
{
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(uchar shi1,uchar ge1,uchar shi2,uchar ge2,uchar shi3,uchar ge3)
{
dula=1;
P0=table[shi1];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(2);
dula=1;
P0=table[ge1];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(2);
dula=1;
P0=table[shi2];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(2);
dula=1;
P0=table[ge2];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(2);
dula=1;
P0=table[shi3];
dula=0;
P0=0xef;
wela=1;
P0=0xef;
wela=0;
delay(2);
dula=1;
P0=table[ge3];
dula=0;
P0=0xdf;
wela=1;
P0=0xdf;
wela=0;
delay(2);
}
void main()
{
inint();
while(1)
{
display(shi1,ge1,shi2,ge2,shi3,ge3);
}
}
void zhongduan() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
{
aa=0;
num3++;
if(num3==60)
{
num3=0;
num2++;
if(num2==60)
{
num2=0;
num1++;
}
}
if(num1==24 && num3==1)
{
num1=0;
num2=0;
num3=0;
}
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
shi3=num3/10;
ge3=num3%10;
}
}
|