


版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、/帶溫度和時(shí)間顯示程序/? C/neo/V1.1 2011-7-16/MCS-51 12MHZ C?/?: DS1302?DS18B20*/#include <reg52.h>#include <intrins.h>#define uint8 unsigned char#define uchar unsigned char#define uint unsigned intuchar Disp_Buff4;char SB=4; / clock set time bit/bit Set_Flag; / set time flagbit T=0; / display Temp
2、erature and Time flagbit TT=0; / 10S Auto change display Temperature and Time flag/#define T0_H0xf0/ 4ms/#define T0_L0x60#define T0_H0xf5/ 2666us#define T0_L0x96#define ST20#define T1_H0xb1/20ms#define T1_L0xe0#define NumLed_Bit P2#define DispP0#define KeyP3#define Key1 1#define Key2 2#define Key3 3
3、#define Key4 4#define Key_NULL 0sbit Beep=P07; void Play(uchar t);sbit Red_Led=P37;/ Driver DS1302 /*/sbit RST=P12;sbit IO=P10;sbit SCLK=P11;#define second_write 0x80#define minute_write 0x82 #define hour_write 0x84 #define week_write 0x8a #define day_write 0x86 #define month_write 0x88 #define year
4、_write 0x8c #define second_read 0x81#define minute_read 0x83#define hour_read 0x85#define week_read 0x8b#define day_read 0x87#define month_read 0x89#define year_read 0x8d#define sclk_highSCLK=1;#define sclk_lowSCLK=0;#define io_highIO=1;#define io_lowIO=0;#define io_readIO#define rst_highRST=1;#defi
5、ne rst_lowRST=0;struct uint8 second;uint8 minute;uint8 hour;uint8 day;uint8 week;uint8 month;uint8 year; current_time;/* static void ds1302write(uint8 content)uint8 i;for(i=8;i>0;i-) if(content&0x01) io_highelse io_lowcontent>>=1; sclk_high sclk_low/*/static uint8 ds1302read(void)uint8
6、i,readvalue;io_highfor(i=8;i>0;i-) readvalue>>=1; if(io_read) readvalue|=0x80;else readvalue&=0x7f; sclk_high sclk_low return readvalue;/* void ds1302write_byte (uint8 address,uint8 content)rst_low sclk_low rst_high ds1302write(address); ds1302write(content); rst_low sclk_highuint8 ds13
7、02read_byte(uint8 address)uint8 readvalue;rst_low sclk_low rst_high ds1302write(address);readvalue=ds1302read(); rst_low sclk_high return readvalue;/* void Clock_Init(void)uchar R;if(ds1302read_byte(0xc1)!=0xf0) ds1302write_byte(0x8e,0x00); ds1302write_byte(year_write,0x11); ds1302write_byte(week_wr
8、ite,0x06); ds1302write_byte(month_write,0x04); ds1302write_byte(day_write,0x09); ds1302write_byte(hour_write,0x23); ds1302write_byte(minute_write,0x59); ds1302write_byte(second_write,0x30);ds1302write_byte(0x90,0xa5); ds1302write_byte(0xc0,0xf0);for (R=0;R<10;R+=2) ds1302write_byte(0xc2+R,0);ds13
9、02write_byte(0x8e,0x80); /* */void Clock_Updata(void) current_time.second=ds1302read_byte(second_read); current_time.minute=ds1302read_byte(minute_read); current_time.hour= ds1302read_byte(hour_read); current_time.day= ds1302read_byte(day_read); current_time.month= ds1302read_byte(month_read); curre
10、nt_time.week= ds1302read_byte(week_read); current_time.year= ds1302read_byte(year_read);/* */void Write_Time(void) ds1302write_byte(0x8e,0x00); ds1302write_byte(0x82,(Disp_Buff2<<4)|Disp_Buff3); ds1302write_byte(0x84,(Disp_Buff0<<4)|Disp_Buff1);ds1302write_byte(0x8e,0x80);/* */void Write
11、_Alarm(void)ds1302write_byte(0x8e,0x00);ds1302write_byte(0xca,(Disp_Buff2<<4)|Disp_Buff3); / alarm minute ds1302write_byte(0xc8,(Disp_Buff0<<4)|Disp_Buff1); / alarm hour ds1302write_byte(0xc6,1);ds1302write_byte(0x8e,0x80);/* void Alarm(void)if(ds1302read_byte(0xc7)=1&& current_t
12、ime.minute=ds1302read_byte(0xcb)&& current_time.hour=ds1302read_byte(0xc9) ) ds1302write_byte(0x8e,0x00); ds1302write_byte(0xc6,0); ds1302write_byte(0x8e,0x80); Play(3);/*/ DS18B20 driversbit io_DQ=P06;#define DQ_HIGH io_DQ=1;#define DQ_LOW io_DQ=0;#define DQ_READ io_DQunsigned char Temperat
13、ure4;void Delay_10Us (unsigned int Count)while(-Count)_nop_();/*/unsigned char Ds18b20_Init(void)unsigned char Flag;DQ_HIGH Delay_10Us(3);DQ_LOW Delay_10Us(80);DQ_HIGH Delay_10Us(15);Flag=DQ_READ;return Flag;/*/void Write_f(unsigned char cmd)unsigned char i;for(i=8;i>0;i-) EA=0;DQ_LOWDQ_READ=cmd&
14、amp;0x01;Delay_10Us(5);DQ_HIGHEA=1;cmd>>=1;/*/unsigned char Read_f(void)unsigned char Read_Value,i;for (i=8;i>0;i-) EA=0;DQ_LOWRead_Value>>=1;DQ_HIGHif (DQ_READ=1) Read_Value|=0x80;EA=1;Delay_10Us(3);return Read_Value;/* */unsigned int Read_Temp(void)unsigned char Temp_H, Temp_L;unsig
15、ned int Return_Temp;EA=0; / close interrupt;Ds18b20_Init();Write_f(0xcc);Write_f(0x44);Ds18b20_Init();Write_f(0xcc);Write_f(0xbe);Temp_L=Read_f();Temp_H=Read_f();EA=1;Return_Temp=Temp_H;Return_Temp<<=8;Return_Temp|=Temp_L;return Return_Temp;/* */void Temperature_Update(void)unsigned char T_fla
16、g=0;unsigned int Temp_Dat;float Temp;Temp_Dat=Read_Temp();if(Temp_Dat&0xf000) T_flag=1; Temp_Dat=Temp_Dat+1; Temp=Temp_Dat*0.0625;Temp_Dat=Temp*10;Temperature0=T_flag;Temperature1=Temp_Dat/100;Temperature2=Temp_Dat%100/10;Temperature3=Temp_Dat%10;/*/void Timer0_Init(void)TMOD|=0x01;TH0=T0_H;TL0=
17、T0_L;EA=1;ET0=1;TR0=1;/*/bit T_10S,T_1S;bit S;/ shining flagbit pp=1; / open or close :unsigned int ms1,ms2,ms3;uchar Bit;/ Number Led select0-9,uchar code Disp_NumCode=0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8, 0x80,0x90, / dp-a P07-P00 0xC6, /c 10 0xc8,0x86,0xc0, /NEO 11-13 0x92,0xc6,0x88, / S,C,A
18、14-16 0xa1,0x8c,0x8e, / d,p,F17-190xff,/ " " 200xc7,0xf7/ L 21 _ 22;/* uchar code Open_Logo=11,12,13,20;uchar code S_C=14,22,15,20;uchar code S_A=14,22,16,20;uchar code d_p=17,22,18,20;uchar code BELL=17,12,21,21;uchar code ON= 20,13,11,20;uchar code OFF=20,13,19,19;void Put_In(uchar *P)uc
19、har a;for (a=0;a<4;a+)Disp_Buffa=Pa;/* */void Timer0_Isr(void) interrupt 1TH0=T0_H; /4msTL0=T0_L;Disp=0xff;/* switch(Bit) case 0 : NumLed_Bit=0xfe; break;case 1 : NumLed_Bit=0xfd; break;case 2 : NumLed_Bit=0xfb; break;case 3 : NumLed_Bit=0xf7; break;case 4 : NumLed_Bit=0xf3; break; / display : de
20、fault : break;*/switch(Bit) case 0 : 共陽(yáng)是 0X01 以下都是要改/0X00if(SB=0)if (S) NumLed_Bit=0x01;if(S=0) NumLed_Bit=0x00;else NumLed_Bit=0x01;/0X01/ 如break;case 1 : /0X02/0X00if (S)NumLed_Bit=0x02;if(S=0) NumLed_Bit=0x00;else NumLed_Bit=0x02; / 0X02break;case 2 : if(SB=2)if (S)NumLed_Bit=0x04;if(SB=1)/0X04/0
21、X00/0X08/0X00case 3 : if(SB=3)if (S)NumLed_Bit=0x08;if(S=0)NumLed_Bit=0x00;if(S=0) NumLed_Bit=0x00;else NumLed_Bit=0x04; /0X04 break;else NumLed_Bit=0x08; /0X08 break;case 4 : 0X0C0X04if(T=0|TT=0) NumLed_Bit=0x0c; / display if( T | TT ) NumLed_Bit=0x04; / display break;default : break;if(Bit<4) D
22、isp=Disp_NumCodeDisp_BuffBit;else if(pp=1)if (T=0|TT=0) if(current_time.second%2) Disp=0x7f;else Disp=0xff; if( T | TT ) Disp=0x7f;else Disp=0xff;/ close :if(+Bit>4) Bit=0;/*/void Timer1_Init(void)TMOD|=0x10;TH1=T1_H; /20msTL1=T1_L;EA=1;ET1=1;TR1=1;/*/uchar Key_Time;void Timer1_Isr(void) interrup
23、t 3TH1=T1_H;TL1=T1_L;if(Key!=0xff) Key_Time+;if(+ms1>ST) ms1=0; S=S; /when set time Shining bit if(+ms2>=50) ms2=0;T_1S=1; if(+ms3>500) ms3=0; T_10S=1;/* */void DelayM(unsigned int a)/-? 1MS/?unsigned char i;while(a-)for(i = 0; i < 125; i+)/i ?0?125,CPU?1?/* */void Play(uchar t)uchar i;s
24、witch(t) case 1:Beep=0;DelayM(100); break;case 2:Beep=0;DelayM(400);Beep=1;DelayM(500);Beep=0;DelayM(100); break;case 3:for(i=0;i<20;i+)Beep=0;DelayM(100);Beep=1;DelayM(100);Beep=0;DelayM(100);Beep=1;DelayM(500); break;default : break;Beep=1;/* */uchar Key_Scan(void)static bit Key_Down;static uch
25、ar K;uchar K_Value=0;if(Key_Time>250) Key_Time=3; if(Key_Time>=3&&Key_Down=0)Key_Time=0;Key_Down=1; switch(Key)case0xfe: K=1; break;case0xfd: K=2; break;case0xfb: K=3; break;case0xf7: K=4; break;default :K=0; break;if(Key=0xff&&Key_Down=1)Key_Down=0;K_Value=K;Play(1);return K_V
26、alue;/* void Disp_Time(void)Disp_Buff3=current_time.minute%16;Disp_Buff2=current_time.minute/16;Disp_Buff1=current_time.hour%16;Disp_Buff0=current_time.hour/16;/* */void Disp_Temperature_3bit(void)Disp_Buff3=20;Disp_Buff2=10; / display 'c'Disp_Buff1=Temperature2;Disp_Buff0=Temperature1;/* vo
27、id Disp_Temperature_4bit(void)Disp_Buff3=Temperature3;Disp_Buff2=10; / display cDisp_Buff1=Temperature2;Disp_Buff0=Temperature1;*/uchar Select_M=4;void MENU (void)uchar K;char Menu=0;pp=0; / close ':'while(Menu!=4)K=Key_Scan();switch (Menu)case 0 : Put_In(S_C); break;case 1 : Put_In(S_A); br
28、eak;case 2 : Put_In(d_p); break; case 3 : Put_In(BELL); default : break;if(K=Key3) Menu=4;if(K=Key2) Menu=(Menu+1)%4; if(K=Key1) Select_M=Menu; Menu=4; pp=1;/* */void Set_Time(void)bit Set_Flag=1; / set time flaguchar K;SB=0;Disp_Time();T=0;TT=0;while(Set_Flag)K=Key_Scan();if(K=Key1) switch(SB)case
29、0 : if(Disp_Buff1>3)Disp_Buff0=(Disp_Buff0+1)%2;elseDisp_Buff0=(Disp_Buff0+1)%3;case 1 : break;if(Disp_Buff0=2)Disp_Buff1=(Disp_Buff1+1)%4;elseDisp_Buff1=(Disp_Buff1+1)%10; break;case 2 : Disp_Buff2=(Disp_Buff2+1)%6;case 3 :break;Disp_Buff3=(Disp_Buff3+1)%10;break;default :break; if(K=Key2) SB= (
30、SB+1)%4; if(K=Key3) Set_Flag=0; SB=4; if(K=Key4) Set_Flag=0; SB=4; Write_Time(); T_10S=0; /*/void Write_Ds1302Ram(uchar address,uchar dat)ds1302write_byte(0x8e,0x00);ds1302write_byte(address,dat);ds1302write_byte(0x8e,0x80);/*/uchar dp; / display modle select bitvoid Set_Dp(void)bit dp_Set=1;uchar K
31、;pp=0; / close ':'/dp=ds1302read_byte(0xc3);while(dp_Set)K=Key_Scan();switch(dp)case 1 : Put_In(ON); break;case 0 : Put_In(OFF); break; default : break; if(K=Key3) dp_Set=0; if(K=Key2) dp=(dp+1)%2;if(K=Key1) dp_Set=0;Write_Ds1302Ram(0xc2,dp); T=0; TT=0; T_10S=0; pp=1;/*/uchar Bell_State;void
32、 Set_Bell(void)bit Bell_Set=1;uchar K;pp=0;/Bell_State=ds1302read_byte(0xc5);while(Bell_Set)K=Key_Scan();switch(Bell_State)case 1 : Put_In(ON); break;case 0 : Put_In(OFF); break;default : break;if(K=Key3) Bell_Set=0;if(K=Key2) Bell_State=(Bell_State+1)%2;if(K=Key1) Write_Ds1302Ram(0xc4,Bell_State);
33、Bell_Set=0; T=0; TT=0; T_10S=0; pp=1;void Set_Alarm(void)static bit First_Alarm_Set=0;bit Set_Flag=1; / set time flag uchar K;SB=0;T=0;TT=0;if(First_Alarm_Set)Disp_Buff0=ds1302read_byte(0xc9)/16; /alarm hourDisp_Buff1=ds1302read_byte(0xc9)%16;Disp_Buff2=ds1302read_byte(0xcb)/16; /alarm minuteDisp_Bu
34、ff3=ds1302read_byte(0xcb)%16;else Disp_Time();while(Set_Flag)K=Key_Scan();if(K=Key1)switch(SB)case 0 : if(Disp_Buff1>3)Disp_Buff0=(Disp_Buff0+1)%2;elseDisp_Buff0=(Disp_Buff0+1)%3; break;case 1 : if(Disp_Buff0=2)Disp_Buff1=(Disp_Buff1+1)%4;elseDisp_Buff1=(Disp_Buff1+1)%10; break;case 2 : Disp_Buff2=(Disp_Buff2+1)%6; break;case 3 : Disp_Buff3=(Disp_Buff3+1)%10; default : break;break; if(K=Key2) SB= (SB+1)%4; if(K=Key3) Set_Flag=0; S
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- TrkA-IN-10-生命科學(xué)試劑-MCE
- 診斷學(xué)胸膜腔穿刺術(shù)
- RIPK3-IN-5-生命科學(xué)試劑-MCE
- 科學(xué)防疫 健康成長(zhǎng)
- 交通運(yùn)輸行業(yè)人才需求與培養(yǎng)模式變革趨勢(shì)研究報(bào)告
- 初中信息技術(shù)課件比賽
- 保健知識(shí)培訓(xùn)課件
- 學(xué)前兒童健康常識(shí)
- 俄羅斯課件英文作文
- 二零二五年度WPS借款合同模板企業(yè)信用評(píng)級(jí)版
- GB/T 15056-2017鑄造表面粗糙度評(píng)定方法
- GB/T 13912-2020金屬覆蓋層鋼鐵制件熱浸鍍鋅層技術(shù)要求及試驗(yàn)方法
- 天然氣泄漏應(yīng)急演練方案及總結(jié)
- GA 254-2009警服襯衣
- 化學(xué)水處理安全檢查表
- DB34-T 4102-2022廢舊鋰離子動(dòng)力蓄電池貯存安全技術(shù)條件-高清現(xiàn)行
- 景陵峪構(gòu)造報(bào)告構(gòu)造地質(zhì)學(xué)
- GB∕T 8163-2018 輸送流體用無(wú)縫鋼管
- T∕ASC 17-2021 電動(dòng)汽車(chē)充換電設(shè)施系統(tǒng)設(shè)計(jì)標(biāo)準(zhǔn)
- 機(jī)動(dòng)車(chē)排放檢驗(yàn)檢測(cè)方法內(nèi)部審批程序
- 2MW工商業(yè)分布式光伏電站項(xiàng)目可行性研究報(bào)告
評(píng)論
0/150
提交評(píng)論