




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、#include <reg52.h>#include <string.h>#define uint unsigned int#define uchar unsigned charsbit IO = P10;sbit SCLK = P11;sbit RST = P12;sbit SPEAK = P17;sbit RS = P20;sbit RW = P21;sbit EN = P22; sbit DQ = P23;sbit Key1 = P24;sbit Key2 = P25;sbit Key3 = P26;sbit Key4 = P27;uchar WEEK74=&qu
2、ot;SUN","MON","TUS","WEN","THU","FRI","SAT" /用于存儲星期uchar LCD_DSY_BUFFER1="DATE 00-00-00 " /用于存儲年月日uchar LCD_DSY_BUFFER2="T 00:00:00 " /用于存儲時分秒uchar DateTime7;/存儲從ds1302中讀出的時間數(shù)據(jù)uchar b1,b2,b3;int t,a1,a2;uchar min=0,
3、h=0,day=0,mon=0,year=0,weak=0;uchar change1=0,change2=0;uchar bcd1=0,bcd2=0;void DelayXus(uint ms); /延時函數(shù)void Write_A_Byte_TO_DS1302(uchar x); /該函數(shù)用于從ds1302中寫入一字節(jié)的數(shù)據(jù)uchar Get_A_Byte_FROM_DS1302(); /該函數(shù)用于向ds1302中讀出一字節(jié)的數(shù)據(jù)uchar Read_Data(uchar addr); /用于向ds1302中讀出數(shù)據(jù)void GetTime();void ds1302_init() ; /
4、對ds1302進行初始化void write_1302(uchar add,uchar dat) ; /用于向ds1302寫入數(shù)據(jù)void Write_LCD_Data(uchar dat); /向lcd的控制器寫入數(shù)據(jù)void Write_LCD_Command(uchar cmd);/向lcd控制器寫入指令void Init_LCD();/lcd的初始化void Set_LCD_POS(uchar p); /lcd現(xiàn)實的地址進行選擇void Display_LCD_String1(uchar p,uchar *s); /下面的兩個函數(shù)是用于把數(shù)組中的內(nèi)容寫入lcd控制器void Displ
5、ay_LCD_String2(uchar p,uchar *s);void Format_DateTime(uchar d,uchar *a); /把ds1302中讀出的bcd碼數(shù)據(jù)進行轉(zhuǎn)化成字符型void Delayus(uchar i); /延時函數(shù) 用于ds18b20的時序的控制bit reset(void); void ds_18b20_init(); /ds18b20的初始化函數(shù)uchar rdbyte(); /從ds18b20中讀出一字節(jié)的數(shù)據(jù)void wrbyte(uchar dat);/向ds18b20中寫入一字節(jié)的數(shù)據(jù)void convert();/控制ds18b20進行數(shù)據(jù)
6、的轉(zhuǎn)換int readt();/控制ds18b20對數(shù)據(jù)進行輸出void ds18_b_20_show(); /用于在lcd中顯示溫度數(shù)值void Time_change();void main() / char i; Init_LCD();ds1302_init();while(1) GetTime();Format_DateTime(DateTime6,LCD_DSY_BUFFER1+5);Format_DateTime(DateTime4,LCD_DSY_BUFFER1+8);Format_DateTime(DateTime3,LCD_DSY_BUFFER1+11);Format_Dat
7、eTime(DateTime2,LCD_DSY_BUFFER2+2);Format_DateTime(DateTime1,LCD_DSY_BUFFER2+5);Format_DateTime(DateTime0,LCD_DSY_BUFFER2+8); strcpy(LCD_DSY_BUFFER1+13,WEEKDateTime5); Display_LCD_String1(0x00,LCD_DSY_BUFFER1); Display_LCD_String2(0x40,LCD_DSY_BUFFER2); while(Key4=0)Time_change();change1=0;ds18_b_20
8、_show();while(a1>70&&a1!=85)SPEAK=SPEAK;if(DateTime2=1) for(i=0;i<120;i+) SPEAK=SPEAK;DelayXus(2); if(DateTime2=1) for(i=0;i<120;i+) SPEAK=SPEAK;DelayXus(2); void DelayXus(uint ms)/ uchar i;while(ms-) for(i=0;i<120;i+);void Delayus(uchar i) uchar j; for(j=i;j>0;j-);void Write_
9、A_Byte_TO_DS1302(uchar x) / uchar i;SCLK=0;for(i=0;i<8;i+) IO=x&0x01;SCLK=1; DelayXus(2);SCLK=0;x>>=1;uchar Get_A_Byte_FROM_DS1302()/ uchar i,b=0x00;for(i=0;i<8;i+) b>>=1; if(IO=1) b|=0x80; SCLK=1; DelayXus(2); SCLK=0; DelayXus(2); return b;uchar Read_Data(uchar addr) / uchar d
10、at;RST = 0;RST=1; Write_A_Byte_TO_DS1302(addr);dat = Get_A_Byte_FROM_DS1302();RST=0;return dat;void GetTime()/ uchar i,addr=0x81;for(i=0;i<7;i+) DateTimei=Read_Data(addr);addr+=2; void Write_LCD_Data(uchar dat)/ DelayXus(2);RS=1;RW=0;EN=0;P0=dat;EN=1;DelayXus(1);EN=0;void Write_LCD_Command(uchar
11、cmd) / DelayXus(2);RS=0;RW=0;EN=0;P0=cmd;EN=1;DelayXus(1);EN=0;void Init_LCD() / Write_LCD_Command(0x38);DelayXus(1);Write_LCD_Command(0x01);DelayXus(1);Write_LCD_Command(0x06);DelayXus(1);Write_LCD_Command(0x0c);DelayXus(1);void Display_LCD_String1(uchar p,uchar *s) / uchar i;Set_LCD_POS(p);for(i=0
12、;i<18;i+)Write_LCD_Data(si);DelayXus(1); void Display_LCD_String2(uchar p,uchar *s) / uchar i;Set_LCD_POS(p);for(i=0;i<11;i+)Write_LCD_Data(si);DelayXus(1); void Set_LCD_POS(uchar p) Write_LCD_Command(p|0x80);void Format_DateTime(uchar d,uchar *a) / *a=d/16+'0'*(a+1)=d%16+'0'vo
13、id write_1302(uchar add,uchar dat) /ds1302的寫入函數(shù) RST=0; RST=1; Write_A_Byte_TO_DS1302(add); Write_A_Byte_TO_DS1302(dat); RST=0; void ds1302_init() /ds1302的初始化函數(shù) RST=0; SCLK=0; write_1302(0x8e,0x00); write_1302(0x80,0x00); write_1302(0x82,0x00); write_1302(0x84,0x09); write_1302(0x8a,0x04); write_1302
14、(0x86,0x22); write_1302(0x88,0x06); write_1302(0x8c,0x15); write_1302(0x90,0x01); write_1302(0x8e,0x80);void ds18_b_20_show() convert(); t=readt(); a1=(int)(t*0.0625); a2=(int)(t*0.625)-a1*10; b1=a1/10+'0' b2=a1%10+'0' b3=a2+'0' Write_LCD_Command(0xcc); Write_LCD_Data(b1); Wr
15、ite_LCD_Data(b2); Write_LCD_Data('.'); Write_LCD_Data(b3); bit reset(void)/ds18b20的復(fù)位函數(shù) bit flag; DQ=0; Delayus(70); DQ=1; Delayus(3); flag=DQ; Delayus(15); return flag;void ds_18b20_init() /ds18b20的初始化函數(shù) while(1) if(!reset() DQ=1; break; else reset(); uchar rdbyte()/ds18b20的讀一字節(jié)函數(shù) uchar i,d
16、at=0;DQ = 1;for(i=0;i<8;i+) DQ = 0;dat >>= 1;DQ = 1;Delayus(1);if(DQ)dat |= 0X80;Delayus(4);DQ = 1;return dat;void wrbyte(uchar dat)/ds18b20寫一字節(jié)函數(shù) uchar i;for(i=0;i<8;i+) DQ = 0;DQ = dat& 0x01;Delayus(5);DQ = 1;dat >>= 1;void convert()/ds18b20的轉(zhuǎn)換函數(shù) ds_18b20_init(); wrbyte(0xcc)
17、; wrbyte(0x44);int readt() /ds18b20的讀數(shù)據(jù)函數(shù) uchar h,l; ds_18b20_init(); wrbyte(0xcc); wrbyte(0xbe); l=rdbyte(); h=rdbyte(); Write_LCD_Command(0xcb); if(h>=8) h=h; l=l; Write_LCD_Data('-'); return h*256+l+1; else Write_LCD_Data(' '); return h*256+l; void Time_change() write_1302(0x8e
18、,0x00); if(Key1=1&&Key2=1&&Key3=0) /秒 if(Key4=0&&change1=change2) write_1302(0x80,0x00); change1=1; if(Key1=1&&Key2=0&&Key3=1) /分 if(Key4=0&&change1=change2) bcd2+; if(bcd2=10)bcd1+,bcd2=0; if(bcd1=6)bcd1=0; min=16*bcd1+bcd2; write_1302(0x82,min); chan
19、ge1=1; if(Key1=1&&Key2=0&&Key3=0) /時 if(Key4=0&&change1=change2) bcd2+; if(bcd2=10)bcd1+,bcd2=0; if(bcd1=2&&bcd2=4)bcd1=0,bcd2=0; h=16*bcd1+bcd2; write_1302(0x84,h); change1=1; if(Key1=0&&Key2=1&&Key3=1) /日 if(Key4=0&&change1=change2) bcd2+; if(bcd2=10)bcd1+,bcd2=0; if(bcd1=3&a
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度高端別墅室內(nèi)裝飾設(shè)計與施工合同
- 體育產(chǎn)業(yè)智慧場館建設(shè)與賽事運營支持方案
- 《國際政治格局演變歷程:高中政治教學教案》
- 乘用車行業(yè)智能化生產(chǎn)與銷售方案
- 經(jīng)典科學故事讀后感
- 車輛銷售服務(wù)合同附加條款
- 防盜門銷售合同協(xié)議書
- 服裝公司服裝買賣協(xié)議
- 健康產(chǎn)業(yè)產(chǎn)品推廣與營銷策略
- 裝修增項補充合同協(xié)議
- 2025年湖南省高職單招《職業(yè)技能測試》核心考點試題庫500題(重點)
- 2025年無錫科技職業(yè)學院高職單招高職單招英語2016-2024歷年頻考點試題含答案解析
- 《復(fù)式條形統(tǒng)計圖》(說課稿)-2023-2024學年四年級下冊數(shù)學人教版
- 微量注射泵培訓
- 2025年紹興市上虞大眾勞動事務(wù)代理(所)有限公司招聘筆試參考題庫附帶答案詳解
- 酒店會議接待服務(wù)方案
- 2025年人教版新教材英語小學三年級下冊教學計劃(含進度表)
- 2025年山東商務(wù)職業(yè)學院高職單招高職單招英語2016-2024年參考題庫含答案解析
- 人工智能在企業(yè)人力資源招聘中的運用研究
- 2023年2024年演出經(jīng)紀人之演出經(jīng)紀實務(wù)考試題庫附答案(達標題)
- DG-T 076-2024 采茶機標準規(guī)范
評論
0/150
提交評論