资源描述:
《基于stc89c52单片机时钟》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、基于STC89C52单片机时钟1.1602显示。第一行显示年月日,第二行显示时分秒。2.开机显示个性的画面,约5S后进入时间显示界面。3.汉字显示“年”“月”“日”。4.时间可调。时间调节由三按键控制。键一控制调节位,按下键一后,时钟停止走时,出现光标,每按一次光标移向下一个调节位,按五次后,退出调节模式。键二为加键,键三为减键。只有在模式调节下才起作用。5.该时钟程序仅仅只是时钟功能的实现,走时并不精确。或者说是参考模型,可以在此基础上进行优化和更改。按键部分可进行大优化,为了在实验板上做实验
2、,而实验板为矩阵键盘。所以按键定义了四个端口。#include#include#defineucharunsignedchar#defineuintunsignedintsbitLCD_RS=P1^0;//定义寄存器选择sbitLCD_RW=P1^1;//定义读写信号线sbitLCD_EN=P1^2;//定义定义使能端sbitkey1=P0^0;sbitkey2=P0^4;sbitkey3=P0^5;sbitkey4=P0^6;voiddelay_ms(u
3、intxms);//延时函数声明bitlcd_busy();//忙检查函数声明voidlcd_wcmd(ucharcmd);//写指令寄存器IR函数声明voidlcd_wdat(uchardat);//写数据寄存器DR函数声明voidlcd_clr();//清屏函数声明voidlcd_init();//LCD初始化函数声明voidkey_mode();voidyear_moon_day();uchardis_buf[19];uchardis[]={'0','1','2','3','4','5',
4、'6','7','8','9'};ucharcodename1[]={"helpyourself!"};ucharcodename2[]={"holdon!"};ucharyear_month_day[3][8]={{0x04,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0},//年{0x0f,0x09,0x0f,0x09,0x0f,0x09,0x13,0x00},//月{0x0e,0x0a,0x0a,0x0e,0x0a,0x0a,0x0e,0x02}//日};ucharding
5、shi=0;//50ms计数ucharflag=0;//按键控制变量charmiao=55,fen=59,shi=23;charmoon=12,day=31;intyear=2012;ucharleap;ucharshan;//控制时分的闪烁位ucharkey_value;/****************LCD显示部分******************///读忙bitlcd_busy(){bitresult;LCD_RS=0;LCD_RW=1;LCD_EN=1;_nop_();_nop_()
6、;_nop_();_nop_();result=(bit)(P2&0x80);LCD_EN=0;returnresult;}//清屏voidlcd_clr(){lcd_wcmd(0x01);delay_ms(5);}//写指令voidlcd_wcmd(ucharcmd){while(lcd_busy());//delay_ms(2);LCD_RS=0;LCD_RW=0;LCD_EN=0;_nop_();_nop_();P2=cmd;_nop_();_nop_();_nop_();_nop_();
7、LCD_EN=1;_nop_();_nop_();_nop_();_nop_();LCD_EN=0;}//写数据voidlcd_wdat(uchardat){while(lcd_busy());//delay_ms(2);LCD_RS=1;LCD_RW=0;LCD_EN=0;_nop_();_nop_();P2=dat;_nop_();_nop_();_nop_();_nop_();LCD_EN=1;_nop_();_nop_();_nop_();_nop_();LCD_EN=0;}//显示初始
8、化voidlcd_init(){//delay_ms(15);lcd_wcmd(0x38);//显示模式为16*25*7点阵8位数据delay_ms(5);lcd_wcmd(0x38);delay_ms(5);lcd_wcmd(0x01);//清屏delay_ms(5);lcd_wcmd(0x06);//移动光标delay_ms(5);lcd_wcmd(0x0c);//开光标delay_ms(5);}voiddelay_ms(uintxms){uchari,j;for(i=xms;i>0;i--