基于51单片机的电子日历.docx

基于51单片机的电子日历.docx

ID:61490212

大小:13.13 KB

页数:13页

时间:2021-02-06

基于51单片机的电子日历.docx_第1页
基于51单片机的电子日历.docx_第2页
基于51单片机的电子日历.docx_第3页
基于51单片机的电子日历.docx_第4页
基于51单片机的电子日历.docx_第5页
资源描述:

《基于51单片机的电子日历.docx》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、#include#defineucharunsignedchar#defineuintunsignedintsbitLCD_RS=P2^6;sbitLCD_RW=P2^5;sbitLCD_EP=P2^7;sbitSDA=P2^1;sbitSCL=P2^0;sbits1=P3^0;sbits2=P3^1;sbits3=P3^2;sbitbeep=P1^5;ucharcount=0,s1num=0,week=5;intsecond,minute,hour,year1=20,year2=10,mouth=12,day=25;unsigne

2、dcharcodemouth_0[]={31,28,31,30,31,30,31,31,30,31,30,31};//设置闰年和非闰年每个月的天数unsignedcharcodemouth_1[]={31,29,31,30,31,30,31,31,30,31,30,31};voiddelay0(){;;}voiddelay(uintz)//延时函数{uintx,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}voiddi(){beep=0;delay(100);//扬声器beep=1;}voidstart()//24c02

3、开始信号{SDA=1;delay0();SCL=1;delay0();SDA=0;delay0();}voidstop()//24c02停止信号{SDA=0;delay0();SCL=1;delay0();SDA=1;delay0();}voidrespons()//应答{uchari;SCL=1;delay0();while((SDA==1)&&(i<250))i++;SCL=0;delay0();}voidinit()//I2c初始化{SDA=1;delay0();SCL=1;delay0();}voidwrite_byte(uchardate)

4、//写一个字节{uchari,temp;temp=date;for(i=0;i<8;i++){temp=temp<<1;SCL=0;delay0();SDA=CY;delay0();SCL=1;delay0();}SCL=0;delay0();SDA=1;delay0();}ucharread_byte()//读一个字节{uchari,k;SCL=0;delay0();SDA=1;delay0();for(i=0;i<8;i++){SCL=1;delay0();k=(k<<1)

5、SDA;SCL=0;delay0();}returnk;}voidwri

6、te_add(ucharaddress,uchardate)//指定地址写一个字节{start();write_byte(0xa0);respons();write_byte(address);respons();write_byte(date);respons();stop();}ucharread_add(ucharaddress)//指定地址读一个字节{uchardate;start();write_byte(0xa0);respons();write_byte(address);respons();start();write_byte(0xa

7、1);respons();date=read_byte();stop();returndate;}voidwrite_com(ucharcom)//液晶写命令函数{LCD_RS=0;LCD_RW=0;LCD_EP=0;P0=com;delay0();LCD_EP=1;delay(5);LCD_EP=0;}voidwrite_date(uchardate)//液晶写数据函数{LCD_RS=1;LCD_RW=0;LCD_EP=0;P0=date;delay(5);LCD_EP=1;delay(5);LCD_EP=0;}voidwrite_sfm(ucha

8、radd,uchardate)//写时分秒函数{ucharshi,ge;shi=date/10;ge=date%10;write_com(0x80+0x40+add);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_nyr(ucharadd,uchardate)//写年、月、日函数{charshi,ge;shi=date/10;ge=date%10;write_com(0x80+add);write_date(0x30+shi);write_date(0x30+ge);}voidwrite_we

9、ek(charwe)//写星期函数{write_com(0x80+12);switch(we){case1:

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。