【文章內(nèi)容簡介】
到單片機(jī)中首先雙擊單片機(jī) 點(diǎn)擊 Program File 欄的文件包添加 HEX 文件 之后便可以仿真了但沒有出現(xiàn)預(yù)期結(jié)果時(shí)就要檢查程序的功能實(shí)現(xiàn)是否正確還可以添加 omf 文件查看程序運(yùn)行情況以檢查出現(xiàn)錯(cuò)誤的原因具體這里就不再介紹如下圖 下圖為仿真的結(jié)果是將 200Hz 的正弦波檢測(cè)并顯示出來的結(jié)果 第 5 章 單片機(jī)應(yīng)用系統(tǒng)調(diào)試 單片機(jī)應(yīng)用系統(tǒng)的硬件調(diào)試和軟件調(diào)試是分不開的許多硬件故障是在調(diào)試軟件時(shí)才發(fā)現(xiàn)的但通常是先排除系統(tǒng)中明顯的硬件故障后才和軟件結(jié)合起來調(diào)試如電解電容二極管的極性錯(cuò)誤集成塊安裝方向 錯(cuò)誤等在印刷電路板布線密度高的情況下 極易因工藝原因造成短路引起系統(tǒng)不可靠的因素很多如金屬化孔接插件接觸不良會(huì)造成系統(tǒng)時(shí)好時(shí)壞內(nèi)部和外部的干擾電源紋波系數(shù)過大器件負(fù)載過大等造成邏輯電平不穩(wěn)定另外走線和布局的不合理等也會(huì)引起系統(tǒng)可靠性差若樣機(jī)中存在電源故障則加電后將造成器件損壞電源的故障包括電壓值不符合設(shè)計(jì)要求電源引出線和插座不對(duì)應(yīng)電源功率不足負(fù)載能力差對(duì)于樣機(jī)所用的電源事先必須單獨(dú)調(diào)試調(diào)試好后檢查其電壓值負(fù)載能力極性等均符合要求才能加到系統(tǒng)的各個(gè)部件上在不插片子的情況下加電檢查各插件上引腳的電位仔細(xì)測(cè)量各地 點(diǎn)電位是否正常尤其應(yīng)注意單片機(jī)插座上的各點(diǎn)電位是否正常若有高壓聯(lián)機(jī)時(shí)將會(huì)損壞開發(fā)機(jī)對(duì)于模塊結(jié)構(gòu)程序要一個(gè)個(gè)子程序分別調(diào)試調(diào)試子程序時(shí)一定要符合現(xiàn)場環(huán)境即入口條件和出口條件調(diào)試的手段可采用單步運(yùn)行方式和斷點(diǎn)運(yùn)行方式通過檢查用戶系統(tǒng) CPU 的現(xiàn)場 RAM 的內(nèi)容和 IO 口的狀態(tài)檢測(cè)程序執(zhí)行結(jié)果是否符合設(shè)計(jì)要求通過檢測(cè)可以發(fā)現(xiàn)程序中的死循環(huán)錯(cuò)誤機(jī)器碼錯(cuò)誤及轉(zhuǎn)移地址的錯(cuò)誤同時(shí)也可以發(fā)現(xiàn)用戶系統(tǒng)中的硬件故障軟件算法及硬件設(shè)計(jì)錯(cuò)誤在調(diào)試過程中不斷調(diào)整用戶系統(tǒng)的軟件和硬件逐步通過一個(gè)個(gè)程序模塊各程序模塊通過后可以把各功能塊聯(lián)合起 來一起進(jìn)行整體程序綜合調(diào)試在這階段若發(fā)生故障可以考慮各子程序在運(yùn)行時(shí)是否破壞現(xiàn)場緩沖單元是否發(fā)生沖突零位的建立和清除在設(shè)計(jì)上有否失誤堆棧區(qū)域有否溢出輸入設(shè)備的狀態(tài)是否正常等等若用戶系統(tǒng)是在開發(fā)系統(tǒng)的監(jiān)控程序下運(yùn)行時(shí)還要考慮用戶緩沖單元是否和監(jiān)控程序的工作單元發(fā)生沖突單步和斷點(diǎn)調(diào)試后還應(yīng)進(jìn)行連續(xù)調(diào)試這是因?yàn)閱尾竭\(yùn)行只能驗(yàn)證程序的正確與否而不能確定定時(shí)精度 CPU 的實(shí)時(shí)響應(yīng)等問題待全部完成后應(yīng)反復(fù)運(yùn)行多次除了觀察穩(wěn)定性之外還要觀察用戶系統(tǒng)的操作是否符合原始設(shè)計(jì)要求安排的用戶操作是否合理等必要時(shí)還要作適當(dāng)修正在全部 調(diào)試和修改完成后將用戶軟件固化于 EPROM 中插入用戶樣機(jī)后用戶系統(tǒng)即能脫離開發(fā)機(jī)獨(dú)立工作至此系統(tǒng)研制完成 1 晶振的準(zhǔn)確度會(huì)影響一秒定時(shí)的準(zhǔn)確度從而引起測(cè)量結(jié)果誤差 2 單片機(jī)計(jì)數(shù)速率的限制引起誤差被測(cè)信號(hào)頻率越高測(cè)量誤差越大且所測(cè)信號(hào)頻率不能超過 500kHz 這是因?yàn)橛密浖姆椒ㄊ箚纹瑱C(jī)定時(shí) 1秒時(shí)測(cè)量頻率最大為 25kHz 20Hz當(dāng)所測(cè)頻率越接近 25kHz 20Hz時(shí)測(cè)量結(jié)果與實(shí)際頻率的誤差就越大 3 原理上存在177。 1 誤差由于該設(shè)計(jì)是在計(jì)數(shù)門限時(shí)間一秒內(nèi)的頻率信號(hào)脈沖數(shù)所以定時(shí)開始時(shí)的第一個(gè)脈沖和定 時(shí)時(shí)間到時(shí)的最后一個(gè)脈沖信號(hào)是否被記錄存在隨機(jī)性這種誤差對(duì)測(cè)量頻率低的信號(hào)影響較大 54 減小誤差措施 1 選用頻率較高和穩(wěn)定性好的晶振如選 12 MHz的晶振可使測(cè)量范圍擴(kuò)大穩(wěn)定性好的晶振 2 測(cè)量頻率較高的信號(hào)時(shí)可先對(duì)信號(hào)進(jìn)行分頻再進(jìn)行測(cè)量 3 延長門限時(shí)間減少原理上177。 1 的相對(duì)誤差 4 可多次測(cè)量取平均值 第 6 章 總結(jié) 本文通過運(yùn)用單片機(jī) Proteus 及 keil 仿真軟件成功地實(shí)現(xiàn)了數(shù)字頻率計(jì)的設(shè)計(jì)數(shù)字頻率計(jì)是一種基本的測(cè)量儀器是用數(shù)字顯示被測(cè)信號(hào)頻率的儀器 如配以適當(dāng)?shù)膫鞲衅? 可以對(duì)多種物理 量進(jìn)行測(cè)試 因此 它被廣泛應(yīng)用于航天電子測(cè)控等領(lǐng)域隨著電子技術(shù)的快速發(fā)展 它將被更廣泛的應(yīng)用到各個(gè)領(lǐng)域中去 目前市場上的頻率計(jì)功能很多價(jià)格不菲然而在很多實(shí)際應(yīng)用場合只需要單獨(dú)測(cè)量頻率不需要太多功能如果使用市面上的頻率計(jì)就會(huì)有很大的浪費(fèi)本文研究的頻率計(jì)已經(jīng)通過了仿真板調(diào)試各項(xiàng)功能達(dá)到了預(yù)定的設(shè)計(jì)指標(biāo)整個(gè)系統(tǒng)體積較小價(jià)格便宜操作簡單顯示清晰且誤差小有較高的實(shí)用價(jià)值 致 謝 感謝 參考文獻(xiàn) [1]華成英童 出版社 20215 [2] 出版社 20215 [3]譚 出版社 20217 [4]周潤景張麗娜 劉應(yīng)群主編 proteus 入門使用教程機(jī)械工業(yè)出版社 20219 [5]張毅坤陳善久裘雪紅編單片微型計(jì)算機(jī)原理與應(yīng)用西安電子科技大學(xué)出版社 202112 [6]張 出版社 20217 [7]王幸之鐘愛琴王雷王閃編 AT89 系列單片機(jī)原理與接口技術(shù)北京航空航天大學(xué)出版社 20215 [8]閆玉德俞虹編 MCS51單片機(jī)原理與應(yīng)用 C語言版機(jī)械工業(yè)出版社 20211 [9]尹國光編基于單片機(jī)的數(shù)字頻率計(jì)的設(shè)計(jì)和仿真中國新通信 技術(shù)版 20214 [10]郝建國劉立新黨建華編 基于單片機(jī)的頻率計(jì)設(shè)計(jì) 西安郵電學(xué)院學(xué)報(bào) 20218 附錄Ⅰ 電路原理圖 附錄Ⅱ 外文資料與翻譯 Remote Type MCU TimerEvent Counters TimerEvent Counters As the HT48RA02HT48CA02 and HT48RA01HT48CA01 do not contain internal timers note that this section does not apply to these devices The provision of internal timers form an important part of any microcontroller giving the designer ameans of carrying out time related functionsAlthough the HT48RA02HT48CA02 and HT48RA01HT 48CA01 devices do not possess any internal TimerEvent Counters the HT48RA1HT48CA1 HT48RA3HT48CA 3 and HT48RA5HT48CA5 devices contain two internalTimerEvent Counters namely one 8bit timer and one 16bit timer As each timer has three different operating modes they can be configured to operate as a general timer an external event counteror as a pulse width measurement device In the case of 8bit timers the provision of an internal8stage prescaler in the timer clock circuitry gives added range to the 8bit timers There are two types of registers related to the TimerEvent Counters The first is the register thatcontains the actual value of the timer and into which an initial value can be preloaded Reading from this register retrieves the contents of the TimerEvent Counter The second type of associated register is the timer control register which defines the timer options and determines how thetimer is to be used The timer clock source for the 8bit timer can be configured to e from the internal system clock source fSYS or alternately from the external timer input pin TMR0 The timer clock source for the 16bit timer can be configured to e from the internal system clock source divided by 4 namely fSYS4 or alternately from the external timer input pin TMR1 An external clock source is used when the timer is in the event counting mode the clock source beingprovided on the external timer pin known as TMR0 or TMR1 which are pinshared with the PC0 and PC5 IO pins respectively Depending upon the condition of the T0ET1E bit in the correspondingtimer control register each high to low or low to high transition on the external timer inputpin will increment the counter by one Configuring the TimerEvent Counter Input Clock Source The internal timer_s clock source can originate from either the system clock or from an external clock source The system clock input timer source is used when the timer is in the timer mode or in the pulse width measurement mode For the 8bit timers the internal timer clock also passes through a prescaler the value of which is conditioned by the TMR0C Timer Control Register bitsT0PSC2 T0PSC1 and T0PSC0 An external clock source is used when the timer is in the event counting mode the clock source being provided on an external timer pin TMR0 or TMR1 depending upon which timer is used Depending upon the condition of the T0ET1E bit each high to low or low to high transition on the external timer pin will increment the counter by one Timer Registers _ TMR0 TMR1LTMR1H The timer registers are special function registers located in the special purpose Data Memory and is the place where the actual timer value is stored For the 8bit timer this register is known as TMR0 In the case of the 16bit timer a pair of 8bit registers known as TMR1Land TMR1H are required to store the 16bit timer value The value in the timer registers increases by one each time an internal clock pulse is received or an external transition occurs on the external timer pin The timer will count from the initial value loaded by the preload register to the full count of FFH for the 8bit timer or FFFFH for the 16bit timer at which point the timer overflows and an interna