1、 /写数据寄存器DR函数声明void lcd_clr(); / 清屏函数声明void lcd_init(); / LCD初始化函数声明void key_mode();void year_moon_day();uchar dis_buf19;uchar dis=0,123456789;uchar code name1=help yourself!uchar code name2=hold on!uchar year_month_day38= 0x04,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0,/年 0x0f,0x09,0x0f,0x09,0x0f,0x09,0x13,0x0
2、0,/月 0x0e,0x0a,0x0a,0x0e,0x0a,0x0a,0x0e,0x02 /日uchar dingshi=0;/50ms计数uchar flag=0;/按键控制变量char miao=55,fen=59,shi=23;char moon=12,day=31;int year=2012;uchar leap;uchar shan;/控制时分的闪烁位uchar key_value;/*LCD显示部分*/读忙bit lcd_busy() bit result; LCD_RS=0; LCD_RW=1; LCD_EN=1; _nop_(); result=(bit)(P2&0x80);
3、LCD_EN=0; return result;/清屏void lcd_clr() lcd_wcmd(0x01); delay_ms(5);/写指令void lcd_wcmd(uchar cmd) while(lcd_busy();/ delay_ms(2); LCD_RW=0; P2=cmd;/写数据void lcd_wdat(uchar dat) LCD_RS=1; P2=dat;/显示初始化void lcd_init()/ delay_ms(15); lcd_wcmd(0x38); /显示模式为16*2 5*7点阵 8位数据 /清屏 lcd_wcmd(0x06); /移动光标 lcd_w
4、cmd(0x0c); /开光标void delay_ms(uint xms) uchar i,j; for(i=xms;i0;i-) for(j=110;jj-);void lcd_conv(uchar shi,fen,miao) dis_buf0=disshi/10; dis_buf1=disshi%10; dis_buf2=0x3a; dis_buf3=disfen/10; dis_buf4=disfen%10; dis_buf5=0x3a; dis_buf6=dismiao/10; dis_buf7=dismiao%10;void lcd_conv_year(uint year,ucha
5、r moon,day) dis_buf8=disyear/1000; dis_buf9=dis(year%1000)/100; dis_buf10=dis(year%100)/10; dis_buf11=disyear%10; dis_buf12=1; dis_buf13=dismoon/10; dis_buf14=dismoon%10; dis_buf15=2; dis_buf16=disday/10; dis_buf17=disday%10; dis_buf18=3;void lcd_dis() uchar i; lcd_conv(shi,fen,miao); lcd_conv_year(
6、year,moon,day); lcd_wcmd(0x00|0x80); for(i=8;i19;i+) lcd_wdat(dis_bufi); lcd_wcmd(0x40|0x80); for(i=0;8;/自定义字符图形void lcd_wCGROM() /将汉字写入CGROM for(i=1;4; for(j=0;j5) flag=0; lcd_wcmd(0x0c); /关光标 TR0=1; if(key3=0) key_value=2; if(key4=0) key_value=3; while(key2=0|key3=0|key4=0); void keyprocess() swit
7、ch(flag) case 1: if(key_value=2) shi+;if(shi23)shi=0;lcd_dis();lcd_wcmd(0xc0+1);delay_ms(1); if(key_value=3) shi-;if(shi59)fen=0;lcd_wcmd(0xc0+4); fen-;if(fen9999)year=2000;lcd_wcmd(0x80+3); year-;if(year12)moon=1;lcd_wcmd(0x80+6); moon-;if(moon29)day=1;(year-2000)%4!=0)&28)day=1; if(moon=1|moon=3|m
8、oon=5|moon=7|moon=8|moon=10|moon=12)&31) day=1; if(moon=4|moon=6|moon=9|moon=11)&30) lcd_dis();lcd_wcmd(0x80+9); day-;day20) miao+; dingshi=0; if(miao59) miao=0; fen+; if(fen fen=0; shi+; if(shi23) shi=0; year_moon_day();/年月日void year_moon_day() day+; if(year-2000)%4=0) leap=1; else leap=0; if(day28
9、) switch(moon)if(day31)day=1;break;if(leap=1) if(day29) day=1; moon+; else break;moon+;30)day=1; case 6: case 7: case 8: case 9: case 10: case 11: case 12: if(moon12) moon=1; year+; if(year9999) year=2000;void display() /开机个性化显示 i=0; while(i14) lcd_wdat(name1i); i+;8) lcd_wdat(name2i);void main() int i,j; lcd_init(); lcd_clr(); display();5; for(j=0;1000; delay_ms(2); zoushi_inint(); lcd_wCGROM(); while(1) lcd_dis(); delay_ms(5); keyscan(); if(flag!=0) while(1) keyprocess(); keyscan(); if(TR0=1) break;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1