资源描述:
《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