资源描述:
《单片机液晶时钟显示模块的C程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintucharcodetabledu[]={'0','1','2','3','4','5','6','7','8','9'};ucharcodetablewe[]={20,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};ucharcode*tableweek[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};sbitrs=P1^0;sbitrw=P1^1;sbitlcden=P1^
2、2;sbitkeybe=P3^2;sbitkeysw=P3^3;sbitkeyin=P0^0;sbitring=P3^4;sbitL1=P0^4;voidsecond(uchar,uchar);voidminute(uchar,uchar);voidhour(uchar,uchar);voidday(uchar,uchar);voidmonth(uchar,uchar);voidyear(uchar,uchar,uchar,uchar);voidweek(uchar);voiddelay(uchar);voiddelay1(uchar);uintdissec,dismi
3、n,dishou,disweek,disday,dismon,disyear;ucharcount,a,num1=0,num2=0,sec1=0,sec2=0,min1=0,min2=0,hou1=0,hou2=0,week1=0,day1=0,day2=0,mon1=0,mon2=0,year1=0,year2=0,year3=0,year4=0;voidwrite_com(ucharcom)//液晶控制{rs=0;P2=com;delay(1);lcden=1;delay(1);lcden=0;}voidwrite_date(uchardate)//数据控制{rs=
4、1;P2=date;delay1(1);lcden=1;delay1(1);lcden=0;}voidinit()//初始化{lcden=0;rw=0;write_com(0x38);//显示模式的设置delay(2);write_com(0x0c);//开显示delay(2);write_com(0x06);//读或者写入数据光标自动加1delay(2);write_com(0x01);//清0,复位可重新开始delay(2);}voidstring()//日期分隔符号{write_com(0x84);delay(1);write_date('-');delay(1)
5、;write_com(0x87);delay(1);write_date('-');delay(1);write_com(0xc7);delay(1);write_date(':');delay(1);write_com(0xca);delay(1);write_date(':');delay(1);}voidmain()//主函数{while(1){init();second(sec2,sec1);minute(min2,min1);hour(hou2,hou1);week(week1);day(day2,day1);month(mon2,mon1);year(yea
6、r4,year3,year2,year1);L1=0;if(0==keysw)//按S18键可进行位调换{delay(1);if(0==keysw){num2++;if(num2==16)num2=1;}}while(!keysw);if(0==keyin)//按S1可进行数值增加{delay(1);if(0==keyin){switch(tablewe[num2]){case1:sec1++;if(10==sec1)sec1=0;break;case2:sec2++;if(6==sec2)sec2=0;break;case3:min1++;if(10==min1)mi
7、n1=0;break;case4:min2++;if(6==min2)min2=0;break;case5:hou1++;if(4==hou1)hou1=0;break;case6:hou2++;if(3==hou2)hou2=0;break;case7:week1++;if(8==week1)week1=0;break;case8:day1++;if(10==day1)day1=0;break;case9:day2++;if(4==day2)day2=0;break;case10:mon1++;if(10==mon1)mon1=0;br