【文章內(nèi)容簡介】
到單片機中首先雙擊單片機 點擊 Program File 欄的文件包添加 HEX 文件 之后便可以仿真了但沒有出現(xiàn)預(yù)期結(jié)果時就要檢查程序的功能實現(xiàn)是否正確還可以添加 omf 文件查看程序運行情況以檢查出現(xiàn)錯誤的原因具體這里就不再介紹如下圖 下圖為仿真的結(jié)果是將 200Hz 的正弦波檢測并顯示出來的結(jié)果 第 5 章 單片機應(yīng)用系統(tǒng)調(diào)試 單片機應(yīng)用系統(tǒng)的硬件調(diào)試和軟件調(diào)試是分不開的許多硬件故障是在調(diào)試軟件時才發(fā)現(xiàn)的但通常是先排除系統(tǒng)中明顯的硬件故障后才和軟件結(jié)合起來調(diào)試如電解電容二極管的極性錯誤集成塊安裝方向 錯誤等在印刷電路板布線密度高的情況下 極易因工藝原因造成短路引起系統(tǒng)不可靠的因素很多如金屬化孔接插件接觸不良會造成系統(tǒng)時好時壞內(nèi)部和外部的干擾電源紋波系數(shù)過大器件負載過大等造成邏輯電平不穩(wěn)定另外走線和布局的不合理等也會引起系統(tǒng)可靠性差若樣機中存在電源故障則加電后將造成器件損壞電源的故障包括電壓值不符合設(shè)計要求電源引出線和插座不對應(yīng)電源功率不足負載能力差對于樣機所用的電源事先必須單獨調(diào)試調(diào)試好后檢查其電壓值負載能力極性等均符合要求才能加到系統(tǒng)的各個部件上在不插片子的情況下加電檢查各插件上引腳的電位仔細測量各地 點電位是否正常尤其應(yīng)注意單片機插座上的各點電位是否正常若有高壓聯(lián)機時將會損壞開發(fā)機對于模塊結(jié)構(gòu)程序要一個個子程序分別調(diào)試調(diào)試子程序時一定要符合現(xiàn)場環(huán)境即入口條件和出口條件調(diào)試的手段可采用單步運行方式和斷點運行方式通過檢查用戶系統(tǒng) CPU 的現(xiàn)場 RAM 的內(nèi)容和 IO 口的狀態(tài)檢測程序執(zhí)行結(jié)果是否符合設(shè)計要求通過檢測可以發(fā)現(xiàn)程序中的死循環(huán)錯誤機器碼錯誤及轉(zhuǎn)移地址的錯誤同時也可以發(fā)現(xiàn)用戶系統(tǒng)中的硬件故障軟件算法及硬件設(shè)計錯誤在調(diào)試過程中不斷調(diào)整用戶系統(tǒng)的軟件和硬件逐步通過一個個程序模塊各程序模塊通過后可以把各功能塊聯(lián)合起 來一起進行整體程序綜合調(diào)試在這階段若發(fā)生故障可以考慮各子程序在運行時是否破壞現(xiàn)場緩沖單元是否發(fā)生沖突零位的建立和清除在設(shè)計上有否失誤堆棧區(qū)域有否溢出輸入設(shè)備的狀態(tài)是否正常等等若用戶系統(tǒng)是在開發(fā)系統(tǒng)的監(jiān)控程序下運行時還要考慮用戶緩沖單元是否和監(jiān)控程序的工作單元發(fā)生沖突單步和斷點調(diào)試后還應(yīng)進行連續(xù)調(diào)試這是因為單步運行只能驗證程序的正確與否而不能確定定時精度 CPU 的實時響應(yīng)等問題待全部完成后應(yīng)反復(fù)運行多次除了觀察穩(wěn)定性之外還要觀察用戶系統(tǒng)的操作是否符合原始設(shè)計要求安排的用戶操作是否合理等必要時還要作適當修正在全部 調(diào)試和修改完成后將用戶軟件固化于 EPROM 中插入用戶樣機后用戶系統(tǒng)即能脫離開發(fā)機獨立工作至此系統(tǒng)研制完成 1 晶振的準確度會影響一秒定時的準確度從而引起測量結(jié)果誤差 2 單片機計數(shù)速率的限制引起誤差被測信號頻率越高測量誤差越大且所測信號頻率不能超過 500kHz 這是因為用軟件的方法使單片機定時 1秒時測量頻率最大為 25kHz 20Hz當所測頻率越接近 25kHz 20Hz時測量結(jié)果與實際頻率的誤差就越大 3 原理上存在177。 1 誤差由于該設(shè)計是在計數(shù)門限時間一秒內(nèi)的頻率信號脈沖數(shù)所以定時開始時的第一個脈沖和定 時時間到時的最后一個脈沖信號是否被記錄存在隨機性這種誤差對測量頻率低的信號影響較大 54 減小誤差措施 1 選用頻率較高和穩(wěn)定性好的晶振如選 12 MHz的晶振可使測量范圍擴大穩(wěn)定性好的晶振 2 測量頻率較高的信號時可先對信號進行分頻再進行測量 3 延長門限時間減少原理上177。 1 的相對誤差 4 可多次測量取平均值 第 6 章 總結(jié) 本文通過運用單片機 Proteus 及 keil 仿真軟件成功地實現(xiàn)了數(shù)字頻率計的設(shè)計數(shù)字頻率計是一種基本的測量儀器是用數(shù)字顯示被測信號頻率的儀器 如配以適當?shù)膫鞲衅? 可以對多種物理 量進行測試 因此 它被廣泛應(yīng)用于航天電子測控等領(lǐng)域隨著電子技術(shù)的快速發(fā)展 它將被更廣泛的應(yīng)用到各個領(lǐng)域中去 目前市場上的頻率計功能很多價格不菲然而在很多實際應(yīng)用場合只需要單獨測量頻率不需要太多功能如果使用市面上的頻率計就會有很大的浪費本文研究的頻率計已經(jīng)通過了仿真板調(diào)試各項功能達到了預(yù)定的設(shè)計指標整個系統(tǒng)體積較小價格便宜操作簡單顯示清晰且誤差小有較高的實用價值 致 謝 感謝 參考文獻 [1]華成英童 出版社 20215 [2] 出版社 20215 [3]譚 出版社 20217 [4]周潤景張麗娜 劉應(yīng)群主編 proteus 入門使用教程機械工業(yè)出版社 20219 [5]張毅坤陳善久裘雪紅編單片微型計算機原理與應(yīng)用西安電子科技大學出版社 202112 [6]張 出版社 20217 [7]王幸之鐘愛琴王雷王閃編 AT89 系列單片機原理與接口技術(shù)北京航空航天大學出版社 20215 [8]閆玉德俞虹編 MCS51單片機原理與應(yīng)用 C語言版機械工業(yè)出版社 20211 [9]尹國光編基于單片機的數(shù)字頻率計的設(shè)計和仿真中國新通信 技術(shù)版 20214 [10]郝建國劉立新黨建華編 基于單片機的頻率計設(shè)計 西安郵電學院學報 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