基于單片機的數(shù)字溫度計c程序(Microcontroller based digital thermometer C program)_第1頁
基于單片機的數(shù)字溫度計c程序(Microcontroller based digital thermometer C program)_第2頁
基于單片機的數(shù)字溫度計c程序(Microcontroller based digital thermometer C program)_第3頁
基于單片機的數(shù)字溫度計c程序(Microcontroller based digital thermometer C program)_第4頁
基于單片機的數(shù)字溫度計c程序(Microcontroller based digital thermometer C program)_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、基于單片機的數(shù)字溫度計c程序(MicrocontrollerbaseddigitalthermometerCprogram)#包括reg52?!?包括信息?!?定義unsignedchar函數(shù)#unsignedint定義單元#定義delaynop()_nop_();_nop_();_nop_();_nop_();公司DQP22;普通雙=P26;/定義鎖存器鎖存端普通焊接=P27;普通RS=P35;/定義1602液晶RS端公司lcden=P34;/定義1602液晶lcden端P3了S1=0;/定義按鍵-功能鍵公司S2=P31;/定義按鍵-增加鍵P3了S3=2;/定義按鍵-減小鍵P3了S4=6;/

2、鬧鐘查看鍵P3了RD=7;普通嗶=P23;/定義蜂鳴器端函數(shù)代碼temp_disp_title=“當(dāng)前溫度:“;函數(shù)current_temp_display_buffer=“臨時”;函數(shù)代碼alarm_temp=“報警溫度高低”;函數(shù)alarm_hi_lo_str=“嗨:Lo:“;函數(shù)temp_data2=0 x00,0 x00;函數(shù)temp_alarm2=0 x00,0 x00;函數(shù)顯示5=0 x00,0 x00,0 x00,0 x00,0 x00;函數(shù)顯示3=0 x00,0 x00,0 x00;函數(shù)代碼df_table=0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9;函數(shù),

3、=0;/當(dāng)前讀取的溫度整數(shù)部分函數(shù)temp_value=0 x00,0 x00;/從DS18B20讀取的溫度值函數(shù)display_digit=0,0,0,0;/待顯示的各溫度數(shù)位點ds18b20_is_ok=1;/傳感器正常標(biāo)志/-延時/1/-無效的極限(個X)我的函數(shù);當(dāng)(x)為(i0;i200;i+);/-延時/2/-虛空Delay(個X)(x);/-/忙檢查/-無效write_com(UCHARCOM)/液晶寫命令函數(shù)RS0;lcden=0;P0=COM;極限(5);lcden=1;極限(5);lcden=0;write_lcd_data(void函數(shù)日期)/液晶寫數(shù)據(jù)函數(shù)RS1;lcd

4、en=0;P0=日期;極限(5);lcden=1;極限(5);lcden=0;/-/設(shè)置液晶顯示位置/-無效set_disp_pos(ucharPos)write_com(POS|0 x80);/-/液晶初始化/-無效initialize_lcd()函數(shù)數(shù);RD=0;/軟件將矩陣按鍵第4列一端置低用以分解出獨立按鍵班杜拉=0;/關(guān)閉兩鎖存器鎖存端,防止操作液晶時數(shù)碼管會出亂碼維拉=0;lcden=0;write_com(0X38);/初始化1602液晶write_com(0 x0c);write_com(0 x06);write_com(0 x01);write_com(0 x80);/設(shè)置顯

5、示初始坐標(biāo)對于(num=0;數(shù)14;數(shù)+)/顯示年月日星期write_lcd_data(temp_disp_title民);極限(5);/-/函數(shù)功能:初始化DS18B20/出口參數(shù):現(xiàn)狀DS18B20是否復(fù)位成功的標(biāo)志/-init_ds18b20()函數(shù)函數(shù)的狀態(tài);/儲存DS18B20是否存在的標(biāo)志,狀態(tài)=0,表示存在;狀態(tài)=1,表示不存在DQ1;Delay(8);/6微秒略微延時約先將數(shù)據(jù)線拉高DQ0;Delay(90);/再將數(shù)據(jù)線從高拉低,要求保持480960us600/略微延時約微秒以向DS18B20發(fā)出一持續(xù)480960us的低電平復(fù)位脈沖DQ1;Delay(8);/釋放數(shù)據(jù)線(將

6、數(shù)據(jù)線拉高)/延時約30us(釋放總線后需等待1560us讓DS18B20輸出存在脈沖)狀態(tài)=DQ;Delay(100);Todetectwhethertheoutputofthemicrocontroller/presencepulse(DQ=0saidtherewasenoughlongtimedelay)/,waitingfortheexistenceofoutputpulse.DQ=1;/datalinespulledReturnstatus;/returntestsuccess/-/function:readabyteExportparameters:dat-/readdata/-U

