资源描述:
《基于51单片机的年历程序,12864液晶显示》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintsbitLCD_RS=P3^5;sbitLCD_RW=P3^6;sbitLCD_EN=P3^4;sbitLCD_PSB=P2^4;sbits1=P3^0;//独立按键sbits2=P3^1;sbits3=P3^2;sbitrd=P3^7;sbitbeep=P2^3;//定义蜂鸣器端口ucharmiao,shi,fen,mon,day,week,year1,year2,i,s1num,count;uinta,b,year;uc
2、harcodedis2[]={"星期"};ucharcodedis3[]={"北华大学"};voiddelay_1ms(uintz){uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voiddi()//蜂鸣器{beep=0;delay_1ms(100);beep=1;}voidwrite_cmd(ucharcmd)//写命令{LCD_RS=0;LCD_RW=0;LCD_EN=0;P0=cmd;delay_1ms(5);LCD_EN=1;delay_1ms(5);LCD_EN=0;}voidwrite_dat(
3、uchardat)//写数据{LCD_RS=1;LCD_RW=0;LCD_EN=0;P0=dat;delay_1ms(5);LCD_EN=1;delay_1ms(5);LCD_EN=0;}voidwrite_sfm(ucharadd,chardat)//写时分秒{ucharshi1,ge1;shi1=dat/10;ge1=dat%10;write_cmd(0x90+add);//写显示地址的指令write_dat(0x30+shi1);write_dat(0x30+ge1);//ge2=dat%10;//write_cmd(0x88+add);//
4、write_dat(0x30+ge2);}voidwrite_nyr(ucharadd,chardat)//写年月{charshi,ge;shi=dat/10;ge=dat%10;write_cmd(0x80+add);write_dat(0x30+shi);write_dat(0x30+ge);}voidwrite_week(ucharadd,chardat)//写星期{charge2;ge2=dat%10;write_cmd(0x88+add);write_dat(0x30+ge2);}voidinit(){//初始化2014年11月6日星期1
5、23:59:59LCD_PSB=1;rd=0;LCD_EN=0;fen=59;miao=59;shi=23;week=1;year1=20;year2=14;mon=11;day=6;count=0;s1num=0;TMOD=0x01;//中断0,方式1TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;write_cmd(0x30);delay_1ms(5);write_cmd(0x0c);delay_1ms(5);write_cmd(0x01);delay_1ms(5);wr
6、ite_cmd(0x91);write_dat(':');delay_1ms(5);write_cmd(0x93);write_dat(':');delay_1ms(5);write_sfm(4,miao);write_sfm(2,fen);write_sfm(0,shi);write_cmd(0x82);write_dat('-');delay_1ms(5);write_cmd(0x84);write_dat('-');delay_1ms(5);write_nyr(5,day);write_nyr(3,mon);write_nyr(0,year1
7、);write_nyr(1,year2);write_week(2,week);}voidkeyscan()//独立键盘检测{if(s1==0){delay_1ms(5);if(s1==0){s1num++;while(!s1);di();if(s1num==1){TR0=0;write_cmd(0x84);//光标定位到日的位置write_cmd(0x0f);//光标开始闪数}if(s1num==2){write_cmd(0x82);//光标定位到月的位置}if(s1num==3){write_cmd(0x80);//光标定位到年的位置}if(s
8、1num==4){write_cmd(0x95);//光标定位到秒的位置}if(s1num==5){write_cmd(0