电路图:
代码:
#include
#include
#include
#include
#define uint unsigned int
#define uchar unsigned char
uint num,A_num,x=0;
uint h,m,s,year=2012,month=1,day=22,lcd_x=0,lcd_y=0;
uchar code Zifu[]="0123456789";
sbit beep = P2^3;
sbit LCD_EN = P3^4;
sbit LCD_RS = P3^5;
sbit duan = P2^6;
sbit wei = P2^7;
sbit key_A = P3^6;
sbit key_B = P3^7;
void delay_1ms(uchar x){
uchar i,j;
for(j=0;j for(i=0;i<110;i++); } void write_command(uchar command){ LCD_RS = 0; LCD_EN = 0; P0 = command; delay_1ms(2); LCD_EN = 1; //EN 由1 -- 0 完成 有效数据 的 锁存 delay_1ms(2); LCD_EN = 0; } void write_data(uchar fuck){ LCD_RS = 1; LCD_EN = 0; P0 = fuck; delay_1ms(2); LCD_EN = 1; delay_1ms(2); LCD_EN = 0; } void lcd_post(int X,int Y){ //0,1表征 第一行 和 第二行 write_command(0x80+X*(0x40)+Y); } void init(){ h=m=s=0; num=A_num=0; LCD_EN=0; write_command(0x38); write_command(0x0c); //write_command(0x06); //写字符后地址指针加一 write_command(0x01); TMOD = 0x02; TH0 = 6; TL0 = 6; EA = 1; ET0 = 1; TR0 = 1; /*时分秒*/ lcd_post(0,0); write_data(Zifu[h/10]); lcd_post(0,1); write_data(Zifu[h%10]); lcd_post(0,2); write_data(':'); lcd_post(0,3); write_data(Zifu[m/10]); lcd_post(0,4); write_data(Zifu[m%10]); lcd_post(0,5); write_data(':'); lcd_post(0,6); write_data(Zifu[s/10]); lcd_post(0,7); write_data(Zifu[s%10]); /*年月日*/ lcd_post(1,6); write_data(Zifu[year/1000]); lcd_post(1,7); write_data(Zifu[(year%1000)/100]); lcd_post(1,8); write_data(Zifu[(year%100)/10]); lcd_post(1,9); write_data(Zifu[year%10]); lcd_post(1,10); write_data('-'); lcd_post(1,11); write_data(Zifu[month/10]); lcd_post(1,12); write_data(Zifu[month%10]); lcd_post(1,13); write_data('-'); lcd_post(1,14); write_data(Zifu[day/10]); lcd_post(1,15); write_data(Zifu[day%10]); } void di(){ beep=0; delay_1ms(100); beep=1; } void keyscan(){ if(key_A==0){ delay_1ms(3); if(key_A==0){ A_num++; di(); switch(A_num){ case 1: //时 TR0=0; lcd_post(0,1); write_command(0x0f); break; case 2:lcd_post(0,4);break; //分 case 3:lcd_post(0,7);break; //秒 case 4:lcd_post(1,6);break; //年 case 5:lcd_post(1,7);break; case 6:lcd_post(1,8);break; case 7:lcd_post(1,9);break; case 8:lcd_post(1,12);break; //月 case 9:lcd_post(1,15);break; //日 case 10: A_num=0; write_command(0x0c); TR0=1; break; } } while(!key_A); } if(A_num!=0){ if(key_B==0){ delay_1ms(3); if(key_B==0){ di(); switch(A_num){ case 1: h=(++h)%24; lcd_post(0,0); write_data(Zifu[h/10]); lcd_post(0,1); write_data(Zifu[h%10]); break; //时 case 2: m=(++m)%60; lcd_post(0,3); write_data(Zifu[m/10]); lcd_post(0,4); write_data(Zifu[m%10]); break; //分 case 3: s=(++s)%60; lcd_post(0,6); write_data(Zifu[s/10]); lcd_post(0,7); write_data(Zifu[s%10]); break; //秒 case 4: //年 lcd_post(1,6); write_data(Zifu[(++x)%10]); break; case 5: lcd_post(1,7); write_data(Zifu[(++x)%10]); break; case 6: lcd_post(1,8); write_data(Zifu[(++x)%10]); break; case 7: lcd_post(1,9); write_data(Zifu[(++x)%10]); break; case 8: month=(++month)%13; lcd_post(1,11); write_data(Zifu[month/10]); lcd_post(1,12); write_data(Zifu[month%10]); break; //月 case 9: day=(++day)%32; lcd_post(1,14); write_data(Zifu[day/10]); lcd_post(1,15); write_data(Zifu[day%10]); break; //日 case 10:break; }write_command(0x10); } while(!key_B); } } } void main() { init(); while(1){ if(num==3686){ num=0; s++; if(s==60){ s=0; m++; if(m==60){ m=0; h++; if(h==24)h=0; lcd_post(0,0); write_data(Zifu[h/10]); lcd_post(0,1); write_data(Zifu[h%10]); } lcd_post(0,3); write_data(Zifu[m/10]); lcd_post(0,4); write_data(Zifu[m%10]); } lcd_post(0,6); write_data(Zifu[s/10]); lcd_post(0,7); write_data(Zifu[s%10]); } keyscan(); } } void T0_time() interrupt 1 { num++; }
上一篇:51单片机第六弹---LCD液晶显示模块
下一篇:51单片机配合超声波测距以及用1602液晶进行显示
推荐阅读最新更新时间:2024-03-16 16:06
- 热门资源推荐
- 热门放大器推荐
设计资源 培训 开发板 精华推荐
- 深扒TI教室2.0,那些你不能错过的精彩
- 下载有礼|是德科技电子书 《通过了解测试精度的基础知识, 提高良率并降低风险》,不做“差不多先生”
- 评论赢好礼|TI SK-AM64评估套件测评
- 看咱坛友自己的研讨会~ST-EEWORLD线下网友见面会实录
- EEW网友专题之“我爱龙芯”
- 了解ADI电网管理、能源计量方案,答题赢Kindle、《新概念模拟电路》【世健的ADI之路主题游 能源站】
- 深入剖析恩智浦LPC1000处理器
- ST AMG SensorTile开发大赛驾到,重磅大奖与知识兼得,速来~
- 助推电动时代,与英飞凌一起探索电动汽车三大产品技术
- 有奖直播:安森美电感式位置传感器接口 NCS32100