12864电子日历

12864电子日历

ID:38103924

大小:27.75 KB

页数:33页

时间:2019-06-06

12864电子日历_第1页
12864电子日历_第2页
12864电子日历_第3页
12864电子日历_第4页
12864电子日历_第5页
资源描述:

《12864电子日历》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include#include#defineLCD_DataP0#defineucharunsignedcharunsignedcharsec,min,hour,day,month,year,cen,week,next,aa,bb,cc,dd,mm,temp0,LunarMonth,LunarDay,LunarYear;inttemp;uchartt=1;bitc_moon;bitcenbit=1;bitw;sbitLCD_RS=P2^0;sbitLCD_RW=

2、P2^1;sbitLCD_E=P2^2;sbitPSB=P2^3;sbitDS1302_CLK=P3^7;sbitDS1302_IO=P3^6;sbitDS1302_RST=P3^5;sbitDS18B20=P2^5;sbitspeak=P2^7;sbitSetKey=P1^4;//按键功能:设置sbitSureKey=P1^5;//按键功能:确定sbitPlusKey=P1^6;//按键功能:加sbitReduceKey=P1^7;//按键功能:减sbitscl=P1^1;sbitsda=P1^0;v

3、oidDisplayShengXiao(void);voiddelay(unsignedinta)//延时1MS/次{unsignedchari;while(--a){for(i=0;i<125;i++);}}voiddelayb(unsignedintcount){while(count--);}voiddelays(){;;}voidstart(){sda=1;scl=1;delays();sda=0;delays();}voidstop(){sda=0;scl=1;delays();sda=1;d

4、elays();}voidresponse(){uchari;while((sda==1)&&i<255)i++;//给应答信号sda=0;错误(while((sda==0)

5、i<255)i++;)程序进入while死循环scl=1;delays();scl=0;//没有这一步出错,如果没有sda将保持0状态,一直处于应答中。程序停止。delays();}voidwrite24c02(uchardate){uchartemp,i;temp=date;for(i=0;i<8;i++){scl=0;sda=

6、temp&0x80;delays();scl=1;delays();temp=temp<<1;}scl=0;delays();sda=1;delays();}ucharread24c02(){uchark,i;scl=0;delays();sda=1;//仅仅是释放数据线,可有可无for(i=0;i<8;i++){scl=1;delays();k=k<<1;if(sda)k++;scl=0;delays();}returnk;}voidwrite_24c02add(ucharaddress,uchard

7、ate){start();write24c02(0xa0);response();write24c02(address);response();write24c02(date);response();stop();}ucharread_24c02add(ucharaddress){uchara;start();write24c02(0xa0);response();write24c02(address);response();start();write24c02(0xa1);response();a=r

8、ead24c02();stop();returna;}unsignedcharDS18B20Init(){unsignedcharx;DS18B20=1;delayb(2);DS18B20=0;delayb(80);DS18B20=1;delayb(5);x=DS18B20;delayb(20);returnx;}unsignedcharTempRead(void){unsignedchari,dat;DS18B20=1;delayb(1);for(i=0;i<8;i++){DS18B20=0;dat=

9、dat>>1;DS18B20=1;if(DS18B20)dat=dat

10、0x80;delayb(4);}returndat;}voidTempWriteByte(unsignedchardat){unsignedinti;DS18B20=1;delayb(2);for(i=0;i<8;i++){DS18B20=0;DS18B20=dat&0x01;delayb(8);DS18B20=1;dat=dat>>1;delayb(2);}}intG

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

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

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