基于AT89C52单片机的简易频率计设计说明书
基于单片机简易频率计设计
基于单片机简易频率计设计一、前言频率计是一种测量电信号频率的仪器,其应用广泛。
本文将介绍如何基于单片机设计一个简易的频率计。
二、设计思路本次设计采用单片机作为核心控制芯片,通过捕获输入信号的上升沿和下降沿来计算出信号的周期,从而得到信号的频率。
具体实现过程如下:1. 选择合适的单片机选择一款适合本次设计要求的单片机,需要考虑其性能、价格、易用性等因素。
常见的单片机有STC89C52、AT89C51等。
2. 硬件电路设计硬件电路主要包括输入端口、捕获定时器模块、显示模块等。
其中输入端口需要接收待测信号,捕获定时器模块用于捕获信号上升沿和下降沿的时间,显示模块则用于显示测得的频率值。
3. 软件程序设计软件程序主要包括初始化程序、捕获中断服务函数和主函数等。
其中初始化程序用于设置捕获定时器模块和显示模块参数,捕获中断服务函数则是实现对输入信号上升沿和下降沿时间的捕获与计算,主函数则用于控制程序流程和显示结果。
三、硬件设计1. 输入端口设计输入端口需要接收待测信号,一般采用BNC接头。
由于输入信号可能存在较高的电压和噪声,因此需要加入滤波电路以保证输入信号的稳定性。
2. 捕获定时器模块设计捕获定时器模块是本次设计的核心部分,其主要功能是捕获输入信号的上升沿和下降沿时间,并通过计算得到信号周期和频率值。
常见的捕获定时器模块有16位定时器/计数器、32位定时器/计数器等。
在本次设计中,我们选择了16位定时器/计数器。
3. 显示模块设计显示模块主要用于显示测得的频率值。
常见的显示模块有LED数码管、LCD液晶屏等。
在本次设计中,我们选择了LCD液晶屏。
四、软件程序设计1. 初始化程序初始化程序主要包括设置捕获定时器模块参数、设置LCD液晶屏参数等。
2. 捕获中断服务函数捕获中断服务函数是实现对输入信号上升沿和下降沿时间的捕获与计算,其具体实现过程如下:(1)当捕获定时器模块捕获到输入信号上升沿时,记录当前时间值。
基于AT89S52单片机的简易频率计设计
简易频率计的设计中文摘要频率测量是电子学测量中最为基本的测量之一。
频率计主要是由信号输入和放大电路、单片机模块、分频模块及显示电路模块组成。
AT89S52单片机是频率计的控制核心,来完成它待测信号的计数,译码,显示以及对分频比的控制。
利用它内部的定时/计数器完成待测信号频率的测量。
在整个设计过程中,所制作的频率计采用外部分频,实现10Hz~2MHz的频率测量,而且可以实现量程自动切换流程。
以AT89S52单片机为核心,通过单片机内部定时/计数器的门控时间,方便对频率计的测量。
其待测频率值使用四位共阳极数码管显示,并可以自动切换量程,单位分别由红、黄、绿3个LED指示。
本次采用单片机技术设计一种数字显示的频率计,具有测量准确度高,响应速度快,体积小等优点。
关键词:频率计;单片机;计数器;量程自动切换The design of simple Frequency MeasurementABSTRACTFrequency measurement is the most basic measurement in Electronic field. A simple frequency meter mainly by the signal input and amplifying circuit, microcontroller module, sub-frequency circuit module and display module. AT89S52 MCU is the control core frequency of dollars to complete its count of the signal under test, decoding, display and control of the frequency division ratio. Using its internal timer or counter to complete the signal of the under test cycle / frequency of measurement.Throughout the design process, periodic measurement of the frequency meter application and the corresponding mathematical treatment to achieve 10Hz ~ 2MHz frequency measurements, and can automatically switch the flow to achieve scale. To the core of AT89S52 microcontroller, with the MCU internal timer / counter gate time, it can be easier for frequency measurement. The use of microcomputer technology to design a digital display of frequency meter, have a measurement of high accuracy, fast response, small size and so on.KEY WORD: Frequency meter; single chip; counter; range automatically switch目录第一章前言 (1)1.1频率计概述 (1)1.2频率计发展与应用 (1)1.3频率计设计内容 (1)第二章系统总体方案设计 (2)2.1测频的原理 (2)2.2总体思路 (3)2.3具体模块 (3)第三章硬件电路具体设计 (5)3.1AT89S52主控制器模块 (5)3.1.1 AT89S52的介绍 (5)3.1.2 复位电路及时钟电路 (6)3.1.3 引脚功能 (7)3.1.4 单片机引脚分配 (8)3.2电源模块 (9)3.2.1 直流稳压电源的基本原理 (9)3.2.2 电源电路设计 (10)3.3放大整形模块 (11)3.4分频设计模块 (11)3.4.1 分频电路分析 (11)3.4.2 74LS161芯片介绍 (12)3.4.3 74LS151芯片介绍 (13)3.4.4 分频电路 (14)3.5显示模块 (14)3.5.1 数码管介绍 (15)3.5.2 频率值显示电路 (15)3.5.3 档位转换指示电路 (16)第四章系统的软件设计 (17)4.1软件模块设计 (17)4.2中断服务子程序 (18)4.3显示子程序 (19)4.4量程档自动转换子程序 (20)4.5应用软件简介 (20)4.5.1 Keil简介 (21)4.5.2 protues简介 (22)第五章频率计的系统调试 (23)5.1硬件调试 (23)5.1.1 电源模块调试 (23)5.1.2整形模块调试 (24)5.1.3 分频模块调试 (25)5.2软件调试 (25)5.2.1 Pouteus软件调试 (25)5.2.2 功能调试 (26)5.3系统调试 (27)5.3.1 系统软件调试 (27)5.3.2 系统软硬件调试 (27)5.4误差分析 (28)第六章总结 (23)参考文献 (24)致谢 (25)附录 (1)第一章前言频率测量是电子学测量中最为基本的测量之一。
基于AT89S52的数字频率计设计
基于AT89S52的数字频率计设计基于AT89S52的数字频率计设计标签:频率计AT89S521602ALED分享到:在电子领域内,频率是一种最基本的参数,并与其他许多电参量的测量方案和测量结果都有着十分密切的测量精度。
因此,频率的测量就显示得尤为重要,测频方法的研究越来越受到重视。
频率计作为测量仪器的一种,常称为电子计数器,它的基本功能是测量信号的频率和周期,频率计的应用范围很广,它不仅应用于一般的简单仪器测量,而且还广泛应用于教学、科研、高精度仪器测量、工业控制等其他领域。
随着微电子技术和计算机的迅速发展,特别是单片机的出现和发展,使传统的电子测量仪器在原理、功能、耗电、可靠性等方面都发生了重大的变化。
目前,市场上有各种多功能、高精度、高频率的数字频率计,但价格不菲。
为适应实际工作的需要,本文考虑以单片机(AT89 S52)为控制平台和一个1602ALED显示器作为显示部件设计的一种频率计,整个设计采用定时、计数的方法测量频率,不但切实可行,而且体积小、成本低、低功耗、精度高、可自动量程转换、保密性强、设计简单,大大降低了设计成本和实现复杂度。
频率计的硬件电路是用PRIT EL绘图软件绘制而成,软件部分的单片机控制程序,是以KELL-51作为开发工具用汇编语言编写而成,而频率计的实现则是选用Proteus仿真软件来模拟和测试,最后通过综合调试,能实现所有要求的功能,完全满足本次设计的要求。
1 设计思路传统的测频仪器体积很大,耗能量大,主要靠手工操作,而最大的缺点是不以可编程,其量程转换、数据测量、采样控制和处理等均不能通过程序指令来进行控制,无法作为一个微型智能子系统与某一大型自动控制或测试系统进行接口。
针对这些缺点,本频率计在设计上做了改进,首先以信号放大整形后的方波脉冲作为控制闸门信号,然后采用计数器和锁存器对不同频率范围的信号直接进行计数来完成分频功能,分频后的信号由接口电路送给单片机,由单片机的计数对其进行计数,最后将计数结果通过运算转变为原号的频率数值,最后通过动态显示电路显示数值。
简易数字频率计设计论文
课程设计报告设计课题:简易书数字频率计专业班级:学生姓名:学号:指导教师:设计时间:2011年6月20号中文摘要频率测量是电子学测量中最为基本的测量之一。
频率计主要是由信号输入和放大电路、单片机模块、分频模块及显示电路模块组成。
AT89C52单片机是频率计的控制核心,来完成它待测信号的计数,译码,显示以及对分频比的控制。
利用它内部的定时/计数器完成待测信号频率的测量。
在整个设计过程中,所制作的频率计采用外部分频,实现1Hz~1MHz的频率测量,而且可以实现量程自动切换流程。
以AT89C52单片机为核心,通过单片机内部定时/计数器的门控时间,方便对频率计的测量。
其待测频率值使用四位共阴极数码管显示,并可以自动切换量程,单位分别由3个发光二极管指示。
本次采用单片机技术设计一种数字显示的频率计,具有测量准确度高,响应速度快,体积小等优点。
关键词:频率计;单片机;计数器;量程自动切换The design of simple Frequency MeasurementABSTRACTFrequency measurement is the most basic measurement in Electronic field. A simple frequency meter mainly by the signal input and amplifying circuit, microcontroller module, sub-frequency circuit module and display module. AT89S52 MCU is the control core frequency of dollars to complete its count of the signal under test, decoding, display and control of the frequency division ratio. Using its internal timer or counter to complete the signal of the under test cycle / frequency of measurement.Throughout the design process, periodic measurement of the frequency meter application and the corresponding mathematical treatment to achieve 1Hz ~ 1MHz frequency measurements, and can automatically switch the flow to achieve scale. To the core of AT89S52 microcontroller, with the MCU internal timer / counter gate time, it can be easier for frequency measurement. The use of microcomputer technology to design a digital display of frequency meter, have a measurement of high accuracy, fast response, small size and so on.KEY WORD: Frequency meter; single chip; counter; range automatically switch目录第一章前言 (1)1.1频率计概述 (1)1.2频率计发展与应用 (1)1.3频率计设计内容 (1)第二章系统总体方案设计 (2)2.1测频的原理 (2)2.2总体思路 (3)2.3具体模块 (4)第三章硬件电路具体设计 (4)3.1AT89C52主控制器模块 (4)3.1.1 AT89C52的介绍 (4)3.1.2 复位电路及时钟电路 (5)3.1.3 引脚功能 (6)3.1.4 单片机引脚分配................................................. 错误!未定义书签。
基于AT89C52单片机操纵的简易RLC测试仪
基于AT89C52单片机操纵的简易RLC测试仪本文所设计的系统是基于AT89C52单片机操纵的简易RLC测试仪。
为了充分利用单片机的运算和操纵功能,方便的实现测量。
把参数R、L、C 转换成频率信号f,然后用单片机计数后再运算求出R、L、C的值,并送显示。
转换的原理别离是RC振荡电路和电容三点式振荡电路。
为了比较准确的测试而频率的计数那么是利用等精度数字频率计完成。
然后再将结果送单片机运算,并在LED显示器上显示所测得的数值。
通过一系列的系统调试,本测试仪抵达了测试标准。
通过测试,第1章:绪论电路参数R,L,C电路参数—电阻、电容和电感是电路的三种大体参数,也是描述网络和系统的重要参数,普遍应用于科学研究、教学实验、工农业生产、通信、医疗及军事等领域中。
例如在强电系统中,输电线路中的传输线,电气设备中继电器、变压器、发电机等,都是用阻抗参数R、L、C来描述的。
人们通过测试阻抗参数能够判定设备的好坏,是不是存在故障隐患。
在弱电系统中,电路参数元件的好坏、量值的大小直接阻碍所设计的线路板的正常工作和靠得住性。
因此对它们的测试具有重要的意义。
电路参数的测量方式电路参数的测量一般是把被测参数通过转换电路变成直流电压或频率后进行测量。
1. 传统的RLC参数测量的方式种类很多,例如:对电阻的测量经常使用欧姆表直接测量,也能够利用对电阻施加一个电压,利用模拟电表和电流表测量取得电阻两头的电压值和流过电阻的电流值。
然后利用欧姆定理计算出电阻值;而对电感或电容的测试常采纳测量阻抗角和负阻抗,然后用数学公式计算出电阻和电抗的参数。
也能够采纳过度进程法测出时刻常数,由于电路中利用已知的固定电阻,因此能够通过计算,得出电抗参数。
在要求测试准确度高的地址常采纳交流电桥通过调整已知参数使得电桥达到平稳,读出电感或电容值。
上述方式,简单明了,测试也有必然的准确度;但必需采纳手工操作,费时费力且测量精度带有必然的人为因素。
2. 在上世纪70年代后,由于数字电子技术的进展,显现了数字式的RLC测试仪。
基于52单片机数字频率计系统设计报告
基于52单片机数字频率计系统设计报告学号:1108441096课程设计报告基于AT89C52单片机数字频率计系统设计院系电子信息工程学院专业电气工程及其自动化班级( 2 )姓名华杰摘要在电子技术中,频率是最基本的参数之一,同时也是一个非常重要的参数,并且与许多电参量的测量方案、测量结果都有十分密切的关系,因此,频率的测量就显得更为重要。
数字频率计是计算机、通讯设备、音频视频等科研生产领域不可缺少的测量仪器。
它是一种用十进制数字显示被测信号频率的数字测量仪器。
频率测量是电子学测量中最为基本的测量之一。
本文中详细介绍了频率计的仿真及设计过程。
本文设计了一种以单片机STC89C52为核心的数字频率计。
介绍了单片机、放大整形模块、分频模块和LCD1602显示模块等各个模块的组成和工作原理。
测量时,将被测输入信号送给单片机,通过程序控制计数,结果送LCD1602显示频率值。
本次设计是以单片机STC89C52为控制核心,利用它内部的定时/计数器完成待测信号频率的测量。
应用单片机的控制功能和数学运算能力,实现计数功能和频率的换算,最后显示测量的频率值。
本次设计所制作的频率计外围电路简单,大部分功能都通过软件编程实现,利用单片机控制实现频率计的自动换挡功能;用单片机中断控制端口实现频率的测量功能;通过分频电路实现对频率档位的控制。
本次设计的频率计具有测量准确度高,响应速度快,体积小等优点。
实现了1Hz~4MHz范围的频率测量,而且可以实现量程自动切换。
关键词:AT89C52;数字频率计;分频;放大电路目录摘要 (I)目录 (II)1 引言 (1)1.1研究背景及意义 (1)1.2 国内外研究现状 (1)2 总体方案设计 (2)2.1 数字频率计设计内容 (2)2.2 总体思路 (2)2.3 具体模块 (2)3 硬件设计 (4)3.1 电路设计的步骤 (4)3.2 STC89C52简介 (4)3.2.1STC89C52RC引脚功能说明 (5)3.2.2 单片机引脚分配 (6)3.3 信号调理及放大整形模块 (6)3.3.1 LM318介绍 (6)3.2.2 1N4733及74LS14介绍........................................... 错误!未定义书签。
单片机AT89C52简要说明
附录A 英文原文Microcomputer AT89C52 Synoptic ElucidationThe microcomputer AT89C52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, three 16-bit timer/counters, a six-vector two-level interrupt architecture,a full duplex serial port, on-chip oscillator, and clock circuitry.In addition, the AT89C52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning.The Power Down Mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next hardware reset,for the figure 1.Pin DescriptionVCC:Supply voltage.GND:Ground.Port 0:Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high impedance inputs.Port 0 can also be configured to be the multiplexed low order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pullups.Port 0 also receives the code bytes during Flash programming and outputs the code bytes during program verification.External pull-ups are required during program verification.Port 1:Port 1 is an 8-bit bidirectional 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 pull-ups 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 pull-ups.In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the following table.Port 1 also receives the low-order address bytes during Flash programming and verification.Port 2:Port 2 is an 8-bit 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 pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. Port 2 emits the high order address byte during fetches from external program memory and during accesses to external data memory that use 16-bit addresses (MOVX @DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.Port 2 also receives the high-order address bits and some control signals during Flash programming and verification.Port 3:Port 3 is an 8-bit 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 pull-ups 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 AT89C51, as shown in the following table.Port 3 also receives some control signals for Flash programming and verification.RST:Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device.ALE/PROG:Address Latch Enable 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/6the oscillator frequency and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped during each access to external data memory.If 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. Other- wise, the pin is weakly pulled high. Setting the ALE-disable bit hasno effect if the microcontroller is in external execution mode.PSEN:Program Store Enable is the read strobe to external program memory.When the AT89C52 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/VPP:External Access Enable. EA must be strapped to GND in order to enable the图A.1 AT89C52方框图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 the12-volt programming enable voltage(VPP) during Flash programming when 12-volt programming is selected.XTAL1:Input to the inverting oscillator amplifier and input to the internal clock operating circuit.XTAL2:Output from the inverting oscillator amplifier.Special Function Registers:Not all of the addresses are occupied, and unoccupied addresses may not be implemented on the chip.Read accesses to these addresses will in general return random data, and write accesses will have an indeterminate er software should not write 1s to these unlisted locations, since they may be used in future products to invoke new features. In that case, the reset or inactive values of the new bits will always be 0.Timer 2 Registers: Control and status bits are contained in registers T2CON and T2MOD for Timer 2. The register pair (RCAP2H,RCAP2L) are the Capture/Reload registers for Timer 2 in 16-bit capture mode or 16-bit auto-reload mode.Interrupt Registers: The individual interrupt enable bits are in the IE register. Two priori- ties can be set for each of the six interrupt sources in the IP register.Data Memory:The AT89C52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the Special Function Registers. That means the upper 128 When an instruction accesses an internal location above address 7FH, the address mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR space. Instructions that use direct addressing access SFR space. For example, the following direct addressing instruction accesses the SFR at location 0A0H (which is P2).Instructions that use indirect addressing access the upper 128 bytes of RAM. For example, the following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at address 0A0H, rather than P2 (whose address is 0A0H). Note that stack operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available as stack space.Timer 0 and 1:Timer 0 and Timer 1 in the AT89C52 operate the same way as Timer 0 and Timer 1 in the AT89C51.Timer 2:Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. The type of operation is selected by bit C/T2 in the SFR T2CON.Timer 2 has three operating modes: capture, auto-reload(up or down counting), and baud rate generator. The modes are selected by bits in T2CON.Timer 2consists of two 8-bit registers, TH2 and TL2. In the Timer function, the TL2 register is incremented every machine cycle. Since a machine cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency. In the Counter function, the register is incremented in response to a 1-to-0 transition at its corresponding external input pin, T2. In this function, the external input is sampled during S5P2 of every machine cycle. When the samples show a high in one cycle and a low in the next cycle, the count is incremented. The new count value appears in the register during S3P1 of the cycle following the one in which the transition was detected. Since two machine cycles (24 oscillator periods) are required to recognize a 1-to-0 transition,the maxi- mum count rate is 1/24 of the oscillator frequency.To ensure that a given level is sampled at least once before it changes, the level should be held for at least one full machine cycle.Capture Mode:In the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 is a 16-bit timer or counter which upon overflow sets bit TF2 in T2CON.This bit can then be used to generate an interrupt. If EXEN2 = 1, Timer 2 performs the same operation, but a 1-to-0 transition at external input T2EX also causes the current value in TH2 and TL2 to be captured into RCAP2H and RCAP2L, respectively. In addition, the transition at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt.Auto-Reload (Up or Down Counter):Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reload mode. This feature is invoked by the DCEN (Down Counter Enable) bit located in the SFR T2MOD (see Table 4). Upon reset, the DCEN bit is set to 0 so that timer 2 will default to count up. When DCEN is set, Timer 2 can count up or down, depending on the value of the T2EX pin. Timer 2 automatically count up when DCEN = 0. In this mode, two option s are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow. The overflow also causes the timer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The values in Timer in Capture ModeRCAP2H and RCAP2L are preset by software.If EXEN2 = 1, a 16-bit reload can be triggered either by an overflow or by a 1-to-0 transition at external input T2EX. This transi- tion also sets the EXF2 bit. Both the TF2 and EXF2 bits cangenerate an interrupt if enabled.Setting the DCEN bit enables Timer 2 to count up or down,as shown in Figure 3. In this mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timer registers,TH2 and TL2, respect- tively.A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded into the timer registers.The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit of resolution. In this operating mode, EXF2 does not flag an inter- rupt.Baud Rate Generator:Timer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON (Table 2). Note that the baud rates for transmit and receive can be different if Timer 2 is used for the receiver or trans- mitter and Timer 1 is used for the other function. Setting RCLK and/or TCLK puts Timer 2 into its baud rate generator mode, as shown in Figure 4.The baud rate generator mode is similar to the auto-reload mode, in that a rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which are preset by software.The baud rates in Modes 1 and 3 are determined by Timer2’s overflow rate according to the following (A.1)equation.Modes1 and 3 band rates=Timer 2 Overflow Rate16(A.1)The Timer can be configured for either timer or counter operation. In most applications, it is configured for timer operation (CP/T2 = 0). The timer operation is different for Timer 2 when it is used as a baud rate generator. Normally,as a timer, it increments every machine cycle (at 1/12 the oscillator frequency). As a baud rate generator, however, it increments every state time (at 1/2 the oscillator frequency).The baud rate formula is given below(A.2).modes 1 and 3 band Rate =Oscillator frequency32[65536-(RCAP2H,RCAP2L)](A.2)where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bit unsigned integer Timer 2 as a baud rate generator is showed.This figure is valid only if RCLK or TCLK = 1 in T2CON. Note that a rollover in TH2 does not set TF2 and will not generate an interrupt. Note too, that if EXEN2 is set, a 1-to-0 transition in T2EX will set EXF2 but will not cause a reload from (RCAP2H, RCAP2L) to (TH2, TL2). Thus when timer 2 is in use as a baud rate generator, T2EX can be used as an extra external interrupt. Note that when Timer 2 is running (TR2 = 1) as a timer in the baud rate generator mode, TH2 or TL2 should not be read from or written to. Under these conditions, the Timer is incremented every state time, and the results of a read or write may not be accurate. The RCAP2 registers may be read but should not be written to, because a write might overlap a reload and cause write and/or reload errors. The timer should be turned off (clear TR2) before accessing the Timer 2 or RCAP2 registers.附录B 中文翻译单片机AT89C52简要说明AT89C52提供以下标准功能:8k字节Flash闪速存储器,256字节内部RAM,32个I/O口线,3个16位定时/计数器,一个6向量两级中断结构,一个全双工串行通信口,片内振荡器及时钟电路。
毕业设计(论文)-基于AT89C52单片机的数字频率计设计
数字频率计设计摘要:本文提出设计数字频率计的多种方案,重点介绍以单片机AT89C52为控制核心,实现频率测量的数字频率计设计。
测频的基本原理是采用在高频段直接测频法,在低频段测周期法的设计思路;硬件部分由放大电路、波形变换和整形电路、闸门时基控制电路、分频电路、单片机和数据显示电路组成;软件部分由信号频率测量模块、周期测量模块、定时器中断服务模块、数据显示模块等功能模块实现。
应用单片机的控制功能和数学运算能力,实现计数功能和频率、周期的换算。
设计的频率计测量范围能够达到2HZ~50MHZ,满足所要求的频率范围,测量精度较高,平均相对误差仅为0.3401%。
另外,文章对频率测量过程中数据误差的来源进行了探讨,提出了减小误差的措施。
最后,文章还对频率计的设计方案提出了可扩展的地方。
关键词:数字频率计;单片机AT89C52;频率测量;周期测量;误差The design of digital frequency meterLU JiabinCollege of Engineering and Technology, Southwest University, Chongqing 400716, ChinaAbstract:This article proposes many kinds of plans design digital frequency meter, highlighting the design taking monolithic integrated circuit AT89C52 as the control core, the realization frequency measurement of digital frequency meter.Selected design ideas which directly measuring frequency law in the high-band and testing cycle law in the low-band; The hardware partially is composed by enlarged circuit、the profile transformation and the reshaping circuit、the gate at the base control circuits、sub-frequency circuits、the microcontroller and the data display electric circuit; The software design is achieved by many functional modules, such as the signal frequency measurement module、the signal cycle survey module、timer interruption of service module、the data display module and so on. Achieving counting function and conversion between cycle and frequency by using control functions and mathematics operation ability of microcontroller. Like these the survey scope can achieve 2HZ ~ 50MHZ, both can reach the frequency range requirements designed, the measuring accuracy high, and can cause the average relative measuring error to be only 0.3401%. In addition, the article has carried on the discussion to the data error origin in the process surveyed the frequency, and proposed the measures reduce the measuring error. Finally, the article also raise the frequency of the design options will be further improved.Key Words:Digital frequency meter; Microcontroller AT89C52; Frequency measurements; Measure- ment cycle; error文献综述科学技术发展到今天,数字化产品以其独特的优越性而越来越受到广大消费者的认可。
基于AT89C52单片机的计算器设计说明
电子设计大赛训练设计报告基于AT89C52 单片机的计算器设计指导老师:曾祥志.管立新.许粮作者:黄红平学校:赣南师范学院物理与电子信息工程完成时间2011年8月20日摘要计算器是微型电子计算机的一种特殊类型。
它与一般通用计算机的主要区别在于程序输入方式的不同。
计算器的程序一般都已经固定,只需按键输入数据和运算符号就会得出结果,很容易就能掌握。
而一般计算机的程序可以根据需要随时改动,或重新输入新的程序。
简易计算器主要用于加减乘除;科学计算器,又增添了初等函数运算。
随着微电子技术的不断发展,微处理芯片的集成程度越来越高,单片机已可以在一片芯片上同时集成cpu,存储器,定时器,计数器,并行和串行接口,看门狗,前置放大器,A|D 转换器,D|A 转换器等多种电路。
关键词:计算器、at89s52、液晶显示16021.简易计算器的设计方案1.1 硬件部分设计方案1. 单片机以AT89S52 来作为核心元器件2.按键部分采用4*4 行列式键盘,分别设定数字键和功能键。
3. 显示部分方案一:使用8 位LED 数码管来做显示。
LED 显示器是由发光二极管显示字段组成的显示器件,在单片机应用系统中通常使用的是七段LED,这种显示器有共阴极和共阳极两种,它具有成本低廉、配置灵活和单片机接口方便等特点。
方案二:使用液晶显示器来显示。
液晶是介于固态和液态间的有机化合物,将其加热会变成透明液态,冷却后变成结晶的混作固态。
在点击的作用下,产生冷热变化,从而影响它的透光性,来达到显示的目的。
LED 还具有以下几个优点:低压、微功耗、显示信息量大、长寿命、无辐射、无污染。
后选择的显示是液晶显示。
大致原理图如下。
(后改用AT89S52 代替AT89C51 )总的电路设计方案以单片机AT89S52 来作为核心元器件,外围采用4*4 行列式键盘作为输入,采用led1602 液晶显示来做输出。
这里重点介绍液晶输出地管脚,因为一开始本打算用数码管来做显示,后改为液晶,不是很熟悉。
基于单片机89C52的数字频率计
一引言1.1 课题的背景数字频率计是一种基础工业电子测量仪器,迄今已有30多年的发展历史。
早期,设计师们追求的目标主要是扩展测量范围,和提高测量精度、稳定度等。
这些也是人们衡量数字频率计的技术水平,决定数字频率计价格高低的主要依据。
目前随着微型处理器技术的迅速发展,数字频率计装置外观、功能日臻完善,成熟。
随着科学技术的发展和数字频率计的广泛应用,用户对数字频率计也提出了更高的要求。
对于低档产品要求操作方便,量程足够宽,可靠性高,价格低。
而对于中高档产品,则要求有高分辨率,高精度,高稳定度,高测量速率。
除通常通用频率计所具有的功能外,还要有数据处理功能,数据存储功能,统计分析功能,时域分析功能等等,或者包含电压测量等其他功能。
这些要求有的已经实现或者部分已经实现,但要真正完美的实现这些目标,对于设计者来说,还有许多工作要做。
随着数字集成电路技术的飞速发展,应用计数法原理制成的数字式频率测量仪器具有精度高、测量范围宽、稳定度高、便于实现测量过程自动化等一系列的突出特点。
1.2课题意义众所周之,电能质量直接关系到电力系统的供电安全和供电质量。
电能质量具有一个很重要的指标—频率。
频率不仅影响这系统中的有功功率,而且影响系统的有功与无功的平衡,即功率因数。
保证电力系统的频率合乎标准是系统运行调整的一项基本任务。
用电电器必须工作在合适的频率条件下。
变压器也是利用频率进行电压的变换。
频率在现代工业和日常生活中具有很重要的作用。
国防军事、科学研究、深空探索、GPS定位、罗兰定位、机械尺寸测量、大地测量、物理基准、导弹发射、卫星探测、空间技术等对频率具有精确的要求。
利用现在的控制技术对频率精确得测量据用很重要的意义。
1.3单片机的发展前景1.3.1单片机的特点单片机问世以来,以其惊人的速度占领市场。
目前单片机几乎渗透到我们生活的各个领域,几乎很难找到哪个领域没有单片机的踪迹。
单片机的主要优点在于:(1)控制性能强与可靠性能高单片机的设计是为了满足工业控制,所以实时控制能力特别强,CPU可以对I/O端口直接进行操作,位操作能力更是其它控制器无法比拟的。
基于89C52单片机的数字频率计的设计(DOC)
单片机课程设计报告题目:基于89C52单片机的数字频率计院(系):信息与通信学院专业:电子信息工程学生姓名: ------ 学号: ---------- 指导教师: -----2012 年 11 月 15 日摘要该系统以STC89S51单片机为核心, 应用单片机的运算和控制功能并采用LCD 显示器实时地将所测频率显示出来, 通过测量结果对比,分析了测量误差的来源,提出了减小误差应采取的措施。
频率计具有电路结构简单、成本低、测量方便、精度较高等特点,适合测量低频信号。
关键词:单片机,频率测量AbstractThe paper introduces one cymometer system Based on singlechip which applys the singlechip`s function of operation and control and displays the result by LCD. By comparing results, the source of measurement error is analysed, the measures are proposed for reducing errors. T he frequency meter has characteristics of simple circuit, low cost, easy measurement and high precision, it fits for measuring low frequency signals.Key words : Singlechip,frequency- measure引言 (1)1 课程设计概述 (1)1.1 课程设计任务及要求 (1)1.2 主要仪器 (1)1.3 数字频率计概述 (1)1.4 测频基本设计原理 (2)2 方案论证 (2)2.1 总体方案 (2)2.2 测频方案选择 (3)3硬件设计 (3)3.1系统功能描述 (3)3.2硬件电路设计框架 (3)3.3单片机部分 (4)3.4 放大整形部分 (4)3.5分频部分 (5)3.6 LCD显示和键盘部分 (6)4 软件设计 (6)4.1 主程序流程图设计 (6)4.2 子程序流程图设计 (7)4.2.1 显示程序 (7)4.2.2频率测量程序框图 (8)4.2.3 中断服务流程图 (8)5 系统调试 (9)5.1显示调试 (9)5.2键盘调试 (9)5.3前置放大整形调试 (9)5.4软件调试 (9)6结果分析与结论 (10)7总结 (10)参考文献 (11)附录 (12)引言:在工业生产、仪器仪表行业及实验教学中,经常会遇到频率的测量,我们经常使用的及目前市场上所售的频率测量装置,大多数是采用小规模集成电路及分离元件组成。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
单片机系统开发与应用工程实习报告选题名称:基于AT89C52单片机的简易频率计设计系(院):专业:计)班级:姓名:学号:指导教师:学年学期: 2009 ~ 2010 学年第 2 学期2010 年 5 月 30 日摘要:在电子技术中,频率是一个经常用到的参数之一,并且与许多电参量的测量方案、测量结果都有十分密切的关系,因此频率的测量就显得更为重要。
本项目主要阐述了以AT89C52单片机作为核心器件,采用模块化布局,设计一个简易数字频率计,以达到测量频率并进行显示的目的。
本项目利用单片机的内部定时器溢出产生中断来实现定时,把单片机内部的定时/计数器0作为定时器,实现2.5ms定时。
外部待测脉冲从单片机的TI(第15引脚)输入,以定时/计数器1作为计数器,利用中断方式来达到间接测量的目的。
最后采用四位数码管显示。
本设计采用C语言进行软件编程,用keil软件进行调试。
最后把调试成功后的程序固化到AT89C52单片机中,接到预先焊好的电路板上,接上待测脉冲,通电运行,数码管成功显示待测脉冲频率。
关键词:单片机;频率计;AT89C52目录1 项目综述 (1)1.1 设计要求 (1)1.2 系统设计 (1)2硬件设计 (2)2.1 电路原理图 (2)2.2 元件清单 (2)2.3 主要芯片引脚说明 (3)3 软件设计 (5)3.1 程序流程图 (5)3.2 软件设计简述 (5)3.3 程序清单 (6)4 系统仿真及调试 (11)4.1 硬件调试 (12)4.2 软件调试 (12)5 结果分析 (12)总结 (13)参考文献 (14)1 项目综述在电子技术中,频率是最基本的参数之一,并且与许多电参量的测量方案、测量结果都有十分密切的关系,因此频率的测量就显得更为重要。
本项目主要阐述了选择AT89C52单片机作为核心器件,采用模块化布局,设计一个简易数字频率计测量频率并进行显示。
1.1 设计要求基于AT89C52单片机简易频率计的设计要求如下:(1)测量范围。
幅度:0.5~5V;频率:1Hz~1MHz.(2)测试误差≤0.1%。
(3)用4位数码管显示。
当频率变化时,能通过数码管及时看到变化后的信号频率。
1.2 系统设计1.2.1 框图设计基于AT89C52单片机简易频率计的电路主要由数码管显示电路、复位电路、晶振电路、电源电路等几部分组成,系统框图如图3.1所示。
图3.1 基于AT89C52单片机简易频率计系统框图1.2.3 知识点本项目需要通过学习和查阅资料,掌握和了解如下知识:1)+5V电源原理及设计。
2)单片机复位电路工作原理及设计。
3)单片机晶振电路工作原理及设计。
4)频率信号发生器的特性及使用。
5)驱动电路74LS244的特性及使用。
6)AT89C52单片机引脚结构及功能。
7)单片机C语言程序设计方法。
2 硬件设计2.1 电路原理图基于AT89C52单片机简易频率计电路原理图如图2-1所示。
图2-1 基于AT89C52单片机简易频率计电路原理图2.2 元件清单基于AT89C52单片机简易频率计元件清单如表2-1所示。
表2-1 基于AT89C52单片机简易频率计元件清单元件名称型号数量/个用途单片机AT89C52 1 控制核心晶振12MHz 1 晶振电路电容30pF 2 晶振电路电解电容10uF/10V 1 复位电路电阻10kΏ 1 复位电路驱动器74LS244 1 LED驱动非门74LS04 1 位选信号数码管4位共阴 1 显示电路按键 1 复位电路电源+5V/0.5A 1 提供+5V2.3 主要芯片引脚说明2.3.1 AT89C52引脚说明AT89C52为40脚双列直插封装8位通用微处理器,采用工业标准的C51内核,在内部功能及管脚排布上与通用的8xc52 相同,其主要用于会聚调整时的功能控制。
功能包括对会聚主IC 内部寄存器、数据RAM及外部接口等功能部件的初始化,会聚调整控制,会聚测试图控制,红外遥控信号IR的接收解码及与主板CPU 通信等。
AT89C52 共有 6 个中断向量:两个外中断(INT0 和INT1),3 个定时器中断(定时器0、1、2)和串行口中断。
AT89C52引脚图如下:图2-2 AT89C52引脚图主要管脚有:XTAL1(19 脚)和XTAL2(18 脚)为振荡器输入输出端口。
RST/Vpd(9脚)为复位输入端口,外接电阻电容组成的复位电路。
VCC(40 脚)和VSS(20 脚)为供电端口,分别接+5V电源的正负端。
P0 口是一组8 位漏极开路型双向I/O 口,也即地址/数据总线复用口。
P1,P2,P3是一组带有内部上拉电阻的8 位双向I/O 口。
2.3.2 74HC244引脚说明74HC244可以让输入的数据保持比较长的时间,简单输入接口扩展通常使用的典型芯片为74HC244,由该芯片可构成三态数据缓冲器。
74HC244 芯片的引脚排列如下图所示:图2-3 74HC244引脚图74HC244芯片内部共有两个四位三态缓冲器,使用时可分别以1C和2G作为它们的选通工作信号。
当1/OE和2/OE都为低电平时,输出端Y和输入端A状态相同;当1/OE和2/OE都为高电平时,输出呈高阻态。
3 软件设计本项目利用单片机的内部定时器溢出产生中断来实现定时。
待测信号由单片机的TI中断来间接测量。
定时/计数器0定时2.5ms中断并对中断次数进行计数,当2.5ms 中断次数计到40次即0.1s时,查看定时/计数器1上的计得的数值,经过计算得到的待测信号的频率值,放入显示缓冲区,由数码管进行显示。
3.1 程序流程图主程序流程图如图3-1所示。
图3-1 主程序流程图3.2 软件设计简述1)利用单片机的内部定时器溢出产生中断来实现定时。
2)待测信号由单片机的TI (第15引脚)中断来间接测量。
3)采用12MHz 晶振,机器周期为1us4)定时/计数器0工作方式:定时方式,工作方式1,每次定时2.5ms 。
实现2.5ms 定时算法:1663(2)10 2.510(63036)1111011000111100DX X ---⨯=⨯== (3-1)即TH0=0xf6,TL0=0x3c5)定时/计数器1工作方式:计数方式,工作方式1。
当2.5ms 中断次数计到40次即0.1s 时,查看定时/计数器1上的计得的数值 。
6)通过公式:0.2540=⨯计数值脉冲频率 (3-2)可以计算出脉冲频率。
最后的数据以KHz 单位,采用四舍五入的方法保留一位小数。
7)显示采用四位共阴LED 数码管,用单片机P0口的8位控制数码管的8段二极管的明暗。
用P2口的P2.0~P2.3作为4位数码管的选通信号,采用从低到高逐位扫描的方法。
3.3 程序清单基于AT89C52单片机简易频率计程序清单如下: #include<reg52.h> bit timeint0,timeint1; unsigned char dispbuf[4]; unsigned int period;unsigned int timecount=0;unsigned int count_1s;unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //7段数码管代码表HEX_TO_BCD(unsigned int n) //十六进制数转BCD码子程序,//将BCD码送至显示缓存数组{unsigned char i; //当显示的频率超出范围,显示EEEE 报错if (n>9361)for(i=0;i<4;i++)dispbuf[i]=0x0e;else{dispbuf[3]=n/1000; //取出千位字节dispbuf[2]=(n/100)%10; //取出百位字节dispbuf[1]=(n/10)%10; //取出十位字节dispbuf[0]=n%10; //取出个位字节}}void scandisp(void) //显示子程序,//将显示缓存数组中的BCD码扫描并显示在数码管上{unsigned char posi=0x01;unsigned char i,j,temp;for(i=0;i<4;i++) //依次选中4个数码管{temp=dispbuf[i];//查出字码temp=table[temp];//第三位显示小数点if(i==1){for(j=0;j<200;j++){P2=posi;P0=temp|0x80;}}else{for(j=0;j<200;j++){P2=posi;P0 =temp;}}//依次点亮字位posi<<=1;}}void INIT_TMR1INT(void) //定时器初始化了程序,定义了两种{//定时/计数器0工作定时器方式,定时/计数器1工作在计数器方式 TMOD=0x51;ET1=1;//中断0开中断ET0=1;//CPU开中断EA=1;count_1s=0;//启动定时/计数器0开始定时TR0=1;TR1=1;void time0(void) interrupt 1 //定时器0中断服务程序,系统自动调用,//每2.5ms执行一次{TH0=0xf6;TH1=0x3c;//每次定时是2.5 ms, 40次即0.1sif(++count_1s>40){count_1s=0;//每0.1s对计数器1所计数值进行统计timecount=TH1*256+TL1;TH1=0;TL1=0;//精确到小数点后1位,以KHz为单位period=timecount/10;//四舍五入显示if((timecount%10)>4)period++;timecount=0;HEX_TO_BCD(period);}void timer1(void) interrupt 3 //定时器1中断服务程序,溢出后中断{TH1=0x00;TL1=0x00;}void main(void) //主函数{//初始化INIT_TMR1INT();while(1){//显示子程序scandisp();}}4 系统仿真及调试应用系统设计完成之后,就要进行硬件调试和软件调试,软件调试可以利用开发及仿真系统进行。
4.1 硬件调试硬件调试的调试主要是把电路各种参数调整到符合设计要求。
先排除硬件电路故障,包括设计性错误和工艺性故障。
一般原则是先静态后动态。
利用万用表或逻辑测试仪器,检查电路中各器件以及引脚是否连接正确,是否有短路故障。
先将单片机AT89C52芯片取下,对电路板进行通电检查,通过观察看是否有异常,是否有虚焊的情况,然后用万用表测试各电源电压,若这些都没有问题,则接上仿真机进行联机调试,观察各接口电路是否正常。