DS18b20溫度傳感器_第1頁
DS18b20溫度傳感器_第2頁
DS18b20溫度傳感器_第3頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、最小的溫度顯示程序 -c51(2010-12-07 00:45:27)轉(zhuǎn)載標(biāo)簽:分類:51單片機(jī)雜談#in clude<reg52.h>#in clude<math.h>sbit DQ=P2A0;bitprese nee;un sig ned char templ,temph;char array10=0x7e,0x48,0x3d,0x6d,0x4b,0x67,0x73,0x4c,0x7f,0x4f;void Delay (un sig ned int num)/可定義延時(shí)while( -num );bit In it_DS18B20(void)DQ = 1;/DQ 復(fù)

2、位Delay(8);/稍做延時(shí)DQ = 0;/單片機(jī)將DC拉低Delay(90);/精確延時(shí)大于480usDQ = 1;/拉高總線Delay(8);presenee = DQ;/如果=0則初始化成功=1則初始化失敗Delay(100);DQ = 1;return(prese nee); /返回信號(hào),0=prese nce,1= no prese nee un sig ned int Read On eChar(void) un sig ned char i = 0;un sig ned char dat = 0;for (i = 8; i > 0; i-)DQ = 0; / 給脈沖信號(hào)d

3、at >>= 1; / 位右移DQ = 1; / 給脈沖信號(hào) 等待傳感器返回脈沖if(DQ)dat |= 0x80;Delay(4);return (dat);void WriteOneChar(unsigned char dat) unsigned char i = 0;for (i = 8; i > 0; i-)DQ = 0;DQ = dat&0x01;Delay(5);DQ = 1; dat>>=1;void Read_Temperature(void) Init_DS18B20();WriteOneChar(0xcc);WriteOneChar(0

4、x44);/ 跳過讀序號(hào)列號(hào)的操作/ 啟動(dòng)溫度轉(zhuǎn)換Init_DS18B20();WriteOneChar(0xCC);WriteOneChar(0xBE);/ 跳過讀序號(hào)列號(hào)的操作/ 讀取溫度寄存器templ = ReadOneChar(); / 溫度低 8 位temph = ReadOneChar();/ 溫度高 8 位void main() float temp; char a;Init_DS18B20();WriteOneChar(0xcc);WriteOneChar(0x44); / 啟動(dòng)溫度轉(zhuǎn)換 Init_DS18B20();WriteOneChar(0xcc);/ 溫度高 8 位W

5、riteOneChar(0xbe); / 讀取溫度寄存器 templ = ReadOneChar();/ 溫度低 8 位temph = ReadOneChar();temph&=0x07;temp=(templ>>4)|(temph<<4);temp+=(templ&0x0f)*0.0625;a= temp/10;P1=arraya;a=temp-10*a;P0=arraya;/*DS18b20 溫度傳感器p3.4 作為數(shù)據(jù)傳輸口晶振: 11.0592M*/#include<reg51.H> sbit DQ= P3八4;int tempera

6、ture ;void delay(int us) int s;for ( s=0; s<us; s+);void rst(void)DQ = 1;delay(2);DQ = 0;delay(30); / 精確延時(shí) 480960usDQ = 1;delay(8);unsigned int read(void)int i=0;unsigned int u=0;for (i=0;i<16;i+)DQ=0;u>>=1;DQ=1;if(DQ) u|=0x8000;delay(4);return (u);void write(unsigned char ku)int i=0;for (i=0;i<8;i+)DQ=0;DQ =ku&0x01;delay(3);DQ=1;ku>>=1;void read0(void)/int temperature ; unsigned int tp; unsigned int lsb;rst(); write(0xCC);write(0x44);rst();write(0xCC);write(0xBE); tp=read();lsb=(unsigned int)(tp*6.25); / tem

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論