资源描述:
《单片机的年历程序,12864液晶显示_电子电路_工程科》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintsbitLCD_RS=P3A5;sbitLCD_RW=P3A6;sbitLCD_EN=P3A4;sbitLCD_PSB=P2A4;sbitsl=P3A0;〃独立按键sbits2=P3Al;sbits3=P3A2;sbitrd=P3A7;sbitbeep=P2A3;〃定义蜂鸣器端口ucharmiao.shi,fen,mon,day,week,year1,year2,i5sinum,count;uinta,b,year;ucharcodedis2[]={H星期"};
2、ucharcodedis3[]={"北华大学"};voiddelay_lms(uintz){uintx,y;for(x=z;x>0;x~)for(y=110;y>0;y-);}voiddi()〃蜂鸣器{bccp=0;delay_lms(100);beep=1;}voidwritc_cmd(ucharemd)〃写命令{LCD_RS=0;LCD_RW=0;LCD_EN=0;P0=cmd;delay_lms(5);LCD_EN=1;delay_lms(5);LCD_EN=();}voidwrite_dat(uchardat)//写数据LCD_RS=1;LCD_RW=O;LCD_EN=O;PO
3、=dat;delay_lms(5);LCD_EN=1;dclay_lms(5);LCD_EN=O;voidwrite_sfm(ucharadd,chardat)〃写时分秒{ucharshil.gel;shil=dat/10;gel=dat%10;write_cmd(0x90+add);〃写显示地址的指令write_dat(0x30+shi1);write_dat(0x30+ge1);//ge2=dat%10;//write_cmd(()x88+add);//write_dat(0x30+ge2);}voidwrite_nyr(ucharadd,chardat)〃写年月{charshi.
4、gc;shi=dat/10;ge=dat%10;write_cmd(0x80+add);write_dat(0x30+shi);write_dat(0x30+ge);}voidwrite_week(ucharadd,chardat)〃写星期{charge2;gc2=dat%10;write_cmd(0x88+add);write_dat(0x30+ge2);}voidinit()〃初始化2014年11月6日星期123:59:59LCD_PSB=1;rd=O;LCD_EN=O;fen=59;miao=59;shi=23;week=l;year1=20;year2=14;mon=ll;da
5、y=6;count=0;slnum=0;〃中断0,方式1TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR()=1;write_cmd(0x30);delay_lms(5);write_cmd(()x()c);dclay_lms(5);write_cmd(0x01);delay_lms(5);write_cmd(0x91);write_dat(Y);delay_lms(5);write_cmd(0x93);write-datC:1);dclay_lms(5);write_sfm(4,miao);writ
6、e_sfm(2,fen);write_sfm(0,shi);writc_cmd(0x82);write_dat(tJ);delay_lms(5);write_cmd(0x84);writc_dat(L,);delay_lms(5);write_nyr(5,day);write_nyr(3,mon);write_nyr((),year1);writc_nyr(l,ycar2);write_week(2,week);}voidkeyscan(){if(sl==O){delay_lms(5);if(sl==O){slnum++;while(!sl);di();if(s1num==l){TR0
7、=0;write_cmd(0x84);write_cmd(0x0f);}if(slnum==2){write_cmd(0x82);}if(slnum==3){write_cmd(0x80);}if(slnum==4){write_cmd(0x95);)if(slnum==5){write_cmd(0x93);}if(slnum==6)〃独立键盘检测〃光标定位到II的位置〃光标开始闪数〃光标定位到月的位置〃光标定位到年的位遥〃光标定位到秒的位置〃