|
程序如下:#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs = P2^6; //LCD的数据/命令选择端
sbit rw = P2^5; //LCD的读写选择端
sbit e = P2^7; //LCD的使能信号端
sbit s1 = P3^0;
sbit s2 = P3^1;
sbit s3 = P3^2;
sbit s4 = P3^3;
uchar count,s1num,s4num;
char i,miao,shi,fen;
uchar nian,yue,ri,xq,xqs;
uchar code table[] = " 2018-00-00 xxx";
uchar code table1[] = " 00:00:00 ";
uchar code week1[] = "Sun";
uchar code week2[] = "Mon";
uchar code week3[] = "Tue";
uchar code week4[] = "Wed";
uchar code week5[] = "Thu";
uchar code week6[] = "Fri";
uchar code week7[] = "Sat";
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com) //写命令
{
rs = 0;
rw = 0;
P0 = com;
delay(5);
e = 1;
delay(5);
e = 0;
}
void write_data(uchar date) //写数据
{
rs = 1;
rw = 0;
P0 = date;
delay(5);
e = 1;
delay(5);
e = 0;
}
void int_all()
{
uchar num;
// miao = 58;
// fen = 59;
// shi = 23;
nian = 18;
// yue = 12;
// ri = 31;
write_com(0x38);
delay(5);
write_com(0x0c);
delay(5);
write_com(0x06);
delay(5);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_data(table[num]);
delay(20);
}
write_com(0x80+0x40);
for(num=0;num<13;num++)
{
write_data(table1[num]);
delay(20);
}
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_data(0x30+shi);
write_data(0x30+ge);
}
void write_ry(uchar add,uchar date)
{
uchar ge,shi;
shi = date/10;
ge = date%10;
write_com(0x80+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void write_ryn(uchar add,uchar date)
{
uchar ge,shi,bai,qian;
//qian =0;
//bai =0;
shi =date/10;
ge =date%10;
write_com(0x80+add);
//write_data(0x30+qian);
//write_data(0x30+bai);
write_data(0x30+shi);
write_data(0x30+ge);
}
void write_xq(uchar add,uchar date)
{
switch(xq)
{
case(1):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week1[i]);
}
break;
case(2):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week2[i]);
}
break;
case(3):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week3[i]);
}
break;
case(4):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week4[i]);
}
break;
case(5):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week5[i]);
}
break;
case(6):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week6[i]);
}
break;
case(7):
for(i=0;i<3;i++)
{
write_com(0x80+13+i);
write_data(week7[i]);
}
break;
}
}
void keyscan()
{
if(s1==0 && s4num==0)
{
delay(5);
if(s1==0)
{
s1num++;
while(!s1);
if(s1num==1)
{
TR0 = 0;
write_com(0x0f);
write_com(0x80+0x40+10);
}
if(s1num==2)
{
write_com(0x80+0x40+7);
}
if(s1num==3)
{
write_com(0x80+0x40+4);
}
if(s1num==4)
{
s1num = 0;
write_com(0x0c);
TR0=1;
}
}
}
if(s1num!=0 && s4num==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(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(s4==0 && s1num==0)
{
delay(5);
if(s4==0)
{
s4num++;
while(!s4);
if(s4num==1)
{
TR0 = 0;
write_com(0x80+10);
write_com(0x0f);
}
if(s4num==2)
{
write_com(0x80+7);
}
if(s4num==3)
{
write_com(0x80+4);
}
if(s4num==4)
{
write_com(0x80+13);
}
if(s4num==5)
{
s4num = 0;
write_com(0x0c);
TR0=1;
}
}
}
if(s4num!=0 && s1num==0)
{
if(s2==0)
{
if(s2==0)
{
delay(5);
while(!s2);
if(s4num==1)
{
ri++;
if(ri==32)
ri = 1;
write_ry(10,ri);
write_com(0x80+10);
}
if(s4num==2)
{
yue++;
if(yue==13)
yue = 1;
write_ry(7,yue);
write_com(0x80+7);
}
if(s4num==3)
{
nian++;
write_ryn(4,nian);
write_com(0x80+4);
}
if(s4num==4)
{
xq++;
if(xq==8)
xq = 1;
write_xq(13,xq);
write_com(0x80+13);
}
}
}
if(s3==0)
{
if(s3==0)
{
delay(5);
while(!s3);
if(s4num==1)
{
if(ri==0)
ri = 31;
ri--;
write_ry(10,ri);
write_com(0x80+10);
}
if(s4num==2)
{
if(yue==0)
yue = 12;
yue--;
write_ry(7,yue);
write_com(0x80+7);
}
if(s4num==3)
{
if(nian==0)
nian = 1;
nian--;
write_ryn(4,nian);
write_com(0x80+4);
}
if(s4num==4)
{
if(xq==0)
xq = 7;
xq--;
write_xq(13,xq);
write_com(0x80+13);
}
}
}
}
}
void main()
{
int_all();
while(1)
{
keyscan();
if(miao==60)
{
miao = 0;
fen++;
if(fen==60)
{
fen = 0;
shi++;
if(shi==24)
{
shi = 0;
ri++;
xq++;
if(xq==8)
{
xq = 1;
}
write_xq(15,xq);
if(ri==32)
{
ri = 1;
yue++;
if(yue==13)
{
yue = 1;
nian++;
write_ryn(4,nian);
}
write_ry(7,yue);
}
write_ry(10,ri);
}
write_sfm(4,shi);
}
write_sfm(7,fen);
}
write_sfm(10,miao);
}
}
void timer0() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
count++;
if(count==20)
{
count = 0;
miao++;
}
}
|
评分
-
查看全部评分
|