【正文】
print1(0x8c,0+0x30)。 } if(s4num==3) { print(0x80,inteset)。 print1(0xcb,h_shi+0x30)。 else print1(0xc9,0x20)。 print1(0x80+10,0x20)。 } if(s4num==2) { print(0x80,hunset)。 print1(0xcb,0x2e)。 else print1(0xc8,0x20)。 print1(14,0+0x30)。 print1(0x8e,0x43)。 if(s4==0) { s4num++。 write_(0x80+11)。 if(inteset1==25) inteset1=0。 if(s2==0) { while(!s2)。 write_(0x80+11)。 if(hunset1==90) hunset1=10。 if(s2==0) { while(!s2)。 write_(0x80+11)。 if(tempset1==40) tempset1=15。 if(s2==0) { while(!s2)。 } if(s1num==5) { s1num=0。 print1(0x80+13,0+0x30)。 } if(s1num==3) { write_(0x01)。 print1(0x8d,0x25)。 delay(20)。 print1(0x80+12,0+0x30)。 if(s1num==1) { write_(0x01)。}////////////////////////////////////////////////////////////void keyscan() //鍵盤掃描函數(shù){ rd=0。 sge=t1%10。 }void print1(uchar a,uchar t) //輸出18b20數(shù)據(jù)到1602{ write_(a)。 while(*str!=39。 delay(10)。 delay(10)。 inteset1=15。 lcden=0。 P0=date。}void write_data(uchar date) //lcd寫數(shù)據(jù)函數(shù){ lcdrs=1。 delay(10)。 //個(gè)位數(shù)}///////////////////////////////////////////////////////////void write_(uchar ) //lcd寫命令函數(shù){ lcdrs=0。 //讀數(shù)完畢 hun1=hun2/。 //稍延時(shí),等待讀完數(shù) delay(20)。 wr = 1。 wr = 1。 //讀數(shù)完畢 i_bai = inte1/100。 _nop_()。 wr = 0。 }/////////////////////////////////////////////////////////////void inteadc0804() //光照度adc轉(zhuǎn)換子程序與數(shù)據(jù)處理{ rd = 1。 t_ge=y/100。 t_bai=(uint)temp1/10000。 T_H=T_Hamp。 k=T_Hamp。 tmpwritebyte(0xcc)。 tmpwritebyte(0xcc)。 uchar T_H=0。 i++。 } else { DS=0。i++。0x01。 bit testb。 dat=(j7)|(dat1)。 dat=0。 i=8。 //i++ for delay 小延時(shí)一下 DS=1。}bit tmpreadbit(void) //read a bit 讀一位{ uint i。 while(i0)i。y)。 for(x=z。sbit lcdrs=P3^5。sbit cs2=P3^1。sbit relay1=P1^5。sbit s1=P1^0。uchar tempset1,s1num,s4num,hunset1,hun1,hun2,inteset1,inte1。uchar code hunset[]={hunset: }。systemElectronic Information Engineering, Department of Electronic Information Engineering118542007050 Pan Xiaoqi Teacher: Yu Jianming【Abstract】The system consists of microcontroller STC89C52, the temperature detection circuit, humidity detection circuit, light detection circuit, the keyboard scanning circuit, clock circuit, sensor circuit and relay control circuit and other ponents. System uses STC89C52 SCM, the features of which as follows: strong function, low power consumption, low prices, stable and reliable, widely used, versatile and so on. The thesis mainly focus on: the base block diagram, working principle and the design of relay control which use STC89C52 microcontroller as the core to collect, conduct, display the data of the air temperature, soil humidity, illuminance and so on. The system use Realtime and continuous detection, display intuitively and control automatically on soil moisture, ambient temperature, illuminance in the process of plant growth. To overe the defects from the traditional manual methods of measurement which can not measure continuously, save the amount of work, avoid omissions or unnecessary losses that caused by errors. 【Key words】 SCM, humidity sensors, digital temperature sensors, light dependent resistor, relay control. 附錄1 電子元器件明細(xì)表類 型封 裝型 號(hào)數(shù)量備 注瓷片電容1042 瓷片電容302 瓷片電容1502 電解電容2200uF1 電解電容10uF1 電位器RP310K1 插針HDR1X22p4 插針HDR1X33p1 插針HDR1X916p1 三極管BCYW3IN54013二極管IN40078 發(fā)光二極管LED1LED13電阻576K1 電阻50K1 電阻3K3電阻1K8 電阻909K1電阻10K15 光敏電阻MG45141液晶模塊HDRX16LCD16021 集成電路N020ADC08042 集成電路40P6STC89C521 集成電路DIP08TLC5551 集成電路Header 2HHS11011 集成電路Header 3HDS18B201 穩(wěn)壓電路T03BLM78051 按鍵SWKEP ()12晶振XTAL1 附錄2:系統(tǒng)總體電路圖:::附錄3:實(shí)物圖系統(tǒng)實(shí)物圖1系統(tǒng)實(shí)物圖2系統(tǒng)實(shí)物圖3附錄4:系統(tǒng)源代碼程序:/*項(xiàng) 目(Project) :基于單片機(jī)的溫室光溫濕度自動(dòng)控制系統(tǒng)創(chuàng) 建 人 (Author) : 日 期 (Data) :201111編 譯 器 (Complie) :keil 3 版 本 :單 片 機(jī) (MCU type):STC89C52RC注意事項(xiàng)(Attention):修改時(shí)間:*/ include includeincludeincludedefine uchar unsigned chardefine uint unsigned intdefine T_cont 。automatic monitoring and control 鍵盤掃描子程序流程如圖53圖53 鍵盤掃描流程圖 鍵盤掃描子程序一開始先掃描按鍵,判斷是否有按鍵被按下,確定有按鍵被按下時(shí)判斷被按下的是哪個(gè)按鍵,如果是按鍵S1,系統(tǒng)將進(jìn)入設(shè)置模式,這時(shí)按鍵S2和S3被啟用,進(jìn)入那個(gè)參數(shù)的設(shè)置取決于按鍵S1被按下的次數(shù),S1被按下一次,進(jìn)行溫度值設(shè)置,S1被按下兩次,進(jìn)行濕度值設(shè)置,S1被按下三次,進(jìn)行光照度設(shè)置,當(dāng)按下第四次,返回正常顯示,按鍵S2和S3被禁用。(4)各項(xiàng)參數(shù)的繼電器控制。二極管起保護(hù)作用,防止繼電器產(chǎn)生的感應(yīng)電動(dòng)勢燒壞三極管或繼電器。繼電器驅(qū)動(dòng)就是一個(gè)典型的、簡單的功率驅(qū)動(dòng)環(huán)節(jié)。這樣的方式可以方便鍵盤掃描部分的的編程。與單片機(jī)的鏈接電路如圖44:圖44 LCD1602與單片機(jī)的連接電路圖 為了確保系統(tǒng)中的電路溫度可靠工作,復(fù)位電路[9]是必不可少的部分 ,其第一功能就是低電平復(fù)位,低電平復(fù)位是在通電瞬間通過充電來實(shí)現(xiàn)的。數(shù)字溫度傳感器的測量電路如圖42所示:圖42 溫度測量電路圖 系統(tǒng)采用價(jià)格低廉的光敏電阻測量光照度,因其沒有良好的線性度,所以只能大致的測量。HS1101/HS1100作為電容變量接在555的TRIG與THRES兩引腳上,引腳7用作電阻R20的短路。圖34 光照度控制流程圖 STC89C52特點(diǎn)(1)它是MCS51系列單片機(jī)的派生產(chǎn)品,在指令系統(tǒng)、硬件結(jié)構(gòu)和片內(nèi)資源上與標(biāo)準(zhǔn)8052單片機(jī)完全兼容,DIP40封裝系列與8051兼容均為PintoPin,使用時(shí)容易掌握; (2)高速(最高時(shí)鐘頻率90 MHz)、低功耗、價(jià)格低、穩(wěn)定可靠、應(yīng)用廣泛、通用性強(qiáng),在系統(tǒng)/在應(yīng)用可編程(ISP,IAP),不占用戶資源。 若一開始檢測的光照度在適宜范圍,單片機(jī)將維持現(xiàn)有狀態(tài)。(3) 信號(hào)處理 由并行口 LCD液晶顯示屏和繼電器控制電路組成。系統(tǒng)可通過按鍵人為地設(shè)定合適的參數(shù),便于根據(jù)不同的植被的環(huán)境中使用。靈敏度和半導(dǎo)體材料、以及入射光的波長有關(guān),價(jià)格低廉,性價(jià)比高。但價(jià)格昂貴,性價(jià)比不高,且不易購買。例如+125℃的數(shù)字輸出為07D0H (正溫度直接把16進(jìn)制數(shù)轉(zhuǎn)成10進(jìn)制即得到溫度值 )。 綜合比較方案一和方案二,兩方案都可以滿足設(shè)計(jì)所要求的精度溫度要求,但方案一的后續(xù)電路復(fù)雜,需要經(jīng)過放大,數(shù)模轉(zhuǎn)換等步驟,增加了設(shè)計(jì)的復(fù)雜度和成本,并需要占用單片機(jī)較多的I/O口。AD590為電流型傳感器溫度每變化1℃其電流變化1uA在35℃和95℃ 。AD590溫度傳感器是美國模擬器件公司生產(chǎn)的單片集成兩端感溫電流源。因此,我們選擇方案二作為本設(shè)計(jì)的濕度傳感器。這種傳感器只限于一定范圍內(nèi)使用時(shí)具有良好的線性度。電容式、電阻式和濕漲式濕敏元件分別是根據(jù)其高分子材料吸水