【正文】
tional I/O port with internal pullups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pullups. In addition, and can be configured to be the timer/counter 2 external count input () and the timer/counter 2 trigger input (), respectively, Port 1 also receives the loworder address bytes during Flash programming and verificationPort 2Port 2 is an 8bit bidirectional I/O port with internal pullups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the internal pullups and can be used as inputs. Port 2 emits the highorder address byte during fetches from external program memory and during accesses to external data memory that use 16bit addresses (MOVX DPTR). In this application, Port 2 uses strong internal pullups when emitting 1s. During accesses to external data memory that use 8bit addresses (MOVX RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the highorder address bits and some control signals during Flash programming and verification.Port 3Port 3 is an 8bit bidirectional I/O port with internal pullups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal pullups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pullups. Port 3 also serves the functions of various special features of the STC89C52, as shown in the following table. Port 3 also receives some control signals for Flash programming and verification.RSTReset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin drives High for 96 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.ALE/PROGAddress Latch Enable (ALE) is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external timing or clocking desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALEdisable bit has no effect if the microcontroller is in external execution mode.PSENProgram Store Enable (PSEN) is the read strobe to external program memory. When the STC89C52 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to external data memory.EA/VPPExternal Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12volt programming enable voltage (VPP) during Flash programming.XTAL1Input to the inverting oscillator amplifier and input to the internal clock operating circuit.XTAL2Output from the inverting oscillator amplifier.譯文:STC89C52 數(shù)據(jù)手冊(cè)功能特性描述STC89C52是一種低功耗、高性能CMOS8位微控制器,具有8K在系統(tǒng)可編程Flash 存儲(chǔ)器。在完成學(xué)業(yè)的過(guò)程中,家人的關(guān)懷和鼓勵(lì)給予了我支持和鼓力,使我順利完成學(xué)業(yè)。通過(guò)幾個(gè)月的畢業(yè)設(shè)計(jì),我取得了很大的進(jìn)步,這與齊老師在生活上、工作上和學(xué)習(xí)上給予我的關(guān)心和幫助是分不開(kāi)的,在此我深表謝意。致謝本設(shè)計(jì)是在導(dǎo)師齊懷琴教授的悉心指導(dǎo)下完成的。本次設(shè)計(jì)的可燃性氣體報(bào)警控制警器靈敏度高,在測(cè)量范圍內(nèi)具有較理想的特性,適用于低流速的可燃性氣體測(cè)量。此電路具有結(jié)構(gòu)簡(jiǎn)單,調(diào)試方便,線性度好,溫漂小等優(yōu)點(diǎn)。應(yīng)用程序用C語(yǔ)言編寫(xiě),充分利用芯片資源,提高了測(cè)量精度和代碼執(zhí)行效率,減小代碼容量。它的靈敏度適中,響應(yīng)與恢復(fù)特性好,長(zhǎng)期工作穩(wěn)定性、重現(xiàn)性、抗環(huán)境氣氛影響及抗溫濕度影響等性能均優(yōu)。根據(jù)設(shè)計(jì)要求、使用環(huán)境、成本等因素,選用MQ2氣體傳感器。結(jié)論本次設(shè)計(jì)對(duì)可燃性氣體報(bào)警控制器進(jìn)行了深入的研究,在參考國(guó)內(nèi)外一些資料的基礎(chǔ)上,比較合理地選擇了系統(tǒng)的設(shè)計(jì)方案,采用了“探測(cè)器+單片機(jī)控制電路”設(shè)計(jì)思路,由于具有操作簡(jiǎn)單,實(shí)用性強(qiáng),價(jià)格便宜,安全性高等特點(diǎn),所以非常適合貯氣倉(cāng)庫(kù),以及家庭等場(chǎng)所使用,具有很高的實(shí)用價(jià)值。對(duì)調(diào)試過(guò)程中出現(xiàn)的錯(cuò)誤要仔細(xì)分析,然后不斷更正錯(cuò)誤,直至達(dá)到理想效果為止。如果調(diào)試成功了才能說(shuō)明此系統(tǒng)的功能實(shí)現(xiàn),系統(tǒng)設(shè)計(jì)已經(jīng)成功。單一的軟件或是硬件的調(diào)試通過(guò)了并不能驗(yàn)證總的方案的可行性。、硬件整體調(diào)試軟、硬件聯(lián)調(diào)是將已經(jīng)調(diào)試通過(guò)的軟件和硬件結(jié)合起來(lái)一起進(jìn)行調(diào)試。由于由于STC89C52可以擦寫(xiě)上千次,所以在這個(gè)調(diào)試過(guò)程中,并沒(méi)有用仿真器來(lái)實(shí)踐,而是直接將程序燒寫(xiě)進(jìn)單片機(jī)來(lái)操作。若調(diào)試通過(guò)后,就可以編制應(yīng)用程序了。對(duì)應(yīng)進(jìn)行編程調(diào)試時(shí),分為兩個(gè)步驟:第一,對(duì)其進(jìn)行初始化(即寫(xiě)入命令控制字,最好定義為輸出方式)。顯示器部分調(diào)試為了使調(diào)試順利進(jìn)行,首先將LED顯示分離,這樣就可以用靜態(tài)方法先測(cè)試LED顯示,分別用規(guī)定的電平加至控制數(shù)碼管段和位顯示的引腳,看數(shù)碼管顯示是否與理論上一致。例如對(duì)復(fù)位信號(hào)觀測(cè)就可以直接利用示波器,當(dāng)按下復(fù)位鍵時(shí),可以看到的復(fù)位引腳將變?yōu)楦唠娖?;一旦松開(kāi),電平將變低。執(zhí)行程序后,就可以利用示波器觀察芯片的片選信號(hào)引出腳(用示波器掃描時(shí)間為1μs/每格檔),這時(shí)應(yīng)看到周期為數(shù)微秒的負(fù)脈沖波形,若看不到則說(shuō)明譯碼信號(hào)有錯(cuò)誤。應(yīng)該利用軟件編程的方法來(lái)實(shí)現(xiàn)。52系列單片機(jī)的信號(hào)線大體分為讀、寫(xiě)信號(hào)線、片選信號(hào)線、時(shí)鐘信號(hào)線、外部程序存貯器讀選通信號(hào)(PSEN)、地址鎖存信號(hào)(ALE)、復(fù)位信號(hào)等幾大類。這些工具是單片機(jī)開(kāi)發(fā)的最基本工具。若有高壓,聯(lián)機(jī)仿真器調(diào)試時(shí),將會(huì)損壞仿真器等,有時(shí)會(huì)使應(yīng)用系統(tǒng)中的集成塊發(fā)熱損壞。 排除電源故障在通電前,一定要檢查電源電壓的幅值和極性,否則很容易造成集成塊損壞??梢圆扇z查元器件與設(shè)計(jì)要求的型號(hào)、規(guī)格和安裝是否一致。必要時(shí)利用數(shù)字萬(wàn)用表的短路測(cè)試功能,可以縮短排錯(cuò)時(shí)間。排除的方法是首先將加工的印制板認(rèn)真對(duì)照原理圖,看兩者是否一致。 排除邏輯故障這類故障往往由于設(shè)計(jì)和加工制板過(guò)程中工藝性錯(cuò)誤所造成的??梢?jiàn)硬件的調(diào)試是基礎(chǔ),如果硬件調(diào)試不通過(guò),軟件設(shè)計(jì)則是無(wú)從做起。單片機(jī)系統(tǒng)的硬件調(diào)試和軟件調(diào)試是不能分開(kāi)的,許多硬件錯(cuò)誤是在軟件調(diào)試中被發(fā)現(xiàn)和糾正的。調(diào)試部分是單片機(jī)系統(tǒng)設(shè)計(jì)中至關(guān)重要的部分。5 系統(tǒng)調(diào)試 硬件的調(diào)試在單片機(jī)開(kāi)發(fā)過(guò)程中,從硬件設(shè)計(jì)到軟件設(shè)計(jì)都需要做到準(zhǔn)確無(wú)誤。仿真圖2單片機(jī)煤氣報(bào)警系統(tǒng)仿真圖2所示,此模塊使用LED數(shù)碼管進(jìn)行選擇動(dòng)態(tài)顯示ACD0809采集的濃度信息。單片機(jī)煤氣報(bào)警系統(tǒng)仿真圖1所示,仿真圖中用05V的電壓表顯示當(dāng)前輸入的電壓,并代替了傳感器。圖44 十六進(jìn)制轉(zhuǎn)化十進(jìn)制子程序流程圖 顯示子程序設(shè)計(jì)本次設(shè)計(jì)采用的是四位并行接口動(dòng)態(tài)顯示電路 開(kāi)始調(diào)入字符偏移量和位選代碼查表送入顯示延時(shí)2MS指向下一個(gè)偏移量3位顯示完成?圖45 顯示子程序流程圖 數(shù)據(jù)處理模塊Y煙霧超標(biāo)信號(hào)輸入打開(kāi)繼電器、蜂鳴器開(kāi)始定時(shí)器打開(kāi)時(shí)間計(jì)時(shí)報(bào)警時(shí)間已到?N停止報(bào)警46數(shù)據(jù)處理模塊 電路仿真單片機(jī)煤氣報(bào)警系統(tǒng)仿真圖如圖47所示,此為濃度檢測(cè)正常狀態(tài);單片機(jī)煤氣報(bào)警系統(tǒng)仿真圖如圖47所示,此為濃度超限報(bào)警狀態(tài);單片機(jī)煤氣報(bào)警系統(tǒng)仿真圖如圖47所示,此為傳感器顯示當(dāng)前的濃度。 (41)式中Y上區(qū)間上限濃度值Y下區(qū)間下限濃度值Y濾實(shí)際氣體測(cè)試濃度值X上區(qū)間上限濃度對(duì)應(yīng)電壓值X下區(qū)間下限濃度對(duì)應(yīng)電壓值X濾實(shí)際氣體測(cè)試濃度對(duì)應(yīng)電壓值圖43 線性化處理子程序流程圖 十六進(jìn)制轉(zhuǎn)化十進(jìn)制子程序設(shè)計(jì)經(jīng)過(guò)線性化處理后的濃度是十六進(jìn)制的,而LED顯示的濃度是十進(jìn)制的,所以要進(jìn)行十六進(jìn)制轉(zhuǎn)化十進(jìn)制子程序處理,再送入顯示子程序。濃度0%LEL99%LEL分成8段如下: 0%LEL~10%LEL 10%LEL~20%LEL 20%