




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、/頭文件#include <STC12C5A60S2.h>#include <intrins.h>#include <key.h> #include <adc0804.h> #include <lcd1602.h> #include <DHT11.h> #define uchar unsigned char #define uint unsigned intuint HIGH,LOW;uchar flag=0;uchar dj_flag=0;uchar countt;char level=0;uint HHH=0;sbit
2、 beep=P23;uchar counter1=0;uchar counter11=1;uchar num11=0;int W=40;int S=80;int G=200;void key() if(K1=0) /K1 menu counter11+; if(counter11>3) counter11=0; while(K1=0); if(counter11=0) lcd_xy_puts(4,0," ");lcd_xy_puts(10,0," ");lcd_xy_puts(5,1," ");if(K3=0) flag=0;l
3、cd_init(); if(counter11=1)/設(shè)置W值 lcd_xy_puts(4,0,"<");lcd_xy_puts(10,0," ");lcd_xy_puts(5,1," "); if(K2=0) /K2 + W=W+1; if(W>99)W=99; while(K2=0); if(K3=0) /K3 - W=W-1; if(W<1)W=0; while(K3=0); if(counter11=2)/設(shè)置S值 lcd_xy_puts(4,0," ");lcd_xy_puts(10,0
4、,"<");lcd_xy_puts(5,1," "); if(K2=0) /K2 + S=S+1; if(S>99)S=99; while(K2=0); if(K3=0) /K3 - S=S-1; if(S<1)S=0; while(K3=0); if(counter11=3)/設(shè)置H值 lcd_xy_puts(4,0," ");lcd_xy_puts(10,0," ");lcd_xy_puts(5,1,"<"); if(K2=0) /K2 + G=G+10; if(G&
5、gt;990)G=990; while(K2=0); if(K3=0) /K3 - G=G-10; if(G<10)G=0; while(K3=0); uchar i,j;uint dianya1,dianya2,dianya3;void main(void) K1=K2=K3=1; lcd_init(); dj_flag=10; counter11=0; W=30;S=50;G=200; JDQ1=JDQ2=1; while(1) /溫度檢測處理與顯示 dianya1 = DHT11_Tem(); dianya1=dianya1%100; lcd_xy_puts(0,0,"W
6、D:"); lcd_goto_xy(3,0);lcd_number(dianya1%100/10); lcd_number(dianya1%10); /濕度數(shù)據(jù)讀取與轉(zhuǎn)換 dianya2 = DHT11_Hum(); dianya2=dianya2%100; lcd_xy_puts(8,0,"SD:"); lcd_goto_xy(11,0);lcd_number(dianya2%100/10); lcd_number(dianya2%10); /光線數(shù)據(jù)讀取與轉(zhuǎn)換 ad0804(); dianya3=(num*jizhun/256)*100; /123 lcd_x
7、y_puts(0,1,"GX:"); lcd_goto_xy(3,1);lcd_number(dianya3%1000/100); lcd_number(dianya3%100/10); lcd_number(dianya3%10); if(K1=0) flag+;if(flag>1) flag=0;/lcd_init(); while(K1=0); if(flag=1) lcd_init(); while(flag=1) lcd_xy_puts(0,0,"W-");lcd_goto_xy(2,0);lcd_number(W/10); lcd_nu
8、mber(W%10);lcd_xy_puts(6,0,"S-");lcd_goto_xy(8,0);lcd_number(S/10); lcd_number(S%10);lcd_xy_puts(0,1,"G-");lcd_goto_xy(2,1);lcd_number(G%1000/100);lcd_number(G%100/10); lcd_number(G%10); key(); if(dianya1>W) beep=LED1=JDQ1=0;LED2=LED3=1; else if(dianya2>S) beep=LED2=JDQ1=0;
9、LED1=LED3=1; else if(dianya3>G) beep=JDQ2=LED3=0;LED2=LED1=1; else beep=LED1=LED2=LED3=JDQ2=JDQ1=1; Key:#ifndef _key_H_#define _key_H_#define uchar unsigned char#define uint unsigned intsbit K1=P33;sbit K2=P34;sbit K3=P35;sbit LED1=P22;sbit LED2=P21;sbit LED3=P20;sbit JDQ1=P37;/溫度 濕度sbit JDQ2=P24
10、;/光線void delay1(uint a)/數(shù)碼管顯示部分延時函數(shù) unsigned int i; while( -a != 0) for(i = 0; i < 200; i+); /一個 ; 表示空語句,CPU空轉(zhuǎn)。 /i 從0加到125,CPU大概就耗時1毫秒 #endifDHT11:#ifndef _DHT11_H_ #define_DHT11_H_ #define uchar unsigned char #define uint unsigned int /*/ /* 引 腳 定 義 */ /*/ sbit DHT = P36; /管腳定義,DHT11總線輸入輸出; /*/
11、/* 變 量 定 義 */ /*/ uchar RH,RL,TH,TL; uchar data_byte; uchar Tem_Z,Tem_X,Hum_Z,Hum_X,Check; uint DHT11_num=0; void delays19ms()/12.000MHz unsigned char i, j, k; i = 1; j = 222; k = 197; do do while (-k); while (-j); while (-i); /延時ius void delay10us() unsigned char i; i = 27; while (-i); /*主機發(fā)出開始信號*/
12、 void DHT11_Start() DHT=1; delay10us(); DHT=0; delays19ms(); /保持電平時間大于18ms,延時20ms DHT=1; delay10us(); /延遲等待20-40us,延時20us delay10us(); delay10us(); delay10us(); DHT=1; /拉高等待DHT11響應(yīng) /DHT11接收一個字節(jié)數(shù)據(jù) uchar receive_data() uchar i,temp,count; data_byte=0; for(i=0;i<8;i+) count=2; while(!DHT)&&c
13、ount+); /等待50us低電平結(jié)束 delay10us(); /等待40us高電平,后判斷電平高低,高:DHT為1,低:DHT為0 delay10us(); delay10us(); delay10us(); temp=0; if(DHT=1) temp=1; /DHT為高:1,位為1 count=2; while(DHT)&&count+); /等待DHT高電平結(jié)束 if(count=1) break; /DHT為低:0,位為0 data_byte<<=1; /字節(jié)左移 data_byte|=temp; return data_byte; /返回讀取值 /D
14、HT11接收數(shù)據(jù) void Rec_DHT()/聲明Rec_DHT,DHT11接收數(shù)據(jù)函數(shù) uchar flag; uchar T_H,T_L,H_H,H_L,check,num_check; /定義采集參數(shù)中間變量 DHT11_Start(); /主機發(fā)出開始信號if(!DHT) /等待從機響應(yīng)信號輸出低電平 flag = 2; while(!DHT) && flag+); /判斷從機是否發(fā)出 80us 的低電平響應(yīng)信號是否結(jié)束 flag = 2; while(DHT && flag+); /判斷從機是否發(fā)出 80us 的高電平,若發(fā)出則開始采集數(shù)據(jù) H_H=
15、receive_data(); /采集濕度整數(shù)部分 H_L=receive_data(); /采集濕度小數(shù)部分 T_H=receive_data(); /采集溫度整數(shù)部分 T_L=receive_data(); /采集溫度小數(shù)部分 check=receive_data(); /采集校驗位 DHT = 1; num_check=H_H+H_L+T_H+T_L; if(num_check=check) /進行校核 Hum_Z = H_H; Hum_X = H_L; Tem_Z = T_H; Tem_X = T_L; unsigned char DHT11_Hum()/返回濕度整數(shù) unsigned
16、 char Get_back_num; Rec_DHT(); Get_back_num = Hum_Z ; return Get_back_num; unsigned char DHT11_Tem()/返回溫度整數(shù) unsigned char Get_back_num; Rec_DHT(); Get_back_num = Tem_Z ; return Get_back_num; #endifLCD1602:#ifndef _lcd1602_H_ #define_lcd1602_H_ #include <intrins.h>#define uchar unsigned char #d
17、efine uint unsigned intsbit rs= P25;sbit rw = P26;sbit ep = P27;code uchar LCDnumber="0123456789"/* - 函數(shù)名稱:delayus(); - 功能描述:延時1us左右 - 隸屬模塊:延時公共函數(shù)模塊 - 函數(shù)屬性:外部,用戶可調(diào)用 - 參數(shù)說明:uint a為1us的多少倍設(shè)置參數(shù) - 返回說明:無 */void delayus(uint a) /延時1us左右uchar b;for(;a>0;a-)for(b=12;b>0;b-);bit lcd_bz()bit
18、result;rs = 0;rw = 1;ep = 1;delayus(20);result = (bit)(P0 & 0x80);ep = 0;return result;void lcd_wcmd(unsigned char cmd)while(lcd_bz();/判斷LCD是否忙碌rs = 0;rw = 0;ep = 0;delayus(20);P0 = cmd;delayus(20);ep = 1;delayus(20);ep = 0;void lcd_wdat(unsigned char dat)while(lcd_bz();/判斷LCD是否忙碌rs = 1;rw = 0;e
19、p = 0;delayus(20);P0 = dat;delayus(20);ep = 1;delayus(20);ep = 0;/ 設(shè)置顯示位置(即寫入顯示地址),x,y均從0開始 4行液晶顯示 void lcd_goto_xy(unsigned char x, unsigned char y) unsigned char p; / p為字符顯示位置,即DDRAM中的地址 if (y=0) p = 0x00 + x; / (0,0)顯示位置為0x00 if (y=1) p=0x40+x; / (0,1)顯示位置為0x40 if (y=2) p=0x10+x; / (0,2)顯示位置為0x10
20、 if (y=3) p = 0x50 + x; / (0,3)顯示位置為0x50 lcd_wcmd(p + 0x80); / 寫入顯示地址時DB7須為高電平,加0x80 void lcd_putc(unsigned char c) / 寫字符(傳入的參數(shù)實際為所需顯示字符的地址,即液晶字符產(chǎn)生器中字符的地址) rw = 0; / RW置0,狀態(tài)為寫 rs = 1; / RS置1,寫入數(shù)據(jù) lcd_wdat(c); void lcd_puts(unsigned char *s) / 寫字符串函數(shù) while(*s) lcd_wdat(*s); s+; /* 函數(shù)名稱: display_char*
21、 入口參數(shù):x(unsigned char型),y(unsigned char型),dat(unsigned char型)* 出口參數(shù):無* 功能描述: 在具體位置顯示單個字符,x是列號,y是行號*/void lcd_xy_putc(unsigned char x,unsigned char y,unsigned char dat) lcd_goto_xy(x,y); lcd_wdat(dat);/* 函數(shù)名稱: display_string* 入口參數(shù):x(unsigned char型),y(unsigned char型),s(指針型)* 出口參數(shù):無* 功能描述: 在具體位置顯示字符串,以
22、/0結(jié)束,x是列號,y是行號*/void lcd_xy_puts(unsigned char x,unsigned char y,unsigned char *s) lcd_goto_xy(x,y); while(*s) lcd_wdat(*s); s+; void lcd_number(unsigned char a) /變量數(shù)字顯示 rw = 0; / RW置0,狀態(tài)為寫 rs = 1; / RS置1,寫入數(shù)據(jù) lcd_wdat(LCDnumbera); void lcd_init()lcd_wcmd(0x38);delayus(5);lcd_wcmd(0x0c);delayus(5);lcd_wcmd(0x06);delayus(5);lcd_wcmd(0x01);delayus(5); #endifADC0804:#ifn
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 自動駕駛法規(guī)標準化研究-洞察闡釋
- 2025智能硬件銷售合同協(xié)議范本
- 詳盡財產(chǎn)分配與子女教育撫養(yǎng)責任離婚協(xié)議
- 2025年某市區(qū)房屋租賃合同范本
- 2025個性化家具定制合同
- 2025合同范本合同審批與簽署流程詳解
- 護理實踐中的裸體護理方法
- 2025年無線通信設(shè)備的租賃合同
- 2025四川省水果種植產(chǎn)銷合同
- 武理工《水處理生物學(xué)》教學(xué)大綱
- 2025年高考作文專練(25道真題+審題立意+范文)- 2025年高考語文作文備考總復(fù)習(xí)
- 血管通路并發(fā)癥竊血綜合征
- 患者日常生活護理
- 藥物化學(xué)智慧樹知到答案2024年山西醫(yī)科大學(xué)
- 《中華民族一家親-同心共筑中國夢》隊會課件
- TCAICC 001-2024 張家界莓茶質(zhì)量等級評價
- 安徽省銅陵市義安區(qū)2023-2024學(xué)年七年級下學(xué)期期末生物題(無答案)
- 2024結(jié)腸鋸齒狀病變診斷及治療進展
- 【保險營銷策略探究文獻綜述6900字】
- 航空公司客戶價值分析數(shù)據(jù)挖掘設(shè)計
- 2024年全國能源行業(yè)供熱技能競賽考試題庫大全-中(判斷題)
評論
0/150
提交評論