#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
sbit K1=P3^4;
sbit K2=P3^5;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint aa;
uchar num1,num2,shi1,ge1,shi2,ge2;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar num1,uchar num2)
{
shi1=num1/10;
ge1=num1%10;
shi2=num2/10;
ge2=num2%10;
dula=1;
P0=table[shi1];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[ge1];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[shi2];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[ge2];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
}
void key()
{
if(K1==0)
{
delay(5);
if(K1==0)
{
if(num1==0)
{
num1=60;
}
num1--;
while(!12);
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
num1++;
if(num1>=60)
{
num1=num1-60;
}
while(!23);
}
}
}
void main()
{
while(1)
{
key();
display(num1,num2);
}
} |