#include <reg51.h>
unsigned char code LED[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char s=55,m=59,h=23;
unsigned char i1,j1,i2,j2,i3,j3,t;
void delay(unsigned int time)
{
unsigned int j=0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
void main()
{
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
TR0=1;
ET0=1;
EA=1;
while(1);
{
if (s==60)
{ s=0;m++;}
i1=s/10;
j1=s%10;
if (m==60)
{ m=0;h++;}
i2=m/10;
j2=m%10;
if (h==24)
h=0;
i3=h/10;
j3=h%10;
P2=0xfe;P0=LED[j1];delay(1);
P2=0xfd;P0=LED[i1];delay(1);
P2=0xfb;P0=LED[j2];delay(1);
P2=0xf7;P0=LED[i2];delay(1);
P2=0xef;P0=LED[j3];delay(1);
P2=0xdf;P0=LED[i3];delay(1);
}
}
void timer0() interrupt 1 {
t++;
if (t==20)
{ t=0;
s++;
}
TH0=0x3c;
TL0=0xb0;
}
|