DHT11溫濕度傳感器驅(qū)動程序(共10頁)_第1頁
DHT11溫濕度傳感器驅(qū)動程序(共10頁)_第2頁
DHT11溫濕度傳感器驅(qū)動程序(共10頁)_第3頁
DHT11溫濕度傳感器驅(qū)動程序(共10頁)_第4頁
DHT11溫濕度傳感器驅(qū)動程序(共10頁)_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上/* 本程序適用于DHT11溫濕度傳感器由于DHT11使用拉高總線的不同時常來代替0和1 0 28US 1 70us 同時數(shù)據(jù)送入1602a顯示 */#include#include#include#define Data P0/數(shù)據(jù)端口sbit RS = P24; /Pin4sbit RW = P25; /Pin5sbit E = P26; /Pin6sbit dat=P12;unsigned int shidu_h=0,shidu_l=0,wendu_h=0,wendu_l=0,i,xiaoyan=0;/定義濕度 溫度變量unsigned char code ta

2、b=0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39;/定義1602a顯示0-9unsigned int a16=0 ;void delayus(unsigned char i) /延時2uswhile(-i);void delayms(unsigned char j) /延時1mswhile(-j)delayus(125);delayus(125);delayus(125);delayus(125);/*/* 寫入命令函數(shù) 1602 */*/void WriteCommand(unsigned int c) delayms(10);/操作前短

3、暫延時,保證信號穩(wěn)定代替狀態(tài)監(jiān)測 E=0; RS=0; RW=0; _nop_(); E=1; Data=c; E=0;/*/* 寫入數(shù)據(jù)函數(shù) */*/void WriteData(unsigned char c) delayms(10);/操作前短暫延時,保證信號穩(wěn)定 E=0; RS=1; RW=0; _nop_(); E=1; Data=c; E=0; RS=0;/*/* 寫入字節(jié)函數(shù) */*/void ShowChar(unsigned char pos,unsigned int c) unsigned char p; if (pos=0x10) p=pos+0xb0; /是第二行則命令

4、代碼高4位為0xc p低兩位表示位置顯示代碼只用DDRAM前16位 else p=pos+0x80; /是第一行則命令代碼高4位為0x8 p低兩位表示位置顯示代碼只用DDRAM前16位 WriteCommand (p);/寫命令寫入數(shù)據(jù)指針確定行中哪一位顯示 WriteData (c); /寫數(shù)據(jù)/*/* 寫入字符串函數(shù) */*/void ShowString (unsigned char line,unsigned int *ptr) unsigned char l,i;/l表示行中某一位顯示 l=line4;/L為0x01時左移四位為了與b0H相加變?yōu)?xc for (i=0;i16;i+

5、) ShowChar (l+,*(ptr+i);/循環(huán)顯示16個字符/*/* 初始化函數(shù) */*/void InitLcd() WriteCommand(0x38); /display mode WriteCommand(0x38); /display mode WriteCommand(0x38); /display mode WriteCommand(0x06); /顯示光標移動位置 WriteCommand(0x0c); /顯示開及光標設(shè)置 WriteCommand(0x01); /顯示清屏void main(void)InitLcd(); /初始化LCDdelayms(30);whil

6、e(1) dat=0;delayms(18);/延時18ms拉低主線 dat=1;/主機拉高總線/*delayus(20);*/_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();while(!dat);/判斷從機是否相應(yīng)完畢相應(yīng)完畢會拉高總線while(dat);/

7、等待從機拉高總線準備開始傳送數(shù)據(jù)while(!dat);/判斷是否開始1bit 開始會拉高總線for(i=0;i8;i+)shidu_h=1; /右移1位delayus(14); /延時30us判斷是否為1if(dat)shidu_h+;while(dat);/為一則等待從機拉低總線 為零直接跳出while(!dat);/判斷是否開始1bit 開始會拉高總線for(i=0;i8;i+)delayus(14);shidu_l=1;if(dat)shidu_l+;while(dat);while(!dat);for(i=0;i8;i+)delayus(14);wendu_h=1;if(dat)wendu_h+;while(dat);while(!dat);for(i=0;i8;i+)delayus(14);wendu_l=1;if(dat)wendu_l+;while(dat);while(!dat);for(i=0;i8;i+)delayus(14);xiaoyan=1;if(dat)xiaoyan+;while(dat);while(!dat);a0=tab(wendu_h)/10;a1=tab(wendu_h)%10;a2=tab(shidu_h)/10;a3=tab(shidu_h)%1

溫馨提示

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

評論

0/150

提交評論