#include <REGX52.H>
sbit dula=P2^6;
sbit wela=P2^7;
unsigned int anjian,key,a,b,c,
numnian,numyue,numri,numshi,numfen,nummiao,T0count,T1count,
num,num1,nu,nu1,nu2,nu3,nu4,nu5,nu6,nu7,nu8,nu9,nu10,nu11,nu12,nu13;
bit ting=0;
bit huan=0;
unsigned char code duanxuan[]={
0x3f, 0x06, 0x5b, 0x4f,
0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c,
0x39, 0x5e, 0x79, 0x71,
0x40,0x09,0x49};
unsigned char code weixuan[]={
0xfe, 0xfd, 0xfb, 0xf7,
0xef, 0xdf,0xbf,0x7f};
void delay(unsigned int xms)
{
unsigned char i, j;
while(xms--)
{
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
unsigned char MatrixKey()
{
unsigned char KeyNumber;
// num=MatrixKey();
P3=0xFf;
P3_3=0;
if(P3_7==0){delay(20);while(P3_7==0);delay(20);KeyNumber=1;}
if(P3_6==0){delay(20);while(P3_6==0);delay(20);KeyNumber=5;}
if(P3_5==0){delay(20);while(P3_5==0);delay(20);KeyNumber=9;}
if(P3_4==0){delay(20);while(P3_4==0);delay(20);KeyNumber=13;}
P3=0xFf;
P3_2=0;
if(P3_7==0){delay(20);while(P3_7==0);delay(20);KeyNumber=2;}
if(P3_6==0){delay(20);while(P3_6==0);delay(20);KeyNumber=6;}
if(P3_5==0){delay(20);while(P3_5==0);delay(20);KeyNumber=10;}
if(P3_4==0){delay(20);while(P3_4==0);delay(20);KeyNumber=14;}
P3=0xFf;
P3_1=0;
if(P3_7==0){delay(20);while(P3_7==0);delay(20);KeyNumber=3;}
if(P3_6==0){delay(20);while(P3_6==0);delay(20);KeyNumber=7;}
if(P3_5==0){delay(20);while(P3_5==0);delay(20);KeyNumber=11;}
if(P3_4==0){delay(20);while(P3_4==0);delay(20);KeyNumber=15;}
P3=0xFf;
P3_0=0;
if(P3_7==0){delay(20);while(P3_7==0);delay(20);KeyNumber=4;}
if(P3_6==0){delay(20);while(P3_6==0);delay(20);KeyNumber=8;}
if(P3_5==0){delay(20);while(P3_5==0);delay(20);KeyNumber=12;}
if(P3_4==0){delay(20);while(P3_4==0);delay(20);KeyNumber=16;}
return KeyNumber;
}
void shuzi(int x,y)
{
dula=1;
P0=duanxuan[y];
dula=0;
P0=0xff;
wela=1;
P0=weixuan[x];
wela=1;
delay(1);
}
void init(){
TMOD=0X01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
TR0=1;
TR1=1;
EA=1;
ET0=1;
ET1=1;}
void main()
{
init();
//anjian=KeyNumber;
numnian=2023;
numyue=10;
numri=27;
numshi=15;
numfen=30;
nummiao=00;
while(1)
{ key=MatrixKey();
//nummiao++;
if(nummiao>=60)
{
nummiao=0;
numfen++;
}
if(numfen>=60)
{
numfen=0;
numshi++;
}
if(numshi>=24)
{
numshi=0;
numri++;
}
if(numri>=31)
{
numri=0;
numyue++;
}
if(numyue>=13)
{
numyue=0;
numnian++;
}
nu=nummiao%10;
nu1=nummiao/10;
nu2=numfen%10;
nu3=numfen/10;
nu4=numshi%10;
nu5=numshi/10;
nu6=numri%10;
nu7=numri/10;
nu8=numyue%10;
nu9=numyue/10;
nu10=numnian%10;
nu11=numnian%100/10;
nu12=numnian%1000/100;
nu13=numnian/1000;
// anjian=KeyNumber;
// if(P3_1==0)
// {
// delay(15);
// if(P3_1==0){
// huan=~huan;
// while(P3_1==0);}
// }
//
if(key==5)//key==5huan==0
{
shuzi(7,nu6);
shuzi(6,nu7);
shuzi(5,nu8);
shuzi(4,nu9);
shuzi(3,nu10);
shuzi(2,nu11);
shuzi(1,nu12);
shuzi(0,nu13);
}
if(key==6)//key==6huan==1
{
shuzi(7,nu);
shuzi(6,nu1);
shuzi(4,nu2);
shuzi(3,nu3);
shuzi(1,nu4);
shuzi(0,nu5);
}
if(key==10)
{
if(a==0)
{
shuzi(7,nu6);
shuzi(6,nu7);
shuzi(5,nu8);
shuzi(4,nu9);
shuzi(3,nu10);
shuzi(2,nu11);
shuzi(1,nu12);
shuzi(0,nu13);
}
if(a==1)
{
shuzi(7,nu);
shuzi(6,nu1);
shuzi(4,nu2);
shuzi(3,nu3);
shuzi(1,nu4);
shuzi(0,nu5);
}
}
if(P3_2==0)
{
delay(15);
if(P3_2==0){
ting=~ting;
while(P3_2==0);}
}} }
void t0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
if(ting==0)
{
T0count++;
nummiao++;
if(T0count>=20)
{
T0count=0;
}
}}
void t1() interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
T1count++;
if(T1count>=200)
{
T1count=0;
a=a+1;
if(a>=2)
a=0;
}
}