51單片機18B20溫度傳感器程序_第1頁
51單片機18B20溫度傳感器程序_第2頁
51單片機18B20溫度傳感器程序_第3頁
51單片機18B20溫度傳感器程序_第4頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、51單片機18b20溫度傳感器程序51單片機18b20溫度傳感器程序 編輯整理:尊敬的讀者朋友們:這里是精品文檔編輯中心,本文檔內(nèi)容是由我和我的同事精心編輯整理后發(fā)布的,發(fā)布之前我們對文中內(nèi)容進行仔細校對,但是難免會有疏漏的地方,但是任然希望(51單片機18b20溫度傳感器程序)的內(nèi)容能夠給您的工作和學習帶來便利。同時也真誠的希望收到您的建議和反饋,這將是我們進步的源泉,前進的動力。本文可編輯可修改,如果覺得對您有幫助請收藏以便隨時查閱,最后祝您生活愉快 業(yè)績進步,以下為51單片機18b20溫度傳感器程序的全部內(nèi)容。(完整word版)51單片機18b20溫度傳感器程序親愛的讀者:本文內(nèi)容由我和

2、我的同事精心收集整理后編輯發(fā)布到文庫,發(fā)布之前我們對文中內(nèi)容進行詳細的校對,但難免會有錯誤的地方,如果有錯誤的地方請您評論區(qū)留言,我們予以糾正,如果本文檔對您有幫助,請您下載收藏以便隨時調(diào)用.下面是本文詳細內(nèi)容.最后最您生活愉快 o(_)o /18b20單線溫度檢測的應用樣例程序includeincludeincludeintrins。hdefine uchar unsigned char#define uint unsigned int;/*/sbit seg1=p20;sbit seg2=p21;sbit seg3=p22;sbit dq=p17;/ds18b20 端口sfr datale

3、d=0x80;/顯示數(shù)據(jù)端口/*/ uchar temp;uchar flag_get,count,num,minute,second;uchar code tab=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;/7段數(shù)碼管段碼表共陽uchar str3;/*/void delay1(uchar ms);unsigned char readtemperature(void);void init_ds18b20(void);unsigned char readonechar(void);void writeonechar(unsigned c

4、har dat);void delay(unsigned int i);/*/main()tmod=0x01;/定時器設置th0=0xef;tl0=0xf0;ie=0x82;tr0=1;p2=0x00; count=0;while(1) str2=0x39;/顯示c符號 str0=tabtemp/10; /十位溫度 str1=tabtemp10; /個位溫度 if(flag_get=1) /定時讀取當前溫度 temp=readtemperature(); flag_get=0; void tim(void) interrupt 1 using 1/中斷,用于數(shù)碼管掃描和溫度檢測間隔th0=0x

5、ef;/定時器重裝值tl0=0xf0;num+;if (num=50) num=0; flag_get=1;/標志位有效 second+; if(second=60) second=0; minute+; count+;if(count=1) p2=0; dataled=str0;/數(shù)碼管掃描if(count=2) p2=1; dataled=str1;if(count=3) p2=2; dataled=str2; count=0;/*/void delay(unsigned int i)/延時函數(shù) while(i);/*/18b20初始化函數(shù)void init_ds18b20(void) u

6、nsigned char x=0; dq = 1; /dq復位 delay(8); /稍做延時 dq = 0; /單片機將dq拉低 delay(80); /精確延時 大于 480us dq = 1; /拉高總線 delay(10); x=dq; /稍做延時后 如果x=0則初始化成功 x=1則初始化失敗 delay(5);/讀一個字節(jié)unsigned char readonechar(void)unsigned char i=0;unsigned char dat = 0;for (i=8;i0;i-) dq = 0; / 給脈沖信號 dat=1; dq = 1; / 給脈沖信號 if(dq)

7、dat=0x80; delay(5); return(dat);/寫一個字節(jié)void writeonechar(unsigned char dat) unsigned char i=0; for (i=8; i0; i-) dq = 0; dq = dat&0x01; delay(5); dq = 1; dat=1; delay(5);/讀取溫度unsigned char readtemperature(void)unsigned char a=0;unsigned char b=0;unsigned char t=0;/float tt=0;init_ds18b20();writeonech

8、ar(0xcc); / 跳過讀序號列號的操作writeonechar(0x44); / 啟動溫度轉換delay(200);init_ds18b20();writeonechar(0xcc); /跳過讀序號列號的操作 writeonechar(0xbe); /讀取溫度寄存器等(共可讀9個寄存器) 前兩個就是溫度a=readonechar();b=readonechar();b4;t=b;/tt=t*0。0625;/t= tt*10+0。5; /放大10倍輸出并四舍五入return(t);結尾處,小編送給大家一段話.米南德曾說過,“學會學習的人,是非常幸福的人”。在每個精彩的人生中,學習都是永恒的

9、主題。作為一名專業(yè)文員教職,我更加懂得不斷學習的重要性,“人生在勤,不索何獲”,只有不斷學習才能成就更好的自己。各行各業(yè)從業(yè)人員只有不斷的學習,掌握最新的相關知識,才能跟上企業(yè)發(fā)展的步伐,才能開拓創(chuàng)新適應市場的需求.本文檔也是由我工作室專業(yè)人員編輯,文檔中可能會有錯誤,如有錯誤請您糾正,不勝感激!at the end, xiao bian gives you a passage. minand once said, people who learn to learn are very happy people.。 in every wonderful life, learning is an

10、eternal theme。 as a professional clerical and teaching position, i understand the importance of continuous learning, ”life is diligent, nothing can be gained”, only continuous learning can achieve better self。 only by constantly learning and mastering the latest relevant knowledge, can employees fro

11、m all walks of life keep up with the pace of enterprise development and innovate to meet the needs of the market。 this document is also edited by my studio professionals, there may be errors in the document, if there are errors, please correct, thank you!此處將被文件名替換 編輯整理:尊敬的讀者朋友們:這里是精品文檔編輯中心,本文檔內(nèi)容是由我和我的

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論