7、char,ReadOneByte()Uchar,I,dat=0;DQ=1;(_nop_);/thefirstdatalineup/waitforamachinecycleFor(i=0;i=1;(_nop_);/waitforamachinecycleDQ=1;/datalineartificialpullup,readyforthedetectionofDS18B20MCUoutputlevel_nop_(_nop_);();/delayofabout6us,sothatthehostsamplingin15USIf(DQdat|=0 x80);/ifthereaddatais1,willb

8、e1inDAT,ifthe0willremaintheoriginalvalueunchanged.Delay(30);/3usdelay,theremustbemorethan1USoftherecoveryperiodbetweentworeadtimingDQ=1;/datalinespulled,readyforthenextdatareadReturndat;/-/function:writeabyteEntranceparameters:dat-/datatobewritten/-VoidWriteOneByte(ucharDAT)Uchari;For(i=0;i=1;/datin

9、the1bitbinarydata./-/function:readthetemperaturevalueEntranceparameters:/-Void,Read_Temperature()If(Init_DS18B20)(/DS18B20=1)faultDS18B20_IS_OK=0;ElseWriteOneByte(0 xCC);/readserialnumbercolumnnumberoperationskipWriteOneByte(0 x44);/converttemperature(Init_DS18B20);/initializeDS18B20WriteOneByte(0 x

10、CC);/readserialnumbercolumnnumberoperationskipWriteOneByte(0 xBE);/readthetemperatureregister,thefirsttwoarelowandhightemperatureTemp_Value0=ReadOneByte(8);/lowtemperatureTemp_Value1=ReadOneByte(hightemperature);/8DS18B20_IS_OK=1;/-/function:displaythecurrenttemperatureinLCD/entranceparameters:/-Voi

11、d,Display_Temperature()Uchari;/delayvalueandnegativeidentificationUchar,t=150,ng=0;5all1/high(0 xF8)isnegative,negativecounterplus1,andsetthenegativesignIf(Temp_Value1&0 xF8)=0 xF8)Temp_Value1=Temp_Value1;Temp_Value0=Temp_Value0+1;If(Temp_Value0=0 x00Temp_Value1+);/plus1ifthelowbyteis00bitsthatcarry

12、,thenaddedtothehighbyteNg=1;/the1negativesignDisplay_Digit0=df_TableTemp_Value0&0 x0F;/findthedecimalparttemperature/getthetemperature(highbyteintegerpartofthelower3andthelowbyteinthehigh4bitunsigned)CurrentT=(Temp_Value0&0 xF0)(4)|(Temp_Value1&0 x07)4);/integerpartisdecomposedinto3bitdigitaltodispl

13、ayDisplay_Digit3=CurrentT/100;/100digitCurrentT/100;Display_Digit2=CurrentT%100/10;/tenDisplay_Digit1=CurrentT%10;/A/LCDdisplayrefreshbufferCurrent_Temp_Display_Buffer11=Display_Digit0+0;/thefirst0willbeconvertedintotheinteger48,thenaddthedigitalfront,GetstheASCIIcharacterofthecorrespondingnumberCur

14、rent_Temp_Display_Buffer10=.;Current_Temp_Display_Buffer9=Display_Digit1+0;/ACurrent_Temp_Display_Buffer8=Display_Digit2+0;/tenCurrent_Temp_Display_Buffer7=Display_Digit3+0;/100Nottodisplay0/highIf(Display_Digit3=0)Current_Temp_Display_Buffer7=;Forthe0timeandhigh/high0times,donotshowhighIf(Display_D

15、igit2=0andDisplay_Digit3=0)Current_Temp_Display_Buffer8=;/negativesymbolsaredisplayedintherightpositionIf(NG)If(Current_Temp_Display_Buffer8=)Current_Temp_Display_Buffer8=-;Elseif(Current_Temp_Display_Buffer7=)Current_Temp_Display_Buffer7=-;ElseCurrent_Temp_Display_Buffer6=-;/inthefirstrowshowtitleSet_Disp_Pos(0 x00);For(i=0;i16;i+)Write_LCD_Data(Temp_Disp_Titlei);Set_Disp_Pos(0 x40);/inthesecondlineshowsthecurrenttemperatureFor(i=0;i16;i+)Write_LCD_Data(Current_Temp_Display_Bufferi);/temperaturedisplaysymbols/Set_Disp_Pos(0 x4D);Write_LCD_Data(0 x00);Set_Disp_Pos(0 x4D);Write_LCD

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論