#include
#define uchar unsigned char
#define uint unsigned int
sbit qingling=P1^0;
sbit tiaofen=P1^1;
sbit tiaoshi=P1^2;
sbit sounder=P1^3;
uint a,b;
uchar hour,minu,sec,
hour0,minu0,sec0,
hour1,minu1,sec1;
h1,h2,m1,m2,s1,s2,
k,s;
uchar code select[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar code table[]= {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void keyscan();
void init();
void delay(int z);
void display(uchar,uchar,uchar);
void sounde();
void main()
{
init();
while(1)
{
while(TR1)
{
keyscan();
while(s==1)
{
keyscan();
display(hour1,minu1,sec1);
}
display(hour0,minu0,sec0);
while(k)
{
display(hour,minu,sec);
}
}
}
}
void init()
{
a=0;
b=0;
k=0;
s=0;
hour0=0;
minu0=0;
sec0=0;
hour=0;
minu=0;
sec=0;
hour1=0;
minu1=0;
sec1=0;
TMOD=0x11;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
EX0=1;
EX1=1;
ET0=1;
ET1=1;
IT0=1;
IT1=1;
PX0=1;
PX1=1;
TR0=0;
TR1=1;
}
void timer0_int() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
a++;
if(a==2)
{
a=0;
sec++;
if(sec==100)
{
sec=0;
minu++;
if(minu==60)
{
minu=0;
hour++;
if(hour==60)
{
hour=0;
}
}
}
}
}
void ex0_int() interrupt 0
{
k++;
if(k==3)
k=0;
if(k==1)
{
TR0=~TR0;
if(TR0==1)
{
hour=0;
minu=0;
sec=0;
}
}
if(k==2)
{
TR0=~TR0;
}
}
void ex1_int() interrupt 2
{
s++;
if(s==3)
s=0;
}
void timer1_int() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(s==2)
{
if(hour1==hour0 && minu0==minu1)
sounde();
}
b++;
if(b==20)
{
b=0;
sec0++;
if(sec0==60)
{
sec0=0;
minu0++;
if(minu0==60)
{
minu0=0;
hour0++;
if(hour0==24)
hour0=0;
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』