星期的显示无法实现。望高人指导!!!
#include<reg52.h>
#include<string.h>
#include "yejing.h"
#define uchar unsigned char
#define uint unsigned int
sbit s1=P1^4;
sbit s2=P1^5;
sbit s3=P1^6;
sbit s4=P1^7;
uchar code table0[]=" 2013-12-30";
uchar code table1[]=" 23:59:53";
uchar table2[3];
uchar t0,s1num,xingqi;
char shi,fen,miao,nian,yue,ri;
void init()
{
uchar num;
s1num=0;
miao=0x35;
fen=0x3b;
shi=0x17;
nian=13;
yue=12;
ri=30;
initlcd();
writecom(0x80+2);
for(num=0;num<11;num++)
{
writedate(table0[num]);
delay(5);
}
writecom(0x80+0x40);
for(num=0;num<12;num++)
{
writedate(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void writesfm(uchar add,uchar date)
{
uchar sh,ge;
writecom(add+0x80+0x40);
sh=date/10;
ge=date%10;
writedate(0x30+sh);
writedate(0x30+ge);
}
void writenyr(uchar add,uchar date)
{
uchar sh,ge;
writecom(add+0x80);
sh=date/10;
ge=date%10;
writedate(0x30+sh);
writedate(0x30+ge);
}
void writexq(uchar xq)
{
uchar num;
//xq++;
if(xq==8)
{
xq=1;
}
writecom(0x80+12);
switch(xq)
{
case 1:writedate('M');delay(5);break;
case 2:writedate('T');delay(5);break;
case 3:writedate('W');delay(5);break;
case 4:writedate('H');delay(5);break;
case 5:writedate('F');delay(5);break;
case 6:writedate('S');delay(5);break;
case 7:writedate('U');delay(5);break;
}
writecom(12+0x80);
for(num=0;num<3;num++)
{
writedate(table2[num]);
delay(5);
}
}
void keyscan() //最重要的一个函数;;?
{
if(s1==0) //判断功能键;?
{
delay(5);
if(s1==0)
{ s1num++;
while(!s1);
if(s1num==1)
{
TR0=0;
writecom(0x80+0x40+11);
writecom(0x0f);
}
} //设置好光标后直接关闭判断语句;;?
if(s1num==2)
{
writecom(0x80+0x40+8);
}
if(s1num==3)
{
writecom(0x80+0x40+5);
}
if(s1num==4)
{
writecom(0x80+12);
}
if(s1num==5)
{
writecom(0x80+9);
}
if(s1num==6)
{
writecom(0x80+6);
}
if(s1num==7)
{
s1num=0;
writecom(0x0c);
TR0=1;
}
}
if(s1num!=0)
{
if(s2==0)
{
delay(5);
if(s2==0)
{
while(!s2);
if(s1num==1)
{
miao++;
if(miao==60)
miao=0;
writesfm(10,miao);
writecom(0x80+0x40+11);
}
if(s1num==2)
{
fen++;
if(fen==60)
fen=0;
writesfm(7,fen);
writecom(0x80+0x40+8);
}
if(s1num==3)
{
shi++;
if(shi==24)
shi=0;
writesfm(4,shi);
writecom(0x80+0x40+5);
}
if(s1num==4)
{
ri++;
if(ri==32)
ri=1;
writenyr(11,ri);
writecom(0x80+12);
}
if(s1num==5)
{
yue++;
if(yue==13)
yue=1;
writenyr(8,yue);
writecom(0x80+9);
}
if(s1num==6)
{
nian++;
writenyr(5,nian);
writecom(0x80+6);
}
}
}
if(s3==0)
{
delay(5);
if(s3==0)
{
while(!s3);
if(s1num==1)
{
miao--;
if(miao==-1)
miao=59;
writesfm(10,miao);
writecom(0x80+0x40+11);
}
if(s1num==2)
{
fen--;
if(fen==-1)
fen=59;
writesfm(7,fen);
writecom(0x80+0x40+8);
}
if(s1num==3)
{
shi--;
if(shi==-1)
shi=23;
writesfm(4,shi);
writecom(0x80+0x40+5);
}
if(s1num==4)
{
ri--;
if(ri==0)
ri=31;
writenyr(11,ri);
writecom(0x80+12);
}
if(s1num==5)
{
yue--;
if(yue==0)
yue=12;
writenyr(8,yue);
writecom(0x80+9);
}
if(s1num==6)
{
nian--;
writenyr(5,nian);
writecom(0x80+6);
}
}
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(t0==20)
{
t0=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
ri++;
writexq(++xingqi);
//writecom(0x80+12);
//xingqi++;
if(ri==32)
{
ri=1;
yue++;
if(yue==13)
{
yue=1;
nian++;
writenyr(5,nian);
}
writenyr(8,yue);
}
writenyr(11,ri);
// delay(5);
}
writesfm(4,shi);
}
writesfm(7,fen);
}
writesfm(10,miao);
}
}
void main()
{
init();
while(1)
{
keyscan();
}
}
//以下为"yejing.h"
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit bu=P0^7;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
/*bit bt()
{
bit res;
rs=0;
rw=1;
en=1;
res=bu;
delay(5);
//en=1;
//delay(5);
en=0;
return res;
}*/
void writecom(uchar com)
{
//while(bt()==1);
rs=0;
rw=0;
en=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void writedate(uchar date)
{
//while(bt()==1);
rs=1;
rw=0;
en=0;
P0=date;
delay(5);
en=1;
delay(5);
en=0;
}
void initlcd()
{
rw=0;
rs=0;
en=0;
delay(5);
writecom(0x38);
delay(2);
writecom(0x38);
delay(2);
writecom(0x0c);
delay(2);
writecom(0x06);
delay(2);
writecom(0x01);
delay(2);
}
|