uchar code disp1[]=\" 2012-12-30\"; uchar code disp2[]=\" 00:00:00\";
uchar aa,shi,fen,miao,ri=1,yue=1,nian=12,KNUM; void delay(uint); void write_com(uchar); void write_data(uchar); void write_str(uchar,uchar *str); void init();
void sfmdisplay(uchar,uchar); void keyscan(); void shanping();
void main() { init(); write_str(0x80,disp1);
write_str(0x80+0x40,disp2); while(1) {
keyscan();//键盘扫描 if(aa==20) {
aa=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=0; yue++; }
if((yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)&&ri==32)
{ }
}
ri=0;
yue++;
if(yue==13) { }
yue=0; nian++;
}
if((yue==4||yue==6||yue==9||yue==11)&&ri==31) {
ri=0; yue++; if(yue==13) { yue=0; nian++; }
sfmdisplay(0x05,nian);
sfmdisplay(0x08,yue); }
sfmdisplay(0x0b,ri);
}
sfmdisplay(0x40+0x03,shi);
}
sfmdisplay(0x40+0x06,fen);
}
sfmdisplay(0x40+0x09,miao);
void timer0() interrupt 1
TH0=(65535-50000)/256; TL0=(65535-50000)%256; aa++;
}
void delay(uint z) { uint x,y; for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)//写控制字 {
lcd_rs=0; lcd_en=0; delay(1); lcd_en=1;
lcd_com=com; delay(1); lcd_en=0;
}
void write_data(uchar lcddata)//显示字符 {
lcd_rs=1; lcd_en=0; delay(1); lcd_en=1;
lcd_data=lcddata; delay(1);
lcd_en=0; }
void write_str(uchar addr,uchar *str)//显示字符串 { }
void init() { write_com(0x38); //设置显示模式 write_com(0x08); //关闭显示屏
write_com(0x01); //清楚显示屏
write_com(0x0c); //开启显示屏(无光标)
write_com(0x06); //读写字符时指针自动加1(整屏不移动) write_com(addr); do {
write_data(*str); str++;
}
while(*str!='\\0');
}
TMOD=0x01;
TH0=(65535-50000)/256; TL0=(65535-50000)%256; EA=1; ET0=1; TR0=1;
void sfmdisplay(uchar addr,uchar date) {
write_com(0x80+addr); write_data(date/10+0x30); write_data(date%10+0x30);
}
void keyscan() {
if(KEY==0) {
delay(5); if(KEY==0) {
while(!KEY) ;
KNUM++; switch(KNUM) {
case 1: TR0=0;
write_com(0x80+0X40+0x0a); write_com(0x0f); break;
case 2: write_com(0x80+0x40+0x07); break; case 3:
write_com(0x80+0x40+0x04); break;
write_com(0x80+0x0b); break;
write_com(0x80+0x08);
case 4:
case 5:
break; case 6: write_com(0x80+0x05);
} {
}
}
break;
case 7: write_com(0x0c); TR0=1; KNUM=0;
break;
if(KNUM==1)
if(KUP==0) {
delay(5); if(KUP==0) {
while(!KUP); miao++;
if(miao==60) miao=0; sfmdisplay(0x40+0x09,miao); write_com(0x80+0X40+0x0a);
write_com(0x0f); } }
if(KDOWN==0) { }
delay(5);
if(KDOWN==0) { while(!KDOWN); }
miao--;
if(miao==-1) miao=59; sfmdisplay(0x40+0x09,miao); write_com(0x80+0X40+0x0a); write_com(0x0f);
}
if(KNUM==2) {
if(KUP==0) {
delay(5); if(KUP==0)
} {
{ }
while(!KUP); fen++;
if(fen==60) fen=0;
sfmdisplay(0x40+0x06,fen); write_com(0x80+0X40+0x07); write_com(0x0f);
if(KDOWN==0)
delay(5); if(KDOWN==0) { }
while(!KDOWN); fen--;
if(fen==-1) fen=59;
sfmdisplay(0x40+0x06,fen); write_com(0x80+0X40+0x07); write_com(0x0f);
} }
if(KNUM==3) {
if(KUP==0) {
delay(5); if(KUP==0) { }
while(!KUP); shi++;
if(shi==24) shi=0;
sfmdisplay(0x40+0x03,shi); write_com(0x80+0X40+0x04); write_com(0x0f);
}
if(KDOWN==0) {
delay(5);
if(KDOWN==0) { while(!KDOWN);
shi--;
}
}
if(shi==-1) shi=23;
sfmdisplay(0x40+0x03,shi); write_com(0x80+0X40+0x04); write_com(0x0f);
}
if(KNUM==4) {
if(KUP==0) {
delay(5); if(KUP==0) {
while(!KUP);
ri++; if(yue==2&&ri==29) ri=1;
if((yue==1||yue==3||yue==5||yue==5||yue==8||yue==10||yue==12)&&ri==32)
}
}
ri=1;
if((yue==4||yue==6||yue==9||yue==11)&&ri==31)
ri=1; sfmdisplay(0x0a,ri); write_com(0x80+0x0b); write_com(0x0f);
if(KDOWN==0)
{ delay(5);
if(KDOWN==0) {
while(!KDOWN); ri--;
if(yue==2&&ri==0) ri=28;
if((yue==1||yue==3||yue==5||yue==5||yue==8||yue==10||yue==12)&&ri==00)
ri=31;
if((yue==2||yue==4||yue==6||yue==9||yue==11)&&ri==00) ri=30;
}
}
sfmdisplay(0x0a,ri); write_com(0x80+0x0b); write_com(0x0f);
}
if(KNUM==5) { if(KUP==0) { }
}
delay(5); if(KUP==0) { }
while(!KUP); yue++;
if(yue==13) yue=1; sfmdisplay(0x07,yue); write_com(0x80+0x08); write_com(0x0f);
if(KDOWN==0)
{ delay(5); }
if(KDOWN==0) { }
while(!KDOWN); yue--;
if(yue==0) yue=12; sfmdisplay(0x07,yue); write_com(0x80+0x08); write_com(0x0f);
if(KNUM==6)
{
if(KUP==0) { }
delay(5); if(KUP==0) { }
while(!KUP); nian++;
sfmdisplay(0x04,nian); write_com(0x80+0x05); write_com(0x0f);
}
}
if(KDOWN==0) { }
delay(5);
if(KDOWN==0) { }
while(!KDOWN); nian--;
sfmdisplay(0x04,nian); write_com(0x80+0x05); write_com(0x0f);
因篇幅问题不能全部显示,请点此查看更多更全内容