#include<reg52.h>
sbit key =P1^7;
sbit LED1=P2^0;
sbit LED2=P2^1;
unsigned char keycnt;
unsigned char Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned int counet,second,msecond,minute;
void delay(unsigned int m)
{
unsigned char s;
for(;m>0;m--)
for(s=124;s>0;s--);
}
void display()
{
P0=Tab[msecond%10];
LED1=1;
delay(5);
LED1=0;
P0=Tab[second%10];
LED2=1;
delay(5);
LED2=0;
}
main()
{
unsigned char i,j;
P0=0xff;
P1=0xff;
TMOD=0x01;
// TH0=0x3c;
// TL0=0xb0;
EA=1;
ET0=1;
// TR0=1;
while(1)
{
display();
if(key==0)
{
for(i=20;i>0;i--)
for(j=248;j>0;j--);
if(key==0)
{
keycnt++;
switch(keycnt)
{
case 1:
TH0=0x3c;
TL0=0xb0;
TR0=1;
break;
case 2:
TR0=0;
break;
case 3:
second=0;
msecond=0;
minute=0;
keycnt=0;
break;
}
while(P3_5==0);
}
}
}
}
void time0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
counet++;
if(counet==20)
{
msecond++;
counet=0;
if(msecond==100)
{
msecond=0;
}
}
}
温馨提示:内容为网友见解,仅供参考