#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit S1=P2^2;
sbit S2=P2^3;
sbit S3=P2^4;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c};
void delayms(uint);
uchar num,num1,num2,num3,shi,ge,shi1,ge1,shi2,ge2;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar num1s,uchar num2s,uchar num3s )
{ shi2=num3s/10;
ge2=num3s%10;
shi1=num2s/10;
ge1=num2s%10;
shi=num1s/10;
ge=num1s%10;
S1=0;
S2=0;
S3=0;
P0=table[ge];
delayms(2);
P0=0;
S1=1;
S2=0;
S3=0;
P0=table[shi];
delayms(2);
P0=0;
S1=0;
S2=1;
S3=0;
P0=0x40;
delayms(2);
P0=0;
S1=1;
S2=1;
S3=0;
P0=table[ge1];
delayms(2);
P0=0;
S1=0;
S2=0;
S3=1;
P0=table[shi1];
delayms(2);
P0=0;
S1=1;
S2=0;
S3=1;
P0=0x40;
delayms(2);
P0=0;
S1=0;
S2=1;
S3=1;
P0=table[ge2];
delayms(2);
P0=0;
S1=1;
S2=1;
S3=1;
P0=table[shi2];
delayms(2);
P0=0;
}
void init()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)/256;
TH1=(65536-45872)/256;
TH1=(65536-45872)/256;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
if(key1==0)
{
delayms(2);
if(key1==0)
{
num1++;
if(num1==60)
{
num1=0;
}
while(!key1);
}
}
if(key2==0)
{
delayms(2);
if(key2==0)
{
num2++;
if(num2==60)
{
num2=0;
}
while(!key2);
}
}
if(key3==0)
{
delayms(2);
if(key3==0)
{
num3++;
if(num3==24)
{
num3=0;
}
while(!key3);
}
}
if(key4==0)
{
delayms(2);
if(key4==0)
{
while(!key4);
TR0=~TR0;
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num1,num2,num3);
}
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)/256;
num++;
if(num==20)
{
num=0;
num1++;
if(num1==60)
{
num1=0;
num2++;
if(num2==60)
{
num2=0;
num3++;
if(num3==24)
{
num3=0;
}
}
}
}
} |