AT89S52单片机应用.doc

上传人:豆**** 文档编号:29962925 上传时间:2022-08-02 格式:DOC 页数:8 大小:57.50KB
返回 下载 相关 举报
AT89S52单片机应用.doc_第1页
第1页 / 共8页
AT89S52单片机应用.doc_第2页
第2页 / 共8页
点击查看更多>>
资源描述

《AT89S52单片机应用.doc》由会员分享,可在线阅读,更多相关《AT89S52单片机应用.doc(8页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、原 文 Title:AT89S52 MCU APPLICATIONSFunction Characteristic DescriptionThe AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with

2、 the indus-try-standard 80C51 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory pro-grammer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a po

3、werful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications.The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vec

4、tor two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 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 th

5、e RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM con-tents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.Watchdog TimerThe WDT is intended as a recovery method in situations

6、 where the CPU may be subjected to software upsets. The WDT consists of a 14-bit counter and the Watchdog Timer Reset (WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H). When the

7、WDT is enabled, it will increment every machine cycle while the oscillator is running. The WDT timeout period is dependent on the external clock frequency. There is no way to disable the WDT except through reset (either hardware reset or WDT overflow reset). When WDT over-flows, it will drive an out

8、put RESET HIGH pulse at the RST pin.In Power-down mode the oscillator stops, which means the WDT also stops. While in Power-down mode, the user does not need to service the WDT. There are two methods of exiting Power-down mode: by a hardware reset or via a level-activated external interrupt which is

9、 enabled prior to entering Power-down mode. When Power-down is exited with hardware reset, servicing the WDT should occur as it normally does whenever the AT89S52 is reset. Exiting Power-down with an interrupt is significantly different. The interrupt is held low long enough for the oscillator to st

10、abilize. When the interrupt is brought high, the interrupt is serviced. To prevent the WDT from resetting the device while the interrupt pin is held low, the WDT is not started until the interrupt is pulled high. It is suggested that the WDT be reset during the interrupt service for the interrupt us

11、ed to exit Power-down mode. To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best to reset the WDT just before entering Power-down mode. Before going into the IDLE mode, the WDIDLE bit in SFR AUXR is used to determine whether the WDT continues to count if ena

12、bled. The WDT keeps counting during IDLE (WDIDLE bit = 0) as the default state. To prevent the WDT from resetting the AT89S52 while in IDLE mode, the user should always set up a timer that will periodically exit IDLE, service the WDT, and reenter IDLE mode. With WDIDLE bit enabled, the WDT will stop

13、 to count in IDLE mode and resumes the count upon exit from IDLE.Timer 0 and 1Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in the AT89C51 and AT89C52. For further information on the timers operation, please click on the document link below:Timer 2Timer 2 is a 16-bit

14、 Timer/Counter that can operate as either a timer or an event counter. The type of operation is selected by bit C/ 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, as shown in Table 6-1.

15、 Timer 2 consists 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 oscil-lator frequency.In the Counter function, the register is incremented in resp

16、onse to a 1-to-0 transition at its corre-sponding 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 d

17、uring 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 maximum count rate is 1/24 of the oscillator frequency. To ensure that a given level is sampled at least once before it

18、changes, the level should be held for at least one full machine cycle.InterruptsThe AT89S52 has a total of six interrupt vectors: two external interrupts ( and ), three timer interrupts (Timers 0, 1, and 2), and the serial port interrupt. Each of these interrupt sources can be individually enabled o

19、r disabled by setting or clearing a bit in Special Function Register IE. IE also contains a global disable bit, EA, which disables all interrupts at once. Note that bit position IE.6 is unimplemented. User software should not write a 1 to this bit position, since it may be used in future AT89 produc

20、ts. Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON. Nei-ther of these flags is cleared by hardware when the service routine is vectored to. In fact, the service routine may have to determine whether it was TF2 or EXF2 that generated the interrupt, and that bi

21、t will have to be cleared in software. The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timers overflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag, TF2, is set at S2P2 and is polled in the same cycle in which the tim

22、er overflows.Oscillator CharacteristicsXTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier that can be configured for use as an on-chip oscillator. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 should

23、be left unconnected while XTAL1 is driven,. There are no requirements on the duty cycle of the external clock signal, since the input to the internal clock-ing circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.Power-down

24、 ModeIn the Power-down mode, the oscillator is stopped, and the instruction that invokes Power-down is the last instruction executed. The on-chip RAM and Special Function Registers retain their values until the Power-down mode is terminated. Exit from Power-down mode can be initiated either by a har

25、dware reset or by an enabled external interrupt. Reset redefines the SFRs but does not change the on-chip RAM. The reset should not be activated before VCC is restored to its normal operating level and must be held active long enough to allow the oscillator to restart and stabilize.Idle ModIn idle m

26、ode, the CPU puts itself to sleep while all the on-chip peripherals remain active. The mode is invoked by software. The content of the on-chip RAM and all the special functions regis-ters remain unchanged during this mode. The idle mode can be terminated by any enabled interrupt or by a hardware res

27、et. Note that when idle mode is terminated by a hardware reset, the device normally resumes pro-gram execution from where it left off, up to two machine cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to internal RAM in this event, but access to the port pi

28、ns is not inhibited. To eliminate the possibility of an unexpected write to a port pin when idle mode is terminated by a reset, the instruction following the one that invokes idle mode should not write to a port pin or to external memory.译文题目:AT89S52单片机应用功能特性描述AT89S52是一种低功耗、高性能CMOS8位微控制器,具有8K 在系统可编程

29、Flash 存储器。使用Atmel 公司高密度非易失性存储器技术制造,与工业80C51 产品指令和引脚完全兼容。片上Flash允许程序存储器在系统可编程,亦适于常规编程器。在单芯片上,拥有灵巧的8 位CPU 和在系统可编程Flash,使得AT89S52为众多嵌入式控制应用系统提供高灵活、超有效的解决方案。AT89S52具有以下标准功能:8k字节Flash,256字节RAM,32 位I/O 口线,看门狗定时器,2个数据指针,三个16 位定时器/计数器,一个6向量2级中断结构,全双工串行口,片内晶振及时钟电路。另外,AT89S52 可降至0Hz 静态逻辑操作,支持2种软件可选择节电模式。空闲模式下

30、,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。掉电保护方式下,RAM内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。看门狗定时器WDT是一种需要软件控制的复位方式。WDT 由14位计数器和特殊功能寄存器中的看门狗定时器复位存储器(WDTRST)构成。WDT 在默认情况下无法工作;为了激活WDT,户用必须往WDTRST 寄存器(地址:0A6H)中依次写入01EH 和0E1H。当WDT激活后,晶振工作,WDT在每个机器周期都会增加。WDT计时周期依赖于外部时钟频率。除了复位(硬件复位或WDT溢出复位),没有办法停止WDT工作。当WDT溢出,它将驱动R

31、SR引脚一个高电平输出。在掉电模式下,晶振停止工作,这意味WDT也停止了工作。在这种方式下,用户不必设置WDT。有两种方式可以避免掉电模式:硬件复位或通过一个激活的外部中断。通过硬件复位退出掉电模式后,用户就应该设置WDT,就如同通常AT89S52 复位一样。通过中断退出掉电模式的情形有很大的不同。中断应持续拉低很长一段时间,使得晶振稳定。当中断拉高后,执行中断服务程序。为了防止WDT在中断保持低电平的时候复位器件,WDT 直到中断拉低后才开始工作。这就意味着WDT 应该在中断服务程序中复位。为了确保在离开掉电模式最初的几个状态WDT不被溢出,最好在进入掉电模式前就复位WDT。在进入待机模式前

32、,特殊寄存器AUXR的WDIDLE位用来决定WDT是否继续计数。默认状态下,在待机模式下,WDIDLE0,WDT继续计数。为了防止WDT在待机模式下复位AT89S52,用户应该建立一个定时器,定时离开待机模式,设置WDT,再重新进入待机模式。定时器0和定时器1在AT89S52 中,定时器0 和定时器1 的操作与AT89C51 和AT89C52 一样。为了获得更深入的关于UART 的信息,可参考ATMEL 网站()。从这个主页,选择“Products”,然后选择“8051-Architech Flash Microcontroller”,再选择“Product Overview”即可。定时器2定

33、时器2是一个16位定时/计数器,它既可以做定时器,又可以做事件计数器。其工作方式由特殊寄存器T2CON中的C/T2位选择。定时器2有三种工作模式:捕捉方式、自动重载(向下或向上计数)和波特率发生器。如表3 所示,工作模式由T2CON中的相关位选择。定时器2 有2 个8位寄存器:TH2和TL2。在定时工作方式中,每个机器周期,TL2 寄存器都会加1。由于一个机器周期由12 个晶振周期构成,因此,计数频率就是晶振频率的1/12。在计数工作方式下,寄存器在相关外部输入角T2 发生1 至0 的下降沿时增加1。在这种方式下,每个机器周期的S5P2期间采样外部输入。一个机器周期采样到高电平,而下一个周期采

34、样到低电平,计数器将加1。在检测到跳变的这个周期的S3P1 期间,新的计数值出现在寄存器中。因为识别10的跳变需要2个机器周期(24个晶振周期),所以,最大的计数频率不高于晶振频率的1/24。为了确保给定的电平在改变前采样到一次,电平应该至少在一个完整的机器周期内保持不变。中断AT89S52 有6个中断源:两个外部中断( 和),三个定时中断(定时器0、1、2)和一个串行中断。每个中断源都可以通过置位或清除特殊寄存器IE 中的相关中断允许控制位分别使得中断源有效或无效。IE还包括一个中断允许总控制位EA,它能一次禁止所有中断。IE.6位是不可用的。对于AT89S52,IE.5位也是不能用的。用户

35、软件不应给这些位写1。它们为AT89系列新产品预留。定时器2可以被寄存器T2CON中的TF2和EXF2的或逻辑触发。程序进入中断服务后,这些标志位都可以由硬件清0。实际上,中断服务程序必须判定是否是TF2 或EXF2激活中断,标志位也必须由软件清0。定时器0和定时器1标志位TF0 和TF1在计数溢出的那个周期的S5P2被置位。它们的值一直到下一个周期被电路捕捉下来。然而,定时器2 的标志位TF2 在计数溢出的那个周期的S2P2被置位,在同一个周期被电路捕捉下来。晶振特性AT89S52 单片机有一个用于构成内部振荡器的反相放大器,XTAL1 和XTAL2 分别是放大器的输入、输出端。石英晶体和陶

36、瓷谐振器都可以用来一起构成自激振荡器。从外部时钟源驱动器件的话,XTAL2 可以不接,而从XTAL1 接入。由于外部时钟信号经过二分频触发后作为外部时钟电路输入的,所以对外部时钟信号的占空比没有其它要求,最长低电平持续时间和最少高电平持续时间等还是要符合要求的。掉电模式在掉电模式下,晶振停止工作,激活掉电模式的指令是最后一条执行指令。片上RAM和特殊功能寄存器保持原值,直到掉电模式终止。掉电模式可以通过硬件复位和外部中断退出。复位重新定义了SFR 的值,但不改变片上RAM 的值。在VCC未恢复到正常工作电压时,硬件复位不能无效,并且应保持足够长的时间以使晶振重新工作和初始化。空闲模式在空闲工作

37、模式下,CPU 处于睡眠状态,而所有片上外部设备保持激活状态。这种状态可以通过软件产生。在这种状态下,片上RAM和特殊功能寄存器的内容保持不变。空闲模式可以被任一个中断或硬件复位终止。由硬件复位终止空闲模式只需两个机器周期有效复位信号,在这种情况下,片上硬件禁止访问内部RAM,而可以访问端口引脚。空闲模式被硬件复位终止后,为了防止预想不到的写端口,激活空闲模式的那一条指令的下一条指令不应该是写端口或外部存储器。8器器或端应指下令一的活激的到止为终件式闲。端可,部问禁上,这号信期机个模止位硬终复断中被模闲不内器功特 片态在。过以种态激保部片而状处 ,作工模化始工重以的够保,无复硬压工复恢 值 片

38、改值的 新复退部和件通可。止电,值保功和 上令一最令式活作停下模的的要还续电高时持电求其有占号部所,电时作发二号钟外。 从不以 的器时从荡振构一可振和英端、的器分 大反振内用一片 特来捉路期个,被 期个数计 标 器而下路期个直值。被 期个溢在 0 标定0定清由也,断 或 否判须服断际清由可标,服入程发或 中 存以 定品产系 它 这件用。不也 的可位 断所禁能位控允一括 或源中别控允中 殊除置以都个每串和、0定中个,(断个断个 中变持期器整在至平,采改电给确。 的晶不计最,期振 周个需的0为中寄现计, 期这的检在器计低样周而电到采个。外间 器个下方在时沿 至 角部关在,作 振是频此构振 由器个。

39、加器 ,周个,工在 器位有 。选关 式, 表生特)上向载自方:作工 。位/ 器殊式工。件做,时以它计时位是器可即 择再” “然 择页主) / (站 可的 入深为。 和 操器定 定 器器式机待新 置式开定,个立用 式待 。计 ,机,状。计否 来用 的 存殊式待在。复就掉在,被 态的最电开确。复务在 意这工后断到 件复时电断在止了序服行后拉当振,段长续断。大有式模退过样 常就 设就,模掉复过通部的过或件式免以种。 设户下这作了 味意止停式出平个脚 动, 当 法有复溢 件位除频部外依 。增周器 ,工晶 当 0 0写 地器 用户 了工无情默 构 器位时门中寄殊和计由 式位控软一时定止位件或一,止切单冻荡存容内下护掉。断口、/定 许,停,模空电择件 支逻 0降 ,外钟时片行串,断量 ,/定 三,个器定门 /位 字 准以具 案决超活提用控入众 得 可系 的有,芯在编适,统器序允 上。完引品 工与技存性度公 使储 可在 具控位 性耗种一 描性应片 译 , - , . . . - . - , - - . - , , , 0 , , ( ) ( , , 0 - . , - , . ) ( / . - 0 . 0= - , - , , . - : . . , - ) ( , 0 . ) - , / , - / , - , - - , :文: - , 0 ,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com