(原创)51单片机C语言程序设计--速学教程实例(进阶篇)之可调电子日历

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

/******************************************************************//*名称:可调电子日历钟*//*作者:苏涛*//*时间:2011-01-20*//*单位:安徽建筑工业学院电子与信息工程学院*//*07级电子信息工程专业二班*//******************************************************************/#includereg52.h#includelcd12864.h#includetimergo.h#includekeyscan.h/******************************************************************/#defineucharunsignedchar#defineuintunsignedint/******************************************************************/ucharcodetable1[]=单片机内部定时器;ucharcodetable2[]=可调电子日历时钟;ucharcodetable3[]=S*00:00:00**T*;ucharcodetable4[]=日期:11--01--20;/******************************************************************/voiddelay(uintdly){uchari=0,j=0;while(dly--){for(i=0;i10;i++)for(j=0;j60;j++);}}/******************************************************************/voidmain(){uchari,key;init_12864();write_12864_com(0x80);for(i=0;i16;i++){write_12864_dat(table1[i]);delay_50us(1);}write_12864_com(0x90);for(i=0;i16;i++){write_12864_dat(table2[i]);delay_50us(1);}write_12864_com(0x88);for(i=0;i16;i++){write_12864_dat(table3[i]);delay_50us(1);}write_12864_com(0x98);for(i=0;i16;i++){write_12864_dat(table4[i]);delay_50us(1);}TMOD=0x01;TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;tcount=0;second=0;minute=0;hour=0;day=0;month=0;year=0;while(1){key=keyscan();switch(key){case0x7e:{ET0=0;while((key=keyscan())!=0xbb){if(key==0x7e)t_second();delay(100);}ET0=1;}break;//0调整秒case0x7d:{ET0=0;while((key=keyscan())!=0xbb){if(key==0x7d)t_minute();delay(100);}ET0=1;}break;//1调整分case0x7b:{ET0=0;while((key=keyscan())!=0xbb){if(key==0x7b)t_hour();delay(100);}ET0=1;}break;//2调整时case0x77:{ET0=0;while((key=keyscan())!=0xbb){if(key==0x77)t_day();delay(100);}ET0=1;}break;//3调整日case0xbe:{ET0=0;while((key=keyscan())!=0xbb){key=keyscan();if(key==0xbe)t_month();delay(100);}ET0=1;}break;//4调整月case0xbd:{ET0=0;while((key=keyscan())!=0xbb){key=keyscan();if(key==0xbd)t_year();delay(100);}ET0=1;}break;//5调整年case0xbb:{ET0=1;}break;//6调整完成后确定}timergo();}}/******************************************************************/voidtimer0()interrupt1using0{tcount++;TH0=(65536-50000)/256;TL0=(65536-50000)%256;}/******************************************************************//*头文件:LCD12864.H*//******************************************************************/#defineucharunsignedchar#defineuintunsignedint/******************************************************************/sbitrs=P2^4;sbitrw=P2^5;sbite=P2^6;sbitpsb=P2^1;/******************************************************************/voiddelay_1ms(uintz){uintx,y;for(x=z;x0;x--)for(y=110;y0;y--);}voiddelay_50us(uintt){ucharj;for(;t0;t--)for(j=19;j0;j--);}/******************************************************************/voidwrite_12864_com(ucharcom){rw=0;rs=0;delay_50us(1);P0=com;e=1;delay_50us(10);e=0;delay_50us(2);}/******************************************************************/voidwrite_12864_dat(uchardat){rw=0;rs=1;delay_50us(1);P0=dat;e=1;delay_50us(10);e=0;delay_50us(2);}/******************************************************************/voidinit_12864(){delay_1ms(100);write_12864_com(0x30);delay_50us(4);write_12864_com(0x30);delay_50us(4);write_12864_com(0x0c);delay_50us(4);write_12864_com(0x01);delay_50us(240);write_12864_com(0x06);delay_50us(10);}/******************************************************************//*头文件:TIMERGO.H*//******************************************************************/#defineucharunsignedchar#defineuintunsignedint/******************************************************************/ucharsecond,tcount,minute,hour,day,month,year;/******************************************************************/voidwrite_sfm(ucharadd,uchardate){ucharshi,ge;shi=date/10;ge=date%10;write_12864_com(0x88+add);write_12864_dat(0x30+shi);//十进制码转换成十六进制码要加上0x30write_12864_dat(0x30+ge);}/******************************************************************/voidwrite_nyr(ucharadd1,uchardate1){ucharshi,ge;shi=date1/10;ge=date1%10;write_12864_com(0x98+add1);write_12864_dat(0x30+shi);//十进制码转换成十六进制码要加上0x30write_12864_dat(0x30+ge);}/******************************************************************/voidt_second(){second++;if(second==60){second=0;}write_sfm(5,second);}/******************************************************************/voidt_minute(){minute++;if(minute==60){minute=0;}write_sfm(3,minute);}/******************************************************************/voidt_hour(){hour++;if(hour==24){hour=0;}write_sfm(1,hour);}/******************************************************************/voidt_day(){day++;if(day==31){day=0;}write_nyr(7,day);}/******************************************************************/voidt_month(){month++;if(month==13){month=0;}write_nyr(5,month);}/******************************************************************/voidt_year(){year++;if(year==100){year=0;}write_nyr(3,year);}/******************************************************************/voidtimergo(){if(tcount==20){tcount=0;second++;if(second==60){second=0;minute++

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功