#include<reg51.h>
sbit kh=P1^0;
sbit km=P1^1;
sbit ks=P1^2;
sbit st=P1^3;
sbit b=P3^7;
Unsigned; char
table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; unsigned char i=0,hour=0,minute=0,second=0;
void delayms(unsigned int x)
{ unsigned char a=160;
while(x--) { while(a--);
a=160; } }
main() {
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TMOD=1;
TR0=0;
ET0=1;
EA=1;
while(1) { P0=table[hour/10];
P2=~32;
delayms(1);
P2=0xff;
P0=table[hour%10];
P2=~16;//
delayms(1);
P2=0xff;
P0=table[minute/10];
P2=~8;
delayms(1);
P2=0xff;
P0=table[minute%10];
P2=~4;
delayms(1);
P2=0xff;
P0=table[second/10];
P2=~2;
delayms(1);
P2=0xff;
P0=table[second%10];
P2=~1;
delayms(1);
P2=0xff;
if(!kh)
{
delayms(200);
hour++;
if(hour>23)
hour=23; }
else if(!km)
{ delayms(200);
minute++;
if(minute>59)
minute=59; }
else if(!ks)
{ delayms(200);
second++;
if(second>59)
second=59; }
if(!st)
{ delayms(200);
TR0=1; }
if(TR0==1&&hour==0&&minute==0&&second<3)
b=!b;
delayms(1);}
}
void t0() interrupt 1
{ TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i++;
if(i>=20)
{ i=0;
second--;
if(second>59)
{ second=59;
minute--;
if(minute>59)
{ minute=59;
hour--;
if(hour>23)
{ hour=0;
minute=0;
second=0;
TR0=0;} } } } } |