#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar qian,bai,shi,ge,aa,modal,flag;
uchar qian1,bai1,shi1,ge1,modal1;
uchar code table []={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
sbit sound=P1^2;
sbit den1=P0^2;
sbit den2=P0^5;
sbit den3=P0^7;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
void init();
void keyscan();
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void alarmclock();
//void light();
void show();
void delay(uint z);
void main()
{
init();
while(1)
{
display(qian,bai,shi,ge);
if(ge==ge1 && shi==shi1 && bai==bai1 && qian==qian1)
{
sound=0;
delay(1000);
sound=1;
}
while(flag==2)
{
display(qian,bai,shi,ge);
alarmclock();
display(qian1,bai1,shi1,ge1) ;
}
while(flag==1)
{
display(0,0,0,0);
keyscan();
}
// light();
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
show();
}
void exter0() interrupt 0
{
den3=0;
flag++;
TR0=0;
if(flag==3)
{
flag=0;
}
}
void show()
{
den1=0;
if(aa==20)
{
aa=0;
ge++;
if(ge==10)
{
ge=0;
shi++;
if(shi==6)
{
shi=0;
bai++;
switch(qian)
{
case 0:
if(bai==10)
{
bai=0;
qian++;
break;
}
// break;
case 1:
if(bai==10)
{
bai=0;
qian++;
break;
}
break;
case 2:
if(bai==4)
{
bai=0;
qian=0;
}
break;
}
}
}
}
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1);
modal++;
if(modal>=5)
{
den3=1;
flag=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa=0;
TR0=1;
modal=0;
}
while(modal)
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1);
modal++;
if(modal>=5)
{
den3=1;
flag=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa=0;
TR0=1;
modal=0;
}
}
}
switch(modal)
{
case 1:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
qian++;
if(qian>2)
{
qian=0;
}
display(qian,bai,shi,ge);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
qian--;
if(qian<0)
{
qian=2;
}
display(qian,bai,shi,ge);
}
}
break;
case 2:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
bai++;
switch(qian)
{
case 0 :
if(bai>9)
{
bai=0;
}
case 1 :
if(bai>9)
{
bai=0;
}
case 2 :
if(bai>4)
{
bai=0;
}
}
display(qian,bai,shi,ge);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
bai--;
display(qian,bai,shi,ge);
}
}
break;
case 3:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
shi++;
display(qian,bai,shi,ge);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
shi--;
display(qian,bai,shi,ge);
}
}
break;
case 4:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
ge++;
display(qian,bai,shi,ge);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
ge--;
display(qian,bai,shi,ge);
}
}
break;
}
display(qian,bai,shi,ge);
}
}
}
}
void alarmclock()
{
if(key4==0)
{
delay(10);
if(key4==0)
{
while(!key4);
modal1++;
if(modal1>=5)
{
den3=1;
flag=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa=0;
TR0=1;
modal1=0;
}
while(modal1)
{
if(key4==0)
{
delay(10);
if(key4==0)
{
while(!key4);
modal1++;
if(modal1>=5)
{
den3=1;
flag=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa=0;
TR0=1;
modal1=0;
}
}
}
switch(modal1)
{
case 1:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
qian1++;
display(qian1,bai1,shi1,ge1);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
qian1--;
display(qian1,bai1,shi1,ge1);
}
}
break;
case 2:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
bai1++;
display(qian1,bai1,shi1,ge1);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
bai1--;
display(qian1,bai1,shi1,ge1);
}
}
break;
case 3:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
shi1++;
display(qian1,bai1,shi1,ge1);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
shi1--;
display(qian1,bai1,shi1,ge1);
}
}
break;
case 4:
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
ge1++;
display(qian1,bai1,shi1,ge1);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
ge1--;
display(qian1,bai1,shi1,ge1);
}
}
break;
}
}
}
}
}
/*
void light()
{
if(key2==0 && key3==0)
{
delay(10);
if(key2==0 && key3==0)
{
den2=0;
delay(1000);
den2=1;
}
}
}
*/
void init()
{
TMOD=0x01;
TH0=65536/256;
TL0=65536%256;
EA=1;
EX0=1;
IT0=1;
TF0=0;
ET0=1;
TR0=1;
display(0,0,0,0);
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
P2=table[ge];
P1=0x7f;
delay(10);
P2=table[shi];
P1=0xbf;
delay(10);
P2=table[bai];
P1=0xdf;
delay(10);
P2=table[qian];
P1=0xef;
delay(10);
}
void delay(uint z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
你可以看看这个 看有没有思路 |