版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
環(huán)境測試第一節(jié)環(huán)境測試框圖第二節(jié)溫亮度測試原理第三節(jié)串行雙通道ADC0832第四節(jié)溫亮度測試軟件設(shè)計(jì)第五節(jié)濕度測試在液晶顯示器上顯示出實(shí)驗(yàn)室內(nèi)的溫度、亮度及濕度。顯示效果如圖6-1所示。
環(huán)境測試技術(shù)指標(biāo)如下:
(1)系統(tǒng)工作電壓:5V(DC)。
(2)溫度測量:分辨率:1℃。
測量范圍:10~99℃。
測量誤差:±2℃(0~50℃范圍內(nèi)的誤差)。
(3)濕度測量:分辨率:1%RH。
測量范圍:0~99%RH。
測量誤差:±20%RH。
(4)亮度測量:分三個(gè)等級:弱、適中、強(qiáng)。知識目標(biāo)·了解熱敏電阻、光敏電阻及濕度傳感器的原理。
·了解模擬傳感器的測試原理及其性能指標(biāo)。
·掌握ADC0832的作用、特點(diǎn)及引腳?!な煜DC0832的通道工作方式及其選擇。
·熟悉ADC0832的時(shí)序圖。
·熟悉矩形波頻率的測試方法。
·掌握溫度、亮度及濕度的數(shù)據(jù)處理方法。能力目標(biāo)
·認(rèn)識熱敏電阻、光敏電阻及濕度傳感器。
·正確畫出環(huán)境測試框圖及硬件電路圖。
·能夠看懂ADC0832時(shí)序圖并編寫所需函數(shù)。
·編程測試矩形波頻率。
·正確編寫溫度、亮度及濕度的數(shù)據(jù)處理函數(shù)。
第一節(jié)環(huán)境測試框圖
環(huán)境測試主要用于測試空氣溫度、空氣濕度及亮度,如圖6-2所示。測試溫度和亮度時(shí),采用的是電阻式傳感器,通過傳感器測試電路只能將被測對象轉(zhuǎn)換為模擬電壓,還需要通過ADC(模/數(shù)轉(zhuǎn)換器)將模擬電壓轉(zhuǎn)換為二進(jìn)制表示的數(shù)字信號,才能傳送給AT89S52單片機(jī)進(jìn)行數(shù)據(jù)處理,最終將結(jié)果顯示在液晶顯示器上。測試濕度時(shí),由于濕度傳感器為電容式的,將其作為多諧振蕩器的一部分,將容量的變化轉(zhuǎn)換為矩形波頻率的變化,單片機(jī)通過測量矩形波的頻率獲得濕度值。用液晶屏作為顯示器,可以同時(shí)顯示所測的3個(gè)結(jié)果。
第二節(jié)溫亮度測試原理
測試環(huán)境的溫度時(shí),傳感器件選用熱敏電阻;測試亮度時(shí),傳感器件選用光敏電阻。它們共同的特點(diǎn)為電阻式模擬傳感器。熱敏電阻為接觸式模擬溫度傳感器,它的阻值會隨被測物體溫度的變化而變化。熱敏電阻分為正、負(fù)溫度系數(shù)。溫度增加時(shí),阻值也增加,為正溫度系數(shù);溫度增加時(shí),阻值減小的則為負(fù)溫度系數(shù)。本項(xiàng)目選用的熱敏電阻為負(fù)溫度系數(shù)。光敏電阻的阻值與環(huán)境亮度的關(guān)系是固定的。光線越亮,阻值越小,稱為亮阻;光線越暗,阻值越大,稱為暗阻;亮阻與暗阻之間的差值越大,光敏電阻的性能越好。圖6-3所示為熱敏電阻、光敏電阻的外形圖及溫亮度測試電路圖。R2為熱敏電阻或光敏電阻,分壓點(diǎn)a的電壓將反映被測對象的變化。
第三節(jié)串行雙通道ADC0832
3.1ADC0832特點(diǎn)模/數(shù)轉(zhuǎn)換器ADC0832的作用是將輸入的模擬量轉(zhuǎn)換為輸出的8位數(shù)字量。其特點(diǎn)如下:(1)電源電壓,基準(zhǔn)電壓為5V,輸入模擬電壓范圍為0~5?V。(2)串行器件,逐次逼近型。(3)雙通道模擬量輸入。(4)?8位分辨率。(5)雙數(shù)據(jù)輸出。(6)轉(zhuǎn)換時(shí)間32μs。3.2ADC0832引腳圖1.引腳圖ADC0832引腳圖如圖6-4所示?!CC(VREF)——電源電壓端(基準(zhǔn)電壓端),電源為5V?!ND——接地端·CH0——模擬信號輸入通道0?!H1——模擬信號輸入通道1?!O——串行數(shù)字信號輸出端,串行輸出8位數(shù)字量?!LK——時(shí)鐘信號輸入端。·——片選信號輸入端,低電平有效。只有有效時(shí),才可以選中該芯片,進(jìn)行A/D轉(zhuǎn)換?!I—串行數(shù)據(jù)信號輸入端(或通道選擇端),用以選擇CH0、CH1兩個(gè)模擬信號輸入通道的4種工作方式。2.應(yīng)用電路ADC0832典型應(yīng)用電路如圖6-5所示。一般情況下,ADC0832與單片機(jī)通信需要4條數(shù)據(jù)線,分別是、CLK、DI和DO,如圖6-5(a)所示;但由于串行數(shù)據(jù)輸出端DO與串行數(shù)據(jù)輸入端DI在與單片機(jī)通信時(shí),不能同時(shí)有效,并且單片機(jī)的I/O接口是雙向的,所以電路設(shè)計(jì)時(shí)可以將DO和DI并聯(lián)在一起使用,這樣就只需要3條數(shù)據(jù)線,如圖6-5(b)所示;當(dāng)然,如果控制系統(tǒng)中只有一片ADC0832時(shí),也可將片選信號直接接地,只需要2條數(shù)據(jù)線。3.3ADC性能指標(biāo)1.分辨率ADC的分辨率說明了它對輸入模擬信號的分辨能力,用輸出二進(jìn)制數(shù)字信號的位數(shù)來表示。從理論上講,n位輸出的ADC可以區(qū)分2n個(gè)不同等級的輸入模擬電壓,能識別的模擬電壓的最小值為滿量程的1/2n。當(dāng)最大模擬輸入電壓一定時(shí),輸出數(shù)字信號的位數(shù)越多,分辨率越高,能識別的最小模擬電壓越低。2.轉(zhuǎn)換誤差轉(zhuǎn)換誤差表示ADC實(shí)際輸出的數(shù)字量與理論輸出數(shù)字量之間的差別。一般用最低有效位表示。3.轉(zhuǎn)換時(shí)間轉(zhuǎn)換時(shí)間是指ADC從轉(zhuǎn)換控制信號到來開始,到輸出端得到穩(wěn)定的數(shù)字信號所需要的時(shí)間。不同類型的ADC轉(zhuǎn)換速度相差甚遠(yuǎn),實(shí)際選用時(shí),應(yīng)結(jié)合分辨率、精度、誤差等方面綜合考慮。3.4溫亮度測試硬件設(shè)計(jì)圖6-6所示為溫度、亮度測試硬件電路圖,共由四部分組成,分別是溫亮度測試電路、ADC、AT89S52、12864。以溫度上升為例,分析如下:當(dāng)環(huán)境溫度上升時(shí),熱敏電阻R6阻值減小(R6為負(fù)溫度系數(shù)),分壓點(diǎn)a的電壓會隨之下降,a點(diǎn)電壓輸入給ADC0832的通道CH1,經(jīng)A/D轉(zhuǎn)換后,從DO端輸出的數(shù)字量也跟著下降,單片機(jī)AT89S52從DO端讀入該數(shù)字量后,經(jīng)溫度數(shù)據(jù)處理函數(shù)處理后,還原的實(shí)際溫度值較之前升高,并在12864上顯示出來。即:環(huán)境溫度↑→R6↓→Ua↓→Da↓→實(shí)際溫度(顯示值)↑ADC0832與AT89S52通信的數(shù)據(jù)線宜采用位尋址,約定的定義如下:sbitADCCS=P3^0;sbitADCDI=P3^3;sbitADCCLK=P3^1;sbitADCDO=P3^3;3.5ADC0832通道選擇ADC0832有兩個(gè)模擬信號輸入通道CH0、CH1,每個(gè)通道模擬信號的輸入方式又分為單端輸入和差分輸入兩種,因此兩個(gè)通道共有4種工作方式。ADC0832的4種工作方式由數(shù)字輸入端DI進(jìn)行選擇,如表6-1所示。由DI輸入3位串行控制字START、SGL、ODD,用以設(shè)定ADC0832的通道工作方式。只有通道工作方式設(shè)定后,ADC0832才可以開始模數(shù)轉(zhuǎn)換。ADC0832的3位串行控制字START、SGL、ODD的作用各不相同,如下所示:·START為開始信號,START=0,控制字無效;START=1,控制字有效。·SGL通道選擇,SGL=0,選擇CH0;SGL=1,選擇CH1?!DD輸入方式選擇,ODD=0,差分輸入;ODD=1,單端輸入。3.6ADC0832時(shí)序圖及函數(shù)1.ADC0832的工作時(shí)序ADC0832工作時(shí)序圖如圖6-7所示。ADC0832的工作步驟如下:(1)啟動ADC0832。圖6-7中,在CLK的第一個(gè)上升沿,啟動ADC0832進(jìn)行A/D轉(zhuǎn)換。首先,應(yīng)將置于低電平選中ADC0832,端的低電平應(yīng)保持到轉(zhuǎn)換結(jié)束;其次,給DI端口發(fā)送串行控制字START位(開始信號)所需的高電平,表示ADC0832開始模數(shù)轉(zhuǎn)換;最后,給CLK送出第1個(gè)時(shí)鐘脈沖,在該脈沖的上升沿處接收DI的電平;若讀到高電平,ADC0832開始工作。所以必須在時(shí)鐘上升沿到來前將DI的狀態(tài)設(shè)置好。(2)選擇通道工作方式。圖6-7中,根據(jù)串行控制字SGL位設(shè)置DI后,給CLK送出第2個(gè)時(shí)鐘脈沖,在該脈沖的上升沿處,接收DI的電平;根據(jù)SGL位選擇通道CH0還是CH1;緊接著,根據(jù)串行控制字ODD位設(shè)置DI后,給CLK送出第3個(gè)時(shí)鐘脈沖,仍在上升沿處接收DI的電平;根據(jù)ODD位選擇單端輸入還是差分輸入。串行控制字SGL、ODD根據(jù)表6-1進(jìn)行設(shè)置。在CLK第3個(gè)脈沖的下降沿處,DI端的輸入電平就失去輸入作用,變成高阻態(tài),此后DO/DI端開始利用數(shù)據(jù)輸出DO進(jìn)行轉(zhuǎn)換數(shù)據(jù)的讀取。在單片機(jī)通過DO讀取數(shù)據(jù)之前,必須先給DO/DI輸出1,才能保證讀入數(shù)據(jù)的準(zhǔn)確性。(3)讀取數(shù)據(jù)。在CLK的第4~11個(gè)下降沿,第一次輸出A/D轉(zhuǎn)換后的8位數(shù)字量。由圖6-7可知,在第4個(gè)下降沿時(shí)先輸出的是數(shù)據(jù)的最高位,依次至第11個(gè)下降沿時(shí)輸出數(shù)據(jù)的最低位,即按照先高位后低位的順序完成一個(gè)字節(jié)數(shù)據(jù)的輸出。緊接著,在CLK的第12~19個(gè)下降沿,采用與第一次相反的順序第二次輸出A/D轉(zhuǎn)換后的8位數(shù)字量。即第11個(gè)下降沿輸出數(shù)據(jù)的最低位,直到第19個(gè)下降沿的最高位時(shí),第二次數(shù)據(jù)輸出完成,也標(biāo)志著一次A/D轉(zhuǎn)換結(jié)束。ADC0832將轉(zhuǎn)換后的數(shù)字量以相反順序輸出兩次,是為了起到校驗(yàn)作用,只有兩次輸出的數(shù)據(jù)相同時(shí),才是正確的。一般只讀出第一個(gè)字節(jié)的8個(gè)數(shù)據(jù)位即能滿足要求,對于后8位數(shù)據(jù),也可以不讀。(4)結(jié)束狀態(tài)。當(dāng)一次A/D轉(zhuǎn)換結(jié)束時(shí),要將置高電平,禁止該芯片。2.ADC0832函數(shù)/*函數(shù)名:adc0832du()作用:實(shí)現(xiàn)從啟動ADC0832、選擇通道工作方式、讀取數(shù)據(jù)直至結(jié)束狀態(tài)全過程。入口參數(shù):形參tongdao:存放待轉(zhuǎn)換的通道號。tongdao=1時(shí),選擇通道0單端方式,用于亮度轉(zhuǎn)換;tongdao=3時(shí),選擇通道1單端方式,用于溫度轉(zhuǎn)換。出口參數(shù):變量shujv1:存放ADC0832轉(zhuǎn)換后的8位數(shù)字量。說明:shujv1:存放第一次讀入的8位數(shù)字量,先傳送的是位7。shujv2:存放第二次讀入的8位數(shù)字量,先傳送的是位0。*/ucharadc0832du(uchartongdao){ uchari=0; ucharshujv1,shujv2; ADCCS=0; _nop_();_nop_();ADCDI=1; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_();ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=(tongdao>>1)&0x1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=tongdao&0x01; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=1; _nop_();_nop_();ADCCLK=0; _nop_();_nop_();shujv1=0; for(i=0;i<8;i++) {shujv1=shujv1<<1;shujv1=shujv1|ADCDO;ADCCLK=1; _nop_(); _nop_();ADCCLK=0; _nop_(); _nop_(); }shujv2=0; for(i=0;i<8;i++) {shujv2=shujv2>>1;if(ADCDO) shujv2=shujv2|0x80;ADCCLK=1; _nop_(); _nop_();ADCCLK=0; _nop_(); _nop_(); } ADCCS=1; ADCCLK=0; ADCDO=1; if(shujv1==shujv2) return(shujv1);}
第四節(jié)溫亮度測試軟件設(shè)計(jì)
4.1溫度數(shù)據(jù)讀取并處理函數(shù)1.溫度數(shù)據(jù)處理過程溫度數(shù)據(jù)處理就是將單片機(jī)通過DO引腳采集到的8位數(shù)字量還原為實(shí)際溫度值并顯示的過程。那么數(shù)字量與實(shí)際溫度之間的關(guān)系是什么呢?首先,分析ADC的轉(zhuǎn)換關(guān)系,即模擬量U與數(shù)字量D之間的關(guān)系。ADC0832的輸入模擬電壓范圍是0~5V,輸出8位數(shù)字量的范圍為0x00~0xFF;因此當(dāng)輸入電壓為0?V時(shí),轉(zhuǎn)換后的數(shù)字量為0x00,輸入電壓為5?V時(shí),轉(zhuǎn)換后的數(shù)字量為0xFF;所以模擬量與數(shù)字量之間應(yīng)滿足:其次,分析傳感器的傳輸特性,即輸出電壓U與實(shí)際溫度t之間的關(guān)系。當(dāng)t?=?10℃時(shí),U?=?5?V;當(dāng)t?=?90?℃時(shí),U?=?0?V;故當(dāng)溫度為t時(shí),傳感器的輸出電壓為t?=?-16U?+?90最后,將U=D/51代入上式后得到:t?=?-0.315D?+?90因此,要顯示實(shí)際溫度數(shù)值,需將采集到的數(shù)字量,根據(jù)ADC的轉(zhuǎn)換關(guān)系并結(jié)合傳感器的傳輸特性建立表達(dá)式,然后根據(jù)此表達(dá)式計(jì)算,便可得到實(shí)際溫度值。2.溫度數(shù)據(jù)處理函數(shù)/*函數(shù)名:wendusjcl()作用:將數(shù)字量溫度值還原為實(shí)際溫度值,不需要小數(shù),并在12864上顯示。入口參數(shù):形參wendushuzi:存放待處理的數(shù)字量溫度值,范圍:0~255。出口參數(shù):無說明:wenduf:存放浮點(diǎn)型的實(shí)際溫度值。wenduint:存放整型的實(shí)際溫度值。*/voidwendusjcl(ucharwendushuzi){ floatwenduf;ucharwenduint;wenduf=-0.315*wendushuzi+90; wenduint=(uchar)(wenduf+0.5); lcdxianshi16x8(shuzi[wenduint/10],2,40); lcdxianshi16x8(shuzi[wenduint%10],2,48);}3.溫度測試源程序/*預(yù)處理*/#include<reg51.h>#include<intrins.h>#defineucharunsignedchar#defineuintunsignedint/*全局變量定義*/sbitCS1=P2^5;sbitCS2=P2^2;sbitRS=P2^0;sbitRW=P2^4;sbitE=P2^1;sbitRST=P2^6;sbitADCCS=P3^0;sbitADCDI=P3^3;sbitADCCLK=P3^1;sbitADCDO=P3^3;ucharcodeshuzi[10][16];ucharcodehuan[32];ucharcodejing[32];ucharcodece[32];ucharcodeceshi[32];ucharcodewen[32];ucharcodedu[32];ucharcodeliang[32];ucharcodemaohao[32];ucharcodeshidu[32];ucharcodean[32];ucharcodeliang[32];ucharcodeshizhong[32];ucharcodezhong[32];ucharcodemie[32];ucharcodesheshidu[32];/*函數(shù)聲明*/voidlcdkaixianshi(void);voidlcdguanxianshi(void);voidlcdshezhiye(ucharye);voidlcdshezhilie(ucharlie);voidlcdshezhiyelie(ucharye,ucharlie);voidlcdxiezimo(ucharzijie);voidlcdqingping(void);voidlcdchushihua(void);voidlcdxianshi16x16(uchartab[],ucharqiye,ucharqilie);voidlcdxianshi16x8(uchartab[],ucharqiye,ucharqilie);ucharadc0832du(uchartongdao);voidwendusjcl(ucharwendushuzi);voidliangdusjcl(ucharliangdushuzi);/*主函數(shù)*/main(){ucharwendu; lcdchushihua(); lcdxianshi16x16(huan,0,30); lcdxianshi16x16(jing,0,46); lcdxianshi16x16(ce,0,62); lcdxianshi16x16(ceshi,0,78); lcdxianshi16x16(wen,2,3); lcdxianshi16x16(du,2,19); lcdxianshi16x16(maohao,2,35); lcdxianshi16x16(sheshidu,2,66); lcdxianshi16x16(liang,4,3); lcdxianshi16x16(du,4,19); lcdxianshi16x16(maohao,4,35); lcdxianshi16x16(shidu,6,3); lcdxianshi16x16(du,6,19); lcdxianshi16x16(maohao,6,35); while(1){ wendu=adc0832du(3); wendusjcl(wendu); }}voidwendusjcl(ucharwendushuzi){ float wenduf; ucharwenduint; wenduf=-0.315*wendushuzi+90; wenduint=(uchar)(wenduf+0.5); lcdxianshi16x8(shuzi[wenduint/10],2,40); lcdxianshi16x8(shuzi[wenduint%10],2,48);}ucharadc0832du(uchartongdao){uchari=0; ucharshujv1,shujv2; ADCCS=0; _nop_();_nop_(); ADCDI=1; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=(tongdao>>1)&0x1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=tongdao&0x01; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); shujv1=0; for(i=0;i<8;i++){ shujv1=shujv1<<1; shujv1=shujv1|ADCDO; ADCCLK=1; _nop_(); _nop_(); ADCCLK=0; _nop_(); _nop_(); } shujv2=0; for(i=0;i<8;i++) { shujv2=shujv2>>1; if(ADCDO) shujv2=shujv2|0x80; ADCCLK=1; _nop_(); _nop_(); ADCCLK=0; _nop_(); _nop_(); } ADCCS=1; ADCCLK=0; ADCDO=1; if(shujv1==shujv2) return(shujv1);}voidlcdxianshi16x8(uchartab[],ucharqiye,ucharqilie){ uchari,j; for(i=0;i<2;i++) { for(j=0;j<8;j++) { lcdshezhiyelie(i+qiye,j+qilie); lcdxiezimo(tab[i*8+j]); } }}voidlcdxianshi16x16(uchartab[],ucharqiye,ucharqilie){ uchari,j; for(i=0;i<2;i++) { for(j=0;j<16;j++) { lcdshezhiyelie(i+qiye,j+qilie); lcdxiezimo(tab[i*16+j]); } }}voidlcdkaixianshi(void){ P0=0X3F; RW=0; RS=0; E=1; E=0;}voidlcdguanxianshi(void){ P0=0X3E; RW=0; RS=0; E=1; E=0;}voidlcdshezhiye(ucharye){ P0=0XB8|ye; RW=0; RS=0; E=1; E=0;}voidlcdshezhilie(ucharlie) { P0=0X40|lie; RW=0; RS=0; E=1; E=0;}voidlcdxiezimo(ucharzijie){ P0=zijie; RW=0; RS=1; E=1; E=0;}voidlcdshezhiyelie(ucharye,ucharlie){ lcdshezhiye(ye); if(lie<64) {CS1=1;CS2=0;lcdshezhilie(lie);} else {CS1=0;CS2=1;lcdshezhilie(lie-64);}}voidlcdqingping(void){ uchari,j; for(i=0;i<8;i++) { for(j=0;j<128;j++) { lcdshezhiyelie(i,j); lcdxiezimo(0); } }}voidlcdchushihua(void){ RST=1; lcdguanxianshi(); lcdshezhiye(0); lcdshezhilie(0); lcdkaixianshi(); lcdqingping();}ucharcodehuan[32]={/*"環(huán)",0*//*(16X16,宋體)*/0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0x04,0x04,0x84,0xE4,0x1C,0x84,0x04,0x04,0x00,0x20,0x60,0x20,0x1F,0x10,0x10,0x04,0x02,0x01,0x00,0xFF,0x00,0x00,0x01,0x06,0x00};ucharcodejing[32]={/*"境",1*//*(16X16,宋體)*/0x10,0x10,0xFF,0x10,0x10,0x20,0xA4,0xAC,0xB5,0xA6,0xB4,0xAC,0xA4,0x20,0x20,0x00,0x10,0x30,0x1F,0x08,0x88,0x80,0x4F,0x3A,0x0A,0x0A,0x7A,0x8A,0x8F,0x80,0xE0,0x00};ucharcodece[32]={/*"測",2*//*(16X16,宋體)*/0x10,0x60,0x02,0x8C,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0xFF,0x00,0x00,0x04,0x04,0x7E,0x01,0x80,0x47,0x30,0x0F,0x10,0x27,0x00,0x47,0x80,0x7F,0x00,0x00};ucharcodeceshi[32]={/*"試",3*//*(16X16,宋體)*/0x40,0x40,0x42,0xCC,0x00,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x11,0x16,0x10,0x00,0x00,0x00,0x00,0x3F,0x10,0x28,0x60,0x3F,0x10,0x10,0x01,0x0E,0x30,0x40,0xF0,0x00};ucharcodewen[32]={/*"溫",4*//*(16X16,宋體)*/0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00};ucharcodedu[32]={/*"度",5*//*(16X16,宋體)*/0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00};ucharcodeliang[32]={/*"亮",6*//*(16X16,宋體)*/0x00,0x04,0x04,0x74,0x54,0x54,0x55,0x56,0x54,0x54,0x54,0x74,0x04,0x04,0x00,0x00,0x84,0x83,0x41,0x21,0x1D,0x05,0x05,0x05,0x05,0x05,0x7D,0x81,0x81,0x85,0xE3,0x00};ucharcodemaohao[32]={/*":",7*//*(16X16,宋體)*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};ucharcodeshidu[32]={/*"濕",8*//*(16X16,宋體)*/0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00};ucharcodean[32]={/*"暗",9*//*(16X16,宋體)*/0x00,0xFC,0x84,0x84,0xFC,0x40,0x44,0x54,0x65,0x46,0x44,0x64,0x54,0x44,0x40,0x00,0x00,0x3F,0x10,0x10,0x3F,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00};ucharcodemie[32]={/*"滅",11*//*(16X16,宋體)*/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};ucharcodeshizhong[32]={/*"適",12*//*(16X16,宋體)*/0x40,0x40,0x42,0xCC,0x00,0x10,0x92,0x92,0x92,0xFF,0x91,0x91,0x91,0x10,0x10,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x48,0x48,0x48,0x48,0x48,0x5F,0x40,0x40,0x00};ucharcodezhong[32]={/*"中",13*//*(16X16,宋體)*/0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00};ucharcodesheshidu[32]={/*"℃",14*//*(16X16,宋體)*/0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00};ucharcodeshuzi[10][16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",0*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",2*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*"3",3*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*"4",4*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*"5",5*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"6",6*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",7*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",8*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};/*"9",9*/4.2亮度數(shù)據(jù)讀取并處理函數(shù)1.亮度數(shù)據(jù)處理過程項(xiàng)目要求亮度只要顯示出亮、適中、暗就可以了,因此亮度數(shù)據(jù)處理最簡單,就是將單片機(jī)從ADC0832讀入的亮度數(shù)字量分為亮、適中、暗3個(gè)階段。由于光敏電阻的特點(diǎn)是:光線越亮,阻值越小,亮度測試電路中分壓點(diǎn)的電壓值越小,經(jīng)ADC轉(zhuǎn)換后的數(shù)字量也就越小。即數(shù)字量越小,亮度越亮;數(shù)字量越大,亮度越暗。因此,理論上做如下分段:(1)數(shù)字量<90,亮。(2)數(shù)字量在90~210之間,適中。(3)數(shù)字量>210,暗。2.亮度數(shù)據(jù)處理函數(shù)/*函數(shù)名:liangdusjcl()作用:根據(jù)單片機(jī)讀入的亮度數(shù)字量,在12864上顯示亮、適中、暗。入口參數(shù):形參liangdushuzi:存放亮度的數(shù)字量,范圍:0~255。出口參數(shù):無說明:
liangdushuzi:<90,亮; liangdushuzi:90~210,適中; liangdushuzi:>210,暗。*/voidliangdusjcl(ucharliangdushuzi){ if(liangdushuzi<90) lcdxianshi16x16(liang,4,40); if(liangdushuzi>210) lcdxianshi16x16(an,4,40); if(liangdushuzi>=90&&liangdushuzi<=210) { lcdxianshi16x16(shizhong,4,40); lcdxianshi16x16(zhong,4,56);}}4.3溫亮度測試源程序/*預(yù)處理*/#include<reg51.h>#include<intrins.h>#defineucharunsignedchar#defineuintunsignedint/*全局變量定義*/sbitCS1=P2^5;sbitCS2=P2^2;sbitRS=P2^0;sbitRW=P2^4;sbitE=P2^1;sbitRST=P2^6;sbitADCCS=P3^0;sbitADCDI=P3^3;sbitADCCLK=P3^1;sbitADCDO=P3^3;ucharcodeshuzi[10][16];ucharcodehuan[32];ucharcodejing[32];ucharcodece[32];ucharcodeceshi[32];ucharcodewen[32];ucharcodedu[32];ucharcodeliang[32];ucharcodemaohao[32];ucharcodeshidu[32];ucharcodean[32];ucharcodeliang[32];ucharcodeshizhong[32];ucharcodezhong[32];ucharcodemie[32];ucharcodesheshidu[32];/*函數(shù)聲明*/voidlcdkaixianshi(void);voidlcdguanxianshi(void);voidlcdshezhiye(ucharye);voidlcdshezhilie(ucharlie);voidlcdshezhiyelie(ucharye,ucharlie);voidlcdxiezimo(ucharzijie);voidlcdqingping(void);voidlcdchushihua(void);voidlcdxianshi16x16(uchartab[],ucharqiye,ucharqilie);voidlcdxianshi16x8(uchartab[],ucharqiye,ucharqilie);ucharadc0832du(uchartongdao);voidwendusjcl(ucharwendushuzi);voidliangdusjcl(ucharliangdushuzi);/*主函數(shù)*/main(){ ucharwendu,liangdu; lcdchushihua(); lcdxianshi16x16(huan,0,30); lcdxianshi16x16(jing,0,46); lcdxianshi16x16(ce,0,62); lcdxianshi16x16(ceshi,0,78); lcdxianshi16x16(wen,2,3); lcdxianshi16x16(du,2,19); lcdxianshi16x16(maohao,2,35); lcdxianshi16x16(sheshidu,2,66); lcdxianshi16x16(liang,4,3); lcdxianshi16x16(du,4,19); lcdxianshi16x16(maohao,4,35); lcdxianshi16x16(shidu,6,3); lcdxianshi16x16(du,6,19); lcdxianshi16x16(maohao,6,35); while(1) { wendu=adc0832du(3); wendusjcl(wendu); liangdu=adc0832du(1); liangdusjcl(liangdu); }}voidliangdusjcl(ucharliangdushuzi){ if(liangdushuzi<90) lcdxianshi16x16(liang,4,40); if(liangdushuzi>210) lcdxianshi16x16(an,4,40); if(liangdushuzi>=90&&liangdushuzi<=210) { lcdxianshi16x16(shizhong,4,40); lcdxianshi16x16(zhong,4,56); }}voidwendusjcl(ucharwendushuzi) { float wenduf; ucharwenduint; wenduf=-0.315*wendushuzi+90; wenduint=(uchar)(wenduf+0.5); lcdxianshi16x8(shuzi[wenduint/10],2,40); lcdxianshi16x8(shuzi[wenduint%10],2,48);}ucharadc0832du(uchartongdao){ uchari=0; ucharshujv1,shujv2; ADCCS=0; _nop_();_nop_(); ADCDI=1; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=(tongdao>>1)&0x1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=tongdao&0x01; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); ADCCLK=1; _nop_();_nop_(); ADCDI=1; _nop_();_nop_(); ADCCLK=0; _nop_();_nop_(); shujv1=0; for(i=0;i<8;i++) { shujv1=shujv1<<1; shujv1=shujv1|ADCDO; ADCCLK=1; _nop_(); _nop_(); ADCCLK=0; _nop_(); _nop_(); }
shujv2=0; for(i=0;i<8;i++) { shujv2=shujv2>>1; if(ADCDO) shujv2=shujv2|0x80; ADCCLK=1; _nop_(); _nop_(); ADCCLK=0; _nop_(); _nop_(); } ADCCS=1; ADCCLK=0; ADCDO=1; if(shujv1==shujv2) return(shujv1);}voidlcdxianshi16x8(uchartab[],ucharqiye,ucharqilie){ uchari,j; for(i=0;i<2;i++) { for(j=0;j<8;j++) { lcdshezhiyelie(i+qiye,j+qilie); lcdxiezimo(tab[i*8+j]); } }}voidlcdxianshi16x16(uchartab[],ucharqiye,ucharqilie){ uchari,j; for(i=0;i<2;i++) { for(j=0;j<16;j++) { lcdshezhiyelie(i+qiye,j+qilie); lcdxiezimo(tab[i*16+j]); } }}voidlcdkaixianshi(void){ P0=0X3F; RW=0; RS=0; E=1; E=0;}voidlcdguanxianshi(void){ P0=0X3E; RW=0; RS=0; E=1; E=0;}voidlcdshezhiye(ucharye){ P0=0XB8|ye; RW=0; RS=0; E=1; E=0;}voidlcdshezhilie(ucharlie){ P0=0X40|lie; RW=0; RS=0; E=1; E=0;}voidlcdxiezimo(ucharzijie){ P0=zijie; RW=0; RS=1; E=1; E=0;}voidlcdshezhiyelie(ucharye,ucharlie){ lcdshezhiye(ye); if(lie<64) {CS1=1;CS2=0;lcdshezhilie(lie);} else {CS1=0;CS2=1;lcdshezhilie(lie-64);}}voidlcdqingping(void){ uchari,j; for(i=0;i<8;i++) { for(j=0;j<128;j++) { lcdshezhiyelie(i,j); lcdxiezimo(0); } }}void lcdchushihua(void){ RST=1; lcdguanxianshi(); lcdshezhiye(0);
lcdshezhilie(0); lcdkaixianshi(); lcdqingping();}ucharcodehuan[32]={/*"環(huán)",0*//*(16X16,宋體)*/0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0x04,0x04,0x84,0xE4,0x1C,0x84,0x04,0x04,0x00,0x20,0x60,0x20,0x1F,0x10,0x10,0x04,0x02,0x01,0x00,0xFF,0x00,0x00,0x01,0x06,0x00};ucharcodejing[32]={/*"境",1*//*(16X16,宋體)*/0x10,0x10,0xFF,0x10,0x10,0x20,0xA4,0xAC,0xB5,0xA6,0xB4,0xAC,0xA4,0x20,0x20,0x00,0x10,0x30,0x1F,0x08,0x88,0x80,0x4F,0x3A,0x0A,0x0A,0x7A,0x8A,0x8F,0x80,0xE0,0x00};ucharcodece[32]={/*"測",2*//*(16X16,宋體)*/0x10,0x60,0x02,0x8C,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0xFF,0x00,0x00,0x04,0x04,0x7E,0x01,0x80,0x47,0x30,0x0F,0x10,0x27,0x00,0x47,0x80,0x7F,0x00,0x00};ucharcodeceshi[32]={/*"試",3*//*(16X16,宋體)*/0x40,0x40,0x42,0xCC,0x00,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x11,0x16,0x10,0x00,0x00,0x00,0x00,0x3F,0x10,0x28,0x60,0x3F,0x10,0x10,0x01,0x0E,0x30,0x40,0xF0,0x00};ucharcodewen[32]={/*"溫",4*//*(16X16,宋體)*/0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00};ucharcodedu[32]={/*"度",5*//*(16X16,宋體)*/0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00};ucharcodeliang[32]={/*"亮",6*//*(16X16,宋體)*/0x00,0x04,0x04,0x74,0x54,0x54,0x55,0x56,0x54,0x54,0x54,0x74,0x04,0x04,0x00,0x00,0x84,0x83,0x41,0x21,0x1D,0x05,0x05,0x05,0x05,0x05,0x7D,0x81,0x81,0x85,0xE3,0x00};ucharcodemaohao[32]={/*":",7*//*(16X16,宋體)*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};ucharcodeshidu[32]={/*"濕",8*//*(16X16,宋體)*/0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00};ucharcodean[32]={/*"暗",9*//*(16X16,宋體)*/0x00,0xFC,0x84,0x84,0xFC,0x40,0x44,0x54,0x65,0x46,0x44,0x64,0x54,0x44,0x40,0x00,0x00,0x3F,0x10,0x10,0x3F,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00};ucharcodemie[32]={/*"滅",11*//*(16X16,宋體)*/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};ucharcodeshizhong[32]={/*"適",12*//*(16X16,宋體)*/0x40,0x40,0x42,0xCC,0x00,0x10,0x92,0x92,0x92,0xFF,0x91,0x91,0x91,0x10,0x10,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x48,0x48,0x48,0x48,0x48,0x5F,0x40,0x40,0x00};ucharcodezhong[32]={/*"中",13*//*(16X16,宋體)*/0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00};ucharcodesheshidu[32]={/*"℃",14*//*(16X16,宋體)*/0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00};ucharcodeshuzi[10][16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",0*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",2*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*"3",3*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*"4",4*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*"5",5*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"6",6*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",7*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",8*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};/*"9",9*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",2*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*"3",3*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*"4",4*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*"5",5*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"6",6*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",7*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",8*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00};/*"9",9*/
第五節(jié)濕度測試
5.1濕度測試原理1.濕度傳感器濕度的測試與控制在工業(yè)生產(chǎn)、氣象等部門及人們的舒適與健康方面至關(guān)重要,但是在常規(guī)的環(huán)境參數(shù)中,由于大氣壓強(qiáng)、溫度等因素同時(shí)影響濕度的高低,因而濕度的準(zhǔn)確測試難度較溫亮度要大。測量空氣濕度時(shí),常用相對濕度來表示。相對濕度是指某溫度下氣體中(通常為空氣中)所含水蒸氣量與同一溫度下飽和水蒸氣量的百分比,用RH表示。隨著溫度的增高空氣中可以含的水就越多,也就是說,在同樣多的水蒸氣的情況下溫度升高相對濕度就會降低。因此不提供溫度數(shù)據(jù),只說濕度是沒有意義的。濕敏元件是最簡單的濕度傳感器,濕度傳感器有電阻式和電容式兩大類,如圖6-8所示。濕敏電阻的阻值會隨濕度而變化,它的靈敏度高,但存在較嚴(yán)重的非線性,互換性也不是很理想。濕敏電容一般是用高分子薄膜電容制成的,常用的高分子材料有聚苯乙烯、聚酰亞胺、酪酸醋酸纖維等。當(dāng)環(huán)境濕度發(fā)生改變時(shí),濕敏電容的容量也發(fā)生變化,并且其電容變化量與相對濕度成正比。濕敏電容的主要優(yōu)勢是靈敏度高、互換性好、易于集成化等,但其精度一般低于濕敏電阻。數(shù)字式溫濕傳感器體積小、集成度高,可以直接將溫度、濕度轉(zhuǎn)換為單片機(jī)所需的數(shù)字量,使用方便。2.濕度測試原理濕敏電容HS1101是法國Humirel公司推出的一款電容式相對濕度傳感器。它具有響應(yīng)時(shí)間快、高可靠性和長期穩(wěn)定性、不需要校準(zhǔn)的完全互換性等特點(diǎn)。具體參數(shù)如下:(1)測量范圍:0%~100%RH。(2)電容量典型值:180pF(在50%RH時(shí))。(3)電容量的變化范圍:163pF~202pF(相對濕度從0%RH變化到100%RH時(shí))。(4)溫度系數(shù):0.04pF/℃。(5)濕度滯后量:±1.5%。(6)響應(yīng)時(shí)間:5s。圖6-9所示為HS1101的電容與相對濕度之間的關(guān)系響應(yīng)曲線,測試條件為室溫25℃、工作頻率10kHz。可以看出,HS1101具有極好的線性輸出,可以近似看成線性的。圖6-10所示為濕度測試電路,圖中施密特觸發(fā)器CD40106構(gòu)成多諧振蕩器,利用HS1101的充放電,在輸出端產(chǎn)生方波。當(dāng)環(huán)境濕度增大時(shí),HS1101的容量增大,方波的周期增大,頻率降低;反之,當(dāng)環(huán)境濕度減小時(shí),HS1101的容量減小,方波的周期減小,頻率升高。方波的周期為T≈3.6RC其中:C為HS1101,R=R1+R2。5.2濕度測試硬件設(shè)計(jì)圖6-11所示為濕度測試硬件電路圖,HS1101與40106組成振蕩電路,其輸出信號與單片機(jī)的P3.4端口相連,P3.4為AT89S52片內(nèi)定時(shí)/計(jì)數(shù)器T0的計(jì)數(shù)脈沖輸入端。5.3濕度數(shù)據(jù)處理函數(shù)1.濕度數(shù)據(jù)處理過程單片機(jī)在計(jì)算出濕度測試電路輸出方波的頻率后,通過查表的方式,找到該頻率對應(yīng)的濕度,并顯示出來。濕度數(shù)據(jù)處理的首要問題是建立數(shù)據(jù)表,數(shù)據(jù)表中存放相對濕度從0%RH增加到100%RH,分辨率為1%RH時(shí),所有的頻率值。數(shù)組shidubiao中存放了可供參考的100個(gè)頻率值,每個(gè)頻率值在數(shù)組中的下標(biāo)就是與其對應(yīng)的相對濕度值。uintcodeshidubiao[100]={9604,9591,9578,9565,9552,9539,9526,9513,9500,9487,//0-99474,9461,9448,9435,9422,9409,9396,9383,9370,9357,//10-199344,9331,9318,9305,9292,9279,9266,9253,9240,9227,//20-299214,9201,9188,9175,9162,9149,9136,9123,9110,9097,//30-399084,9071,9058,9045,9032,9019,9006,8993,8980,8967,//40-498954,8941,8928,8915,8902,8889,8876,8863,8850,8837,//50-598824,8811,8798,8785,8772,8759,8746,8733,8720,8707,//60-698694,8681,8668,8655,8642,8629,8616,8603,8590,8577,//70-798564,8551,8538,8525,8512,8499,8486,8473,8460,8447,//80-898434,8421,8408,8395,8382,8369,8356,8343,8330,8317//90-99};濕度表建好之后,測量出實(shí)際濕度頻率值,再與濕度表中的100個(gè)濕度頻率值作比較,找到濕度值。觀察濕度表可以看出,濕度值從1%RH增至2%RH時(shí),頻率值從9591降至9578,減小了13,因此,可以認(rèn)為濕度表中的每個(gè)頻率值代表了以該頻率值為中心的一個(gè)范圍,這樣可以覆蓋從9604~8317內(nèi)的所有頻率值,如表6-5所示。根據(jù)實(shí)測頻率值查表,就是判斷實(shí)測頻率值所處的范圍。由于HS1101的電容與相對濕度的響應(yīng)曲線并非完全的線性,及其他電子元器件參數(shù)的離散性,即便相對濕度保持不變,但是振蕩電路輸出方波的頻率也不可能穩(wěn)定在一個(gè)固定的數(shù)值,存在一定的離散性,在軟件上,可以采用上述方法處理;在硬件上,則可通過調(diào)節(jié)圖6-11中的電位器R2進(jìn)行適當(dāng)?shù)男U?.濕度數(shù)據(jù)處理函數(shù)/*函數(shù)名:shidusjcl()作用:根據(jù)實(shí)際測量的頻率值查找數(shù)據(jù)表(shidubiao),將頻率值轉(zhuǎn)換為濕度值并顯示。入口參數(shù):無出口參數(shù):無 說明:shidushuzigao8:全局變量,存放濕度頻率值的高8位。?shidushuzidi8:全局變量,存放濕度頻率值的低8位。*/voidshidusjcl(void){ uchar i; uint shidushuzi16; shidushuzi16=shidushuzigao8<<8|shidushuzidi8; for(i=0;i<100;i++) { if(shidushuzi16<=(shidubiao[i]+6)&&shidushuzi16>=(shidubiao[i]-6)) break;}lcdxianshi16x8(shuzi[i/10],6,40);lcdxianshi16x8(shuzi[i%10],6,48);}5.4濕度測試軟件設(shè)計(jì)1.矩形波頻率的測量頻率是指單位時(shí)間內(nèi)完成周期性變化的次數(shù),是描述周期運(yùn)動頻繁程度的量。單位時(shí)間為1?s,也就是說,頻率就是1?s內(nèi)矩形波周期的個(gè)數(shù)。用單片機(jī)測量矩形波頻率時(shí)有兩個(gè)關(guān)鍵問題:(1)定時(shí)1?s。用定時(shí)/計(jì)數(shù)器T1定時(shí)50?ms,T1溢出1次是50?ms,溢出20次時(shí),為20次?×?50?ms?=?1000?ms?=?1?s。(2)在1?s的時(shí)間內(nèi),統(tǒng)計(jì)矩形波周期的個(gè)數(shù)。由圖6-11可知,振蕩電路輸出的方波與T0的計(jì)數(shù)脈沖輸入端P3.4相連,只能用T0來統(tǒng)計(jì)矩形波周期的個(gè)數(shù)。當(dāng)T1定時(shí)1?s開始的同時(shí),啟動T0開始從0計(jì)數(shù),1?s定時(shí)結(jié)束時(shí),T0也結(jié)束計(jì)數(shù),CPU關(guān)中斷;此時(shí)TH0中存放的是計(jì)數(shù)值的高8位,TL0中存放的是計(jì)數(shù)值的低8位;單片機(jī)將這一次的計(jì)數(shù)值讀出另存后,CPU開中斷,開始下一次頻率的測量。/*函數(shù)名:t0t1chushihua()作用:初始化T0、T1。T1定時(shí),T0計(jì)數(shù)。入口參數(shù):無出口參數(shù):無說明:T1定時(shí)1?s的原理:1?s?=?50?ms*20次 ?T0計(jì)數(shù):初值為0。*/void
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高一學(xué)生學(xué)習(xí)計(jì)劃15篇
- 我的學(xué)習(xí)計(jì)劃15篇
- 《童年》讀后感(匯編15篇)
- 初一政治教學(xué)計(jì)劃范文集錦六篇
- 公司年會活動方案模板錦集六篇
- 三國演義讀后感
- 甘肅省白銀市靖遠(yuǎn)縣第一中學(xué)2024-2025學(xué)年高二上學(xué)期12月期末模擬語文試卷(含答案)
- 公交巴士有限公司部門崗位職責(zé)
- 工廠車間組租賃合同范本
- 戰(zhàn)略性股權(quán)融資合同書
- 《文明城市建設(shè)問題研究開題報(bào)告3000字》
- JJF 1357-2012濕式氣體流量計(jì)校準(zhǔn)規(guī)范
- GB/T 3917.1-1997紡織品織物撕破性能第1部分:撕破強(qiáng)力的測定沖擊擺錘法
- 玲龍醫(yī)用診斷X 射線系統(tǒng) XR 6000維修手冊
- 殘疾學(xué)生送教上門記錄
- 高中學(xué)校五年發(fā)展規(guī)劃方案
- 大學(xué)物理習(xí)題
- 化工原理課程設(shè)計(jì)換熱器的設(shè)計(jì)
- 膀胱癌診療指南課件
- 藍(lán)橋物流平臺操作手冊范本
- 大班唱歌《吹泡泡》課件
評論
0/150
提交評論