#include<reg51.h>
#define uint unsigned int
uint DIDA=0,SEC=0,MIN=0,HOUR=0,h=0;
code char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f};
void timer0() interrupt 1 using 1
{
TR0=0;
TH0=0x3c;
TL0=0xb0;
DIDA++;
TR0=1;
}
main()
{ uint p,k;
uint KEY();
void CONV();
void ITX();
TMOD=0x01;
TH0=0x3c;TL0=0xb0;
ET0=1;EA=1;
TR0=1;
while(1)
{ if(h==0)
{
P2=0x81;
P0=0x80;
for(p=0;p<200;p++);
}
else
{
P2=0x81;
P0=0x00;
for(p=0;p<200;p++);
}
CONV();
ITX();
P1=0x0f;
if(P1!=0x0f)
{ for(p=0;p<=10000;p++);
if(P1!=0x0f)
{ k=KEY();
if(k==0)
{ MIN++;
if(MIN==60)
{ MIN=0;
HOUR++;
if(HOUR==24)
HOUR=0;
}
}
else if(k==4)
{ HOUR++;
if(HOUR==24)
HOUR=0;
}
}
}
}
}
void CONV()
{
if(DIDA==20)
{
DIDA=0;
SEC++;
h=!h;
if(SEC==60)
{ SEC=0;
MIN++;
if(MIN==60)
{ MIN=0;
HOUR++;
if(HOUR==24)
HOUR=0;
}
}
}
}
void ITX()
{ uint i,j,k,e,p;
i=HOUR/10;
j=HOUR%10;
k=MIN/10;
e=MIN%10;
P2=0x80;
P0=tab[j];
for(p=0;p<200;p++);
P2=0x81;
P0=tab[i];
for(p=0;p<200;p++);
P2=0x82;
P0=tab[e];
for(p=0;p<200;p++);
P2=0x83;
P0=tab[k];
for(p=0;p<200;p++);
}
uint KEY()
{ uint i,k;
unsigned char code tab[16]={0xee,0xde,0xbe,0x7e,0xed,0xdd,0xbd,0x7d,0xeb,
0xdb,0xbb,0x7b,0xe7,0xd7,0xb7,0x77};
P1=0x0f;
i=P1;
P1=0xf0;
i=i|P1;
for(k=0;tab[k]!=i&&k<16;k=k+1);
return (k);
}