【正文】
要對(duì)其進(jìn)行線性化處理。不同溫度條件下,在同一測(cè)量場(chǎng)合測(cè)得的濕度差異很大,所以還需要對(duì)測(cè)量頻率作溫度補(bǔ)償。對(duì)于頻率的測(cè)量,單片機(jī)由多種測(cè)量方法,大體由中斷測(cè)量和定時(shí)計(jì)數(shù)兩大方式。 中斷計(jì)數(shù)是將波源輸入到單片機(jī)的中斷入口中去,通過(guò)檢測(cè)一段時(shí)間內(nèi)中都的次數(shù)也能夠檢測(cè)出波形的頻率,具體工作原理入下,先用一個(gè)定時(shí)器來(lái)實(shí)現(xiàn)計(jì)時(shí)功能,然后開(kāi)中斷,讓中斷工作在邊沿觸發(fā)狀態(tài),這樣中斷就可以對(duì)高低變換的頻率波形進(jìn)行計(jì)數(shù),本設(shè)計(jì)中是來(lái)檢測(cè)波形頻率的所以最好的計(jì)一秒鐘采樣一次,同樣的問(wèn)題,單片機(jī)必須的計(jì)若干次數(shù)才采集一個(gè)中斷次數(shù),這樣才可以實(shí)現(xiàn)一秒采集數(shù)據(jù)。在濕度檢測(cè)模塊程序的開(kāi)始,首先讀取經(jīng)過(guò)A/D轉(zhuǎn)換的相對(duì)濕度的振蕩頻率fo,并把得到的相對(duì)濕度頻率值存儲(chǔ)于STC12C5410AD的一個(gè)變量單元中?!鱢 RH0然后把頻率曲線上相鄰的兩點(diǎn)依次用直線相連,就得到一條新的濕度頻率曲線,它與實(shí)際曲線幾乎重合在一起,所以可以使用該曲線產(chǎn)生進(jìn)行線性化處理。因?yàn)榫€性化處理的過(guò)程中需要將實(shí)測(cè)頻率與fn進(jìn)行多次比較。線性化處理程序子程序流程圖如36所示。同時(shí)取出△RH,定義計(jì)數(shù)量n,分別存入不同變量。如果差值大于0,則說(shuō)明測(cè)得頻率超出檢測(cè)儀的測(cè)量范圍,轉(zhuǎn)入報(bào)告出錯(cuò)子程序,告訴用戶(hù)出錯(cuò)。如果(ff1)的值大于0,說(shuō)明實(shí)測(cè)頻率在濕度頻率曲線的第一段內(nèi),這時(shí)的環(huán)境濕度值:RH=△RH (f f0)/( f1 f0)。因?yàn)檫@一比較涉及到,檢測(cè)儀報(bào)錯(cuò)功能,更重要的是接下來(lái)的頻率比較必須以第一次比較為參考。但是后來(lái)分析發(fā)現(xiàn)如果不進(jìn)行這一比較會(huì)影響到儀表的正常工作。如果前面比較的結(jié)果值還是小于零,說(shuō)明該振蕩頻率f不在該段,就把比較次數(shù)f加1后,從表中再次取值,繼續(xù)進(jìn)行的比較,直至比較結(jié)果大于零。 167。 鍵盤(pán)掃描 鍵盤(pán)是人機(jī)交換的橋梁,一個(gè)好的鍵盤(pán)能夠讓用戶(hù)方便的使用儀表。由于本設(shè)計(jì)為了節(jié)約I/O口,只用一根數(shù)據(jù)線來(lái)實(shí)現(xiàn)鍵盤(pán)的列掃描,是通過(guò)8位并行輸出串行移位寄存器74HC164來(lái)實(shí)現(xiàn)的。由于74HC164是工作在上升沿,所以本設(shè)計(jì)可以在其數(shù)據(jù)端輸入一個(gè)等待送出的數(shù)字,然后通過(guò)在其時(shí)鐘輸入端送入一個(gè)上升沿,就可以實(shí)現(xiàn)把等待送出的數(shù)字發(fā)送出去。SAOMIAO: MOV A,R1 MOV R2,08HXS: JB ,XS1 CLR AJMP CLKXS1: SETB CLK: CLR NOP SETB RR A DJNZ R2,XSRET本段程序就是將一個(gè)單元8位二進(jìn)制數(shù)送出的子程序,,。然后本設(shè)計(jì)再一列一列的掃描鍵值,具體過(guò)程如下:首先通過(guò)164輸出一個(gè)11111110B后,讀入鍵盤(pán)的行,如果為0,則表示是第一個(gè)鍵按下,如果不為0,則表示不是第一個(gè)鍵按下,然后再在164端輸出一個(gè)11111101B再進(jìn)行上述掃描過(guò)程直至行線為0即掃描到鍵值,即完成了鍵盤(pán)的掃描過(guò)程。鍵盤(pán)掃描去抖動(dòng)和鍵值掃描的核心程序如下:ScanKey: SETB KeyRow /*鍵盤(pán)的行置1 MOV Data_OutputBuf, 00H /*鍵盤(pán)的列置0,掃描的初始狀態(tài) LCALL Data_Output /*調(diào)用顯示子程序,將掃描初始值送出 MOV A, P1 /*將P1口狀態(tài)讀入到單片機(jī) JB ,NoKey /*判斷是否有鍵按下,有則繼續(xù)執(zhí)行,沒(méi)有則返回 LCALL DELAY10ms /*調(diào)用延時(shí)程序消除鍵盤(pán)抖動(dòng),一般10 ms足夠 MOV A,P1 JB ,NoKey MOV ArrangeNum,00H /*列設(shè)定初始值 MOV A,07FH /*列掃描的初始值GetKey1: /*列掃描子程序 SETB KeyRow MOV R5, A /*列掃描的初始值,暫時(shí)存在R5中 MOV Data_OutputBuf, A LCALL Data_Output MOV A, P1 JNB ,GetKeyValue MOV A,R5 RR A /*列掃描值右移,從而實(shí)現(xiàn)鍵盤(pán)的列掃描 INC ArrangeNum /*列號(hào)加1 JB ,GetKey1 LJMP NoKey 167。(2).LED的靜態(tài)顯示 LED的靜態(tài)顯示就是在LED上送入待顯示的內(nèi)容后,LED的管腳的狀態(tài)一直保持不變,即在LED上穩(wěn)定靜止的顯示出待顯示的內(nèi)容,該種設(shè)計(jì)軟件編寫(xiě)簡(jiǎn)單,單片機(jī)軟件資源占用少,但相應(yīng)的在沒(méi)加輔助顯示芯片,使電路復(fù)雜,I/O口占用過(guò)多。 , 通過(guò)該芯片來(lái)輔助LED的顯示,就能夠節(jié)約I/O口資源,又能夠減少軟件的開(kāi)支,所以比較適合本設(shè)計(jì)的需要。本設(shè)計(jì)采用靜態(tài)顯示一次必須送完一幀5位數(shù)據(jù),這樣對(duì)單個(gè)數(shù)據(jù)的修改就比較麻煩,尤其是在碰到有小數(shù)點(diǎn)顯示的時(shí)候,不能夠只改變一位來(lái)實(shí)現(xiàn),必須得5位數(shù)據(jù)全部重新送數(shù)。在本設(shè)計(jì)中實(shí)現(xiàn)鍵盤(pán)掃描的74HC164跟LED顯示的第一位顯示的數(shù)據(jù)是同一個(gè),所以在鍵盤(pán)掃描時(shí)本設(shè)計(jì)可通過(guò)軟件將顯示器關(guān)閉,以免按鍵和顯示相互影響,同樣在程序運(yùn)行過(guò)程中,本設(shè)計(jì)也避免顯示和鍵盤(pán)掃描同時(shí)進(jìn)行,例如,本設(shè)計(jì)程序開(kāi)始執(zhí)行時(shí),總是先掃描鍵盤(pán)直到有鍵盤(pán)按下來(lái)確定用戶(hù)需要檢測(cè)濕度還是溫度,然后根據(jù)鍵值跳轉(zhuǎn)到相應(yīng)的子程序來(lái)進(jìn)行檢測(cè),這時(shí)才將檢測(cè)結(jié)果在LED上顯示出來(lái)。 在進(jìn)行軟件設(shè)計(jì)時(shí),先寫(xiě)完各個(gè)模塊的程序,當(dāng)每個(gè)模塊的程序都調(diào)試通過(guò)后,在根據(jù)設(shè)計(jì)的要求,按照最先實(shí)際的總的程序流程圖來(lái)完成子程序之間的相互協(xié)調(diào)調(diào)用來(lái)實(shí)現(xiàn)整個(gè)程序的調(diào)試工作,通過(guò)多次反復(fù)的調(diào)試修改,當(dāng)總程序能夠?qū)崿F(xiàn)設(shè)計(jì)要求時(shí),程序的設(shè)計(jì)才大體完成。由于采用了測(cè)量范圍廣、精度高、響應(yīng)速度快的電容式濕度傳感器來(lái)進(jìn)行濕度采樣,使用溫度補(bǔ)償、線性化處理的方法提高檢測(cè)精度,因此該檢測(cè)儀基本上達(dá)到技術(shù)指標(biāo)中對(duì)相對(duì)濕度測(cè)量精度和分辨力的要求。但是STC12C5410AD單片機(jī)工作頻率較高,并且只有環(huán)境濕度較高時(shí)才會(huì)出現(xiàn)處理時(shí)間延長(zhǎng)現(xiàn)象,因此并不影響檢測(cè)儀的實(shí)時(shí)檢測(cè)指標(biāo)。本設(shè)計(jì)的設(shè)計(jì)主要面臨著硬件設(shè)計(jì)和軟件設(shè)計(jì)的兩大問(wèn)題,以及硬件和軟件的結(jié)合。在指導(dǎo)老師的悉心輔導(dǎo)下和查閱大量資料之后,然后采用了STC12C5410AD數(shù)據(jù)采集芯片并配合其它一些元器件的硬件設(shè)計(jì)方案,使以上問(wèn)題得到了很好解決 。由于這次設(shè)計(jì)的時(shí)間較短,該檢測(cè)儀的主要功能已經(jīng)實(shí)現(xiàn),要達(dá)到實(shí)用,還需繼續(xù)進(jìn)一步進(jìn)行研究設(shè)計(jì)。2004[9] :北京航空航天大學(xué)出版社,1990[10] :電子工業(yè)出版社,2003[11] [M].西安:西安交通大學(xué)出版社,2000[12] 余永權(quán)。C to +125176。C increments. Fahrenheit equivalent is –67176。F in 176。C, since it may not be able to sustain munications given the higher leakage currents the DS1820 exhibits at these temperatures. For applications in which such temperatures are likely, it is strongly remended that VDD be applied to the DS1820. For situations where the bus master does not know whether the DS1820’s on the bus are parasite powered or supplied with external VDD, a provision is made in the DS1820 to signal the power supply scheme used. The bus master can determine if any DS1820’s are on the bus which require the strong pull–up by sending a SkipROM protocol, then issuing the read power supply mand. After this mand is issued, the master then issues read time slots. The DS1820 will send back “0” on the 1–Wire bus if it is parasite powered。C. If the counter reaches zero before the gate period is over, the temperature register, which is also preset to the –55176。C. At the same time, the counter is then preset with a value determined by the slope accumulator circuitry. This circuitry is needed to pensate for the parabolic behavior of the oscillators over temperature. The counter is then clocked again until it reaches zero.If the gate period is still not finished, then this process repeats. The slope accumulator is used to pensate for the non–linear behavior of the oscillators over temperature, yielding a high resolution temperature measurement. This is done by changing the number of counts necessary for the counter to go through for each incremental degree in temperature. To obtain the desired resolution, therefore, both the value of the counter and the number of counts per degree C (the value of the slope accumulator) at a given temperature must be known.Internally, this calculation is done inside the DS1820 to provide 176。C to +125176。C increments. For Fahrenheit usage, a lookup table or conversion factor must be used.Note that temperature is represented in the DS1820 in terms of a 1/2176。C bit (the LSB) from the read value. This value is TEMP_READ. The value left in the counter may then be read. This value is the count remaining (COUNT_REMAIN) after the gate period has ceased. The last value needed is the number of counts per degree C (COUNT_PER_C) at that temperature. The actual temperature may be then be calculated by the user using the following:1–WIRE BUS SYSTEMThe 1–Wire bus is a system which has a single bus master and one or more slaves. The DS1820 behaves as a slave. The discussion of this bus system is broken down into three topics: hardware configuration, transaction sequence, and 1–Wire signaling (signal types and timing).HARDWARE CONFIGURATION The 1–Wire bus has only a single line by definition