帶電子溫度計(jì)的萬(wàn)年歷_第1頁(yè)
帶電子溫度計(jì)的萬(wàn)年歷_第2頁(yè)
帶電子溫度計(jì)的萬(wàn)年歷_第3頁(yè)
帶電子溫度計(jì)的萬(wàn)年歷_第4頁(yè)
帶電子溫度計(jì)的萬(wàn)年歷_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

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" /用于存儲(chǔ)星期uchar LCD_DSY_BUFFER1="DATE 00-00-00 " /用于存儲(chǔ)年月日uchar LCD_DSY_BUFFER2="T 00:00:00 " /用于存儲(chǔ)時(shí)分秒uchar DateTime7;/存儲(chǔ)從ds1302中讀出的時(shí)間數(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í)函數(shù)void Write_A_Byte_TO_DS1302(uchar x); /該函數(shù)用于從ds1302中寫(xiě)入一字節(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、對(duì)ds1302進(jìn)行初始化void write_1302(uchar add,uchar dat) ; /用于向ds1302寫(xiě)入數(shù)據(jù)void Write_LCD_Data(uchar dat); /向lcd的控制器寫(xiě)入數(shù)據(jù)void Write_LCD_Command(uchar cmd);/向lcd控制器寫(xiě)入指令void Init_LCD();/lcd的初始化void Set_LCD_POS(uchar p); /lcd現(xiàn)實(shí)的地址進(jìn)行選擇void Display_LCD_String1(uchar p,uchar *s); /下面的兩個(gè)函數(shù)是用于把數(shù)組中的內(nèi)容寫(xiě)入lcd控制器void Displ

5、ay_LCD_String2(uchar p,uchar *s);void Format_DateTime(uchar d,uchar *a); /把ds1302中讀出的bcd碼數(shù)據(jù)進(jìn)行轉(zhuǎn)化成字符型void Delayus(uchar i); /延時(shí)函數(shù) 用于ds18b20的時(shí)序的控制bit reset(void); void ds_18b20_init(); /ds18b20的初始化函數(shù)uchar rdbyte(); /從ds18b20中讀出一字節(jié)的數(shù)據(jù)void wrbyte(uchar dat);/向ds18b20中寫(xiě)入一字節(jié)的數(shù)據(jù)void convert();/控制ds18b20進(jìn)行數(shù)據(jù)

6、的轉(zhuǎn)換int readt();/控制ds18b20對(duì)數(shù)據(jù)進(jìn)行輸出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的寫(xiě)入函數(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寫(xiě)一字節(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) /時(shí) 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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論