#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^7;
sbit lcden=P3^6;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
uchar count,s1num;
char miao,fen,shi,ri=1,yue=1,nian=15;
uchar code table2[]="(^-^)Made by Ke ";
uchar code table[]=" Welcome to use ";
uchar code table0[]=" 2015-01-01 KE";
uchar code table1[]=" 00:00:00";
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void write_com(uchar com)
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80+0x10);
for(num=0;num<16;num++)
{
write_date(table[num]);
delay(5);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(200);
}
write_com(0x01);
write_com(0x80+0x40+0x10);
for(num=0;num<16;num++)
{
write_date(table2[num]);
delay(5);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(200);
}
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table0[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_sfm0(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void keyscan()
{
if(s1==0)
{
delay(5);
if(s1==0)
{
T0=0;
s1num++;
while(!s1);
if(s1num==1)
{
write_com(0x80+0x40+10);
write_com(0x0f);
}
if(s1num==2)
{
write_com(0x80+0x40+7);
}
if(s1num==3)
{
write_com(0x80+0x40+4);
}
if(s1num==4)
{
write_com(0x80+10);
}
if(s1num==5)
{
write_com(0x80+7);
}
if(s1num==6)
{
write_com(0x80+4);
}
if(s1num==7)
{
s1num=0;
T0=1;
write_com(0x0c);
}
}
}
if(s1num!=0)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
if(s1num==1)
{
miao++;
if(miao>=60)
miao=0;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}
if(s1num==2)
{
fen++;
if(fen>=60)
fen=0;
write_sfm(7,fen);
write_com(0x80+0x40+7);
}
if(s1num==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(4,shi);
write_com(0x80+0x40+4);
}
if(s1num==4)
{
ri++;
if(yue==2&&ri==29)
ri=1;
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
ri=1;
if(ri==32)
ri=1;
write_sfm0(10,ri);
write_com(0x80+10);
}
if(s1num==5)
{
yue++;
if(yue==13)
yue=1;
write_sfm0(7,yue);
write_com(0x80+7);
}
if(s1num==6)
{
nian++;
if(nian==99)
nian=15;
write_sfm0(4,nian);
write_com(0x80+4);
}
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
if(s1num==1)
{
miao--;
if(miao==-1)
miao=59;
write_sfm(10,miao);
write_com(0x80+0x40+10);
}
if(s1num==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(7,fen);
write_com(0x80+0x40+7);
}
if(s1num==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(4,shi);
write_com(0x80+0x40+4);
}
if(s1num==4)
{
ri--;
if(yue==2&&ri==0)
ri=28;
if((yue==4||yue==6||yue==9||yue==11)&&ri==0)
ri=30;
if(ri==0)
ri=31;
write_sfm0(10,ri);
write_com(0x80+10);
}
if(s1num==5)
{
yue--;
if(yue==0)
yue=12;
write_sfm0(7,yue);
write_com(0x80+7);
}
if(s1num==6)
{
nian--;
if(nian==14)
nian=99;
write_sfm0(4,nian);
write_com(0x80+4);
}
}
}
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==18)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
ri++;
if(yue==2&&ri==29)
{
ri=1;
yue++;
if(yue==13)
{
yue=1;
nian++;
if(nian==100)
{
nian=15;
}
write_sfm0(4,nian);
}
write_sfm0(7,yue);
}
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
{
ri=1;
yue++;
if(yue==13)
{
yue=1;
nian++;
if(nian==100)
{
nian=15;
}
write_sfm0(4,nian);
}
write_sfm0(7,yue);
}
if(ri==32)
{
ri=1;
yue++;
if(yue==13)
{
yue=1;
nian++;
if(nian==100)
{
nian=15;
}
write_sfm0(4,nian);
}
write_sfm0(7,yue);
}
write_sfm0(10,ri);
}
write_sfm(4,shi);
}
write_sfm(7,fen);
}
write_sfm(10,miao);
}
}
|