#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit guan1=P2^5;
sbit guan2=P2^6;
sbit guan3=P2^3;
sbit guan4=P2^4;
sbit bell=P2^7;
sbit key1=P2^0;
sbit key2=P3^2;
sbit key3=P3^3;
sbit key4=P3^4;
code table[]=
{0x05,0x7d,0x46,0x54,0x3c,
0x94,0x84,0x5d,0x04,0x14};
uint num1,num2,num3,num4,miao,s=0,fen=30,shi=12;
uchar aa=0xfe,flag1=0,flag2=0;
void display();
void key();
void delay(uint z) /*延时函数*/
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
shi=0;
}
}
num1=shi/10;
num2=shi%10;
num3=fen/10;
num4=fen%10;
if(!key1)
{
delay(10);
if(!key1)
{
shi++;
if(shi==24)
shi=0;
}
while(!key1);
delay(5);
while(!key1);
}
else if(!key2)
{
delay(10);
if(!key2)
{
fen++;
if(fen==60)
fen=0;
}
while(!key2);
delay(5);
while(!key2);
}
else if(!key3)
{
delay(10);
if(!key3)
{
flag1++;
}
while(!key3);
delay(5);
while(!key3);
}
else if(!key4)
{
delay(10);
if(!key4)
{
flag2++;
}
while(!key4);
delay(5);
while(!key4);
}
display();
if(flag1%2==1)
{
bell=0;
delay(10);
bell=1;
}
if(flag2%2==1)
{
P1=aa;delay(500);
aa=_crol_(aa,1);
}
}
}
void display()
{
guan1=0;
P0=table[num1];delay(1);
guan1=1;
guan2=0;
P0=table[num2];delay(1);
guan2=1;
guan3=0;
P0=table[num3];delay(1);
guan3=1;
guan4=0;
P0=table[num4];delay(1);
guan4=1;
}
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
if(s==20)
{
s=0;
miao++;
}
} |