#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wela=P2^7;
sbit dula=P2^6;
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit key4=P3^3;
sbit beep=P2^3;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
void delayms(uint);
void display(uchar,uchar,uchar,uchar,uchar,uchar);
void display1(uchar,uchar,uchar,uchar,uchar,uchar,uchar,uchar);
void display2(uchar,uchar,uchar,uchar);
void display3(uchar,uchar,uchar,uchar,uchar,uchar);
void keycan();
void juzhen();
void tiaonaozhong();
uchar num1,num2,num3,shi1,shi2,fen1,fen2,miao1,miao2;
uchar nian1,nian2,nian3,nian4,yue1,yue2,ri1,ri2;
uint num=0,a=0,b=8,d=24,e=11,f=2019;
uchar qian,bai,shi,ge;
uchar shi3,shi4,fen3,fen4,miao3,miao4;
uint numm=0,aa=0,bb=0;
uint key,c=1;
void main()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
while(1)
{
miao1=num/10;
miao2=num%10;
fen1=a/10;
fen2=a%10;
shi1=b/10;
shi2=b%10;
ri1=d/10;
ri2=d%10;
yue1=e/10;
yue2=e%10;
nian1=f/1000;
nian2=f%1000/100;
nian3=f%1000%100/10;
nian4=f%1000%100%10%10;
miao3=numm/10;
miao4=numm%10;
fen3=aa/10;
fen4=aa%10;
shi3=bb/10;
shi4=bb%10;
if(numm==num&&bb==b&&aa==a) //闹钟响
{beep=0;}
if(numm==num&&b==bb+2&&aa==a) //自动关闹钟
{beep=1;}
keycan();
juzhen();
tiaonaozhong();
if(c%4==1)
{
nian1=16;nian2=16;nian3=16;nian3=16;nian4=16;
yue1=16;yue2=16;ri1=16;ri2=16;
qian=16;bai=16;shi=16;ge=16;
shi3=16;shi4=16;fen3=16;fen4=16;miao3=16;miao4=16;
display(shi1,shi2,fen1,fen2,miao1,miao2);
}
if(c%4==2)
{
shi1=16;shi2=16;fen1=16;fen2=16;miao1=16;miao2=16;
qian=16;bai=16;shi=16;ge=16;
shi3=16;shi4=16;fen3=16;fen4=16;miao3=16;miao4=16;
display1(nian1,nian2,nian3,nian4,yue1,yue2,ri1,ri2);
}
if(c%4==3)
{
nian1=16;nian2=16;nian3=16;nian4=16;
yue1=16;yue2=16;ri1=16;ri2=16;
shi1=16;shi2=16;fen1=16;fen2=16;miao1=16;miao2=16;
shi3=16;shi4=16;fen3=16;fen4=16;miao3=16;miao4=16;
display2(qian,bai,shi,ge);
}
if(c%4==0)
{
nian1=16;nian2=16;nian3=16;nian4=16;
yue1=16;yue2=16;ri1=16;ri2=16;
shi1=16;shi2=16;fen1=16;fen2=16;miao1=16;miao2=16;
qian=16;bai=16;shi=16;ge=16;
display3(shi3,shi4,fen3,fen4,miao3,miao4);
}
if(c==5)
{c=1;}
if(e==13)
{e=1;}
}
}
void display(uchar shi1,uchar shi2,uchar fen1,uchar fen2,uchar miao1,uchar miao2)
{
dula=1;
P0=table[shi1];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(1);
dula=1;
P0=table[shi2];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(1);
dula=1;
P0=table[fen1];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delayms(1);
dula=1;
P0=table[fen2];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delayms(1);
dula=1;
P0=table[miao1];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delayms(1);
dula=1;
P0=table[miao2];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delayms(1);
}
void display1(uchar nian1,uchar nian2,uchar nian3,uchar nian4,uchar yue1,uchar yue2,uchar ri1,uchar ri2)
{
dula=1;
P0=table[nian1];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(1);
dula=1;
P0=table[nian2];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(1);
dula=1;
P0=table[nian3];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delayms(1);
dula=1;
P0=table[nian4];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delayms(1);
dula=1;
P0=table[yue1];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delayms(1);
dula=1;
P0=table[yue2];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delayms(1);
dula=1;
P0=table[ri1];
dula=0;
P0=0xff;
wela=1;
P0=0xbf;
wela=0;
delayms(1);
dula=1;
P0=table[ri2];
dula=0;
P0=0xff;
wela=1;
P0=0x7f;
wela=0;
delayms(1);
}
void display2(uchar qian,uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(1);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delayms(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delayms(1);
}
void display3(uchar shi3,uchar shi4,uchar fen3,uchar fen4,uchar miao3,uchar miao4)
{
dula=1;
P0=table[shi3];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(1);
dula=1;
P0=table[shi4];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(1);
dula=1;
P0=table[fen3];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delayms(1);
dula=1;
P0=table[fen4];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delayms(1);
dula=1;
P0=table[miao3];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delayms(1);
dula=1;
P0=table[miao4];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delayms(1);
}
void tiaonaozhong()
{
if(numm==60)
{numm=0;}
if(aa==60)
{aa=0;}
if(bb==24)
{bb=0;}
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void keycan() //独立键盘
{
if(key4==0) //时间显示切换键
{
if(key4==0)
{
c++;
while(!key4);
}
}
}
void juzhen() //矩阵
{
uchar temp;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
// delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee: //手动关闹钟
beep=1;
break;
beep=1;
case 0xde: //计时清零
qian=0;
bai=0;
shi=0;
ge=0;
num3=0;
break;
case 0xbe: //按下停止计时
TR1=0;
break;
case 0x7e: //按下开始计时
TR1=1;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
// delayms(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed: // 调时
bb=bb+1;
break;
case 0xdd: // 调分
aa=aa+1;
break;
case 0xbd: // 调秒
numm=numm+1;
break;
case 0x7d: //meiyongdao
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256; //50ms
num1++;
if(num1==20) //1秒到了
{
num1=0;
num++;
}
if(num==60) // 一分钟到了
{
num=0;
a++;
}
if(a==60) // 一小时到了
{
a=0;
b++;
}
if(b==24) //一天到了
{
b=0;
d++;
}
if(d==31&&e==1|3|5|7|8|10|12) // d为天数,e为月份,f为年份
{
d=1;
e++;
}
if(d==28&&e==2&&f%4!=0) //平二月
{
d=1;
e++;
}
if(d==29&&e==2&&f%4==0) //闰二月
{
d=1;
e++;
}
if(d==30&&e==4|6|9|11)
{
d=1;
e++;
}
if(e==12) //一年到了
{
f++;
}
miao1=num/10;
miao2=num%10;
fen1=a/10;
fen2=a%10;
shi1=b/10;
shi2=b%10;
ri1=d/10;
ri2=d%10;
yue1=e/10;
yue2=e%10;
nian1=f/1000;
nian2=f%1000/100;
nian3=f%1000%100/10;
nian4=f%1000%100%10%10;
}
void T1_time()interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256; //50ms
num2++;
if(num2==200)
{
num2=0;
num3++;
}
if(num3==60)
{
num3=0;
}
shi=num3/10;
ge=num3%10;
if(shi==5&&ge==9)
{
shi=0;
ge=0;
bai++;
}
if(bai==9)
{
qian++;
}
if(qian==5)
{
TR1=0;
}
}
|