|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
never stop thinking. microcontrollers user?s manual, nov. 1999 C505L 8-bit cmos microcontroller
edition 10.99 published by infineon technologies ag, st.-martin-strasse 53, d-81541 mnchen, germany ? infineon technologies ag 1999. all rights reserved. attention please! the information herein is given to describe certain components and shall not be considered as warranted characteristics. terms of delivery and rights to technical change reserved. we hereby disclaim any and all warranties, including but not limited to warranties of non-infringement, regarding circuits, descriptions and charts stated herein. infineon technologies is an approved cecc manufacturer. information for further information on technology, delivery terms and conditions and prices please contact your nearest infineon technologies office in germany or our infineon technologies representatives worldwide. warnings due to technical requirements components may contain dangerous substances. for information on the types in question please contact your nearest infineon technologies office. infineon technologies components may only be used in life-support devices or systems with the express written approval of infineon technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system, or to affect the safety or effectiveness of that device or system. life support devices or systems are intended to be implanted in the human body, or to support and/or maintain and sustain and/or protect human life. if they fail, it is reasonable to assume that the health of the user or other persons may be endangered. microcontrollers user?s manual, nov. 1999 never stop thinking. C505L 8-bit cmos microcontroller enhanced hooks technology tm is a trademark and patent of metalink corporation licensed to infineon. C505L user?s manual revision history: 10.99 previous version: 04.99 page subjects (major changes since last revision) minor changes on title pages several v cc is replaced by v dd . table 3-3 note 6 added. table 3-5 note 2 added. figure 5-3, figure 5-4, figure 5-5 figures changed. figure 6-40 new version of figure imported. figure 7-1 new version of figure imported. page 8-1 new variable time-out period for programmable watchdog timer. page 8-6 3rd indent text title in bold: external is removed. chapter 10 throughout this chapter the term C505L-4e is replaced by C505L. chapter 10 pages 10-7 to 10-14 were missing, now included. we listen to your comments any information within this document that you feel is wrong, unclear or missing? your feedback will help us to continuously improve the quality of this document. please send your proposal (including a reference to this document) to: mcdocu.comments@infineon.com user?s manual i-1 10.99 contents page general information C505L 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-1 1.1 pin configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 1.2 pin definitions and functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-5 2 fundamental structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-1 2.1 cpu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-3 2.2 cpu timing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-5 3 memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-1 3.1 program memory, ?code space? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2 3.2 data memory, ?data space? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2 3.3 general purpose registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2 3.4 xram operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-3 3.4.1 xram/lcd controller/rtc access control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-3 3.4.2 accesses to xram using the dptr (16-bit addressing mode) . . . . . . . . . . . . . . . . . .3-5 3.4.3 accesses to xram using the registers r0/r1 (8-bit addressing mode) . . . . . . . . . . .3-5 3.4.4 reset operation of the xram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-9 3.4.5 behavior of port 0 and port 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-9 3.5 special function registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-11 4 external bus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-1 4.1 accessing external memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-1 4.1.1 role of p0 and p2 as data/address bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-1 4.1.2 timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-3 4.1.3 external program memory access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-3 4.2 psen, program store enable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-3 4.3 overlapping external data and program memory spaces . . . . . . . . . . . . . . . . . . . . . .4-3 4.4 ale, address latch enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-4 4.5 enhanced hooks emulation concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-5 4.6 eight datapointers for faster external bus access . . . . . . . . . . . . . . . . . . . . . . . . . . .4-6 4.6.1 the importance of additional datapointers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-6 4.6.2 how the eight datapointers of the C505L are implemented . . . . . . . . . . . . . . . . . . . . .4-6 4.6.3 advantages of multiple datapointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-7 4.6.4 application example and performance analysis. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-7 5 system reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-1 5.1 hardware reset operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-1 5.2 fast internal reset after power-on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-3 5.3 hardware reset timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-5 5.4 oscillator and clock circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-6 5.5 system clock output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-8 6 on-chip peripheral components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-1 6.1 parallel i/o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-1 6.1.1 port structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-1 6.1.2 standard i/o port circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-4 6.1.2.1 port 0 circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-6 6.1.2.2 port 1 and port 3 circuitry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7 user?s manual i-2 10.99 contents page general information C505L 6.1.2.3 port 2 circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-8 6.1.3 detailed output driver circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-10 6.1.3.1 type b port driver circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-10 6.1.3.2 type c port driver circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-12 6.1.3.3 type d port driver circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-13 6.1.3.4 type e and f port driver circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-14 6.1.4 port timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-15 6.1.5 port loading and interfacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-16 6.1.6 read-modify-write feature of ports 0 to 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-17 6.2 timers/counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-1 8 6.2.1 timer/counter 0 and 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-18 6.2.1.1 timer/counter 0 and 1 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-19 6.2.1.2 mode 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-22 6.2.1.3 mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-23 6.2.1.4 mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-24 6.2.1.5 mode 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-25 6.2.2 timer/counter 2 with additional compare/capture/reload . . . . . . . . . . . . . . . . . . . .6-26 6.2.2.1 timer 2 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-28 6.2.2.2 timer 2 operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-33 6.2.2.3 compare function of registers crc, cc1 to cc3 . . . . . . . . . . . . . . . . . . . . . . . . . .6-35 6.2.2.4 using interrupts in combination with the compare function . . . . . . . . . . . . . . . . . . .6-41 6.2.2.5 capture function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-43 6.3 serial interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-45 6.3.1 multiprocessor communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-46 6.3.2 serial port registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6- 46 6.3.3 baudrate generation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-48 6.3.3.1 baudrate in mode 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 -49 6.3.3.2 baudrate in mode 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 -49 6.3.3.3 baudrate in mode 1 and 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-50 6.3.4 details about mode 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-53 6.3.5 details about mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-56 6.3.6 details about modes 2 and 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-59 6.4 lcd controller unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-62 6.4.1 functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-62 6.4.1.1 display module organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-62 6.4.2 lcd registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-63 6.4.2.1 control register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-63 6.4.2.2 digit registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-64 6.4.3 lcd input clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 -65 6.4.3.1 lcd input clock selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-66 6.4.4 row signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-67 6.4.5 column signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 -68 6.4.6 voltage levels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-72 6.4.6.1 d/a converter (reference voltage generator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-72 6.4.7 power saving mode options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-72 user?s manual i-3 10.99 contents page general information C505L 6.5 real-time clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-7 3 6.5.1 oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-73 6.5.2 real-time clock registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-74 6.5.3 functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-77 6.5.4 real-time clock wake-up interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-78 6.5.5 power-saving mode options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-79 6.6 a/d converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6- 80 6.6.1 a/d converter operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-80 6.6.2 a/d converter registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-82 6.6.3 a/d converter clock selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-86 6.6.4 a/d conversion timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-87 6.6.5 a/d converter calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-91 6.6.6 a/d converter analog input selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-92 7 interrupt system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-1 7.1 interrupt registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 7.1.1 interrupt enable registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-5 7.1.2 interrupt request / control flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-7 7.1.3 interrupt priority registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-12 7.2 interrupt priority level structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-13 7.3 how interrupts are handled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-14 7.4 external interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7- 16 7.5 interrupt response time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-17 8 fail safe mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-1 8.1 programmable watchdog timer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-1 8.1.1 input clock selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 -2 8.1.2 watchdog timer control / status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-3 8.1.3 starting the watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-4 8.1.4 refreshing the watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-5 8.1.5 watchdog reset and watchdog status flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-5 8.2 oscillator watchdog unit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-6 8.2.1 detailed description of the oscillator watchdog unit . . . . . . . . . . . . . . . . . . . . . . . . . .8-7 8.2.2 fast internal reset after power-on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-8 9 power saving modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1 9.1 power-saving mode control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-1 9.2 idle mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-4 9.3 slow-down mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-6 9.4 software power-down modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-7 9.4.1 invoking software power-down modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-8 9.4.2 exit from software power-down mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-9 9.5 state of pins in software-initiated power-saving mode . . . . . . . . . . . . . . . . . . . . . . .9-12 10 otp memory operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-1 10.1 programming configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-1 10.2 pin configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 0-2 10.3 pin definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-3 user?s manual i-4 10.99 contents page general information C505L 10.4 programming mode selection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-5 10.4.1 basic programming mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-5 10.4.2 otp memory access mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-6 10.5 program/read otp memory bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-7 10.6 programming and reading lock bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-9 10.6.1 access of version bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-11 10.7 otp verification mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-12 11 index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-1 user?s manual 1-1 10.99 introduction C505L 1 introduction the C505L microcontroller is a member of the infineon technologies c500 family of 8-bit microcontrollers. the c505 is fully compatible to the standard 8051 microcontroller. additionally the C505L provides a 128-segment liquid-crystal display (lcd) controller, real-rime clock, a 10-bit a/d converter, on-chip ram, and 32 kbytes of on-chip otp memory, extended power save provisions and rfi related improvements. with a maximum external clock rate of 20 mhz it achieves a 300 ns instruction cycle time. the C505L contains a 32k 8 one time programmable (otp) program memory. this device operates with internal program memory only. figure 1-1 C505L functional units 8 digit. i / o 8 analog inputs / mcb03832 on-chip emulation support module port 4 port 3 port 2 port 1 port 0 8 digit. i / o 8 digit. i / o 2 lcd outputs / real-time clock timer 2 10-bit adc t 0 t 1 oscillator watchdog watchdog timer cpu 8 datapointers 128-segment lcd control xram 256 x 8 256 x 8 ram 8-bit usart port 5 otp 32k x 8 4-channel pwm 8 digit. i / o 8 digit. i / o 8 lcd outputs / 6 digit. i / o 6 lcd outputs / 20 lcd outputs introduction C505L user ? s manual 1-2 10.99 listed below is a summary of the main features of the C505L family: fully compatible with the standard 8051 microcontroller superset of the 8051 architecture with 8 datapointers up to 20 mhz operating frequency ? 375 ns instruction cycle time @ 16 mhz ? 300 ns instruction cycle time @ 20 mhz (50% duty cycle) program memory ? 32k bytes of on-chip otp memory ? externally expandable up to 64 kbytes 256-byte on-chip ram 256-byte on-chip xram five 8-bit and one 6-bit digital i/o ports (port 5 with 6 bits only) ? port 1 with mixed analog/digital i/o capability ? port 3 with 2 lcd output lines as secondary functions ? port 4 and 5 with 8 and 6 lcd output lines respectively as secondary functions three 16-bit timers/counters ? timer 0 / 1 (c501 compatible) ? timer 2 with 4 channels for 16-bit capture/compare operation 128-segment lcd controller ? 1/4 duty cycle drive ? 4 row and 32 column outputs ? on-chip programmable reference voltage generation ? 20 dedicated lcd output lines (4 rows + 16 columns) real-time clock ? 47-bit digital clock counter ? input frequency of 32.768 khz required ? operates in a special power down mode full duplex serial interface with programmable baudrate generator (usart) 10-bit a/d converter with 8 multiplexed inputs twelve interrupt sources with four priority levels on-chip emulation support logic (enhanced hooks tm 1) ) programmable 15-bit watchdog timer oscillator watchdog fast power-on reset power-saving modes ? slow-down mode ? idle mode (can be combined with slow-down mode) ? 3 special power down modes ? software power-down mode with wake up capability through int0 pin or real-time clock p-mqfp-80 package temperature ranges: sab-C505L t a = 0 to 70 c saf-C505L t a = ? 40 to 85 c sah-C505L t a = ? 40 to 110 c (max. operating frequency: 12 mhz) sak-C505L t a = ? 40 to 125 c (max. operating frequency: 12 mhz) 1 ? enhanced hooks technology ? is a trademark and patent of metalink corporation licensed to infineon technologies. user ? s manual 1-3 10.99 introduction C505L figure 1-2 logic symbol agnd aref v v ea psen reset ale xtal2 xtal1 8-bit digital i / o 8-bit digital i / o 8-bit digital i / o port 4 port 2 3 port port 8-bit digital i / o / 8-bit digital i / o 1 port 0 port v ss v dd C505L mcl03833 8-bit analog inputs r3 xtal4 xtal3 r0 c31 c0 port 6-bit digital i / o 5 introduction C505L user ? s manual 1-4 10.99 1.1 pin configuration this section shows the pin configuration of the C505L in the p-mqfp-80 package. figure 1-3 pin configuration, p-mqfp-80-1 package (top view) p2.0 / ad8 p2.1 / ad9 p2.3 / ad11 p2.2 / ad10 xtal3 p2.7 / ad15 ale psen xtal2 ea xtal1 p0.0 / ad0 p0.6 / ad6 p0.7 / ad7 p0.5 / ad5 p0.4 / ad4 p0.2 / ad2 p0.3 / ad3 p1.6 / an6 / clkout p1.5 / an5 / t2ex c12 c9 c1 c3 c2 c0 r0 p4.3 / c19 p4.4 / c20 p4.5 / c21 p4.6 / c22 p5.2 / c26 p3.6 / wr p3.5 / t1 / c30 p3.3 / int1 p3.2 / int0 mcp03834 p2.4 / ad12 p2.5 / ad13 p2.6 / ad14 c4 c5 c6 c10 c11 p3.4 / t0 / c31 C505L 60 61 80 21 40 70 30 41 50 20 10 1 c15 c14 c13 r1 p1.7 / an7 / t2 p3.1 / txd p3.0 / rxd reset p4.0 / c16 p4.2 / c18 p4.1 / c17 p5.1 / c25 p5.0 / c24 c7 c8 p4.7 / c23 xtal4 23456789 13 11 12 14 15 16 17 18 19 22 23 24 25 26 27 28 29 32 39 38 37 36 35 34 33 42 43 44 45 46 47 48 49 54 59 58 56 57 55 52 53 51 62 63 64 65 66 67 68 69 79 74 78 77 76 75 73 72 71 v dd v ss p1.0 / an0 / int3 / cc0 p1.1 / an1 / int4 / cc1 p1.2 / an2 / int5 / cc2 p1.3 / an3 / int6 / cc3 p1.4 / an4 v v aref agnd p0.1 / ad1 r2 r3 p3.7 / rd p5.5 / c29 p5.4 / c28 p5.3 / c27 v v ss dd 31 user ? s manual 1-5 10.99 introduction C505L 1.2 pin definitions and functions this section describes all external signals and functions of the C505L. table 1-1 pin definitions and functions symbol pin number i/o*) function r0-r3 1-4 1 2 3 4 o lcd row outputs output of lcd controller row lines. these pins are driven by the lcd controller and drive the row input lines of the external lcd display. enabling the lcd controller makes these pins available for lcd output levels. r0 lcd row output 0 r1 lcd row output 1 r2 lcd row output 2 r3 lcd row output 3 these pins should not be used for input. c0-c15 5-20 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 o lcd column outputs output of lcd controller column lines 0 to 15. these pins are driven by the lcd controller and drive the column input lines of the external lcd display. enabling the lcd controller makes these pins available for lcd output levels. c0 lcd column output 0 c1 lcd column output 1 c2 lcd column output 2 c3 lcd column output 3 c4 lcd column output 4 c5 lcd column output 5 c6 lcd column output 6 c7 lcd column output 7 c8 lcd column output 8 c9 lcd column output 9 c10 lcd column output 10 c11 lcd column output 11 c12 lcd column output 12 c13 lcd column output 13 c14 lcd column output 14 c15 lcd column output 15 these pins should not be used for input. *) i = input o = output introduction C505L user ? s manual 1-6 10.99 p4.0-p4.7 21-28 21 22 23 24 25 26 27 28 i/o port 4 is a 8-bit quasi-bidirectional port with internal pull-up arrangement. port 4 pins that have a 1 written to them are pulled high by the internal pull-up transistors and in that state can be used as inputs. as inputs, port 4 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pullup transistors. port 4 pins can also be configured as lcd column outputs. the secondary functions are assigned to the pins of port 4 as follows: p4.0 / c16 lcd column output 16 p4.1 / c17 lcd column output 17 p4.2 / c18 lcd column output 18 p4.3 / c19 lcd column output 19 p4.4 / c20 lcd column output 20 p4.5 / c21 lcd column output 21 p4.6 / c22 lcd column output 22 p4.7 / c23 lcd column output 23 these pins should not be used for input when configured as lcd output pins. p5.0-p5.5 29-34 29 30 31 32 33 34 i/o port 5 is a 6-bit quasi-bidirectional port with internal pull-up arrangement. port 5 pins that have a 1 written to them are pulled high by internal pull-up transistors and in that state can be used as inputs. as inputs, port 5 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pullup transistors. port 5 pins can also be configured as lcd column outputs. the secondary functions are assigned to the pins of port 5 as follows: p5.0 / c24 lcd column output 24 p5.1 / c25 lcd column output 25 p5.2 / c26 lcd column output 26 p5.3 / c27 lcd column output 27 p5.4 / c28 lcd column output 28 p5.5 / c29 lcd column output 29 these pins should not be used for input when configured as lcd output pins. *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function user ? s manual 1-7 10.99 introduction C505L p3.7-p3.0 35-42 42 41 40 39 38 37 36 35 i/o port 3 is an 8-bit quasi-bidirectional port with internal pull-up arrangement. port 3 pins that have a 1 written to them are pulled high by the internal pull-up transistors and in that state can be used as inputs. as inputs, port 3 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pullup transistors. the output latch corresponding to a secondary function must be programmed to a one (1) for that function to operate (except for txd and wr ). p3.4 and p3.5 can also be configured as lcd column outputs c31 and c30 respectively. these pins should not be used for input when configured as lcd output pins. the secondary functions are assigned to the pins of port 3 as follows: p3.0 / rxd receiver data input (asynch.) or data input/output (synch.) of serial interface p3.1 / txd transmitter data output (asynch.) or clock output (synch.) of serial interface p3.2 / int0 external interrupt 0 input / timer 0 gate control input p3.3 / int1 external interrupt 1 input / timer 1 gate control input p3.4 / t0 / c31 timer 0 counter input / lcd column 31 output p3.5 / t1 / c30 timer 1 counter input / lcd column 30 output p3.6 / wr wr control output; latches the data byte from port 0 into the external data memory p3.7 / rd rd control output; enables the external data memory *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function introduction C505L user ? s manual 1-8 10.99 reset 43 i reset a high level on this pin for two machine cycles while the oscillator is running resets the device. an internal diffused resistor to v ss permits power-on reset using only an external capacitor to v dd . psen 44 o the program store enable output is a control signal that enables the external program memory to the bus during external fetch operations. it is activated every three oscillator periods except during external data memory accesses. remains high during internal program execution. this pin should not be driven during reset operation. ale 45 o the address latch enable output is used for latching the low-byte of the address into external memory during normal operation. it is activated every three oscillator periods except during an external data memory access. when instructions are executed from internal program memory (ea = 1), the ale generation can be disabled by bit eale in sfr syscon. this pin should not be driven during reset operation. ea 46 i external access enable this pin must be held at high level. instructions are fetched from the internal otp memory when the pc is less than 8000 h . instructions are fetched from external program memory, when the pc is greater than 7fff h . this pin must not be held at low level. *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function user ? s manual 1-9 10.99 introduction C505L xtal2 47 o xtal2 output of the inverting oscillator amplifier. xtal1 48 i xtal1 input to the inverting oscillator amplifier and input to the internal clock generator circuits. to drive the device from an external clock source, xtal1 should be driven, while xtal2 is left unconnected. to operate above a frequency of 16 mhz, a duty cycle of 50% should be maintained. minimum and maximum high and low times as well as rise/fall times specified in the ac characteristics (refer to data sheet) must be observed. xtal4 51 o xtal4 output of the inverting real-time clock oscillator amplifier. xtal3 52 i xtal3 input to the inverting real-time clock oscillator amplifier. to drive the real-time clock from an external clock source, xtal3 should be driven, while xtal4 is left unconnected. minimum and maximum high and low times as well as rise/fall times specified in the ac characteristics (refer to data sheet) must be observed. *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function introduction C505L user ? s manual 1-10 10.99 p2.7-p2.0 53-60 i/o port 2 is a an 8-bit quasi-bidirectional i/o port with internal pullup resistors. port 2 pins that have a 1 written to them are pulled high by the internal pullup resistors, and in that state can be used as inputs. as inputs, port 2 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pullup resistors. 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 it uses strong internal pullup transistors when issuing 1 s. during accesses to external data memory that use 8-bit addresses (movx @ri), port 2 issues the contents of the p2 special function register and uses only the internal pullup resistors. p0.7-p0.0 61-68 i/o port 0 is an 8-bit open-drain bidirectional i/o port. port 0 pins that have a 1 written to them float, and in that state can be used as high-impendance inputs. port 0 is also the multiplexed low-order address and data bus during accesses to external program or data memory. in this application it uses strong internal pullup transistors when issuing 1 s. *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function user ? s manual 1-11 10.99 introduction C505L p1.0-p1.7 71-78 71 72 73 74 75 76 77 78 i/o port 1 is an 8-bit quasi-bidirectional port with internal pull-up arrangement. port 1 pins can be used for digital input/output or as analog inputs to the a/d converter. port 1 pins that have a 1 written to them are pulled high by internal pull-up transistors and in that state can be used as inputs. as inputs, port 1 pins being pulled low externally will source current ( i il , in the dc characteristics) because of the internal pullup transistors. port 1 pins are assigned to be used as analog inputs via the register p1ana. as secondary digital functions, port 1 contains the interrupt, timer, clock, capture and compare pins. the output latch corresponding to a secondary function must be programmed to a one (1) for that function to operate (except for compare functions). the secondary functions are assigned to the pins of port 1 as follows: p1.0 / an0 / int3 / cc0 analog input channel 0 interrupt 3 input / capture/compare channel 0 i/o p1.1 / an1 / int4 / cc1 analog input channel 1/ interrupt 4 input / capture/compare channel 1 i/o p1.2 / an2 / int5 / cc2 analog input channel 2 / interrupt 5 input / capture/compare channel 2 i/o p1.3 / an3 / int6 / cc3 analog input channel 3 interrupt 6 input / capture/compare channel 3 i/o p1.4 / an4 analog input channel 4 p1.5 / an5 / t2ex analog input channel 5 / timer 2 external reload / trigger input p1.6 / an6 / clkout analog input channel 6 / system clock output p1.7 / an7 / t2 analog input channel 7 / timer/counter 2 input *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function introduction C505L user ? s manual 1-12 10.99 v aref 79 ? reference voltage for the a/d converter. v agnd 80 ? reference ground for the a/d converter. v ss 49, 70 ? ground (0 v) v dd 50, 69 ? power supply (+ 5 v) *) i = input o = output table 1-1 pin definitions and functions (cont ? d) symbol pin number i/o*) function user ? s manual 2-1 10.99 fundamental structure C505L 2 fundamental structure the C505L is fully compatible with the architecture of the standard 8051/c501 microcontroller family. while maintaining all architectural and operational characteristics of the c501, the C505L incorporates a central processing unit (cpu) with 8 datapointers, an 10-bit a/d converter, a 4-channel capture/compare unit, a 128-segment lcd controller unit, a real-time clock unit, an xram data memory as well as some enhancements in the fail save mechanism unit. figure 2-1 shows a block diagram of the C505L. fundamental structure C505L user ? s manual 2-2 10.99 figure 2-1 block diagram of the C505L watchdog oscillator port 2 port 1 8-bit digit. i / o port 0 xram ram otp programmable watchdog timer usart generator interrupt unit 10-bit a / d converter emulation support logic port 0 port 1 port 2 port 3 port 4 osc & timing s & h xtal1 xtal2 reset ale psen ea v aref agnd v 8-bit digit. i / o / 8-bit digit. i / o mcb03835 8 datapointers cpu 256 x 8 256 x 8 32k x 8 baudrate timer 0 timer 1 timer 2 8-bit analog in clock real-time mux dd v ss v C505L 8-bit digit. i / o / 2 lcd outputs port 3 8 lcd outputs 8-bit digit. i / o / port 4 port 5 6-bit digit. i / o / 6 lcd outputs port 5 lcd controller 128-segment 20 lcd outputs xtal4 xtal3 user ? s manual 2-3 10.99 fundamental structure C505L 2.1 cpu the C505L is efficient both as a controller and as an arithmetic processor. it has extensive facilities for binary and bcd arithmetic and excels in its bit-handling capabilities. efficient use of program memory results from an instruction set consisting of 44% one-byte, 41% two-byte, and 15% three-byte instructions. with a 16-mhz external clock, 58% of the instructions execute in 375 ns (20mhz: 300ns). the cpu of the C505L consists of the instruction decoder, the arithmetic section and the program control section. each program instruction is decoded by the instruction decoder. this unit generates the internal signals controlling the functions of the individual units within the cpu which have an effect on the source and destination of data transfers and control the alu processing. the arithmetic section of the processor performs extensive data manipulation and is comprised of the arithmetic/logic unit (alu), an a register, b register and a program status word (psw) register. the alu accepts 8-bit data words from one or two sources and generates an 8-bit result under the control of the instruction decoder. the alu performs the arithmetic operations add, subtract, multiply, divide, increment, decrement, bdc-decimal-add-adjust and compare, and the logic operations and, or, exclusive or, complement and rotate (right, left or swap nibble (left four)). also included is a boolean processor performing the bit operations as set, clear, complement, jump-if-set, jump-if-not-set, jump-if-set-and-clear and move to/from carry. between any addressable bit (or its complement) and the carry flag, it can perform the bit operations of logical and or logical or with the result returned to the carry flag. the program control section controls the sequence in which the instructions stored in program memory are executed. the 16-bit program counter (pc) holds the address of the next instruction to be executed. the conditional branch logic enables internal and external events to the processor to cause a change in the program execution sequence. the C505L, additionally, contains 8 datapointers compared to a standard 8051 microcontroller which has only one. for complex applications with peripherals (e.g. lcd controller) located in the external data memory space or extended data storage capacity this turned out to be a ? bottle neck ? for the 8051 ? s communication to the external world. especially programming in high-level languages (plm51, c51, pascal51) requires extended ram capacity and at the same time a fast access to this additional ram because of the reduced code efficiency of these languages. accumulator acc is the acronym for the accumulator register. the mnemonics for accumulator-specific instructions, however, refer to the accumulator simply as a. program status word the psw register contains several status bits that reflect the current state of the cpu. fundamental structure C505L user ? s manual 2-4 10.99 special function register psw (address d0 h ) reset value: 00 h b register the b register is used during multiply and divide and serves as both source and destination. for other instructions it can be treated as another scratch pad register. stack pointer the stack pointer (sp) register is 8 bits wide. it is incremented before data is stored during push and call executions and decremented after data is popped during a pop and ret (reti) execution, i.e. it always points to the last valid stack byte. while the stack may reside anywhere in the on-chip ram, the sp is initialized to 07 h after a reset. this causes the stack to begin a location = 08 h above register bank zero. the sp can be read or written under software control. bit function cy carry flag used by arithmetic instructions. ac auxiliary carry flag used by instructions which execute bcd operations. f0 general purpose flag rs1 rs0 register bank select control bits these bits are used to select one of the four register banks. ov overflow flag used by arithmetic instructions. f1 general purpose flag p parity flag set/cleared by hardware after each instruction to indicate an odd/even number of ? one ? bits in the accumulator, i.e. even parity. cy ac f0 rs1 rs0 ov f1 p d0 h psw d7 h d6 h d5 h d4 h d3 h d2 h d1 h d0 h bit no. msb lsb rs1 rs0 function 0 0 bank 0 selected, data address 00 h -07 h 0 1 bank 1 selected, data address 08 h -0f h 1 0 bank 2 selected, data address 10 h -17 h 1 1 bank 3 selected, data address 18 h -1f h user ? s manual 2-5 10.99 fundamental structure C505L 2.2 cpu timing the C505L has no clock prescaler. therefore, a machine cycle of the C505L consists of 6 states (6 oscillator periods). each state is divided into a phase 1 half and a phase 2 half. thus, a machine cycle consists of 6 oscillator periods, numbered s1p1 (state 1, phase 1) through s6p2 (state 6, phase 2). each state lasts one oscillator period. typically, arithmetic and logic operations take place during phase 1 and internal register-to-register transfers take place during phase 2. the diagrams in figure 2-2 show the fetch/execute timing related to the internal states and phases. since these internal clock signals are not user-accessible, the xtal1 oscillator signals and the ale (address latch enable) signal are shown for external reference. ale is normally activated twice during each machine cycle: once during s1p2 and s2p1, and again during s4p2 and s5p1. execution of a one-cycle instruction begins at s1p2, when the opcode is latched into the instruction register. if it is a two-byte instruction, the second reading takes place during s4 of the same machine cycle. if it is a one-byte instruction, there is still a fetch at s4, but the byte read (which would be the next opcode) is ignored (discarded fetch), and the program counter is not incremented. in any case, execution is completed at the end of s6p2. figures 2-2 (a) and (b) show the timing of a 1-byte, 1-cycle instruction and a 2-byte, 1-cycle instruction. most C505L instructions are executed in one cycle. mul (multiply) and div (divide) are the only instructions that take more than two cycles to complete; they take four cycles. normally two code bytes are fetched from the program memory during every machine cycle. the only exception to this is when a movx instruction is executed. movx is a 1-byte, 2-cycle instruction that accesses external data memory. during a movx, the two fetches in the second cycle are skipped while the external data memory is being addressed and strobed. figure 2-2 (c) and (d) show the timing for a normal 1-byte, 2-cycle instruction and for a movx instruction. fundamental structure C505L user ? s manual 2-6 10.99 figure 2-2 fetch execute sequence s1 p1 p2 p1 p2 s2 p1 p2 p1 p2 s3 s4 p1 p2 p1 p2 s5 s6 p1 p2 p1 p2 s1 s2 p1 p2 p1 p2 s3 s4 p1 p2 p1 p2 s5 s6 osc (xtal2) ale read opcode read next opcode (discard) s1 s2 s3 s4 s5 s6 (a) 1-byte, 1-cycle instruction, e. g. inc a opcode again read next (b) 2-byte, 1-cycle instruction, e. g. add a #data read opcode s1 s2 byte read 2nd s4 s3 s5 s6 opcode read next s6 s5 s3 s4 s2 s1 opcode read read next opcode (discard) s1 s2 s4 s3 s5 s6 read next opcode again (c) 1-byte, 2-cycle instruction, e. g. inc dptr (d) movx (1-byte, 2-cycle) s4 s1 s2 s3 s5 s6 s1 s3 s2 s4 s5 s6 read opcode (movx) (discard) opcode read next no fetch no ale no fetch read next opcode again addr data access of external memory mcd03287 user ? s manual 3-1 10.99 memory organization C505L 3 memory organization the C505L cpu manipulates operands in the following address spaces: ? up to 64 kbytes of program memory (32k on-chip otp memory) ? up to 64 kbytes of external data memory ? 256 bytes of internal data memory ? 256 bytes of internal xram data memory ? 20 bytes of lcd controller registers ? 16 bytes of real-time clock (rtc) registers ? a 128-byte special function register (sfr) area figure 3-1 illustrates the memory address spaces of the C505L. figure 3-1 C505L memory map "code space" (ea = 1) internal h 0000 7fff h h 0000 "data space" data memory external external external memory 8000 h h ffff data internal lcd (36 byte) f3db h & rtc alternatively not used (256 byte) internal xram h h register function "internal data space" ram internal h 00 internal ram 80 h 7f h special mcd03996 80 h address f3dc f3ff h h address indirect h ffff ff00 h ff direct ff memory organization C505L user ? s manual 3-2 10.99 3.1 program memory, ?code space? the C505L has 32 kbytes of on-chip otp memory which can be externally expanded up to 64 kbytes. the C505L executes program code out of the internal otp memory until the program counter address exceeds 7fff h . address locations 8000 h through ffff h are then fetched from the external program memory. the ea pin is always held high. it is recommended to not set the ea pin at low level as this may cause the device to function in a manner that is not defined. 3.2 data memory, ?data space? the data memory address space consists of an internal and an external memory space. the internal data memory is divided into three physically separate and distinct blocks: the lower 128 bytes of ram, the upper 128 bytes of ram, and the 128-byte sfr area. while the upper 128 bytes of data memory and the sfr area share the same address locations, they are accessed through different addressing modes. the lower 128 bytes of data memory can be accessed through direct or register indirect addressing; the upper 128 bytes of ram can be accessed through register indirect addressing; the special function registers are accessible through direct addressing. four 8-register banks, each bank consisting of eight 8-bit general-purpose registers, occupy locations 0 through 1f h in the lower ram area. the next 16 bytes, locations 20 h through 2f h , contain 128 directly addressable bit locations. the stack can be located anywhere in the internal ram area, and the stack depth can be expanded up to 256 bytes. the external data memory can be expanded up to 64 kbytes, and can be accessed by instructions that use a 16-bit or an 8-bit address. the internal lcd controller, the rtc, both peripherals, and the internal xram are located in the external memory address area at addresses f3dc h to f3ef h , f3f0 h to f3ff h and ff00 h to ffff h respectively. the lcd controller registers, the rtc registers and internal xram can therefore be accessed using movx instructions with addresses pointing to the respective address areas. 3.3 general purpose registers the lower 32 locations of the internal ram are assigned to four banks of eight general purpose registers (gprs) each. only one of these banks may be enabled at a time. two bits in the program status word, rs0 (psw.3) and rs1 (psw.4), select the active register bank (see description of the psw in chapter 2 ). this allows fast context switching, which is useful when entering subroutines or interrupt service routines. the eight general purpose registers of the selected register bank may be accessed by register addressing. with register addressing the instruction opcode indicates which register is to be used. for indirect addressing r0 and r1 are used as pointer or index register to address internal or external memory (e.g. mov @r0). reset initializes the stack pointer to location 07 h and increments it once to start from location 08 h which is also the first register (r0) of register bank 1. thus, if one is going to use more than one register bank, the sp should be initialized to a different location of the ram that is not used for data storage. user ? s manual 3-3 10.99 memory organization C505L 3.4 xram operation the xram in the C505L is a memory area that is logically located at the upper end of the external data memory space, but is integrated on the chip. because the xram is used in the same way as external data memory, the same instruction types (movx), must be used for accessing the xram. 3.4.1 xram/lcd controller/rtc access control two bits in sfr syscon, xmap0 and xmap1, control the accesses to xram, the lcd controller and the rtc. xmap0 is a general access enable/disable control bit, and xmap1 controls the external signal generation during xram/lcd controller/rtc accesses. special function register syscon (address b1 h ) reset value: xx10xx01 b when bit xmap1 in sfr syscon is set, during all accesses to xram, lcd controller and rtc rd and wr become active and port 0 and 2 drive the actual address/data information which is read/ written from/to xram/lcd controller/rtc. this feature allows to check the internal data transfers to xram, lcd controller and the rtc. when port 0 and 2 are used for i/o purposes, the xmap1 bit should not be set. otherwise the i/o function of the port 0 and port 2 lines is interrupted. bit function xmap1 xram/lcd controller/rtc visible access control control bit for rd /wr signals during xram/lcd controller/rtc accesses. if addresses are outside the xram/lcd controller/rtc address range or if xram is disabled, this bit has no effect. xmap1 = 0: the signals rd and wr are not activated during accesses to the xram/lcd controller/rtc. xmap1 = 1: ports 0, 2 and the signals rd and wr are activated during accesses to xram/lcd controller/rtc. in this mode, address and data information during xram/lcd controller/rtc accesses are visible externally. xmap0 global xram/lcd controller/rtc access enable/disable control xmap0 = 0: the access to xram, lcd controller and rtc are enabled. xmap0 = 1: the access to xram, lcd controller and rtc are disabled (default after reset!). all movx accesses are performed via the external bus. further, this bit is hardware protected. ? reserved bits for future use. read by cpu returns undefined values. the shaded bits are not described in this section. __ eale rmap b1 h syscon bit no. 76543210 msb lsb __ xmap1 xmap0 memory organization C505L user ? s manual 3-4 10.99 after a reset operation, bit xmap0 is set. this means that accesses to lcd controller, rtc and the internal xram are generally disabled. in this case, all accesses using movx instructions within the address range of f3dc h to f3ef h , f3f0 h to f3ff h and ff00 h to ffff h generate external data memory bus cycles. when xmap0 is cleared, accesses to lcd controller, the rtc and the internal xram are enabled and all accesses using movx instructions with an address in the range as above will access the lcd controller, rtc and the internal xram respectively. internal accesses (xmap0 = 0) in the address range gap from f400 h to feff h (as shown in figure 3-1 ) will have undefined data. bit xmap0 is hardware-protected. if it is cleared once, it cannot be set by software. only a reset operation will set the xmap0 bit again. this hardware protection mechanism is done by an asymmetric latch at xmap0 bit. an unintentional disabling of lcd controller, the rtc and the internal xram could be dangerous since indeterminate values could be read from the external bus. to avoid this the xmap0 bit is forced to ? 1 ? only by a reset operation. additionally, an internal capacitor is charged during reset. therefore, the reset state is a disabled lcd controller, disabled rtc and disabled internal xram. because of the charge time of the capacitor, once the xmap0 bit is written to ? 0 ? (that is, discharging the capacitor) the bit cannot be set to ? 1 ? again by software. on the other hand any distortion (software hang-up, noise, ? ) is not able to charge this capacitor, either. that is, the stable status is with the lcd controller, the rtc and internal xram are enabled. the ? clear ? instruction for the xmap0 bit should be integrated in the program initialization routine before xram/lcd controller/rtc is used. in extremely noisy systems the user may have redundant ? clear ? instructions. user ? s manual 3-5 10.99 memory organization C505L 3.4.2 accesses to xram using the dptr (16-bit addressing mode) the xram, lcd controller and rtc can be accessed by two read/write instructions that use the 16-bit dptr for indirect addressing. these instructions are: ? movx a, @dptr (read) ? movx @dptr, a (write) for accessing the xram, the effective address stored in dptr must be in the range of ff00 h to ffff h . for accessing the lcd controller, the effective address stored in dptr must be in the range of f3dc h to f3ef h . for accessing the rtc, the effective address stored in dptr must be in the range of f3f0 h to f3ff h . 3.4.3 accesses to xram using the registers r0/r1 (8-bit addressing mode) the 8051 architecture also provides instructions for accesses to external data memory range that use only an 8-bit address (indirect addressing with registers r0 or r1). the instructions are: movx a, @ri (read) movx @ri, a (write) a special page register is implemented in the C505L to make it possible to access the xram/lcd controller/rtc also with the movx @ri instructions. xpage serves the same function for the xram, lcd controller and rtc as port 2 for external data memory. special function register xpage (address 91 h ) reset value: 00 h figures 3-2 to 3-4 show the dependencies of xpage- and port 2 - addressing in order to explain the differences in accessing xram/lcd controller/rtc, external ram and to show what to do when port 2 is used as an i/o-port. bit function xpage.7-0 xram/lcd controller/rtc high address xpage.7-0 is the address part a15-a8 when 8-bit movx instructions are used to access internal xram/lcd controller/rtc. xpage 76543210 .5 .4 .3 91 h bit no. msb lsb .2 .1 .7 .6 .0 memory organization C505L user ? s manual 3-6 10.99 figure 3-2 write page address to port 2 ? mov p2, pageaddress ? will write the page address to port 2 and the xpage-register. when external ram is to be accessed in the xram/lcd controller/rtc address range, these modules should remain disabled after reset. when additional external ram is to be addressed in an address range < f3dc h , the xram/lcd controller/rtc may remain enabled and there is no need to overwrite xpage by a second move. mcs03837 controller/ real-time clock port 0 port 2 write to page address address/data xpage port 2 lcd xram/ user ? s manual 3-7 10.99 memory organization C505L figure 3-3 write page address to xpage ? mov xpage, pageaddress ? will write the page address only to the xpage register. port 2 is available for addresses or i/o data. mcs03838 controller/ real-time clock port 0 xpage write to port 2 i/o-data address/data address/ xpage lcd xram/ memory organization C505L user ? s manual 3-8 10.99 figure 3-4 use of port 2 as i/o port on a write to port 2, the xram/lcd controller/rtc address in xpage register will be overwritten because of the concurrent write to port 2 and xpage register. therefore, whenever xram is used and the xram address differs from the byte written to port 2 latch it is absolutely necessary to rewrite xpage with the page address. example: i/o data at port 2 shall be aa h . a byte shall be fetched from xram at address ff30 h . mov r0, #30 h ; mov p2, #0aa h ; p2 shows aa h and xpage contains aa h mov xpage, #0ff h ; p2 still shows aa h but xram is addressed movx a, @r0 ; the contents of xram at ff30 h is moved to accumulator port 2 to port 2 i/o data port 0 write xpage i/o-data mcs03839 xram/ lcd real-time clock controller/ address/data user ? s manual 3-9 10.99 memory organization C505L the register xpage provides the upper address byte for accesses to xram with movx @ri instructions. if the address formed by xpage and ri points outside the xram/lcd controller/rtc address range, an external access is performed. for the C505L the content of xpage must be f7 h -ff h in order to use the xram/lcd controller/rtc. the software has to distinguish two cases, if the movx @ri instructions with paging shall be used: a) access to xram/lcd contr./rtc: the upper address byte must be written to xpage or p2; both writes select the xram/lcd controller/rtc address range. b) access to external memory: the upper address byte must be written to p2; xpage will be automatically loaded with the same address in order to deselect the xram. 3.4.4 reset operation of the xram the contents of the xram are not affected by a reset. after power-up the contents are undefined, although they remain unchanged during and after a reset as long as the power supply is not turned off. if a reset occurs during a write operation to xram, the content of a xram memory location depends on the cycle in which the active reset signal is detected (movx is a 2-cycle instruction): reset during 1st cycle: the new value will not be written to xram. the old value is not affected. reset during 2nd cycle: the old value in xram is overwritten by the new value. 3.4.5 behavior of port 0 and port 2 the behavior of port 0 and port 2 during a movx access depends on the control bits in register syscon. table 3-1 lists the various operating conditions. it shows the following characteristics: a) use of p0 and p2 pins during the movx access. bus: the pins work as external address/data bus. if (internal) xram/lcd controller/rtc are accessed, the data written to the xram/lcd controller/rtc can be seen on the bus in debug mode. i /0: the pins work as input/output lines under control of their latch. b) activation of the rd and wr pin during the access. c) use of internal (xram/lcd controller/rtc) or external xdata memory. the shaded areas in the table describe how each c5xx device without on-chip xram/lcd controller/rtc behaves. for simplicity, the references in this table to the on-chip xram also cover the lcd controller and the rtc accesses. memory organization C505L user ? s manual 3-10 10.99 modes compatible to 8051/c501 family. table 3-2 behavior of p0/p2 and rd /wr during movx accesses xmap1, xmap0 00 10 x1 movx @dptr dptr < xram address range a) p0/p2 bus b) rd /wr active c) ext. memory is used a) p0/p2 bus b) rd /wr active c) ext. memory is used a) p0/p2 bus b) rd /wr active c) ext. memory is used dptr xram address range a) p0/p2 / b) rd /wr inactive c) xram is used a) p0/p2 bus (rd / wr -data) b) rd /wr active c) xram is used a) p0/p2 bus b) rd /wr active c) ext. memory is used movx @ri xpage < xram addr. page range a) p0 bus p2 i /o b) rd /wr active c) ext. memory is used a) p0 bus p2 i /o b) rd /wr active c) ext. memory is used a) p0 bus p2 i /o b) rd /wr active c) ext. memory is used xpage xram addr.page range a) p0/p2 i /o b) rd /wr inactive c) xram is used a) p0 bus (rd / wr -data) p2 i /o b) rd /wr active c) xram is used a) p0 bus p2 i /o b) rd /wr active c) ext. memory is used user ? s manual 3-11 10.99 memory organization C505L 3.5 special function registers all registers, except for the program counter and the four gpr banks reside in the sfr area. the sfr area consists of two portions: the standard sfr area and the mapped sfr area. some of the C505L ? s sfrs (pcon1, vr0, vr1 and vr2) are located in the mapped sfr area. for accessing the mapped sfr area, bit rmap in sfr syscon must be set. all other sfrs are located in the standard sfr area which is accessed when rmap is cleared ( ? 0 ? ). the registers and data locations of the lcd controller (lcd-sfrs) and the rtc (rtc-sfrs) are located in the external data memory area at addresses f3dd h to f3ef h and f3f0 h to f3ff h respectively. details about the access of these registers is described in section 3.4.1 of this chapter. special function register syscon (address b1 h ) reset value: xx100x01 b as long as bit rmap is set, mapped sfr area can be accessed. this bit is not cleared automatically by hardware. thus, when non-mapped/mapped registers are to be accessed, the bit rmap must be cleared/set respectively by software. all sfrs with addresses where address bits 0-2 are 0 (e.g. 80 h , 88 h , 90 h , 98 h , ? , f8 h , ff h ) are bit-addressable. the 51 sfrs in the standard and mapped sfr area include pointers and registers that provide an interface between the cpu and the other on-chip peripherals. the sfrs of the C505L are listed in table 3-3 and table 3-4 . in table 3-3 they are organized in groups which refer to the functional blocks of the C505L. the lcd and rtc-sfrs are also included in table 3-3 . table 3-4 illustrates the contents of the sfrs in numeric order of their addresses. table 3-5 lists the lcd and the rtc-sfrs in numeric order of their addresses. bit function rmap sfr map bit rmap = 0: access to the non-mapped (standard) sfr area is enabled. rmap = 1: access to the mapped sfr area is enabled. ? reserved bits for future use. read by cpu returns undefined values. the shaded bits are not described in this section. __ eale rmap b1 h syscon bit no. 76543210 msb lsb _ _ xmap1 xmap0 memory organization C505L user ? s manual 3-12 10.99 table 3-3 special function registers - functional blocks block symbol name address contents after reset cpu acc b dph dpl dpsel psw sp syscon 2) vr0 4) vr1 4) vr2 4) accumulator b-register data pointer, high byte data pointer, low byte data pointer select register program status word register stack pointer system control register version register 0 version register 1 version register 2 e0 h 1) f0 h 1) 83 h 82 h 92 h d0 h 1) 81 h b1 h fc h fd h fe h 00 h 00 h 00 h 00 h xxxxx000 b 3) 00 h 07 h xx10xx01 b 3) c5 h 85 h 5) a/d- converter adcon0 2) adcon1 addath addatl p1ana 2) a/d converter control register 0 a/d converter control register 1 a/d converter data register high byte a/d converter data register low byte port 1 analog input selection register d8 h 1) dc h d9 h da h 90 h 4) 00x00000 b 3) 01xxx000 b 3) 00 h 00xxxxxx b 3) ff h interrupt system ien0 2) ien1 2) ip0 2) ip1 tcon 2) t2con 2) scon 2) ircon interrupt enable register 0 interrupt enable register 1 interrupt priority register 0 interrupt priority register 1 timer control register timer 2 control register serial channel control register interrupt request control register a8 h 1) b8 h 1) a9 h b9 h 88 h 1) c8 h 1) 98 h 1) c0 h 1) 00 h 00 h 00 h xx000000 b 3) 00 h 00x00000 b 00 h 00 h xram xpage syscon 2) page address register for extended on-chip xram, lcd controller and rtc system control register 91 h b1 h 00 h xx10xx01 b 3) ports p0 p1 p1ana 2) p2 p3 p4 p5 port 0 port 1 port 1 analog input selection register port 2 port 3 port 4 port 5 80 h 1) 90 h 1) 90 h 1) 4) a0 h 1) b0 h 1) e8 h 1) f8 h 1) ff h ff h ff h ff h ff h 00 b xx111111 b 1) bit-addressable sfrs 2) this sfr is listed repeatedly since some bits of it also belong to other functional blocks. 3) ? x ? means that the value is undefined and the location is reserved. 4) this sfr is a mapped sfr. for accessing this sfr, bit rmap in sfr syscon must be set. 5) the content of this sfr varies with the actual step of the C505L (e.g. 01 h for the first step). user ? s manual 3-13 10.99 memory organization C505L serial channel adcon0 2) pcon 2) sbuf scon srell srelh a/d converter control register 0 power control register serial channel buffer register serial channel control register serial channel reload register, low byte serial channel reload register, high byte d8 h 1) 87 h 99 h 98 h 1) aa h ba h 00x00000 b 3) 00 h xx h 3) 00 h d9 h xxxxxx11 b 3) timer 0/ timer 1 tcon th0 th1 tl0 tl1 tmod timer 0/1 control register timer 0, high byte timer 1, high byte timer 0, low byte timer 1, low byte timer mode register 88 h 1) 8c h 8d h 8a h 8b h 89 h 00 h 00 h 00 h 00 h 00 h 00 h compare/ capture unit / timer 2 ccen cch1 cch2 cch3 ccl1 ccl2 ccl3 crch crcl th2 tl2 t2con ien0 2) ien1 2) comp./capture enable reg. comp./capture reg. 1, high byte comp./capture reg. 2, high byte comp./capture reg. 3, high byte comp./capture reg. 1, low byte comp./capture reg. 2, low byte comp./capture reg. 3, low byte reload register high byte reload register low byte timer 2, high byte timer 2, low byte timer 2 control register interrupt enable register 0 interrupt enable register 1 c1 h c3 h c5 h c7 h c2 h c4 h c6 h cb h ca h cd h cc h c8 h 1) a8 h 1) b8 h 1) 00 h 3) 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00x00000 b 3) 00 h 00 h watchdog wdtrel ien0 2) ien1 2) ip0 2) watchdog timer reload register interrupt enable register 0 interrupt enable register 1 interrupt priority register 0 86 h a8 h 1) b8 h 1) a9 h 00 h 00 h 00 h 00 h power save modes pcon 2) pcon1 4) power control register power control register 1 87 h 88 h 1) 00 h 0xx0xxxx b 3) 1) bit-addressable sfrs 2) this sfr is listed repeatedly since some bits of it also belong to other functional blocks. 3) ? x ? means that the value is undefined and the location is reserved 4) sfr is located in the mapped sfr area. for accessing this sfr, bit rmap in sfr syscon must be set. table 3-3 special function registers - functional blocks (cont ? d) block symbol name address contents after reset memory organization C505L user ? s manual 3-14 10.99 lcd controller dac0 6) lcon 6) lcrl 6) lcrh 6) dign 5), 6) d/a conversion register lcd control register lcd timer reload low register lcd timer reload high register lcd digit register ? n ? 5) f3dc h f3dd h f3de h f3df h f3en h 00 h 00 h 00 h 00 h 00 h 5) real-time clock rtcon 6) rtcr0 6) rtcr1 6) rtcr2 6) rtcr3 6) rtcr4 6) clreg0 6) clreg1 6) clreg2 6) clreg3 6) clreg4 6) rtint0 6) rtint1 6) rtint2 6) rtint3 6) rtint4 6) real-time clock control register real-time clock initialization register 0 real-time clock initialization register 1 real-time clock initialization register 2 real-time clock initialization register 3 real-time clock initialization register 4 clock count register 0 clock count register 1 clock count register 2 clock count register 3 clock count register 4 real-time clock interrupt register 0 real-time clock interrupt register 1 real-time clock interrupt register 2 real-time clock interrupt register 3 real-time clock interrupt register 4 f3f0 h f3f1 h f3f2 h f3f3 h f3f4 h f3f5 h f3f6 h f3f7 h f3f8 h f3f9 h f3fa h f3fb h f3fc h f3fd h f3fe h f3ff h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 1) bit-addressable sfrs 2) this sfr is listed repeatedly since some bits of it also belong to other functional blocks. 3) ? x ? means that the value is undefined and the location is reserved. 4) sfr is located in the mapped sfr area. for accessing this sfr, bit rmap in sfr syscon must be set. 5) the notation ? n ? (n = 0 to f) in the lcd digit register address definition defines the number of the related lcd digit. 6) this register is located in the on-chip external data memory area. table 3-3 special function registers - functional blocks (cont ? d) block symbol name address contents after reset user ? s manual 3-15 10.99 memory organization C505L table 3-4 contents of the sfrs, sfrs in numeric order of their addresses addr register content after reset 1) bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 80 h 2) p0 ff h .7 .6 .5 .4 .3 .2 .1 .0 81 h sp 07 h .7 .6 .5 .4 .3 .2 .1 .0 82 h dpl 00 h .7 .6 .5 .4 .3 .2 .1 .0 83 h dph 00 h .7 .6 .5 .4 .3 .2 .1 .0 86 h wdtrel 00 h wdt psel .6 .5 .4 .3 .2 .1 .0 87 h pcon 00 h smod pds idls sd gf1 gf0 pde idle 88 h 2) tcon 00 h tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 88 h 3) pcon1 0xx0-x xxx b ewpd ? ? ws ? ? ? ? 89 h tmod 00 h gate c/t m1 m0 gate c/t m1 m0 8a h tl0 00 h .7 .6 .5 .4 .3 .2 .1 .0 8b h tl1 00 h .7 .6 .5 .4 .3 .2 .1 .0 8c h th0 00 h .7 .6 .5 .4 .3 .2 .1 .0 8d h th1 00 h .7 .6 .5 .4 .3 .2 .1 .0 90 h 2) p1 ff h t2 clk-o ut t2ex .4 .3 int5 int4 .0 90 h 3) p1ana ff h ean7 ean6 ean5 ean4 ean3 ean2 ean1 ean0 91 h xpage 00 h .7 .6 .5 .4 .3 .2 .1 .0 92 h dpsel xxxx-x 000 b ????? .2 .1 .0 98 h 2) scon 00 h sm0 sm1 sm2 ren tb8 rb8 ti ri 99 h sbuf xx h .7 .6 .5 .4 .3 .2 .1 .0 a0 h 2) p2 ff h .7 .6 .5 .4 .3 .2 .1 .0 a8 h 2) ien0 00 h ea wdt et2 es et1 ex1 et0 ex0 a9 h ip0 00 h owds wdts .5 .4 .3 .2 .1 .0 aa h srell d9 h .7 .6 .5 .4 .3 .2 .1 .0 1) ? x ? means that the value is undefined and the location is reserved 2) bit-addressable sfrs 3) sfr is located in the mapped sfr area. for accessing this sfr, bit rmap in sfr syscon must be set. memory organization C505L user ? s manual 3-16 10.99 b0 h 2) p3 ff h rd wr t1 t0 int1 int0 txd rxd b1 h syscon xx10-x x01 b ?? eale rmap ?? xmap1 xmap0 b8 h 2) ien1 00 h exen2 swdt ex6 ex5 ex4 ex3 eswi eadc b9 h ip1 xx00-00 00 b ?? .5 .4 .3 .2 .1 .0 ba h srelh xxxx-x x11 b ?????? .1 .0 c0 h 2) ircon 00 h exf2 tf2 iex6 iex5 iex4 iex3 swi iadc c1 h ccen 00 h coca h3 cocal 3 coca h2 cocal 2 coca h1 cocal 1 coca h0 cocal 0 c2 h ccl1 00 h .7 .6 .5 .4 .3 .2 .1 .0 c3 h cch1 00 h .7 .6 .5 .4 .3 .2 .1 .0 c4 h ccl2 00 h .7 .6 .5 .4 .3 .2 .1 .0 c5 h cch2 00 h .7 .6 .5 .4 .3 .2 .1 .0 c6 h ccl3 00 h .7 .6 .5 .4 .3 .2 .1 .0 c7 h cch3 00 h .7 .6 .5 .4 .3 .2 .1 .0 c8 h 2) t2con 00x0-00 00 b t2ps i3fr ? t2r1 t2r0 t2cm t2i1 t2i0 ca h crcl 00 h .7 .6 .5 .4 .3 .2 .1 .0 cb h crch 00 h .7 .6 .5 .4 .3 .2 .1 .0 cc h tl2 00 h .7 .6 .5 .4 .3 .2 .1 .0 cd h th2 00 h .7 .6 .5 .4 .3 .2 .1 .0 d0 h 2) psw 00 h cy ac f0 rs1 rs0 ov f1 p d8 h 2) adcon0 00x0-00 00 b bd clk ? bsy adm mx2 mx1 mx0 d9 h addath 00 h .9 .8 .7 .6 .5 .4 .3 .2 da h addatl 00xx-x xxx b .1 .0 ?????? 1) ? x ? means that the value is undefined and the location is reserved 2) bit-addressable sfrs table 3-4 contents of the sfrs, sfrs in numeric order of their addresses (cont ? d) addr register content after reset 1) bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 user ? s manual 3-17 10.99 memory organization C505L dc h adcon1 01xx-x 000 b adcl1 adcl0 ??? mx2 mx1 mx0 e0 h 2) acc 00 h .7 .6 .5 .4 .3 .2 .1 .0 e8 h 2) p4 00 h .7 .6 .5 .4 .3 .2 .1 .0 f0 h 2) b 00 h .7 .6 .5 .4 .3 .2 .1 .0 f8 h 2) p5 xx00-00 00 h ? ? .5 .4 .3 .2 .1 .0 fc h 3)4) vr0 c5 h 11000101 fd h 3)4) vr1 85 h 00000101 fe h 3)4) vr2 5) .7 .6 .5 .4 .3 .2 .1 .0 1) ? x ? means that the value is undefined and the location is reserved. 2) bit-addressable sfrs. 3) sfr is located in the mapped sfr area. for accessing this sfr, bit rmap in sfr syscon must be set. 4) these are read-only registers. 5) the content of this sfr varies with the actual of the step C505L (e.g. 01 h for the first step). table 3-4 contents of the sfrs, sfrs in numeric order of their addresses (cont ? d) addr register content after reset 1) bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 memory organization C505L user ? s manual 3-18 10.99 table 3-5 contents of the lcd and the rtc registers in numeric order of their addresses addr. register content after reset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 f3dc h dac0 2) 00 h s7 s6 s5 s4 s3 s2 s1 s0 f3dd h lcon 2) 00 h dsb1 dsb0 0 0 0 0 csel lcen f3de h lcrl 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3df h lcrh 2) 00 h slt .14 .13 .12 .11 .10 .9 .8 f3en h dign 1), 2) 00 h segf sega segg segb sege segc segh segd f3f0 h rtcon 2) 00 h 0 0 0 0 rtpd irtc ertc rtcs f3f1 h rtcr0 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f2 h rtcr1 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f3 h rtcr2 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f4 h rtcr3 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f5 h rtcr4 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f6 h clreg0 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f7 h clreg1 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f8 h clreg2 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3f9 h clreg3 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3fa h clreg4 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3fb h rtint0 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3fc h rtint1 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3fd h rtint2 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3fe h rtint3 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 f3ff h rtint4 2) 00 h .7 .6 .5 .4 .3 .2 .1 .0 1) the notation ? n ? (n = 0 to f) in the lcd digit register address definition defines the number of the related lcd digit. 2) this register is located in the on-chip external data memory area. user ? s manual 4-1 10.99 external bus interface C505L 4 external bus interface the C505L allows for external memory expansion. the functionality and implementation of the external bus interface is identical to the common interface for the 8051 architecture with one exception: if the C505L is used in systems with no external memory the generation of the ale signal can be suppressed. resetting bit eale in sfr syscon register, the ale signal will be gated off. this feature reduces rfi emissions of the system. 4.1 accessing external memory it is possible to distinguish between accesses to external program memory, external data memory or to other peripheral components respectively. this distinction is made by hardware: accesses to external program memory use the signal psen (program store enable) as a read strobe. accesses to external data memory use rd and wr to strobe the memory (alternate functions of p3.7 and p3.6). port 0 and port 2 (with exceptions) are used to provide data and address signals. in this section only the port 0 and port 2 functions relevant to external memory accesses are described. fetches from external program memory always use a 16-bit address. accesses to external data memory can use either a 16-bit address (movx @dptr) or an 8-bit address (movx @ri). 4.1.1 role of p0 and p2 as data/address bus when used for accessing external memory, port 0 provides the data byte time-multiplexed with the low byte of the address. in this state, port 0 is disconnected from its own port latch, and the address/ data signal drives both fets in the port 0 output buffers. thus, in this application, the port 0 pins are not open-drain outputs and do not require external pullup resistors. during any access to external memory, the cpu writes ff h to the port 0 latch (the special function register), thus obliterating whatever information the port 0 sfr may have been holding. whenever a 16-bit address is used, the high byte of the address comes out on port 2, where it is held for the duration of the read or write cycle. during this time, the port 2 lines are disconnected from the port 2 latch (the sfr). thus the port 2 latch does not have to contain 1 s, and the contents of the port 2 sfr are not modified. if an 8-bit address is used (movx @ri), the contents of the port 2 sfr remain at the port 2 pins throughout the external memory cycle. this will facilitate paging. it should be noted that, if a port 2 pin outputs an address bit that is a 1, strong pullups will be used for the entire read/write cycle and not only for two oscillator periods. external bus interface C505L user ? s manual 4-2 10.99 figure 4-1 external program memory execution pcl out pch out one machine cycle one machine cycle out pch in inst (a) without movx pcl out valid pcl out valid pcl out valid pcl out valid ale psen rd p2 a) b) p2 rd psen ale valid pcl out valid pcl out movx with (b) in data in inst inst in dph out or p2 out one machine cycle one machine cycle s6 s5 s4 s3 s2 s1 s6 s5 s4 s3 s2 s1 mcd02575 s1 s2 s3 s4 s5 s6 s1 s2 s3 s4 s5 s6 out pch pch out out pch pch out out pch pch out p0 inst in pcl out in inst out pcl inst in pcl out in inst p0 pcl out dpl or ri valid pcl out inst in user ? s manual 4-3 10.99 external bus interface C505L 4.1.2 timing the timing of the external bus interface and the relationship between the control signals ale, psen , rd , wr and information on port 0 and port 2 are illustrated in figures 4-1 a) and b) . data memory : in a write cycle, the data byte to be written appears on port 0 just before wr is activated and remains there until after wr is deactivated. in a read cycle, the incoming byte is accepted at port 0 before the read strobe is deactivated. program memory : signal psen functions as a read strobe. 4.1.3 external program memory access the external program memory is accessed whenever the program counter (pc) content is greater than 7fff h , provided the ea pin is held at high level at reset. when the cpu is executing out of external program memory, all 8 bits of port 2 are dedicated to an output function and must not be used for general-purpose i/o. the content of the port 2 sfr, however, is not affected. during external program memory fetches, port 2 lines output the high byte of the pc; during accesses to external data memory, they output either dph or the port 2 sfr (depending on whether the external data memory access is a movx @dptr or a movx @ri). 4.2 psen , program store enable the read strobe for external program memory fetches is psen . it is not activated for internal program memory fetches. when the cpu is accessing external program memory, psen is activated twice every instruction cycle (except during a movx instruction) whether or not the byte fetched is actually needed for the current instruction. when psen is activated its timing is not the same as for rd . a complete rd cycle, including activation and deactivation of ale and rd , takes 6 oscillator periods. a complete psen cycle, including activation and deactivation of ale and psen , takes 3 oscillator periods. the execution sequence for these two types of read cycles is shown in figures 4-1 a) and b) . 4.3 overlapping external data and program memory spaces in some applications it is desirable to execute a program from the same physical memory that is used for storing data. in the C505L, the external program and data memory spaces can be combined by the logical-and of psen and rd . a positive result from this and operation produces a low-active read strobe that can be used for the combined physical memory. since the psen cycle is faster than the rd cycle, the external memory needs to be fast enough to adapt to the psen cycle. external bus interface C505L user ? s manual 4-4 10.99 4.4 ale, address latch enable the C505L allows to switch off the ale output signal. if the internal otp is used (ea = 1 and pc 7fff h ) and ale is switched off by eale = 0, then, ale will only go active during external data memory accesses (movx instructions). after a hardware reset, ale generation is enabled. special function register syscon (address b1 h ) reset value: xx10xx01 b bit function eale enable ale output eale = 0: ale generation is disabled; disables ale signal generation during internal code memory accesses; ale is automatically generated during movx instructions eale = 1: ale generation is enabled (default after reset) ? reserved bits for future use. read by cpu returns undefined values. 76543210 eale rmap ? b1 h syscon bit no. msb lsb ? xmap1 ?? xmap0 the shaded bits are not described in this section. user ? s manual 4-5 10.99 external bus interface C505L 4.5 enhanced hooks emulation concept the enhanced hooks emulation concept of the c500 microcontroller family is a new, innovative way to control the execution of c500 mcus, and to gain extensive information on the internal operation of the controllers. emulation of on-chip rom-based programs is possible, too. each c500 production chip has built-in logic for the support of the enhanced hooks emulation concept. therefore, no costly bond-out chips are necessary for emulation, ensuring that emulation and production chips are identical. the enhanced hooks technology tm 1) , which requires embedded logic in the c500, allows the c500 together with an eh-ic to function in a similar way as a bond-out chip. this simplifies the design and reduces costs of an ice-system. ice-systems using an eh-ic and a compatible c500 are able to emulate all operating modes of the different versions of the c500 microcontrollers. this includes emulation of rom, rom with code rollover, and romless modes of operation. it is also able to operate in single-step mode, and to read the sfrs after a break. figure 4-2 basic c500 mcu enhanced hooks concept configuration port 0, port 2 and some of the control lines of the c500-based mcu are used by enhanced hooks emulation concept to control the operation of the device during emulation; and to transfer information about the program execution and data transfer between the external emulation hardware (ice-system) and the c500 mcu. 1) ? enhanced hooks technology ? is a trademark and patent of metalink corporation licensed to infineon technologies. mcs02647 syscon pcon tcon reset ea psen ale port 0 port 2 i/o ports optional port 3 port 1 c500 mcu interface circuit enhanced hooks rport 0 rport 2 rtcon rpcon rsyscon tea tale tpsen eh-ic target system interface ice-system interface to emulation hardware external bus interface C505L user ? s manual 4-6 10.99 4.6 eight datapointers for faster external bus access 4.6.1 the importance of additional datapointers the standard 8051 architecture provides just one 16-bit pointer for indirect addressing of external devices (memories, peripherals, latches, etc.). except for a 16-bit ? move immediate ? to this datapointer and an increment instruction, any other pointer handling is bytewise. for complex applications with peripherals (e.g. lcd controller or real-time clock) located in the external data memory space, or extended data storage capacity, bytewise pointer handling turned out to be a ? bottle neck ? for the 8051 ? s communication to the external world. in particular, programming in high- level languages (plm51, c51, pascal51) requires extended ram capacity and at the same time a fast access to this additional ram because of the reduced code efficiency of these languages. 4.6.2 how the eight datapointers of the C505L are implemented simply adding more datapointers is not suitable because of the need to keep up 100% compatibility with the 8051 instruction set. that instruction set allows the handling of only one single 16-bit datapointer (dptr, consisting of the two 8-bit sfrs dph and dpl). to meet both of the above requirements (speed up external accesses, 100% compatibility with 8051 architecture), the C505L contains a set of eight 16-bit registers from which the actual datapointer can be selected. this means that the user ? s program may keep up to eight 16-bit addresses resident in these registers, but only one register at a time is selected to be the datapointer. thus the desired datapointer in turn is accessed (or selected) via indirect addressing. this indirect addressing is done through a special function register called dpsel (data pointer select register). all instructions of the C505L that handle the datapointer therefore affect only pointer addressed by dpsel at that very moment, rather than the other 7 pointers. figure 4-3 illustrates the addressing mechanism: a 3-bit field in register dpsel points to the currently used dptrx. any standard 8051 instruction (e.g. movx @dptr, a - transfer a byte from accumulator to an external location addressed by dptr) now uses this activated dptrx. special function register dpsel (address 92 h ) reset value: xxxxx000 b bit function dpsel.2-0 data pointer select bits dpsel.2-0 defines the number of the actual active data pointer.dptr0-7. dpsel 76543210 ??? 92 h bit no. msb lsb .2 .1 ?? .0 user ? s manual 4-7 10.99 external bus interface C505L figure 4-3 accessing of external data memory via multiple datapointers 4.6.3 advantages of multiple datapointers using the addressing mechanism described above for external data memory results in less code and faster execution of external accesses. whenever the contents of the datapointer must be altered between two or more 16-bit addresses, one instruction that selects a new datapointer does this job. lf the program uses just one datapointer, then it has to save the old value (with two 8-bit instructions) and load the new address, byte-by-byte. this takes more time and requires additional space in the internal ram. 4.6.4 application example and performance analysis the following example demonstrates the use of multiple data pointers in a table transfer from the code memory to external data memory. start address of rom source table: 1fff h start address of table in external ram: 2fa0 h dph(83 ) dpl(82 ) dptr0 dptr7 .0 .1 .2 - - - - - dpsel(92 ) dpsel selected data- pointer .2 .1 .0 dptr 0 0 0 0 0 0 1 dptr 1 0 1 0 dptr 2 0 1 1 dptr 3 1 0 0 dptr 4 1 0 1 dptr 5 1 1 0 dptr 6 1 1 1 dptr 7 mcd00779 external data memory h hh external bus interface C505L user ? s manual 4-8 10.99 example 1: using only one datapointer (code for a c501) initialization routine mov low(src_ptr), #0ff h ; initialize shadow_variables with source_pointer mov high(src_ptr), #1f h mov low(des_ptr), #0a0 h ; initialize shadow_variables with destination_pointer mov high(des_ptr), #2f h table look-up routine under real time conditions ; number of cycles push dpl ;save old datapointer 2 push dph ; 2 mov dpl, low(src_ptr) ;load source pointer 2 mov dph, high(src_ptr) ; 2 ;inc dptr increment and check for end of table (execution time ;cjne ? not relevant for this consideration) ? movc a,@dptr ;fetch source data byte from rom table 2 mov low(src_ptr), dpl ;save source_pointer and 2 mov high(src_ptr), dph ;load destination_pointer 2 mov dpl, low(des_ptr) ; 2 mov dph, high(des_ptr) ; 2 inc dptr ;increment destination_pointer ;(ex. time not relevant) ? movx @dptr, a ;transfer byte to destination address 2 mov low(des_ptr), dpl ;save destination_pointer 2 mov high(des_ptr),dph ; 2 pop dph ;restore old datapointer 2 pop dpl ; 2 ; total execution time (machine cycles): 28 user ? s manual 4-9 10.99 external bus interface C505L example 2: using two datapointers (code for a C505L) initialization routine mov dpsel, #06 h ;initialize dptr6 with source pointer mov dptr, #1fff h mov dpsel, #07 h ;initialize dptr7 with destination pointer mov dptr, #2fa0 h table look-up routine under real-time conditions ; number of cycles push dpsel ;save old source pointer 2 mov dpsel, #06 h ;load source pointer 2 ;inc dptr increment and check for end of table (execution time ;cjne ? not relevant for this consideration) ? movc a,@dptr ;fetch source data byte from rom table 2 mov dpsel, #07 h ;save source_pointer and ;load destination_pointer 2 movx @dptr, a ;transfer byte to destination address 2 pop dpsel ;save destination pointer and ;restore old datapointer 2 ; total execution time (machine cycles): 12 the example above shows that utilization of the C505L ? s multiple datapointers can make external bus accesses two times as fast as with a standard 8051 or 8051 derivative. here, four data variables in the internal ram and two additional stack bytes were spared, too. for some applications where all eight datapointers are employed, a C505L program has up to 24 byte (16 variables and 8 stack bytes) of the internal ram free for other use. user ? s manual 5-1 10.99 system reset C505L 5 system reset 5.1 hardware reset operation the hardware reset function incorporated in the C505L allows for an easy automatic start-up with a minimum of additional hardware, and forces the controller to a predefined default state. the hardware reset function can also be used during normal operation in order to restart the device. this is commonly done when the power-down mode is to be terminated. in addition to the hardware reset, which is applied externally to the C505L, there are two internal reset sources: the watchdog timer, and the oscillator watchdog. this chapter deals only with the external hardware reset. the reset input is an active-high input. an internal schmitt trigger is used at the input for noise rejection. since the reset is synchronized internally, the reset pin must be held high for at least two machine cycles (12 oscillator periods) while the oscillator is running. with the oscillator running, the internal reset is executed during the second machine cycle, and is repeated every cycle until reset goes low again. during reset, pins ale and psen are configured as inputs and should not be stimulated externally. an external stimulation at these lines during reset activates several test modes that are reserved for test purposes. this may, in turn, cause unpredictable output operations at several port pins. at the reset pin, a pulldown resistor is internally connected to v ss to allow a power-up reset with an external capacitor only. when v dd is applied, an automatic power-up reset can be caused by connecting the reset pin to v dd via a capacitor. after v dd has been turned on, the capacitor must hold the voltage level at the reset pin for a specific time in order to effect a complete reset. system reset C505L user ? s manual 5-2 10.99 the time required for a power-up reset operation is the oscillator start-up time plus 2 machine cycles, which, under normal conditions, must be at least 10 - 20 ms for a crystal oscillator. this requirement is typically met using a capacitor of 4.7 to 10 f. the same considerations apply if the reset signal is generated externally ( figure 5-1 b ). in each case it must be assured that the oscillator has started up properly and, after that, at least two machine cycles have passed before the reset signal goes inactive. figure 5-1 reset circuitries a correct reset leaves the processor in a defined state. the program execution starts at location 0000 h . after reset is accomplished internally, the port latches of ports 0 to 4 default in ff h . this leaves port 0 floating, since it is an open drain port when not used as data/address bus. all other i/ o port lines (ports 1, 3 and 4) output a one (1). port 2 lines output a one after reset. the internal sfrs are set to their initial states as defined in table 3-2 . the contents of the internal ram and xram of the C505L are not affected by a reset. after power-up the contents are undefined, and they remain unchanged during a reset if the power supply is not turned off. a) + b) + C505L reset c) & mcs03840 C505L C505L v dd dd v reset reset user ? s manual 5-3 10.99 system reset C505L 5.2 fast internal reset after power-on the C505L uses the oscillator watchdog unit for a fast internal reset procedure after power-on. figure 5-1 shows the power-on sequence under control of the oscillator watchdog. normally, the devices of the 8051 family do not enter their default reset states before the on-chip oscillator starts. the reason is that the external reset signal must be internally synchronized and processed in order to bring the device into the correct reset state. if a crystal is used, the start up time of the oscillator is relatively long (typ. 10 ms). during this time period, the pins are in an undefined state which could have severe effects, especially to actuators connected to port pins. in the C505L, the oscillator watchdog unit avoids this situation. in this case, after power-on the oscillator watchdog ? s rc oscillator starts working within a very short start-up time (typ. less than 2 microseconds). if the watchdog circuitry detects a failure condition for the on-chip oscillator because the latter has not yet started (a failure is always recognized if the watchdog ? s rc oscillator runs faster than the on-chip oscillator), the watchdog uses the rc oscillator output as clock source for the chip rather than the on-chip oscillator ? s output. this allows correct resetting of the part and brings also all ports to the defined state (see figure 5-2 ). under worst-case conditions (fast v dd rise time - e.g. 1 s, measured from v dd = 4.25 v up to stable port condition), the delay between power-on and the correct port reset state is: ? typ.: 18 s ? max.: 34 s the rc oscillator will already run at a v dd below 4.25 v (lower specification limit). therefore, at slower v dd rise times the delay time will be less than the two values given above. after the on-chip oscillator has finally started, the oscillator watchdog detects the correct function; then the watchdog still holds the reset active for up to 768 cycles of the rc oscillator clock in order to allow the oscillation of the on-chip oscillator to stabilize ( figure 5-2, ii ). subsequently, the clock is supplied by the on-chip oscillator, and the oscillator watchdog ? s reset request is released ( figure 5-2, iii ). however, an externally applied reset still remains active ( figure 5-2, iv ) and the device does not start program execution ( figure 5-2, v ) until the external reset is also released. although the oscillator watchdog provides a fast internal reset, it is also necessary to apply an external reset signal when powering up. the reasons are: ? termination of software power-down mode ? reset of the status flag owds that is set by the oscillator watchdog during the power up sequence. when using a crystal or ceramic resonator for clock generation, the external reset signal must be held active at least until the on-chip oscillator has started and the internal watchdog reset phase is completed (after phase iii in figure 5-2 ). when an external clock generator is used, phase ii is very short. therefore, an external reset time of 1 ms is usually sufficient for most applications. generally, for reset time generation at power-on, an external capacitor can be applied to the reset pin. system reset C505L user ? s manual 5-4 10.99 figure 5-2 power-on reset of the C505L ports undef. reset on-chip osc. rc osc. dd v clock from rc-oscillator; reset at ports reset iii s max. 34 undef.ports power on; typ. 18 s iii iv clock cycles) (max. 768 rc by osc.-wd; final reset sequence osc. starts; on-chip active ext. because of port remains in reset reset signal v start of program mcd02627 execution user ? s manual 5-5 10.99 system reset C505L 5.3 hardware reset timing this section describes the timing of the hardware reset signal. the input pin reset is sampled once during each machine cycle. this happens in state 5 phase 2. thus, the external reset signal is synchronized with the internal cpu timing. when the reset is found active (high level), the internal reset procedure is started. it takes two complete machine cycles to put the complete device into its correct reset state, i.e. all special function registers (sfrs) containing their default values, the port latches containing ? 1 ? s etc. note that this reset procedure may also be performed by the oscillator watchdog if there is no clock available at the device. the oscillator watchdog provides an auxiliary clock at the xtal1 and xtal2 pins for performing a complete reset without another. the reset signal must be active for at least one machine cycle; after this time the C505L remains in its reset state as long as the signal is active. when the signal goes inactive, this transition is recognized in the subsequent state 5 phase 2 of the machine cycle. then the processor starts program execution in the subsequent state 5 phase 1. one phase later (state 5 phase 2), the first falling edge at pin ale occurs. system reset C505L user ? s manual 5-6 10.99 5.4 oscillator and clock circuit xtal1 and xtal2 are the input and output of a single-stage on-chip inverter that can be configured with off-chip components such as a pierce oscillator. the oscillator, in any case, drives the internal clock generator. the clock generator provides the internal clock signals to the chip. these signals define the internal phases, states, and machine cycles. figure 5-3 shows the recommended oscillator circuit. figure 5-3 recommended oscillator circuit in this application, the on-chip oscillator is used as a crystal-controlled, positive-reactance oscillator. a more detailed schematic is given in figure 5-4 . the oscillator is operated in its fundamental response mode as an inductive reactor in parallel resonance with a capacitor external to the chip. the crystal specifications and capacitances are non-critical. in this circuit, 20 pf can be used as single capacitance at any frequency together with a good-quality crystal. a ceramic resonator can be used in place of the crystal in cost-critical applications. if a ceramic resonator is used, the two capacitors normally have different values depending on the oscillator frequency. we recommend consulting the manufacturer of the ceramic resonator for value specifications of these capacitors. mcs04291 c 2 - 20 mhz xtal1 xtal2 c = 20 pf 10 pf for crystal operation C505L c user ? s manual 5-7 10.99 system reset C505L figure 5-4 on-chip oscillator circuitry to drive the C505L with an external clock source, the external clock signal has to be applied to xtal1, as shown in figure 5-5 . xtal2 has to be left unconnected. a pullup resistor is recommended to increase the noise margin, but is optional if v oh of the driving gate corresponds to the v ih1 specification of xtal1 (refer to data sheet). figure 5-5 external clock source xtal2 xtal1 *) to internal timing circuitry C505L c 2 c 1 *) crystal or ceramic resonator mcs04292 n.c. mcs04037 xtal2 xtal1 C505L external clock signal v dd system reset C505L user ? s manual 5-8 10.99 5.5 system clock output for peripheral devices requiring a system clock, the C505L provides a clock output signal derived from the oscillator frequency as an alternate output function on pin p1.6/clkout. if bit clk is set (bit 6 of sfr adcon0), a clock signal with 1/6 of the oscillator frequency is gated to pin p1.6/ clkout. to use this function, the port pin must be programmed to a 1, which is also the default after reset. special function register adcon0 (address d8 h ) reset value: 00x00000 b the system clock is high during s3p1 and s3p2 of every machine cycle and low during all other states. thus, the duty cycle of the clock signal is 1:6. associated with a movx instruction, the system clock coincides with the last state (s3) in which a rd or wr signal is active. a timing diagram of the system clock output is shown in figure 5-6 . note: during slow-down operation, the frequency of the clkout signal is divided by 32. bit function clk clockout enable bit when set, pin p1.6/clkout outputs the system clock which is 1/6 of the oscillator frequency. ? reserved bits for future use. read by cpu returns undefined values. bd clk ? bsy d8 h adcon0 bit no. df h de h dd h dc h db h da h d9 h d8 h msb lsb adm mx2 mx1 mx0 the shaded bits are not used for clock output control. user ? s manual 5-9 10.99 system reset C505L figure 5-6 timing diagram - system clock output mct01858 s6 s1 s2 s3 s4 s5 s6 s1 s2 s3 s4 s5 s6 s1 s2 ale psen rd,wr clkout user ? s manual 6-1 10.99 on-chip peripheral components C505L 6 on-chip peripheral components this chapter gives detailed information about all on-chip peripherals of the C505L except for the integrated interrupt controller, which is described separately in chapter 7 . 6.1 parallel i/o the C505L has five 8-bit and one 6-bit (port 5) digital i/o ports. port 0 is an open-drain bidirectional i/o port, while ports 1 through 5 are quasi-bidirectional i/o ports with internal pull-up resistors. when configured as inputs, ports 1-5 will be pulled high, and will source current when externally pulled low. port 0 will float when configured as input. the output drivers of port 0 and 2 and the input buffers of port 0 are also used for accessing external memory. in this application, port 0 outputs the low byte of the external memory address, time-multiplexed with the byte being written or read. port 2 outputs the high byte of the external memory address when the address is 16 bits wide. otherwise, the port 2 pins continue emitting the p2 special function register (sfr) contents. in this function, port 0 is not an open-drain port, but uses a strong internal pull-up fet. the C505L has 36 output lines (4 rows and 32 columns) for lcd voltage output. of these, 20 are dedicated output lines: r0-r3 and c0-c15. fourteen lcd output lines are used as alternate functions of the bits of port 4 (c16-c23) and port 5 (c24-c29). two lcd output lines c30 and c31 are used as alternate functions of p3.5 / t1 and p3.4 / t0 respectively. 6.1.1 port structures the C505L generally allows digital i/o on 46 lines, grouped into five 8-bit digital and one 6-bit digital i/o ports. each port bit consists of a latch, an output driver and an input buffer. read and write accesses to the i/o ports p0-p5 are performed via their corresponding sfrs. depending on the specific ports, multiple functions are assigned to the port pins. therefore, the parallel i/o ports of the C505L can be grouped into six different types which are listed in table 6-1 . type a and b port pins are standard c501-compatible i/o port lines, which can be used for digital i/o. the type a ports (port 0 and port 2) are also designed for accessing external data or program memory. type b port lines are located at port 3 (except p3.4 and p3.5), and are used for digital i/o or for other alternate functions as described in the pin description. type d port lines provide the lcd controller outputs r0-r3 and c0-c15 as primary functions. type e port lines are located at port 4 and port 5 and provide the lcd controller output lines as alternate functions. type f port lines table 6-1 C505L port structure types type description a standard digital i/o ports which can also be used for external address/data bus b standard multifunctional digital i/o port lines c mixed digital/analog i/o port lines with programmable analog input function d lcd output lines e standard digital i/o or lcd output lines f standard multifunctional digital i/o or lcd output lines on-chip peripheral components C505L user ? s manual 6-2 10.99 are at p3.4 / t0 and p3.5 / t1 and have a digital alternate input each, apart from lcd output functions. the C505L provides eight analog input lines that are implemented as mixed digital/analog inputs (type c). the 8 analog inputs, an0-an7, are located at the port 1 pins p1.0 to p1.7. after reset, all analog inputs are disabled and the related pins of port 1 are configured as digital inputs. the analog function of the specific port 1 pins are enabled by bits in the sfrs p1ana. writing a 0 to a bit position of p1ana assigns the corresponding pin to operate as analog input. note: p1ana is a mapped sfr and can only be accessed if bit rmap in sfr syscon is set. as already mentioned, ports 1, 3, 4 and 5 are provided for multiple alternate functions. these functions are listed in table 6-2 . user ? s manual 6-3 10.99 on-chip peripheral components C505L table 6-2 alternate functions of port 1, 3, 4 and 5 port second / third function port type function p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 p3.0 p3.1 p3.2 p3.3 p3.4 p3.5 p3.6 p3.7 p4.0 p4.1 p4.2 p4.3 p4.4 p4.5 p4.6 p4.7 p5.0 p5.1 p5.2 p5.3 p5.4 p5.5 an0 / int3 / cc0 an1 / int4 /cc1 an2 / int5 /cc2 an3 / int6 / cc3 an4 an5 / t2ex an6 / clkout an7 / t2 rxd txd int0 int1 t0 / c31 t1 / c30 wr rd c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c c c c c c c c b b b b f f b b e e e e e e e e e e e e e e analog input channel 0 / external interrupt 3 / compare/capture channel 0 input/output analog input channel 1 / external interrupt 4 input / compare/capture channel 1 input/output analog input channel 2 / external interrupt 5 input / compare/capture channel 2 input/output analog input channel 3 / external interrupt 6 input / compare/capture channel 3 input/output analog input channel 4 analog input channel 5 / timer 2 external reload / trigger input analog input channel 6 / system clock output analog input channel 7 / timer 2 external count input serial port ? s receiver data input (asynchronous) or data input/output (synchronous) serial port ? s transmitter data output (asynchronous) or data clock output (synchronous) external interrupt 0 input, timer 0 gate control external interrupt 1 input, timer 1 gate control timer 0 external counter input / lcd column 31 output timer 1 external counter input / lcd column 30 output external data memory write strobe external data memory read strobe lcd column 16 output lcd column 17 output lcd column 18 output lcd column 19 output lcd column 20 output lcd column 21 output lcd column 22 output lcd column 23 output lcd column 24 output lcd column 25 output lcd column 26 output lcd column 27 output lcd column 28 output lcd column 29 output on-chip peripheral components C505L user ? s manual 6-4 10.99 6.1.2 standard i/o port circuitry figure 6-1 is a functional diagram of a typical bit latch and i/o buffer, which is the core of each of the five i/o-ports. the bit latch (one bit in the port ? s sfr) is represented as a type-d flip-flop that will clock-in a value from the internal bus in response to a ? write-to-latch ? signal from the cpu. the q output of the flip-flop is placed on the internal bus in response to a ? read-latch ? signal from the cpu. the level of the port pin itself is placed on the internal bus in response to a ? read-pin ? signal from the cpu. some instructions that read from a port (i.e. from the corresponding port sfr p0 to p5) activate the ? read-latch ? signal, while others activate the ? read-pin ? signal. figure 6-1 basic structure of a port circuit mcs01822 d clk port latch q q port read latch to latch read pin write int. bus port driver circuit pin user ? s manual 6-5 10.99 on-chip peripheral components C505L the output drivers of port 1 to 5 have internal pull-up fets (see figure 6-2 ). each i/o line can be used independently as an input or output. to be used as an input, the port bit stored in the bit latch must contain 1 (that means for figure 6-2 : q = 0), which turns off the output driver fet n1. then, for ports 1 to 5, the pin is pulled high by the internal pull-ups, but can be pulled low by an external source. when externally pulled low, the port pins source current ( i il or i tl ). for this reason, these ports are called ? quasi-bidirectional ? . figure 6-2 basic output driver circuit of ports 1 to 5 mcs03844 d clk bit latch q q internal pull up arrangement port read latch to latch read pin write v dd int. bus n1 pin on-chip peripheral components C505L user ? s manual 6-6 10.99 6.1.2.1 port 0 circuitry port 0, in contrast to ports 1 to 5, is considered to be a ? true ? bidirectional, because the port 0 pins float when configured as inputs. thus, this port differs in not having internal pull-ups. the pull-up fet in the p0 output driver (see figure 6-3 ) is used only when the port is emitting 1s during external memory accesses. otherwise, the pull-up is always off. consequently, p0 lines that are used as output port lines are open drain lines. writing a 1 to the port latch leaves both output fets off and the pin floats. in that condition, the pin can be used as high-impedance input. if port 0 is configured as general i/o port and has to emit logic high-level (1), external pull-ups are required. figure 6-3 port 0 circuit mcs03845 d clk bit latch control addr./data mux pin read latch bus latch read pin write to v dd int. & port =1 q q user ? s manual 6-7 10.99 on-chip peripheral components C505L 6.1.2.2 port 1 and port 3 circuitry the pins of ports 1 and 3 are multifunctional. they are port pins and also serve to implement the special features as listed in table 6-2 . figure 6-4 is a functional diagram of a port latch with alternate function. to pass the alternate function to the output pin and vice versa, however, the gate between the latch and driver circuit must be open. thus, to use the alternate input or output functions, the corresponding bit latch in the port sfr has to contain a 1 or the pulldown fet will be on and the port pin will be stuck at 0. after reset, all port latches contain 1 s. figure 6-4 ports 1 and 3 the lcd output functions of port 3.4/t0 and p3.5/t1 pins are of type f. mcs03846 d clk bit latch q q internal pull up arrangement port read latch to latch read pin write v dd int. bus alternate output function alternate input function & pin on-chip peripheral components C505L user ? s manual 6-8 10.99 6.1.2.3 port 2 circuitry as shown in figure 6-3 and figure 6-5 , the output drivers of ports 0 and 2 can be switched to an internal address or address/data bus for use in external memory accesses. in this application these ports cannot be used as general purpose i/o, even if not all address lines are used externally. the switching is done by an internal control signal dependent on the input level at the ea pin and/or the contents of the program counter. if the ports are configured as an address/data bus, the port latches are disconnected from the driver circuit. during this time, the p0/p2 sfr remains unchanged. since it is an address/data bus, port 0 uses a pull-up fet as shown in figure 6-3 . when a 16-bit address is used, port 2 uses the additional strong pull-up p1 ( figure 6-5a ) to emit 1s for the entire external memory cycle instead of the weak 1s (p2 and p3) used during normal port activity. figure 6-5 port 2 circuit if no external bus cycles are generated using data or code memory accesses, port 0 can be used for i/o functions. d clk q latch q mux address control =1 port pin internal pull up arrangement v dd read latch int. bus write to latch read pin mcs03847 user ? s manual 6-9 10.99 on-chip peripheral components C505L figure 6-5a port 2 pull-up arrangement port 2 in i/o function works similar to the type b port driver circuitry (see section 6.1.3.1 ) whereas in address output function, it works similar to port 0 circuitry. mcs03848 1 1 = 1 = 1 v dd port pin ss v input data (read pin) delay p1 p2 p3 n1 = 1 mux addr. control q 1 state < _ _ < on-chip peripheral components C505L user ? s manual 6-10 10.99 6.1.3 detailed output driver circuitry the pull-ups mentioned before and included in figure 6-2, 6-4 and 6-5 are pull-up arrangements. the differences of the port types available in the C505L are described in the following sections. 6.1.3.1 type b port driver circuitry figure 6-6 shows the output driver circuit of the type b multifunctional digital i/o port lines. the basic circuitry of these ports is shown in figure 6-4 . the pull-up arrangement of type b port lines has one n-channel pulldown fet and three pull-up fets: figure 6-6 driver circuit of type b port pins ? the pull-down fet n1 is of n-channel type. it is a very strong driver transistor that is capable of sinking high currents ( i ol ); it is activated only if a 0 is programmed to the port pin. a short circuit to v dd must be avoided if the transistor is turned on, since the high current might destroy the fet. this also means that no 0 must not be programmed into the latch of a pin that is used as input. ? the pull-up fet p1 is of p-channel type. it is activated for two oscillator periods (s1p1 and s1p2) if a 0-to-1 transition is programmed to the port pin, i.e., a ? 1 ? is programmed to the port latch which contained a 0. the extra pull-up can drive a similar current as the pulldown fet n1. this provides a fast transition of the logic levels at the pin. ? the pull-up fet p2 is of p-channel type. it is always activated when a 1 is in the port latch, thus providing the logic high output level. this pull-up fet sources a much lower current than p1; therefore the pin may also be tied to ground, e.g., when used as input with logic low input level. ? the pull-up fet p3 is of p-channel type. it is only activated if the voltage at the port pin is higher than approximately 1.0 to 1.5 v. this provides an additional pull-up current if a logic high level is output at the pin (and the voltage is not forced lower than approximately 1.0 to mcs03849 =1 1 =1 =1 v dd port pin ss v q input data (read pin) p1 p2 p3 n1 delay = 1 state _ < user ? s manual 6-11 10.99 on-chip peripheral components C505L 1.5 v). however, this transistor is turned off if the pin is driven to a logic low level, e.g., when used as input. in this configuration, only the weak pull-up fet p2 is active and sources the current i il . if, in addition, the pull-up fet p3 is activated, a higher current can be sourced ( i tl ). thus, additional power consumption can be avoided if port pins are used as inputs with a low level applied. however, the driving capability is stronger if a logic high level is output. activating and deactivating of the four different transistors translates into four states. pins can be: ? input low state (il), p2 active only ? input high state (ih) = steady output high state (soh) p2 and p3 active ? forced output high state (foh), p1, p2 and p3 active ? output low state (ol), n1 active if a pin is used as input and a low level is applied, it will be in il state. if a high level is applied, it will switch to ih state. if the latch is loaded with 0, the pin will be in ol state. if the latch holds a 0 and is loaded with 1, the pin will enter foh state for two cycles and then switch to soh state. if the latch holds a 1 and is reloaded with a 1 no state change will occur. at the beginning of power-on reset, the pins will be in il state (latch is set to 1, voltage level on pin is below of the trip point of p3). depending on the voltage level and load applied to the pin, it will remain in this state or will switch to ih (= soh) state. if it is used as output, the weak pull-up p2 will pull the voltage level at the pin above p3 ? s trip point after some time, and p3 will turn on and provide a strong 1. note, however, that if the load exceeds the drive capability of p2 ( i il ), the pin might remain in the il state and provide a weak 1 until the first 0-to-1 transition on the latch occurs. until then, the output level might stay below the trip point of the external circuitry. the same is true if a pin is used as bidirectional line, and the external circuitry is switched from output to input when the pin is held at 0 and the load then exceeds the p2 drive capabilities. if the load exceeds i il the pin can be forced to 1 by writing a 0 followed by a 1 to the port pin. on-chip peripheral components C505L user ? s manual 6-12 10.99 6.1.3.2 type c port driver circuitry figure 6-7 shows the C505L ? s port driver circuit of the type c: mixed digital/analog i/o port 1 lines. the analog function is selected by the bits in the sfr p1ana. when the analog function is selected, all output driver transistors (p1, p2, p3 and n1) are switched off. figure 6-7 driver circuit of type c port pins =1 =1 input data (read pin) >1 & >1 >1 =1 port pin delay = 1 state q enable analog input (bits of sfr p1ana) to a / d converter p1 p2 p3 n1 v ss mct03850 dd v user ? s manual 6-13 10.99 on-chip peripheral components C505L 6.1.3.3 type d port driver circuitry figure 6-8 shows the C505L ? s port driver circuit of the type d. these pins are used for the dedicated lcd outputs, r0-r3 and c0-c15. the p-channel transistor p2 is a weak pull-up transistor similar to the p2 transistor in other digital i/o ports. after a reset operation, the lcd controller remains disabled. at this point, the weak pull-up is enabled. when, the lcd controller is enabled by bit lcen in sfr syscon, this transistor is switched off, making the lcd output available at the port pin. lcd levels are in the range mentioned in the dc specifications (refer to data sheet). figure 6-8 driver circuit of type d port pins port pin p2 dd v mcs03851 lcen lcd output ( from lcd controller ) on-chip peripheral components C505L user ? s manual 6-14 10.99 6.1.3.4 type e and f port driver circuitry figure 6-9 describes the output structure of type e port 4 and 5 pins. such pins have both digital i/o and lcd output functions. ports 4 and 5 have no digital alternate function possible. when the lcd output is enabled, all digital output drivers are switched off; the respective output signals from the lcd controller are selected; and lcd voltage levels are available at the pins shown in table 6-2 . after reset, the lcd output functions remain disabled due the lcen bit having been cleared in the register lcon. when the lcd controller is enabled with bit lcen, the bits dsb0 and dsb1 in the register lcon will enable/disable the lcd output lines c16-c23 and c24-c31, respectively. figure 6-9 driver circuit of type e and type f port pins the digital i/o function of the type f pins is similar to that of type e digital i/o pins, with one difference. the digital alternate function is available for p3.4/t0/c31 and p3.5/t1/c30 only (see section 6.1.2.2 ). =1 =1 input data (read pin) >1 & >1 >1 =1 port pin delay = 1 state q lcen dsb0 or dsb1 c16 - c31 (lcd column outputs) p1 p2 p3 n1 v ss mct03852 dd v >1 user ? s manual 6-15 10.99 on-chip peripheral components C505L 6.1.4 port timing when executing an instruction that changes the value of a port latch, the new value arrives at the latch during s6p2 of the final cycle of the instruction. however, port latches are only sampled by their output buffers during phase 1 of any clock period. during phase 2, the output buffer holds the value it noticed during the previous phase 1. consequently, the new value in the port latch will not appear at the output pin until the next phase 1, which will be at s1p1 of the next machine cycle. when an instruction reads a value from a port pin (e.g., mov a, p1), the port pin is actually sampled in state 5 phase 1 or phase 2, depending on port and alternate functions. figure 6-10 illustrates this port timing. it must be noted that this mechanism of sampling once per machine cycle is also used if a port pin is to detect an ? edge ? , e.g., when used as counter input. in this case an edge is detected when the sampled value differs from the value that was sampled the cycle before. therefore, certain requirements must be met with regards to the pulse length of signals, in order to ensure that signal edges are detected. the minimum time period of high and low level is one machine cycle, which guarantees that this logic level is noticed by the port at least once. figure 6-10 port timing mct03231 p1 p2 s4 s5 p2 p1 s6 p2 p1 s1 p2 p1 s2 p2 p1 s3 p2 p1 xtal2 input sampled: e.g. mov a, p1 old data new data port p1 active for 1 state (driver transistor) on-chip peripheral components C505L user ? s manual 6-16 10.99 6.1.5 port loading and interfacing the output buffers of ports 1 to 5 can drive ttl inputs directly. the maximum port load that guarantees correct logic output levels is specified in the dc characteristics in the data sheet of the C505L. the corresponding parameters are v ol and v oh . the same condition applies to port 0 output buffers. they do, however, require external pull-ups to drive floating inputs, except when being used as the address/data bus. when used as inputs, ports 1 to 5 are not floating but have internal pull-up transistors. the driving devices must be capable of sinking a sufficient current if a logic low level shall is applied to the port pin. parameters i tl and i il in the dc characteristics of the data sheet specify these currents. port 1 may be programmed to analog input function, but has floating inputs in these cases. user ? s manual 6-17 10.99 on-chip peripheral components C505L 6.1.6 read-modify-write feature of ports 0 to 5 some port-reading instructions read the latch and others read the pin. instructions that read the latch rather than the pin do read a value, possibly change it, and then rewrite it to the latch. these ? read-modify-write ? instructions are listed in table 6-3 . if the destination is a port or a port pin, these instructions read the latch rather than the pin. note that all other instructions that can be used to read a port just read the port pin. reading from either the latch or the pin is performed by reading the sfr p0, p2 and p3; for example, ? mov a, p3 ? reads the value from port 3 pins, while ? anl p3, #0aah ? reads from the latch, modifies the value and writes it back to the latch. it is not obvious that the last three instructions in table 6-3 are read-modify-write instructions, but they are because they read the port byte - all 8 bits - and modify the addressed bit, then write the complete byte back to the latch. read-modify-write instructions are directed to the latch rather than the pin in order to avoid a possible misinterpretation of the voltage level at the pin. for example, a port bit might be used to drive the base of a transistor. when a 1 is written to the bit, the transistor is turned on. if the cpu then reads the same port bit at the pin rather than the latch, it will read the base voltage of the transistor (approx. 0.7 v, i.e. a logic low level!) and interpret it as 0. for example, when modifying a port bit by a setb or clr instruction, another bit in this port with the configuration mentioned above might be changed if the value read from the pin were written back to the latch. however, reading the latch rather than the pin will return the correct value of 1. table 6-3 ? read-modify-write ? instructions instruction function anl logic and; e.g. anl p1, a orl logic or; e.g. orl p2, a xrl logic exclusive or; e.g. xrl p3, a jbc jump if bit is set and clear bit; e.g. jbc p1.1, label cpl complement bit; e.g. cpl p3.0 inc increment byte; e.g. inc p4 dec decrement byte; e.g. dec p5 djnz decrement and jump if not zero; e.g. djnz p3, label mov px.y,c move carry bit to bit y of port x clr px.y clear bit y of port x setb px.y set bit y of port x user ? s manual 6-18 10.99 on-chip peripheral components C505L 6.2 timers/counters the C505L contains three 16-bit timers/counters (timer 0, 1, and 2) which are useful in many applications for timing and counting. in ? timer ? function, the timer register is incremented every machine cycle. thus one can think of it as counting machine cycles. since a machine cycle consists of 6 oscillator periods, the counter rate is 1/6 of the oscillator frequency. in ? counter ? function, the timer register is incremented in response to a 1-to-0 transition (falling edge) at the corresponding external input pin (t0, t1, or t2, which provide alternate functions of p3.4, p3.5 and p1.7, respectively). in the counter 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 it takes two machine cycles (12 oscillator periods) to recognize a 1-to-0 transition, the maximum count rate is 1/12 of the oscillator frequency. there are no restrictions on the duty cycle of the external input signal, but it must be held for at least one full machine cycle to ensure that a given level is sampled at least once before it changes. 6.2.1 timer/counter 0 and 1 timer/counter 0 and 1 of the C505L are fully compatible with timer/counter 0 and 1 of the c501 and can be used in the same four operating modes: mode 0: 8-bit timer/counter with a divide-by-32 prescaler mode 1: 16-bit timer/counter mode 2: 8-bit timer/counter with 8-bit auto-reload mode 3: timer/counter 0 is configured as one 8-bit timer/counter and one 8-bit timer; timer/counter 1 in this mode holds its count. the effect is the same as setting tr1 = 0. external inputs int0 and int1 can be programmed to function as a gate for timer/counters 0 and 1 to facilitate pulse width measurements. each timer consists of two 8-bit registers (th0 and tl0 for timer/counter 0, th1 and tl1 for timer/counter 1) that may be combined to one timer configuration depending on the mode that is established. the functions of the timers are controlled by two special function registers (sfrs), tcon and tmod. in the following descriptions, th0 and tl0 are used to specify the high byte and the low byte of timer 0 (th1 and tl1 for timer 1, respectively). the operating modes are described and shown for timer 0. if not explicity noted otherwise, this applies also to timer 1. user ? s manual 6-19 10.99 on-chip peripheral components C505L 6.2.1.1 timer/counter 0 and 1 registers six sfrs control the timer/counter 0 and 1 operation: ? tl0/th0 and tl1/th1 - counter registers, low and high part ? tcon and tmod - control and mode select registers special function register tl0 (address 8a h ) reset value: 00 h special function register th0 (address 8c h ) reset value: 00 h special function register tl1 (address 8b h ) reset value: 00 h special function register th1 (address 8d h ) reset value: 00 h bit function tlx.7-0 x=0-1 timer/counter 0/1 low register thx.7-0 x=0-1 timer/counter 0/1 high register bit no. 76543210 msb lsb .7 .6 .5 .4 8d h th1 .3 .2 .1 .0 .7 .6 .5 .4 8b h tl1 .3 .2 .1 .0 .7 .6 .5 .4 8c h th0 .3 .2 .1 .0 .7 .6 .5 .4 8a h tl0 .3 .2 .1 .0 operating mode description 0 ? tlx ? holds the 5-bit prescaler value. 1 ? tlx ? holds the lower 8-bit part of the 16-bit timer/counter value. 2 ? tlx ? holds the 8-bit timer/counter value. 3 tl0 holds the 8-bit timer/counter value; tl1 is not used. operating mode description 0 ? thx ? holds the 8-bit timer/counter value. 1 ? thx ? holds the higher 8-bit part of the 16-bit timer/counter value 2 ? thx ? holds the 8-bit reload value. 3 th0 holds the 8-bit timer value; th1 is not used. user ? s manual 6-20 10.99 on-chip peripheral components C505L special function register tcon (address 88 h ) reset value: 00 h bit function tr0 timer 0 run control bit set/cleared by software to turn timer/counter 0 on/off. tf0 timer 0 overflow flag set by hardware on timer/counter overflow. cleared by hardware when processor vectors to interrupt routine. tr1 timer 1 run control bit set/cleared by software to turn timer/counter 1 on/off. tf1 timer 1 overflow flag set by hardware on timer/counter overflow. cleared by hardware when processor vectors to interrupt routine. 8f h 8e h 8d h 8c h 8b h 8a h 89 h 88 h tf1 tr1 tf0 tr0 88 h tcon bit no. 76543210 msb lsb ie1 it1 ie0 it0 the shaded bits are not used for controlling timer/counter 0 and 1. user ? s manual 6-21 10.99 on-chip peripheral components C505L special function register tmod (address 89 h ) reset value: 00 h bit function gate gating control when set, timer/counter ? x ? is enabled only while ? int x ? pin is high and ? trx ? control bit is set. when cleared, timer ? x ? is enabled whenever ? trx ? control bit is set. c/ t counter or timer select bit set for counter operation (input from ? tx ? input pin). cleared for timer operation (input from internal system clock). m1 m0 mode select bits gate c/t m1 m0 89 h tmod bit no. 76543210 msb lsb gate c/t m1 m0 timer 1 control timer 0 control m1 m0 function 0 0 8-bit timer/counter: ? thx ? operates as 8-bit timer/counter ? tlx ? serves as 5-bit prescaler 0 1 16-bit timer/counter. ? thx ? and ? tlx ? are cascaded; there is no prescaler 1 0 8-bit auto-reload timer/counter. ? thx ? holds a value which is to be reloaded into ? tlx ? each time it overflows 1 1 timer 0: tl0 is an 8-bit timer/counter controlled by the standard timer 0 control bits. th0 is an 8-bit timer only controlled by timer 1 control bits. timer 1: timer/counter 1 stops user ? s manual 6-22 10.99 on-chip peripheral components C505L 6.2.1.2 mode 0 putting either timer/counter 0 or timer/counter 1 into mode 0 configures it as an 8-bit timer/counter with a divide-by-32 prescaler. figure 6-11 shows the mode 0 operation. in this mode, the timer register is configured as a 13-bit register. as the count rolls over from all 1s to all 0 s, it sets the timer overflow flag tf0. the overflow flag tf0 then can be used to request an interrupt. the counted input is enabled to the timer when tr0 = 1 and either gate = 0 or int0 =1. setting gate = 1 allows the timer to be controlled by external input int0 , in order to facilitate pulse width measurements. tr0 is a control bit in the sfr tcon; gate is in tmod. the 13-bit register consists of all 8 bits of th0 and the lower 5 bits of tl0. the upper 3 bits of tl0 are indeterminate and should be ignored. setting the run flag tr0 does not clear the registers. mode 0 operation is the same for timer 0 as for timer 1. substitute tr0, tf0, th0, tl0 and int0 for the corresponding timer 1 signals in figure 6-11 . there are two different gate bits, one for timer 1 (tmod.7) and one for timer 0 (tmod.3). figure 6-11 timer/counter 0, mode 0: 13-bit timer/counter mcs02726 1 & c/t = 0 tl0 th0 tf0 c/t = 1 control interrupt = 1 tr0 p3.4/t0 gate p3.2/int0 bits) (5 (8 bits) osc 6 _ < user ? s manual 6-23 10.99 on-chip peripheral components C505L 6.2.1.3 mode 1 mode 1 is the same as mode 0, except that the timer register is running with all 16 bits. mode 1 is shown in figure 6-12 . figure 6-12 timer/counter 0, mode 1: 16-bit timer/counter mcs02727 1 & c/t = 0 tl0 th0 tf0 c/t = 1 control interrupt = 1 tr0 p3.4/t0 gate p3.2/int0 bits) (8 (8 bits) osc 6 _ < user ? s manual 6-24 10.99 on-chip peripheral components C505L 6.2.1.4 mode 2 mode 2 configures the timer register as an 8-bit counter (tl0) with automatic reload, as shown in figure 6-13 . overflow from tl0 not only sets tf0, but also reloads tl0 with the contents of th0, which is preset by software. the reload leaves th0 unchanged. figure 6-13 timer/counter 0, mode 2: 8-bit timer/counter with auto-reload mcs02728 1 & c/t = 0 tl0 tf0 c/t = 1 control interrupt = 1 tr0 p3.4/t0 gate p3.2/int0 th0 reload bits) (8 (8 bits) 6 osc _ < user ? s manual 6-25 10.99 on-chip peripheral components C505L 6.2.1.5 mode 3 mode 3 has different effects on timer 0 and timer 1. timer 1 in mode 3 simply holds its count. the effect is the same as setting tr1 = 0. timer 0 in mode 3 establishes tl0 and th0 as two separate counters. the logic for mode 3 on timer 0 is shown in figure 6-14 . tl0 uses the timer 0 control bits: c/t , gate, tr0, int0 and tf0. th0 is locked into a timer function (counting machine cycles) and takes over the use of tr1 and tf1 from timer 1. thus, th0 now controls the ? timer 1 ? interrupt. mode 3 is provided for applications requiring an extra 8-bit timer or counter. when timer 0 is in mode 3, timer 1 can be turned on and off by switching it out of and into its own mode 3 or can still be used by the serial channel as a baud rate generator or in any mode as long as an interrupt from timer 1 itself is not required. figure 6-14 timer/counter 0, mode 3: two 8-bit timers/counters mcs02729 1 & c/t = 0 tl0 tf0 c/t = 1 control interrupt = 1 tr0 p3.4/t0 gate p3.2/int0 th0 interrupt tf1 tr1 timer clock bits) (8 (8 bits) 6 osc f osc /6 _ < user ? s manual 6-26 10.99 on-chip peripheral components C505L 6.2.2 timer/counter 2 with additional compare/capture/reload timer 2 has additional compare/capture/reload features that make it one of the most powerful peripheral units of the C505L. it can be used for all kinds of digital signal generation and event capturing, such as pulse generation, pulse width modulation (pwm), pulse width measuring, etc. timer 2 is designed to support various automotive control applications as well as industrial applications (e.g., frequency generation, digital-to-analog conversion, process control). please note that the functionality of this timer is not equivalent to timer 2 of the c501. the C505L ? s timer 2 allows the following operating modes in combination with the compare/capture/reload registers: ? compare: up to 4 pwm output signals with 65535 steps at maximum, and 300-ns resolution ? capture: up to 4 high speed capture inputs with 300-ns resolution ? reload: modulation of timer 2 cycle time the block diagram in figure 6-15 shows the general configuration of timer 2 with the additional compare/capture/reload registers. the i/o pins that can be used for timer 2 control are located as multifunctional port functions at port 1 (see table 6-4 ). table 6-4 alternate port functions of timer 2 pin symbol function p1.0/an0/int3 /cc0 compare output/capture input for crc register p1.1/an1/int4/cc1 compare output/capture input for cc register 1 p1.2/an2/int5/cc2 compare output/capture input for cc register 2 p1.3/an3/int6/cc3 compare output/capture input for cc register 3 p1.5/an5/t2ex external reload trigger input p1.7/an7/t2 external count or gate input to timer 2 user ? s manual 6-27 10.99 on-chip peripheral components C505L figure 6-15 timer 2 block diagram mcb03853 comparator ccl3/cch3 capture input/ output control p1.0/ int3/ cc0 cc1 int4/ p1.1/ cc2 int5/ p1.2/ cc3 int6/ p1.3/ ccl2/cch2 comparator ccl1/cch1 comparator crcl/crch comparator bit 16 16 bit 16 bit 16 bit osc 6 12 t2ps p1.7/ t2 t2ex p1.5/ sync. & t2i1 t2i0 timer 2 th2 tl2 tf2 reload exen2 1 exf2 interrupt request compare _ < an5/ an7/ sync. pin pin reload an0/ an1/ an2/ an3/ user ? s manual 6-28 10.99 on-chip peripheral components C505L 6.2.2.1 timer 2 registers this chapter describes all timer 2 sfrs. the interrupt-related sfrs are also included in this section. table 6-5 summarizes all timer 2 sfrs. table 6-5 special function registers of the timer 2 unit name description address t2con tl2 th2 ccen crcl crch ccl1 cch1 ccl2 cch2 ccl3 cch3 ien0 ien1 ircon timer 2 control register timer 2, low byte timer 2, high byte compare/capture enable register compare/reload/capture register, low byte compare/reload/capture register, high byte compare/capture register 1, low byte compare/capture register 1, high byte compare/capture register 2, low byte compare/capture register 2, high byte compare/capture register 3, low byte compare/capture register 3, high byte interrupt enable register 0 interrupt enable register 1 interrupt control register c8 h cc h cd h c1 h ca h cb h c2 h c3 h c4 h c5 h c6 h c7 h a8 h b8 h c0 h user ? s manual 6-29 10.99 on-chip peripheral components C505L the t2con timer 2 control register is a bit-addressable register which controls the timer 2 function and the compare mode of registers crc, cc1 to cc3. special function register t2con (address c8 h ) reset value: 00x00000 b bit function t2ps prescaler select bit when set, timer 2 is clocked in the ? timer ? or ? gated timer ? function with 1/12 of the oscillator frequency. when cleared, timer 2 is clocked with 1/6 of the oscillator frequency. t2ps must be 0 for the counter operation of timer 2. i3fr external interrupt 3 falling/rising edge flag used for capture function in combination with register crc. if set, a capture to register crc (if enabled) will occur on a positive transition at pin p1.0/an0/int3 /cc0 t2r1 t2r0 timer 2 reload mode selection t2cm compare mode bit for registers crc, cc1 through cc3 when set, compare mode 1 is selected. t2cm = 0 selects compare mode 0. t2i1 t2i0 timer 2 input selection cf h ce h cd h cc h cb h ca h c9 h c8 h t2ps i3fr ? t2r1 c8 h t2con bit no. 76543210 msb lsb t2r0 t2cm t2i1 t2i0 the shaded bits are not used for controlling timer/counter 2. t2r1 t2r0 function 0 x reload disabled 1 0 mode 0: auto-reload upon timer 2 overflow (tf2) 1 1 mode 1: reload on falling edge at pin p1.5 / an5 / t2ex t2i1 t2i0 function 0 0 no input selected, timer 2 stops 0 1 timer function: input frequency = f osc /6 (t2ps = 0) or f osc /12 (t2ps = 1) 1 0 counter function: external input signal at pin p1.7 / an7 / t2 1 1 gated timer function: input controlled by pin p1.7 / an7 / t2 user ? s manual 6-30 10.99 on-chip peripheral components C505L special function register tl2 (address cc h ) reset value: 00 h special function register th2 (address cd h ) reset value: 00 h special function register crcl (address ca h ) reset value: 00 h special function register crch (address cb h ) reset value: 00 h bit function tl2.7-0 timer 2 value low byte the tl2 register holds the 8-bit low part of the 16-bit timer 2 count value. th2.7-0 timer 2 value high byte the th2 register holds the 8-bit high part of the 16-bit timer 2 count value. crcl.7-0 reload register low byte crcl is the 8-bit low byte of the 16-bit reload register of timer 2. it is also used for compare/capture functions. crch.7-0 reload register high byte crch is the 8-bit high byte of the 16-bit reload register of timer 2. it is also used for compare/capture functions. .7 .6 .5 .4 cc h tl2 bit no. 76543210 msb lsb .3 .2 .1 lsb msb.6.5.4 cd h th2 .3 .2 .1 .0 .7 .6 .5 .4 ca h crcl .3 .2 .1 lsb msb.6.5.4 cb h crch .3 .2 .1 .0 user ? s manual 6-31 10.99 on-chip peripheral components C505L special function register ien0 (address a8 h ) reset value: 00 h special function register ien1 (address b8 h ) reset value: 00 h special function register ircon (address c0 h ) reset value: 00 h bit function et2 timer 2 overflow/external reload interrupt enable. if et2 = 0, the timer 2 interrupt is disabled. if et2 = 1, the timer 2 interrupt is enabled. exen2 timer 2 external reload interrupt enable. if exen2 = 0, the timer 2 external reload interrupt is disabled. if exen2 = 1, the timer 2 external reload interrupt is enabled. the external reload function is not affected by exen2. exf2 timer 2 external reload flag. exf2 is set when a reload is caused by a falling edge on pin t2ex while exen2 = 1. if et2 in ien0 is set (timer 2 interrupt enabled), exf2 = 1 will cause an interrupt. exf2 can be used as an additional external interrupt when the reload function is not used. exf2 must be cleared by software. tf2 timer 2 overflow flag. set by a timer 2 overflow and must be cleared by software. if the timer 2 interrupt is enabled, tf2 = 1 will cause an interrupt. exf2 tf2 iex6 iex5 c0 h ircon bit no. c7 h iex4 iex3 swi iadc c6 h c5 h c4 h c3 h c2 h c1 h c0 h the shaded bits are not used in timer/counter 2 interrupt control. eal wdt et2 es a8 h ien0 bit no. af h msb lsb et1 ex1 et0 ex0 ae h ad h ac h ab h aa h a9 h a8 h exen2 swdt ex6 ex5 b8 h ien1 bit no. bf h ex4 ex3 eswi eadc be h bd h bc h bb h ba h b9 h b8 h user ? s manual 6-32 10.99 on-chip peripheral components C505L special function register ccen (address c1 h ) reset value: 00 h bit function cocah3 cocal3 compare/capture mode for cc register 3 cocah2 cocal2 compare/capture mode for cc register 2 cocah1 cocal1 compare/capture mode for cc register 1 cocah0 cocal0 compare/capture mode for crc register cocah3 cocal3 cocah2 cocal2 c1 h ccen bit no. 76543210 msb lsb cocah1 cocal1 cocah0 cocal0 cocah3 cocal3 function 0 0 compare/capture disabled 0 1 capture on rising edge at pin p1.3 / an3 / int6 / cc3 1 0 compare enabled 1 1 capture on write operation into register ccl3 cocah2 cocal2 function 0 0 compare/capture disabled 0 1 capture on rising edge at pin p1.2 / an2 / int5 / cc2 1 0 compare enabled 1 1 capture on write operation into register ccl2 cocah1 cocal1 function 0 0 compare/capture disabled 0 1 capture on rising edge at pin p1.1 / an1 / int4 / cc1 1 0 compare enabled 1 1 capture on write operation into register ccl1 cocah0 cocal0 function 0 0 compare/capture disabled 0 1 capture on falling/rising edge at pin p1.0 / an0 / int3 / cc0 1 0 compare enabled 1 1 capture on write operation into register crcl user ? s manual 6-33 10.99 on-chip peripheral components C505L 6.2.2.2 timer 2 operation timer 2, which is a 16-bit-wide register, can operate as timer, event counter, or gated timer. its operation is described in detail below. timer mode in timer function, the count rate is derived from the oscillator frequency. a prescaler offers the possibility of selecting a count rate of 1/6 or 1/12 of the oscillator frequency. thus, the 16-bit timer register (consisting of th2 and tl2) is incremented either in every machine cycle, or in every second machine cycle. the prescaler is selected by bit t2ps in sfr t2con. if t2ps is cleared, the input frequency is 1/6 of the oscillator frequency. if t2ps is set, the 2:1 prescaler gates 1/12 of the oscillator frequency to the timer. gated timer mode in gated timer function, the external input pin t2 (p1.7) functions as a gate to the input of timer 2. if t2 is high, the internal clock input is gated to the timer. t2 = 0 stops the counting procedure. this facilitates pulse width measurements. the external gate signal is sampled once every machine cycle. event counter mode in the counter function, timer 2 is incremented in response to a 1-to-0 transition at its corresponding external input pin t2 (p1.7). in this function, the external input is sampled every machine cycle. when the sampled inputs show a high in one cycle and a low in the next cycle, the count is incremented. the new count value appears in the timer register in the cycle following the one in which the transition was detected. since it takes two machine cycles (12 oscillator periods) to recognize a 1-to-0 transition, the maximum count rate is 1/12 of the oscillator frequency. there are no restrictions on the duty cycle of the external input signal, but it must be held for at least one full machine cycle to ensure that a given level is sampled at least once before it changes. note: the prescaler must be off for proper counter operation of timer 2, i.e. t2ps must be 0. in either of the cases, where timer 2 is configured as timer, event counter, or gated timer, rolling- over of the count from all 1s to all 0s sets the timer overflow flag tf2 in sfr ircon, which can generate an interrupt. if tf2 is used to generate a timer overflow interrupt, the request flag must be cleared by the interrupt service routine because it may be necessary to check whether the tf2 flag or the external reload request flag exf2 requested the interrupt. both request flags cause the program to branch to the same vector address. user ? s manual 6-34 10.99 on-chip peripheral components C505L reloading of timer 2 the reload mode for timer 2 is selected by bits t2r0 and t2r1 in sfr t2con. figure 6-16 shows the configuration of timer 2 in reload mode. mode 0: when timer 2 rolls over from all i ? s to all 0 ? s, it not only sets tf2 but also causes the timer 2 registers to be loaded with the 16-bit value in the crc registers, which are preset by software. the reload will happen in the same machine cycle in which tf2 is set, thus overwriting the count value 0000 h . mode 1: a 16-bit reload from the crc register is caused by a negative transition at the corresponding input pin p1.5/an5/t2ex. in addition, this transition will set flag exf2, if bit exen2 in sfr ien1 is set. if the timer 2 interrupt is enabled, setting exf2 will generate an interrupt. the external input pin t2ex is sampled in every machine cycle. when the sampling shows a high in one cycle and a low in the next cycle, a transition will be recognized. timer 2 registers will then be reloaded in the cycle following the one in which the transition was detected. figure 6-16 timer 2 in reload mode mcs01903 1 mode 1 exf2 0 mode exen2 tf2 crch crcl reload th2 tl2 input clock timer interrupt request t2ex p1.5 2 < _ user ? s manual 6-35 10.99 on-chip peripheral components C505L 6.2.2.3 compare function of registers crc, cc1 to cc3 the compare function of a timer/register combination is described below. the 16-bit value stored in a compare/capture register is compared to the contents of the timer register. if the count value in the timer register matches the stored value, an appropriate output signal is generated at a corresponding port pin, and an interrupt is requested. the contents of a compare register can be regarded as ? time stamp ? at which a dedicated output reacts in a predefined way (either with a positive or negative transition). variation in this ? time stamp ? somehow changes the wave of a rectangular output signal at a port pin. as a variation of the duty cycle of a periodic signal, this may be used for pwm as well as for a continually-controlled generation of any kind of square wave form. two compare modes are implemented to cover a wide range of possible applications. compare modes 0 and 1 are selected by bit t2cm in sfr t2con. in both compare modes, the new value arrives at the port pin 1 within the same machine cycle in which the internal compare signal is activated. the four registers crc, cc1 to cc3 are multifunctional as they provide a capture, compare or reload capability for the timer (crc register only). the function is selected in register ccen. please note that the compare interrupt register cc0 can be programmed to be activated by either negative or positive transition. the internal compare signal (not the output signal at the port pin!) is active as long as the timer 2 contents equal the contents of one of the appropriate compare registers. thus, when using the crc register, it is possible to determine whether an interrupt is caused when the compare signal goes active or inactive, depending on bit i3fr in t2con. for the cc registers 1 to 3 an interrupt is always requested when the compare signal goes active (see figure 6-18 ). 6.2.2.3.1 compare mode 0 in mode 0, upon matching the timer and compare register contents, the output signal changes from low to high. it goes back to a low level on timer overflow. as long as compare mode 0 is enabled, the appropriate output pin is controlled by the timer circuit only, and not by the user. writing to the port will have no effect. figure 6-17 is a functional diagram of a port latch in compare mode 0. the port latch is directly controlled by the timer overflow and compare signals. the input line from the internal bus and the write-to-latch line are disconnected when compare mode 0 is enabled. compare mode 0 is ideal for generating pulse width modulated output signals, which in turn can be used for digital-to-analog conversion via a filter network or by the controlled device itself (e.g., the inductance of a dc or ac motor). mode 0 may also be used for providing output clocks with an initially-defined period and duty cycle. this is the mode that needs the least cpu time. once set up, the output continues to oscillate without any cpu intervention. figures 6-18 and 6-19 illustrate the function of compare mode 0. user ? s manual 6-36 10.99 on-chip peripheral components C505L figure 6-17 port latch in compare mode 0 figure 6-18 timer 2 with registers ccx in compare mode 0 mcs02661 latch port q q clk d port pin read pin dd v read latch port circuit internal bus latch write to compare reg. compare register circuit comparator timer register timer circuit compare match s r overflow timer 16 bit bit 16 v dd mcs03233 iexx for crc only cc0 int3/ p1.0/ compare signal overflow interrupt set latch reset latch tl2 timer 2 th2 comparator shaded function interrupt 16-bit compare register ccx p1.3/ int6/ cc3 q r ss r q s r q s r q cc2 int5/ p1.2/ p1.1/ int4/ cc1 16-bit i3fr user ? s manual 6-37 10.99 on-chip peripheral components C505L figure 6-19 function of compare mode 0 6.2.2.3.2 modulation range in compare mode 0 generally it can be said that for every pwm generation in compare mode 0 with n-bit wide compare registers, there are 2 n different settings for the duty cycle. starting with a constant low level (0% duty cycle) as the first setting, the maximum possible duty cycle would then be: (1 ? 1/2 n ) 100% this means that a variation of the duty cycle from 0% to real 100% can never be reached if the compare register and timer register have the same length. there is always a spike that is as long as the timer clock period. this spike may appear either when the compare register is set to the reload value (limiting the lower end of the modulation range), or it may occur at the end of a timer period. in a timer 2/ccx register configuration in compare mode 0, this spike is divided into two halves: one at the beginning when the contents of the compare register equal the reload value of the timer; the other half when the compare register contents equal the maximum value of the timer register (here: ffff h ). please refer to figure 6-20 , which illustrates the maximum and minimum duty cycle of a compare output signal. timer 2 is incremented with the machine clock ( f osc /6). thus at 20-mhz operational frequency, these spikes are both approx. 150-ns long. mct01906 timer count = ffff timer count = compare value contents of timer 2 timer count = reload value interrupt can be generated on overflow compare output (p1.x/ccx) interrupt can be generated on compare-match ~ ~ ~ ~ h user ? s manual 6-38 10.99 on-chip peripheral components C505L figure 6-20 modulation range of a pwm signal, generated with a timer 2/ccx register combination in compare mode 0* the following example shows how to calculate the modulation range for a pwm signal. to calculate with reasonable numbers, a reduction of the resolution to 8-bit is used. otherwise for the maximum resolution of 16-bits, the modulation range would be so severely limited that it would be negligible. example: timer 2 in auto-reload mode; contents of reload register crc = ff00 h restriction of modulation range = 1/(256 2) 100% = 0.195% this leads to a variation of the duty cycle from 0.195% to 99.805% for a timer 2/ccx register configuration when 8 of 16 bits are used. mct01907 h l p1.x cchx/cclx = 0000 or = crch/crcl (maximum duty cycle) p1.x l h cchx/cclx = ffff (minimum duty cycle) appr. 1/2 machine cycle a) b) appr. 1/2 machine cycle h h user ? s manual 6-39 10.99 on-chip peripheral components C505L 6.2.2.3.3 compare mode 1 in compare mode 1, the software adaptively determines the transition of the output signal. it is commonly used when output signals are not related to a constant signal period (as in a standard pwm generation) but must be controlled very precisely with high resolution and without jitter. in compare mode 1, both transitions of a signal can be controlled. compare outputs in this mode can be regarded as high-speed outputs that are independent of the cpu activity. if compare mode 1 is enabled and the software writes to the appropriate output latch at the port, the new value will not appear at the output pin until the next compare match occurs. thus, one can choose whether the output signal is to make a new transition (1-to-0 or 0-to-1, depending on the actual pinlevel) or keep its old value when the timer 2 count matches the stored compare value. figure 6-21 and figure 6-22 are functional diagrams of the timer/compare register/port latch configuration in compare mode 1. in this function, the port latch consists of two separate latches. the upper latch (which acts as a ? shadow latch ? ) can be written under software control, but its value will be transferred to the output latch (and thus to the port pin) only in response to a compare match. note that the double latch structure is transparent as long as the internal compare signal is active. while the compare signal is active, a write operation to the port will then change both latches. this may become important when driving timer 2 with a slow external clock. in this case, the compare signal could be active for many machine cycles during which the cpu could inadvertently change the contents of the port latch. a read-modify-write instruction will read the user-controlled shadow-latch and write the modified value back to this shadow-latch. a standard read instruction will read the pin of the corresponding compare output, as usual. user ? s manual 6-40 10.99 on-chip peripheral components C505L figure 6-21 port latch in compare mode 1 figure 6-22 timer 2 with registers ccx in compare mode 1 (ccx stands for crc, cc1 to cc3, iexx stands for iex3 to iex6) mcs02662 latch port q q clk d read pin dd v d clk q shadow latch read latch port circuit internal bus latch write to compare reg. compare register circuit comparator timer register timer circuit compare match pin port 16 bit 16 bit mcs02732 iexx for crc only p1.7 cc0 int3/ p1.0/ compare signal overflow interrupt output latch shadow latch port latch circuit 2 tl2 timer th2 comparator shaded function interrupt 16 bit 16 bit compare register ccx p1.3/ int6/ cc3 i3fr user ? s manual 6-41 10.99 on-chip peripheral components C505L 6.2.2.4 using interrupts in combination with the compare function the compare service of registers crc, cc1, cc2 and cc3 are assigned to alternate output functions at port pins p1.0 to p1.3. another option of these pins is that they can be used as external interrupt inputs. however, when using the port lines as compare outputs, the input line from the port pin to the interrupt system is disconnected (but the pin ? s level can still be read under software control). thus, a change of the pin ? s level will not cause the corresponding interrupt flag to be set. in this case, the interrupt input is directly connected to the (internal) compare signal, thus providing a compare interrupt. the compare interrupt can be used very effectively to change the contents of the compare registers or to determine the level of the port outputs for the next ? compare match ? . the principle is that the internal compare signal (generated by a matching timer count and register contents) not only manipulates the compare output, but also sets the corresponding interrupt request flag. the current task of the cpu is interrupted if the priority of the compare interrupt is higher than the present task ? s priority, and the corresponding interrupt service routine is called. this service routine then sets up all the necessary parameters for the next compare event. advantages of compare interrupts there is no danger of unintentionally overwriting a compare register before a match has been reached. this could happen if the cpu wrote to the compare register without having information about the actual timer 2 count. the most interesting advantage of the compare feature is that the output pin is exclusively controlled by hardware. therefore, it is completely independent of any service delay, which could be disastrous in real-time applications. the compare interrupt, in turn, is not sensitive to such delays, since it loads the parameters for the next event. this, in turn, is supposed to happen after a sufficient amount of time. in some special cases, however, a program using compare interrupts may behave surprisingly. one configuration for such a case is that described for compare mode 1. the fact that the compare interrupts are transition-activated becomes important when driving timer 2 with a slow external clock. in this case it should be carefully considered that the compare signal is active as long as the timer 2 count is equal to the contents of the corresponding compare register, and that the compare signal has a rising and a falling edge. furthermore, the shadow latch used in compare mode 1 is transparent while the compare signal is active. with a slow input clock for timer 2, the comparator signal is active for a long time (= high number of machine cycles). therefore, a fast interrupt- controlled reload of the compare register could change not only the shadow latch (probably intended), but also the output buffer. when using the crc, the programmer can select whether an interrupt should be generated when the compare signal goes active or inactive, depending on the status of bit i3fr in t2con. initializing the interrupt to be triggered by a negative transition is advisable in the case described above. then the compare signal is already inactive, and any write access to the port latch just changes the contents of the shadow-latch. please note that for cc1 to cc3 registers, an interrupt is always requested when the compare signal goes active. user ? s manual 6-42 10.99 on-chip peripheral components C505L the second configuration which should be noted is when the compare function is combined with interrupts activated by negative transitions. if the port latch of port p1.0 contains a 1, the interrupt request flags iex3 will be set immediately after enabling the compare mode for the crc register. the reason is that first the external interrupt input is controlled by the pin ? s level. when the compare option is enabled, the interrupt logic input is switched to the internal compare signal, which carries a low level when no true comparison is detected. the interrupt logic sees a 1-to-0 edge and sets the interrupt request flag. an unintentional generation of an interrupt during compare initialization can be prevented. if the request flag is cleared by software after the compare is activated, and before the external interrupt is enabled. user ? s manual 6-43 10.99 on-chip peripheral components C505L 6.2.2.5 capture function each of the compare/capture registers cc1 to cc3 and the crc register can be used to latch the current 16-bit value of the timer 2 registers tl2 and th2. two different modes are provided for this function. in mode 0, an external event latches the timer 2 contents to a dedicated capture register. in mode 1, a capture will occur upon writing to the low-order byte of the dedicated 16-bit capture register. this mode is provided to allow the software to read the timer 2 contents ? on-the-fly ? . in mode 0, the external event causing a capture is: ? for cc registers 1 to 3: a positive transition at pins cc1 to cc3 of port 1 ? for the crc register: a positive or negative transition at the corresponding pin, depending on the status of the bit i3fr in sfr t2con. if the edge flag is cleared, a capture occurs in response to a negative transition; if the edge flag is set, a capture occurs in response to a positive transition at pin p1.0 / int3 / cc0. in both cases, the appropriate port 1 pin is used as input, and the port latch must be programmed to contain a 1. the external input is sampled in every machine cycle. when the sampled input shows a low (high) level in one cycle and a high (low) in the next cycle, a transition is recognized. the timer 2 contents is latched to the appropriate capture register in the cycle following the one in which the transition was identified. in mode 0 , a transition at the external capture inputs of registers cc1 to cc3 will also set the corresponding external interrupt request flags iex3 to iex6. if the interrupts are enabled, an external capture signal will cause the cpu to vector to the appropriate interrupt service routine. in mode 1 , a capture occurs in response to a write instruction to the low order byte of a capture register. the write-to-register signal (e.g. write-to-crcl) is used to initiate a capture. the value written to the dedicated capture register is irrelevant for this function. the timer 2 contents will be latched into the appropriate capture register in the cycle following the write instruction. in this mode, no interrupt request will be generated. figure 6-23 illustrates the operation of the crc register, while figure 6-23a shows the operation of the compare/capture registers 1 (similarly applicable to registers 2 & 3). the two capture modes can be established individually for each capture register by bits in sfr ccen (compare/capture enable register). in contrast to the compare modes, it is possible to select simultaneously mode 0 for one capture register and mode 1 for another register. user ? s manual 6-44 10.99 on-chip peripheral components C505L figure 6-23 timer 2 - capture with register crc figure 6-23a timer 2 - capture with registers cc1 to cc3 mcs01909 mode 1 iex3 0 mode tf2 crch crcl capture th2 tl2 input clock external interrupt request timer 2 interrupt request 3 t2 con.6 crcl" "write to cc0 3/ p1.0/int mcs01910 mode 1 iex4 0 mode tf2 cch1 ccl1 capture th2 tl2 input clock external interrupt 4 request timer 2 interrupt request ccl1" "write to cc1 4/ p1.1/int user ? s manual 6-45 10.99 on-chip peripheral components C505L 6.3 serial interface the serial port of the C505L is full duplex, meaning it can transmit and receive simultaneously. it is also receive-buffered, meaning it can commence reception of a second byte before a previously received byte has been read from the receive register. however, if the first byte still hasn ? t been read by the time reception of the second byte is complete, one of the bytes will be lost. the serial port receive and transmit registers are both accessed via special function register (sfr) sbuf. writing to sbuf loads the transmit register, and reading sbuf accesses a physically-separate receive register. the serial port can operate in 4 modes (one synchronous mode, three asynchronous modes). the baudrate clock for the serial port is derived from the oscillator frequency (mode 0, 2), or generated either by timer 1 or by a dedicated baudrate generator (mode 1, 3). mode 0, shift register (synchronous) mode: serial data enters and exits through rxd. txd outputs the shift clock. eight data bits are transmitted/received, lsb first. the baudrate is fixed at 1/6 of the oscillator frequency (see section 6.3.4 for more detailed information). mode 1, 8-bit usart, variable baudrate: ten bits are transmitted (through txd) or received (through rxd): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on receive, the stop bit goes into rb8 in sfr scon. the baudrate is variable (see section 6.3.5 for more detailed information). mode 2, 9-bit usart, fixed baudrate: eleven bits are transmitted (through txd) or received (through rxd): a start bit (0), 8 data bits (lsb first), a programmable 9th bit, and a stop bit (1). on transmit, the 9th data bit (tb8 in scon) can be assigned to the value of 0 or 1. or, for example, the parity bit (p, in the psw) could be moved into tb8. on receive, the 9th data bit goes into rb8 in special function register scon, while the stop bit is ignored. the baudrate is programmable to either 1/16 or 1/32 of the oscillator frequency (see section 6.3.6 for more detailed information). mode 3, 9-bit usart, variable baudrate: eleven bits are transmitted (through txd) or received (through rxd): a start bit (0), 8 data bits (lsb first), a programmable 9th data bit, and a stop bit (1). mode 3 is the same as mode 2 in all respects except the baudrate. the baudrate in mode 3 is variable (see section 6.3.6 for more detailed information). in all four modes, transmission is initiated by any instruction that uses sbuf as a destination register. reception is initiated in mode 0 by the condition ri = 0 and ren = 1. reception is initiated in the other modes by the incoming start bit if ren = 1. the serial interface also provides interrupt requests when transmission or reception of frames has been completed. the corresponding interrupt request flags are ti or ri, resp. see chapter 7 of this users manual for more details about the interrupt structure. if the serial interrupt is not enabled, the interrupt request flags ti and ri can also be used for polling the serial interface. user ? s manual 6-46 10.99 on-chip peripheral components C505L 6.3.1 multiprocessor communication modes 2 and 3 have a special provision for multiprocessor communications. in these modes, 9 data bits are received, followed by a stop bit. the 9th data bit goes into rb8. the port can be programmed such that when the stop bit is received, the serial port interrupt will be activated only if rb8 = 1. this feature is enabled by setting bit sm2 in scon. a way to use this feature in multiprocessor systems is described below. when the master processor transmits a block of data to one of several slaves, it first sends out an address byte which identifies the target slave. an address byte differs from a data byte in that the 9th bit is 1 in an address byte and 0 in a data byte. with sm2 = 1, no slave will be interrupted by a data byte. an address byte, however, will interrupt all slaves, so that each slave can examine the received byte and see if it is being addressed. the addressed slave will clear its sm2 bit and prepare to receive the incoming data bytes. the slaves that weren't being addressed leave their sm2s set and do not receive the incoming data bytes. sm2 has no effect in mode 0. sm2 can be used in mode 1 to check the validity of the stop bit. in a mode 1 reception, if sm2 = 1, the receive interrupt will not be activated unless a valid stop bit is received. 6.3.2 serial port registers the serial port control and status register is the sfr scon. this register contains not only the mode selection bits, but also the 9th data bit for transmit and receive (tb8 and rb8), and the serial port interrupt bits (ti and ri). sbuf is the receive and transmit buffer for the serial interface. writing to sbuf loads the transmit register and initiates transmission. reading out sbuf accesses a physically-separate receive register. user ? s manual 6-47 10.99 on-chip peripheral components C505L special function register scon (address 98 h ) reset value: 00 h special function register sbuf (address 99 h ) reset value: xx h bit function sm0 sm1 serial port 0 operating mode selection bits sm2 enable serial port multiprocessor communication in modes 2 and 3 in mode 2 or 3, if sm2 is set to 1 then ri will not be activated if the 9th data bit (rb8) received is 0. in mode 1, if sm2 = 1 then ri will not be activated if a valid stop bit was not received. in mode 0, sm2 should be 0. ren enable receiver of serial port enables serial reception. set by software to enable serial reception. cleared by software to disable serial reception. tb8 serial port transmitter bit 9 tb8 is the 9th data bit that will be transmitted in modes 2 and 3. set or cleared by software as desired. rb8 serial port receiver bit 9 in modes 2 and 3, rb8 is the 9th data bit that was received. in mode 1, if sm2 = 0, rb8 is the stop bit that was received. in mode 0, rb8 is not used. ti serial port transmitter interrupt flag ti is set by hardware at the end of the 8th bit time in mode 0, or at the beginning of the stop bit in the other modes, in any serial transmission. ti must be cleared by software. ri serial port receiver interrupt flag ri is set by hardware at the end of the 8th bit time in mode 0, or halfway through the stop bit time in the other modes, in any serial reception (exception see sm2). ri must be cleared by software. 9f h 9e h 9d h 9c h 9b h 9a h 99 h 98 h sm0 sm1 sm2 ren 98 h scon bit no. msb lsb tb8 rb8 ti ri 99 h sbuf 76543210 serial interface buffer register sm0 sm1 selected operating mode 0 0 serial mode 0: shift register, fixed baudrate ( f osc /6) 0 1 serial mode 1: 8-bit uart, variable baudrate 1 0 serial mode 2: 9-bit uart, fixed baudrate ( f osc /16 or f osc /32) 1 1 serial mode 3: 9-bit uart, variable baudrate user ? s manual 6-48 10.99 on-chip peripheral components C505L 6.3.3 baudrate generation there are several possibilities to generate the baud-rate clock for the serial port depending on the mode of operation. for clarification the difference between ? baud-rate clock ? and ? baudrate ? must be defined. the serial interface requires a clock rate which is 16 times the baudrate for internal synchronization. therefore, the baudrate generators have to provide a ? baudrate clock ? to the serial interface which - divided by 16 - results in the actual ? baudrate ? . however, all formulas given in the following section already include the factor and calculate the final baudrate. further, the abbreviation f osc refers to the external clock frequency (oscillator or external input clock operation). the baudrate of the serial port is controlled by two bits that are located in the sfrs shown below. special function register adcon0 (address d8 h ) reset value: 00x00000 b special function register pcon (address 87 h ) reset value: 00 h figure 6-24 shows the configuration for the baudrate generation of the serial port. bit function bd baud-rate generator enable when set, the baudrate of serial interface is derived from the dedicated baudrate generator. when cleared (default after reset), baudrate is derived from the timer 1 overflow rate. smod double baudrate when set, the baudrate of serial interface in modes 1, 2, 3 is doubled. after reset this bit is cleared. ? reserved bits for future use. read by cpu returns undefined values. smod pds idls sd 87 h pcon bit no. msb lsb gf1 gf0 pde idle 76543210 bd clk ? bsy d8 h adcon0 adm mx2 mx1 mx0 df h de h dd h dc h db h da h d9 h d8 h the shaded bits are not used for controlling the baudrate. user ? s manual 6-49 10.99 on-chip peripheral components C505L figure 6-24 baud-rate generation for the serial port depending on the programmed operating mode, different paths are selected for the baud-rate clock generation. figure 6-24 shows the dependencies of the serial port baud-rate clock generation on the two control bits, and on the mode selected in the sfr scon. 6.3.3.1 baudrate in mode 0 the baudrate in mode 0 is fixed to: 6.3.3.2 baudrate in mode 2 the baudrate in mode 2 depends on the value of bit smod in sfr pcon. if smod = 0 (which is the value after reset), the baudrate is 1/32 of the oscillator frequency. if smod = 1, the baudrate is 1/16 of the oscillator frequency. . mcs02733 rate f osc (smod) baud clock pcon.7 2 (sm0/ sm1) scon.7 scon.6 only one mode can be selected adcon0.7 (bd) 0 1 0 1 baud rate generator (srelh srell) timer 1 mode 2 mode 0 note: the switch configuration shows the reset state. mode 3 mode 1 overflow 6 mode 0 baudrate = oscillator frequency 6 mode 2 baudrate = oscillator frequency 32 2 smod user ? s manual 6-50 10.99 on-chip peripheral components C505L 6.3.3.3 baudrate in mode 1 and 3 in these modes the baudrate is variable and can be generated alternatively by a baudrate generator or by timer 1. 6.3.3.3.1 using the internal baudrate generator in modes 1 and 3, the C505L can use an internal baudrate generator for the serial port. to enable this feature, bit bd (bit 7 of sfr adcon0) must be set. bit smod (pcon.7) controls a divide-by-2 circuit which affect the input and output clock signal of the baudrate generator. after reset the divide-by-2 circuit is active and the resulting overflow output clock will be divided by 2. the input clock of the baudrate generator is f osc . figure 6-25 serial port input clock when using the baudrate generator the baudrate generator consists of a free-running upward counting 10-bit timer. on overflow of this timer (next count step after counter value 3ff h ), there is an automatic 10-bit reload from the registers srell and srelh. the lower 8 bits of the timer are reloaded from srell, while the upper two bits are reloaded from bit 0 and 1 of register srelh. the baudrate timer is reloaded by writing to srell. mcs02734 f osc (smod) pcon.7 0 1 2 srelh srell .1 .0 baud rate generator input clock overflow note : the switch configuration shows the reset state. 10 bit timer clock baud rate user ? s manual 6-51 10.99 on-chip peripheral components C505L special function register srelh (address ba h ) reset value: xxxxxx11 b special function register srell (address aa h ) reset value: d9 h after reset, srelh and srell have a reload value of 3d9 h . with this reload value, the baudrate generator has an overflow rate of input clock/39. with a 6 mhz oscillator frequency, the commonly used baudrates 4800 (smod = 0) and 9600 (smod = 1) are available (with 0.16% deviation). with the baudrate generator as clock source for the serial port in mode 1 and 3, the baudrate of the serial port can be determined as follows: : bit function srelh.0-1 baudrate generator reload high value upper two bits of the baudrate timer reload value. srell.0-7 baudrate generator reload low value lower 8 bits of the baudrate timer reload value. ? reserved bits for future use. read by cpu returns undefined values. aa h srell bit no. msb lsb lsb ba h srelh msb 76543210 ? ? ?? ?? .8 .7 .6 .5 .4 .3 .2 .1 .9 .0 the shaded bits are not used for reload operation. mode 1, 3 baudrate = 32 x (baudrate generator overflow rate) 2 smod oscillator frequency baudrate generator overflow rate = 2 10 ? srel with srel = srelh.1 ? 0, srell.7 ? 0 user ? s manual 6-52 10.99 on-chip peripheral components C505L 6.3.3.3.2 using timer 1 to generate baudrates in mode 1 and 3 of the serial port, timer 1 can also be used for generating baudrates. then the baudrate is determined by the timer 1 overflow rate and the value of smod as follows: the timer 1 interrupt is usually disabled in this application. timer 1 itself can be configured for either ? timer ? or ? counter ? operation in any of its operating modes. in most typical applications, it is configured for ? timer ? operation in the auto-reload mode (high nibble of tmod = 0010 b ). in this case the baudrate is given by the formula: very low baudrates can be achieved with timer 1 by leaving the timer 1 interrupt enabled, configuring the timer to run as 16-bit timer (high nibble of tmod = 0001 b ), and using the timer 1 interrupt for a 16-bit software reload. mode 1, 3 baudrate = (timer 1 overflow rate) 32 2 smod mode 1, 3 baudrate = 32 6 (256 ? (th1)) 2 smod oscillator frequency user ? s manual 6-53 10.99 on-chip peripheral components C505L 6.3.4 details about mode 0 serial data enters and exits through rxd. txd outputs the shift clock. eight data bits are transmitted/received, lsb first. the baudrate is fixed at f osc /6. figure 6-26 is a simplified functional diagram of the serial port in mode 0. the associated timing is illustrated in figure 6-27 . transmission is initiated by any instruction that uses sbuf as a destination register. the ? write-to-sbuf ? signal at s6p2 also loads a 1 into the 9th position of the transmit shift register and tells the tx control block to commence a transmission. the internal timing is such that one full machine cycle will elapse between ? write-to-sbuf ? , and activation of send. send enables the output of the shift register to the alternate output function line of p3.0, and also enables shift clock to the alternate output function line of p3.1. shift clock is low during s3, s4, and s5 of every machine cycle, and high during s6, s1 and s2. at s6p2 of every machine cycle in which send is active, the contents of the transmit shift register are shifted to the right one position. as data bits shift out to the right, zeroes come in from the left. when the msb of the data byte is at the output position of the shift register, then the 1 that was initially loaded into the 9th position is just to the left of the msb, and all positions to the left of that contain zeroes. this condition flags the tx control block to do one last shift and then deactivate send and set ti. both of these actions occur at s1p1 of the 10th machine cycle after ? write-to-sbuf ? . reception is initiated by the condition ren = 1 and ri = 0. at s6p2 of the next machine cycle, the rx control unit writes the bits 1111 1110 to the receive shift register, and in the next clock phase activates receive. receive enables shift clock to the alternate output function line of p3.1. shift clock makes transitions at s3p1 and s6p1 of every machine cycle. at s6p2 of every machine cycle in which receive is active, the contents of the receive shift register are shifted to the left one position. the value that comes in from the right is the value that was sampled at the p3.0 pin at s5p2 of the same machine cycle. as data bits come in from the right, 1s shift out to the left. when the 0 that was initially loaded into the rightmost position arrives at the leftmost position in the shift register, it flags the rx control block to do one last shift and load sbuf. at s1p1 of the 10th machine cycle after the write to scon that cleared ri, receive is cleared and ri is set. user ? s manual 6-54 10.99 on-chip peripheral components C505L figure 6-26 serial interface, mode 0, functional diagram mcs02101 internal bus 1 sbuf zero detector d s clk q shift send 1 tx control start tx clock ti rx control start ri receive shift serial port interrupt input shift register sbuf internal bus write to sbuf shift load sbuf read sbuf rxd p3.0 alt. output function function output p3.1 alt. txd 1 shift clock & ren ri s6 rx clock function input p3.0 alt. rxd 0 1 111111 & & shift baud rate clock _ < _ < user ? s manual 6-55 10.99 on-chip peripheral components C505L figure 6-27 serial interface, mode 0, timing diagram s 12 s 3 s 4 s 5 s 6 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s s 6 s 5 s 4 s 3 s 2 1 s d0 d1 d2 d3 d4 d5 d6 d7 ale write to sbuf send shift rxd (data out) s6p2 txd (shift clock) s3p1 s6p1 write to scon (clear ri) shift receive ri rxd (data in) txd (shift clock) d0 d1 d2 d3 d4 d5 d6 d7 s5p ti mct02102 receive transmit user ? s manual 6-56 10.99 on-chip peripheral components C505L 6.3.5 details about mode 1 ten bits are transmitted (through txd), or received (through rxd): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on reception, the stop bit goes into rb8 in scon. the baudrate is determined either by the timer 1 overflow rate or by the internal baudrate generator. figure 6-28 is a simplified functional diagram of the serial port in mode 1. the associated timings for transmit/receive are illustrated in figure 6-29 . transmission is initiated by an instruction that uses sbuf as a destination register. the ? write-to-sbuf ? signal also loads a 1 into the 9th bit position of the transmit shift register, and flags the tx control unit that a transmission is requested. transmission starts at the next rollover in the divide-by-16 counter. (thus, the bit times are synchronized to the divide-by-16 counter, not to the ? write-to-sbuf ? signal). the transmission begins with activation of send , which puts the start bit at txd. one bit time later, data is activated, which enables the output bit of the transmit shift register to txd. the first shift pulse occurs one bit time after that. as data bits shift out to the right, zeroes are clocked in from the left. when the msb of the data byte is at the output position of the shift register, then the 1 that was initially loaded into the 9th position is just to the left of the msb, and all positions to the left of that contain zeroes. this condition flags the tx control unit to do one last shift and then deactivate send and set ti. this occurs at the 10th divide-by-16 rollover after ? write-to-sbuf ? . reception is initiated by a detecting a 1-to-0 transition at rxd. for this purpose, rxd is sampled at a rate of 16 times the baudrate that has been established. when a transition is detected, the divide-by-16 counter is reset immediately, and 1ff h is written into the input shift register, and reception of the rest of the frame will proceed. the 16 states of the counter divide each bit time into 16ths. at the 7th, 8th and 9th counter states of each bit time, the bit detector samples the value of rxd. the value accepted is the value that was seen in at least 2 of the 3 samples. this kind of sampling is done for noise rejection. if the value accepted during the first bit time is not 0, the receive circuits are reset and the unit goes back to look for another 1-to-0 transition, thereby providing rejection of false start bits. if the start bit is valid, it is shifted into the input shift register, and reception of the rest of the frame will proceed. as data bits come in from the right, 1s shift out to the left. when the start bit arrives at the leftmost position in the shift register (which is a 9-bit register in mode 1), it flags the rx control block to do one last shift, load sbuf and rb8, and set ri. the signal to load sbuf and rb8, and to set ri, will be generated only if the following conditions are met at the time the final shift pulse is generated: 1) ri = 0, and 2) either sm2 = 0, or the received stop bit = 1 if one of these two conditions is not met, the received frame is irretrievably lost. if both conditions are met, the stop bit goes into rb8, the 8 data bit goes into sbuf, and ri is activated. at this time, whether the conditions are met or not, the unit goes back to look for a 1-to-0 transition in rxd. user ? s manual 6-57 10.99 on-chip peripheral components C505L figure 6-28 serial interface, mode 1, functional diagram mcs02103 internal bus 1 sbuf zero detector d s clk q data send 1-to-0 transition detector tx control shift start tx clock rx control start load shift sbuf sample bit detector (9bits) input shift register 1ff sbuf internal bus write to sbuf txd baud rate clock rxd shift load sbuf read sbuf 1 & 16 16 rx interrupt port serial 1 ti ri h _ < _ < user ? s manual 6-58 10.99 on-chip peripheral components C505L figure 6-29 serial interface, mode 1, timing diagram mct02104 to sbuf d7 stop bit d6 d5 d4 d3 d2 d1 d0 start bit ti txd shift data s1p1 send d0 start bit d1 d2 d3 d4 d5 d6 d7 stop bit 16 reset receive transmit write tx clock clock rx rxd sample times bit detector shift ri user ? s manual 6-59 10.99 on-chip peripheral components C505L 6.3.6 details about modes 2 and 3 eleven bits are transmitted (through txd), or received (through rxd): a start bit (0), 8 data bits (lsb first), a programmable 9th data bit, and a stop bit (1). on transmission, the 9th data bit (tb8) can be assigned the value of 0 or 1. on reception, the 9th data bit goes into rb8 in scon. the baudrate is programmable to either 1/16 or 1/32 the oscillator frequency in mode 2. when bit smod in sfr pcon (87 h ) is set, the baudrate is f osc /16. in mode 3, the baudrate clock is generated by timer 1, which is incremented by a rate of f osc /6 or by the internal baudrate generator. figure 6-30 shows a functional diagram of the serial port in modes 2 and 3. the receive portion is exactly the same as in mode 1. the transmit portion differs from mode 1 only in the 9th bit of the transmit shift register. the associated timing for transmit/receive are illustrated in figure 6-31 . transmission is initiated by any instruction that uses sbuf as a destination register. the ? write-to-sbuf ? signal also loads tb8 into the 9th bit position of the transmit shift register and flags the tx control unit that a transmission is requested. transmission starts at the next rollover in the divide-by-16 counter. thus, the bit times are synchronized to the divide-by-16 counter, not to the ? write-to-sbuf ? signal. the transmission begins with activation of send, which puts the start bit at txd. one bit time later, data is activated, which enables the output bit of the transmit shift register to txd. the first shift pulse occurs one bit time after that. the first shift clocks a 1 (the stop bit) into the 9th bit position of the shift register. thereafter, only zeroes are clocked in. thus, as data bits shift out to the right, zeroes are clocked in from the left. when tb8 is at the output position of the shift register, then the stop bit is just to the left of tb8, and all positions to the left of that contain zeroes. this condition flags the tx control unit to do one last shift and then deactivate send and set ti. this occurs at the 11th divide-by-16 rollover after ? write-to-sbuf ? . reception is initiated when a 1-to-0 transition is detected at rxd. for this purpose, rxd is sampled at a rate of 16 times the baudrate that has been established. when a transition is detected, the divide-by-16 counter is reset immediately, and 1ff h is written to the input shift register. at the 7th, 8th and 9th counter states of each bit time, the bit detector samples the value of rxd. the value accepted is the value that was seen in at least 2 of the 3 samples. if the value accepted during the first bit time is not 0, the receive circuits are reset and the unit goes back to looking for another 1-to-0 transition. if the start bit proves valid, it is shifted into the input shift register, and reception of the rest of the frame will proceed. as data bits come from the right, 1s shift out to the left. when the start bit arrives at the leftmost position in the shift register (which is a 9-bit register in modes 2 and 3), it flags the rx control block to do one last shift, load sbuf and rb8, and to set ri. the signal to load sbuf and rb8, and to set ri, will be generated only if the following conditions are met at the time the final shift pulse is generated: 1) ri = 0, and 2) either sm2 = 0 or the received 9th data bit = 1 if either of these conditions is not met, the received frame is irretrievably lost, and ri is not set. if both conditions are met, the received 9th data bit goes into rb8, and the first 8 data bit goes into sbuf. one bit time later, whether the above conditions were met or not, the unit goes back to looking for a 1-to-0 transition at the rxd input. note that the value of the received stop bit is irrelevant to sbuf, rb8 or ri. user ? s manual 6-60 10.99 on-chip peripheral components C505L figure 6-30 serial interface, mode 2 and 3, functional diagram mcs02105 internal bus tb8 sbuf zero detector d s clk q data send 1-to-0 transition detector 1 16 tx control shift start tx clock ti rx control start ri load shift sbuf rx clock serial port interrupt sample bit detector (9bits) input shift register 1ff sbuf internal bus write to sbuf txd baud rate clock rxd shift load sbuf read sbuf & 1 16 stop bit generation _ < _ < user ? s manual 6-61 10.99 on-chip peripheral components C505L figure 6-31 serial interface, mode 2 and 3, timing diagram mct02587 write to sbuf tx clock d7 tb8 stop bit d6 d5 d4 d3 d2 d1 d0 start bit stop bit gen. ti txd shift data mode 2 : s6p1 send rx clock rx d0 start bit d1 d2 d3 d4 d5 d6 d7 rb8 stop bit bit detector sample times shift ri 16 reset receive transmit mode 3 : s1p1 on-chip peripheral components C505L user ? s manual 6-62 10.99 6.4 lcd controller unit the liquid crystal display (lcd) controller unit in the C505L is designed for the control of an lcd display module of 128 display segments (4 rows and 32 columns) using the 1/4 duty-cycle driving method. the C505L can be programmed to generate reference voltages for adjusting the contrast of the display. 6.4.1 functionality 6.4.1.1 display module organization an example of a typical lcd module is shown in figure 6-32 . the table describes the different combinations of the row and column signals required to activate a particular segment. the signals r0-r3 and c0-c31 are the row and column signals, respectively, connected to the display module. figure 6-32 organization of a typical lcd display module a g fb e c d h r2 r3 r1 r0 c1 c0 rows columns c1 c0 r3 fa r2 g b r1 e c r0 dh mcd03858 user ? s manual 6-63 10.99 on-chip peripheral components C505L 6.4.2 lcd registers the memory required by the lcd controller includes a control register and 16 individual digit registers. these registers are implemented in the on-chip external data memory area. accesses to these registers are similar to on-chip xram accesses (movx instructions) and therefore must be preceded by an enable operation on the on-chip xram. the registers are described below. 6.4.2.1 control register in order to display a character, lcon (the control register for the lcd display) must be configured first. lcd control register, lcon (address f3dd h ) reset value: 00 h bit function dsb1 columns c24 to c31 disable dsb1 = 0: disable output column lines c24 to c31. dsb1 = 1: enable output column lines c24 to c31. columns c24 to c31 are disabled by default and are used as digital i/o dsb0 columns c16 to c23 disable dsb0 = 0: disable output column lines c16 to c23. dsb0 = 1: enable output column lines c16 to c23. segments c16 to c23 are disabled by default and are used for digital i/o. csel lcd controller input clock selection csel = 1: use rtc clock input (32.768 khz) for f lcdin csel = 0: use system clock ( f osc ) for f lcdin lcen lcd controller enable lcen = 0: lcd controller is disabled (default after reset). lcen = 1: lcd controller is enabled. 0 these bits are reserved and should be always written with 0. writing a 1 into these bits will give undefined results. dsb1 dsb0 0 0 f3dd h lcon bit no. 76543210 msb lsb 00csellcen on-chip peripheral components C505L user ? s manual 6-64 10.99 6.4.2.2 digit registers the lcd controller has 16 registers that are used to control the 32 column outputs. each digit register contains eight bits that control the individual segments in that digit. for example, the bit sega in register dig0 controls the segment a in digit 0 of the display. a value of ? 1 ? in this bit would represent an active segment, whereas a ? 0 ? would represent an inactive segment. this information is used together with the row/backplane voltage to drive the lcd display. lcd digit register digx (x = 0 to f) reset value: 00 h segf sega segg segb f3ex h digx bit no. 76543210 msb lsb sege segc segh segd user ? s manual 6-65 10.99 on-chip peripheral components C505L 6.4.3 lcd input clock most of the lcd display modules require row and column signals at a maximum frequency of 360 hz in order to activate a display segment. in order to achieve this 360-hz frequency limit, the lcd controller uses a 15-bit timer. this timer has a programmable 15-bit reload register as shown below. lcd timer reload low register, lcrl (address f3de h ) reset value: 00 h lcd timer reload high register, lcrh (address f3df h ) reset value: 00 h the bit slt in the lcrh register should be set to start the 15-bit timer. the timer register is then loaded with the contents of the reload register and the timer begins counting down. when the slt bit is cleared, the counting is stopped and the timer register is reset to 0000 h . the timer cannot continue from its previous count once it is stopped. the lcd clock generator starts counting with a value in the reload register. it is a down counter that decrements once every input clock, f lcdin , up to 0000 h . when an underflow occurs, the lcd clock is toggled and the timer is reloaded with value in the 15-bit reload register lcr (lcrh.6-lcrl.0) and continues counting. initially the lcd clock has a value of ? 1 ? as shown in figure 6-33 . the frequency of the lcd clock is: the generated lcd clock has a duty-cycle of 50%, since two count cycles (from the reload value to 0000 h ) will be used to generate one lcd clock cycle. the table in figure 6-33 shows the recommended reload values at different input frequencies ( f lcdin ) to generate lcd clocks of frequencies less than 360 hz. bit function slt lcd timer control slt = 1: start lcd clock generator slt = 0: stop lcd clock generator lcrh.7-lcrl.0 lcd timer reload value (15-bit) this register should be written with a suitable 15-bit value to control the lcd signal frequency (please see table in figure 6-33 ). 76543210 bit no. f3de h ____ lcrl ___ lsb f3df h slt msb __ lcrh ____ f lcd = f lcdin 2 (15-bit reload value) hz on-chip peripheral components C505L user ? s manual 6-66 10.99 figure 6-33 lcd clock generation 6.4.3.1 lcd input clock selection the input clock, f lcdin , into the lcd clock generation logic can be selected with the bit csel in the lcon register. this bit makes it possible to chose one of the clock sources for the lcd timer: the system clock ( f osc ) or the 32.768 khz clock input into the real-time clock circuit, f rtc . in either case the lcr register can be programmed to derive the f lcd clock frequency. the main purpose of the csel bit is to ensure that the lcd controller can still function when the C505L enters power down mode 2. in this mode, the system clock ( f osc ) is not available and only the real-time clock is running. mcd03859 1 0 rtc f osc f csel slt lcdin f 15-bit down counter lc14-0 lcr14 lcr0 lcr14-0 lc0 lc14 underflow (reload) toggle lcd f (< 360 hz) lcr (15-bit reload) lcd f (in hz) lcdin f 32.768 khz 002e h 356.17 2 mhz 0ada h 359.97 4 mhz 15b4 h 359.97 6 mhz 208e h 359.97 20 mhz 16 mhz 12 mhz 10 mhz 6c84 h 3642 56d0 411c h h h 359.97 359.97 359.97 359.97 user ? s manual 6-67 10.99 on-chip peripheral components C505L 6.4.4 row signals the lcd controller generates four row/backplane signals. these four signals have fixed timing and levels, without any dependency on the individual digit register values. the row signals in combination with the column signals, which depend on the respective digit register values, determine the segments are to be activated or deactivated. figure 6-34 row/backplane signals the row signals, r0-r3, are as shown in figure 6-34 . here t lcd is the clock period of the lcd clock ( f lcd < 360 hz). an lcd frame consists 8 periods of the lcd input clock. v lcd3 v lcd2 v lcd1 time lcd3 lcd2 lcd1 v v v time r0 r1 lcd3 lcd2 lcd1 v v v r2 time lcd3 lcd2 lcd1 v v v r3 mcs03860 time 1 lcd frame t lcd on-chip peripheral components C505L user ? s manual 6-68 10.99 6.4.5 column signals the column signals determine the difference voltages across each segment with respect to the row signal, depending on the digit register values. column outputs are organized in groups of two for the 1/4 duty-cycle driving supported by the C505L. figure 6-35 column signals to display ? 1 ? figure 6-35 shows the segment signals generated by the lcd controller when a digit register is configured to display the number ? 1 ? . figures 6-36 , 6-37 and 6-38 show the difference signals while using the column signals as shown above. the segments that are not activated in a digit have difference voltages across them that are not recognized by the lcd display module. the active segments, however, have fluctuating difference voltages during an lcd frame. these difference voltages are recognized by the lcd display module. in the example above, the difference signal has an amplitude of v lcd3 for the segments b and c (twice within an lcd frame). note: the actual segment organization within the display unit could be different from the example considered here. in such cases, the segment names/positions may vary. user should consult the manufacturer of the lcd display unit regarding the display unit?s segment organization. v lcd3 v lcd2 v lcd1 mcs03861 time lcd3 lcd2 lcd1 v v v time c1 c0 user ? s manual 6-69 10.99 on-chip peripheral components C505L figure 6-36 difference signals to display ? 1 ? - part 1 segment h not activated r0c0 t v lcd3 v lcd2 v lcd1 v lcd1 v lcd2 v lcd3 v v v lcd2 lcd3 lcd1 v v lcd1 lcd2 v lcd3 r1c0 t activated segment c lcd1 v v v lcd2 lcd3 v lcd1 v v lcd2 lcd3 r2c0 mcs03862 t activated segment b on-chip peripheral components C505L user ? s manual 6-70 10.99 figure 6-37 difference signals to display ? 1 ? - part 2 segment a not activated r3c0 t v lcd3 v lcd2 v lcd1 v lcd1 v lcd2 v lcd3 v v v lcd2 lcd3 lcd1 v v lcd1 lcd2 v lcd3 r0c1 t not activated segment d lcd1 v v v lcd2 lcd3 v lcd1 v v lcd2 lcd3 r1c1 mcd03863 t not activated segment e user ? s manual 6-71 10.99 on-chip peripheral components C505L figure 6-38 difference signals to display ? 1 ? - part 3 segment g not activated r2c1 t v lcd3 v lcd2 v lcd1 v lcd1 v lcd2 v lcd3 v v v lcd2 lcd3 lcd1 v v lcd1 lcd2 v lcd3 r3c1 t not activated segment f mcs03864 on-chip peripheral components C505L user ? s manual 6-72 10.99 6.4.6 voltage levels the lcd controller outputs three voltage levels required for driving the lcd display module, namely one-third of v lcd , two-thirds of v lcd , and v lcd . of these voltage levels, v lcd is generated by the 8-bit d/a converter. the other two voltage levels are derived from v lcd through a resistive divider network. 6.4.6.1 d/a converter (reference voltage generator) the d/a converter is enabled by the lcd controller enable bit lcen (lcon.0). it contains an 8-bit register, dac0, mapped to the on-chip xram area at address f3dc h . d/a conversion register, dac0 (address f3dc h ) reset value: 00 h any write operation to this register with the lcd controller enabled, starts the d/a conversion and thereby the display outputs. therefore, the C505L can be used with a wide range of lcd display modules. it is important to note that the output of d/a converter is, in addition to the dac0 register value, also affected by the operating voltage range of the device (refer to data sheet). due to the settling time required by the d/a converter, it is recommended to start a d/a conversion prior to writing to the display registers. 6.4.7 power saving mode options in order to reduce power consumption, the C505L can be put into the software power down mode 2. in this mode, the lcd controller and the d/a converter do not lose their register contents and remain in operation, provided the following conditions are satisfied: - the input clock to the lcd is the 32.768-khz real-time clock input, and - the real-time clock input at xtal3 and xtal4 pins is still valid. please refer to chapter 9 for further details about the power-down modes. 76543210 s5 s4 s3 f3dc h dac0 bit no. msb lsb s2 s1 s7 s6 s0 bit no. user ? s manual 6-73 10.99 on-chip peripheral components C505L 6.5 real-time clock one of the C505L ? s peripherals is the real-time clock that, once started, can work independently of the state of the rest of the microcontroller. this real-time clock contains a 32.768-khz oscillator to count time elapsed with respect to an initial time. the C505L real-time clock does not provide for any error correction. any such corrections can be done by software only. 6.5.1 oscillator the real-time clock contains an oscillator which can receive an input from an external 32.768 khz crystal connected to the xtal3 and xtal4 pins. once started, the oscillator can operate irrespective of the state of the microcontroller. that is, it keeps running even when the device has entered idle, slow-down or certain power-down modes. however, the real-time clock can also be powered down by software if necessary. the oscillator, as well as the whole real-time clock, remains in operation during certain power-down modes with a supply of 3 v (except at start-up when a 5 v range supply is required). on-chip peripheral components C505L user ? s manual 6-74 10.99 6.5.2 real-time clock registers the register memory for the real-time clock is implemented in the on-chip external data memory area. accesses to these registers are similar to on-chip xram accesses (movx instructions) and therefore must be preceded by an enable operation on the on-chip xram. the registers are described below: real-time clock control register, rtcon (address f3f0 h ) reset value: 00 h bit function rtpd real-time clock power-down enable rtpd = 0: real-time clock is enabled rtpd = 1: real-time clock is powered down real-time clock is enabled by default after reset. irtc real-time clock interrupt request flag if ertc bit is set, this bit is set by hardware when the contents of the clreg and rtint registers are equal. this bit has to be cleared by software. a wake-up request is generated only if the C505L is either in software power-down modes 2 or 3. ertc real-time clock interrupt enable ertc = 0: disable real-time clock interrupt ertc = 1: enable real-time clock interrupt rtcs real-time clock start/stop bit rtcs = 1: start real-time clock operation rtcs = 0: stop real-time clock operation 0 these bits are reserved and should be always written with 0. writing a 1 into these bits will give undefined results. 0000 f3f0 h rtcon bit no. 76543210 msb lsb rtpd irtc ertc rtcs user ? s manual 6-75 10.99 on-chip peripheral components C505L real-time clock initialization register, rtcrx (x = 0 to 4) reset values: 00 h registers rtcr4-rtcr0 form the initial value of the upper 40-bits of the real-time clock counter. these bits are collectively referred to as the rtcr register. the contents of the rtcr register are transferred to the clreg register under either of the following conditions: ? once bit rtcs (rtcon.0)is set to start the real-time clock counting, or ? after every subsequent overflow of the real-time clock counter therefore, any write operation on this register while the clock is still running does not affect the clock count. 76543210 bit no. f3f1 h ____ rtcr0 ___ lsb f3f2 h ____ rtcr1 ____ f3f3 h ____ rtcr2 ____ f3f4 h ____ rtcr3 ____ f3f5 h msb ___ rtcr4 ____ on-chip peripheral components C505L user ? s manual 6-76 10.99 clock count register, clregx (x = 0 to 4) reset values: 00 h registers clreg4-clreg0, collectively known as the clreg register, hold the current upper 40-bit value of the real-time clock count. the clreg register can be read at anytime, just like on-chip xram locations. the clreg register can, however, never be written by the user directly. this is to protect the clock count from being manipulated accidentally by any user software. the clreg register covers the upper 40-bits of the real-time clock counter. the lower 7 bits of the counter are never accessible by the user and merely act as prescalers that are initialized to 0000000 b after a start operation on the real-time clock. 76543210 bit no. f3f6 h ____ clreg0 ___ lsb f3f7 h ____ clreg1 ____ f3f8 h ____ clreg2 ____ f3f9 h ____ clreg3 ____ f3fa h msb ___ clreg4 ____ user ? s manual 6-77 10.99 on-chip peripheral components C505L 6.5.3 functionality the real-time clock initialization register rtcr, 40 bits, can be written with any value desired by the user. the value written is used as an initial value for the upper 40 bits of the real-time clock timer, when it is started. the real-time clock is started by setting bit rtcs in the rtcon register to ? 1 ? . this enables the input clock into the 47-bit timer. the contents of the 40-bit rtcr register are transferred to the clreg register. the real-time clock ? s lower 7 bits, which serve as a prescaler into the 40-bit timer, are set to an initial value of 0000000 b . one increment of the clock register is then made for every cycle of the input clock. with an input clock frequency of 32.768 khz, one second in real-time will be equivalent to an overflow of the lower 15-bits of the 47-bit counter. under this condition, the registers clreg4-clreg1 actually hold the real-time value in ? seconds ? . figure 6-39 real-time clock upon an overflow condition of the real-time clock timer, the contents of the rtcr register are reloaded into the clreg for a fresh count sequence. the real-time clock stops counting when the rtcs bit is written with a ? 0 ? . setting the rtcs bit subsequently does not resume the count because a new counting sequence is started. when the real-time clock is in operation, the upper 40-bits of the clreg register can be read on-the-fly just like external data memory. control ertc rtint, 40-bit register 40-bit comparator clreg, 40-bit timer rtcr, 40-bit register mcs03865 lsb msb bit 0 bit 6 osc. irtc 32.768 khz input these bits are not readable. wake - up request rtcs 7-bit timer on-chip peripheral components C505L user ? s manual 6-78 10.99 6.5.4 real-time clock wake-up interrupt the upper 40-bit content of the real-time clock counter can be compared with the content of the rtint register in order to generate an interrupt request while the C505L is in one of software power-down modes 2 or 3. the 40-bit rtint register consists of 5 individual 8-bit registers as described below. real-time clock interrupt register, rtintx (x = 0 to 4) reset value: 00 h the rtint register is programmable by the user, and any 40-bit value can be programmed into it. while the real-time clock is in operation, the contents of this register will be compared to the upper 40-bits of the clock counter (clreg). bit irtc (rtcon.2) will be set when the contents are equal; this will generate a wake-up from software power-down interrupt. the irtc flag can be monitored for the real-time clock interrupt wake-up request, but the flag has to be cleared by user software. the real-time clock can generate a wake-up request to the C505L provided all the following conditions are fulfilled: - the C505L is in one of the software power-down modes 2 or 3, - wake-up from software power-down is enabled (bit ewpd = 1 in sfr pcon1) - real-time clock wake-up source is selected (bit ws = 1 in sfr pcon1), - the real-time clock interrupt is enabled (bit ertc = 1 of rtcon), and - normally operating v dd levels are maintained in this case, the handling is similar to the wake-up from power-down through p3.2/int0 (please see chapter 9 for further details). 76543210 bit no. f3fb h ____ rtint0 ___ lsb f3fc h ____ rtint1 ____ f3fd h ____ rtint2 ____ f3fe h ____ rtint3 ____ f3ff h msb ___ rtint4 ____ user ? s manual 6-79 10.99 on-chip peripheral components C505L 6.5.5 power-saving mode options once started, the real-time clock continues counting until the bit rtcs (rtcr0.0) is cleared. the real-time clock is not affected by any of the idle and slow-down modes of the C505L, and continues counting in these modes. in the software power-down mode 3 the real-time clock continues to run provided: - the externally applied input clock for the real-time clock is available, and - v dd (min) 3.0 volts in software power-down mode 2, however, the supply voltage should remain at normal levels as specified in the device specifications (refer to data sheet). the real-time clock stops operation in software power-down mode 1 (bit rtpd in rtcon.3 is set). please refer to chapter 9 for detailed information regarding the power-down modes. user ? s manual 6-80 10.99 on-chip peripheral components C505L 6.6 a/d converter the C505L includes a high performance, high-speed, 10-bit a/d converter (adc) with 8 analog input channels. it operates with a successive approximation technique, and uses self calibration mechanisms for reduction and compensation of offset and linearity errors. the adc has the following features: ? 8 multiplexed input channels (port 1) that can also be used as digital inputs/outputs ? 10-bit resolution ? single or continuous conversion mode ? internal start-of-conversion trigger capability ? interrupt request generation after each conversion ? using successive approximation conversion technique via a capacitor array ? built-in hidden calibration of offset and linearity errors the externally-applied reference voltages have to be held at fixed values within the specifications (please see data sheet). the main functional blocks of the adc are shown in figure 6-40 . 6.6.1 a/d converter operation an internal start of a single a/d conversion is triggered by a write-to-addatl instruction. the start procedure itself is independent of the value that is written to addatl. when single conversion mode is selected (bit adm = 0), only one a/d conversion is performed. in continuous mode (bit adm = 1), after completion of an a/d conversion, a new a/d conversion is triggered automatically until bit adm is reset. the busy flag bsy (adcon0.4) is set automatically when an a/d conversion is in progress. after completion of the conversion it is reset by hardware. this flag can only be read; a write has no effect. the interrupt request flag iadc (ircon.0) is set when an a/d conversion is completed. the bits mx0 to mx2 in special function registers (sfrs) adcon0 and adcon1 are used for selection of the analog input channel. the bits mx0 to mx2 are represented in both registers adcon0 and adcon1; however, these bits are present only once. therefore, there are two methods of selecting an analog input channel: if a new channel is selected in adcon1 the change is automatically done in the corresponding bits mx0 to mx2 in adcon0, and vice versa. port 1 is a dual purpose input/output port. these pins can be used either for digital i/o functions or as the analog inputs. if fewer than 8 analog inputs are required, the unused analog inputs at port 1 are free for digital i/o functions. on-chip peripheral components C505L user ? s manual 6-81 10.99 figure 6-40 block diagram of the a/d converter eadc iadc ean7 ean4 ean5 ean6 ean3 ean2 ean1 ean0 adcl1 mx2 mx1 mx0 adcon1 (dc ) p1ana (90 ) ircon (c0 ) ien1 (b8 ) h h h h bsy adm mx2 mx1 mx0 adcon0 (d8 ) h mux s&h single / continuous mode clock prescaler 32, 16, 8, 4 f osc port 1 .2 .3 .4 .5 .6 .7 .8 lsb msb .1 addatl (da ) addath (d9 ) hh conversion clock input clock adc f in f aref v agnd v start of conversion write to addatl shaded bit locations are not used in adc - functions. internal bus a / d mcb03866 internal bus bd clk exf2 exen2 swdt iex6 iex5 iex4 iex3 swi converter adcl2 ex6 swdt esw1 tf2 exen2 ex5 ex4 ex3 user ? s manual 6-82 10.99 on-chip peripheral components C505L 6.6.2 a/d converter registers this section describes the bits/functions of all registers which are used by the adc. special function register addath (address d9 h ) reset value: 00 h special function register addatl (address da h ) reset value: 00xxxxxx b the registers addath and addatl hold the 10-bit conversion result in left justified data format. the msb of the 10-bit conversion result is bit 7 of addath. the lsb of the 10-bit conversion result is bit 6 of addatl. to get a 10-bit conversion result, both addat registers must be read. if an 8-bit conversion result is required, only the reading of addath is necessary. the data remains in addat until it is overwritten by the next converted data. addat can be read or written under software control. if the adc of the C505L is not used, register addath can be used as an additional general purpose register. 76543210 d9 h addath lsb da h addatl bit no. msb lsb msb ? ? ?? ?? .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 on-chip peripheral components C505L user ? s manual 6-83 10.99 special function register adcon0 (address d8 h ) reset value: 00x00000 b special function register adcon1 (address dc h ) reset value: 01xxx000 b the shaded bits are not used for adc control. bit function ? reserved bits for future use bsy busy flag this flag indicates whether a conversion is in progress (bsy = 1). the flag is cleared by hardware when the conversion is finished. adm a/d conversion mode when set, a continuous a/d conversion is selected. if cleared during a running a/d conversion, the conversion is stopped at its end. mx2 - mx0 adc input channel select bits bits mx2-0 can be written or read either in adcon0 or adcon1. the channel selection done by writing to adcon 1(0) overwrites the selection in adcon 0(1) when adcon 1(0) is written after adcon 0(1). the analog inputs are selected according to the following table: 76543210 ? bsy adm mx2 mx1 mx0 d8 h adcon0 adcl1 mx2 mx1 mx0 dc h adcon1 bit no. msb lsb adcl0 clk bd ?? ? mx2 mx1 mx0 selected analog input 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 p1.0 / an0 / int3 / cc0 p1.1 / an1 / int4 / cc1 p1.2 / an2 / int5 / cc2 p1.3 / an3 / int6 / cc3 p1.4 / an4 p1.5 / an5 / t2ex p1.6 / an6 / clkout p1.7 / an7 / t2 user ? s manual 6-84 10.99 on-chip peripheral components C505L note: generally, before entering the power-down mode, an a/d conversion in progress must be stopped. if a single a/d conversion is running, it must be terminated by polling the bsy bit or waiting for the a/d conversion interrupt. in continuous conversion mode, bit adm must be cleared and the last a/d conversion must be terminated before entering the power-down mode. a single a/d conversion is started by writing to sfr addatl with dummy data. a continuous conversion is started under the following conditions: ? by setting bit adm during a running single a/d conversion ? by setting bit adm when at least one a/d conversion has occurred after the last reset operation. ? by writing addatl with dummy data after bit adm has been set before (if no a/d conversion has occurred after the last reset operation). when bit adm is reset by software in continuous conversion mode, the just running a/d conversion is stopped after its end. adcl1 adcl0 adc clock prescaler selection adcl1 and adcl0 select the prescaler ratio for the a/d conversion clock f adc . depending on the clock rate f osc of the C505L, f adc must be adjusted in a way that the resulting conversion clock f adc is less than or equal to 2 mhz (see section 6.6.3 ). the prescaler ratio is selected according to the following table: bit function adcl1 adcl0 prescaler ratio 0 0 0 1 1 0 1 1 divide by 4 divide by 8 (default after reset) divide by 16 divide by 32 on-chip peripheral components C505L user ? s manual 6-85 10.99 the adc interrupt is controlled by bits which are located in the sfrs ien1 and ircon. special function register ien1 (address b8 h ) reset value: 00 h special function register ircon (address c0 h ) reset value: 00 h the shaded bits are not used for adc control. bit function eadc enable adc interrupt if eadc = 0, the adc interrupt is disabled. iadc adc interrupt request flag set by hardware at the end of an a/d conversion. must be cleared by software. c7 h c6 h c5 h c4 h c3 h c2 h c1 h c0 h iex6 iex5 iex4 iex3 swi iadc c0 h ircon tf2 exf2 exen2 swdt ex6 ex5 b8 h ien1 bit no. bf h msb lsb ex4 ex3 eswi eadc be h bd h bc h bb h ba h b9 h b8 h user ? s manual 6-86 10.99 on-chip peripheral components C505L 6.6.3 a/d converter clock selection the adc uses two clock signals for operation: the conversion clock f adc (= 1/ t adc ) and the input clock f in (= 1/ t in ). f adc is derived from the C505L system clock f osc which is applied at the xtal pins via the adc clock prescaler as shown in figure 6-41 . the input clock f in is equal to f osc . the conversion clock f adc is limited to a maximum frequency of 2 mhz. therefore, the adc clock prescaler must be programmed to a value that assures that the conversion clock does not exceed 2 mhz. the prescaler ratio is selected by the bits adcl1 and adcl0 of sfr adcon1. the table in figure 6-41 shows the prescaler ratio that must be selected by adcl1 and adcl0 for typical system clock rates. a prescaler ratio equal to 4 is selected for system clocks up to 8 mhz. a prescaler ratio of at least 8 must be selected when using a system clock greater than 8 mhz and less than 16 mhz. a prescaler ratio of at least 16 must be selected when using a system clock greater than 16 mhz. a prescaler ratio of 32 can used for any of the above frequency ranges. figure 6-41 adc clock selection the duration of an a/d conversion is a multiple of the period of the f in clock signal. the calculation of the a/d conversion time is shown in the next section. mcs03867 32 16 8 4 mux adcl0 adcl1 osc f clock prescaler conversion clock f adc input clock in f a/d converter conditions: f adc max = 2 mhz f in = f osc = 1 clp mcu system clock rate ( f osc ) f in [mhz] prescaler ratio f adc [mhz] adcl1 adcl0 2 mhz 2 4 0.5 0 0 6 mhz 6 4 1.5 0 0 8 mhz 8 4200 12 mhz 12 8 1.5 0 1 16 mhz 16 8201 20 mhz 20 16 1.25 1 0 on-chip peripheral components C505L user ? s manual 6-87 10.99 6.6.4 a/d conversion timing an a/d conversion is started by writing into the sfr addatl with dummy data. a write to sfr addatl will start a new conversion, even if another conversion is currently in progress. the conversion begins with the next machine cycle, and the bsy flag in sfr adcon0 will be set. the a/d conversion procedure is divided into three parts: ? sample phase ( t s ), used for sampling the analog input voltage. ? conversion phase ( t co ), used for the real a/d conversion (includes calibration). ? write result phase ( t wr ), used for writing the conversion result into the addat registers. the total a/d conversion time is defined by t adcc , which is the sum of the two phase times, t s and t co . the duration of the phases of an a/d conversion is specified by their corresponding timing parameters as shown in figure 6-42 . figure 6-42 a/d conversion timing sample time t s : during this time, the internal capacitor array is connected to the selected analog input channel and is loaded with the analog voltage to be converted. the analog voltage is fed internally to a voltage comparator. at the beginning of the sample phase, the bsy bit in sfr adcon0 is set. conversion time t co : during the conversion time, the analog voltage is converted into a 10-bit digital value using the mct02619 t adcc t s t co sample phase conversion phase t wr write result phase bsy bit start of an a/d conversion result is written into addat a/d conversion cycle time t wr = in t adcc t = s t + co t ps = prescaler value prescaler ratio (= ps) t s t co t adcc 32 64 t in 320 t in 384 t in 16 32 t in 160 t in 192 t in 8 16 t in 80 t in 96 t in 48 t in 40 t in 48 t in user ? s manual 6-88 10.99 on-chip peripheral components C505L successive approximation technique with a binary-weighted capacitor network. during an a/d conversion, a calibration also takes place. during this calibration, alternating offset and linearity calibration cycles are executed (see also section 6.6.5 ). at the end of the calibration time, the bsy bit is reset and the iadc bit in sfr ircon is set indicating an adc interrupt condition. write result time t wr : during the result phase, the conversion result is written into the addat registers. figure 6-43 shows how an a/d conversion is embedded into the microcontroller cycle scheme using the relation 6 t in = 1 instruction cycle. it also shows the behavior of the busy flag (bsy) and the interrupt flag (iadc) during an a/d conversion. figure 6-43 a/d conversion timing in relation to processor cycles depending on the selected prescaler ratio (see figure 6-41 ), four different relationships between machine cycles and a/d conversion are possible. the a/d conversion is started when sfr addatl is written with dummy data. this write operation may take one or two machine cycles. in figure 6-43 , the instruction mov addatl,#0 starts the a/d conversion (machine cycle x-1 and x). the total a/d conversion (sample, conversion, and calibration phases) is finished with the end of the 8th, 16th, 32nd, or 64th machine cycle after the a/d conversion start. in the next machine cycle, the conversion result is written into the addat registers, and can be read in the same cycle by an instruction (e.g. mov a,addatl). if continuous conversion is selected (bit adm set), the next conversion is started with the beginning of the machine cycle that follows the write result cycle. mct02620 x- 1 x 1 2 3 4 5 6 7 8 9 10 11 12 20 19 18 17 16 15 5 4 3 2 1 x 1 - x 36 35 34 33 32 31 5 4 3 2 1 x 1 - x 68 67 66 65 64 63 5 4 3 2 1 x 1 - x ~ ~~ ~ ~ ~ ~ ~~ ~ ~ ~ mov addatl, #0 1 instruction cycle mov a, addatl write result cycle t adcc a/d conversion cycle start of next conversion (in start of a/d conversion cycle write addat cont. conv. single conv. first instruction of an interrupt routine bsy bit iadc bit adcl1 adcl0 0 1 0 1 1 1 0 0 prescaler selection continuous mode) ~ ~ ~ ~ ~ ~ on-chip peripheral components C505L user ? s manual 6-89 10.99 the bsy bit is set at the beginning of the first a/d conversion machine cycle, and reset at the beginning of the write result cycle. if continuous conversion is selected, bsy is again set with the beginning of the machine cycle that follows the write result cycle. the interrupt flag iadc is set at the end of the a/d conversion. if the adc interrupt is enabled and prioritized to be serviced immediately, the first instruction of the interrupt service routine will be executed in the third machine cycle which follows the write result cycle. iadc must be reset by software. depending on the application, there are three typical methods to handle the a/d conversion in the C505L. ? software delay the machine cycles of the a/d conversion are counted, and the program executes a software delay (e.g. nops) before reading the a/d conversion result in the write result cycle. this is the fastest method to get the result of an a/d conversion. ? polling bsy bit the bsy bit is polled, and the program waits until bsy = 0. note: a polling jb instruction that is two machine cycles long, may not recognize the bsy = 0 condition during the write result cycle in the continuous conversion mode. ? a/d conversion interrupt after the start of an a/d conversion, the adc interrupt is enabled. the result of the a/d conversion is read in the interrupt service routine. if other C505L interrupts are enabled, the interrupt latency must taken into account. therefore, this software method is the slowest way to get the result of an a/d conversion. depending on the oscillator frequency of the C505L and the selected divider ratio of the conversion clock prescaler, the total time of an a/d conversion is calculated according to figure 6-42 and table 6-6. figure 6-44 on the next page shows the minimum a/d conversion time in relation to the oscillator frequency f osc . the minimum conversion time, 6 s, can be achieved at f osc of 8 or 16 mhz (or whenever f adc = 2 mhz). note: the prescaler ratios in table 6-6 are minimum values. table 6-6 a/d conversion time for dedicated system clock rates f osc [mhz] prescaler ratio ps f adc [mhz] sample time t s [ s] total conversion time t adcc [ s] 2 mhz 4 0.5 4 24 6 mhz 4 1.5 1.33 8 8 mhz 42 1 6 12 mhz 8 1.5 1.33 8 16 mhz 82 1 6 20 mhz 16 1.25 1.6 9.6 user ? s manual 6-90 10.99 on-chip peripheral components C505L figure 6-44 minimum a/d conversion time in relation to system clock mcd03868 10 20 30 5 t adcc 2 4 8 16 f ocs adcc t min =6 s] [mhz] [ s 4 6 8 10 12 14 16 18 20 on-chip peripheral components C505L user ? s manual 6-91 10.99 6.6.5 a/d converter calibration the C505L adc includes hidden internal calibration mechanisms to ensure that the adc will function safely according to the dc characteristics. a user program that executes a/d conversions will not affect the adc ? s operation. furthermore, a user program has no control over the calibration mechanism. the calibration itself executes two basic functions: ? offset calibration: correction of offset errors of comparator and the capacitor network ? linearity calibration: correction of the binary-weighted capacitor network the adc calibration operates in two phases: calibration after a reset operation and calibration at each a/d conversion. the calibration phases are controlled by a state machine in the adc. this state machine executes the calibration phases, and stores the calibration results dynamically in a small calibration ram. after a reset operation, the adc calibration is automatically started. this reset calibration phase takes 3328 f adc clocks, alternating offset and linearity calibration. therefore, at 16-mhz oscillator frequency and with the default-after-reset prescaler value of 8, the reset calibration time will be approximately 1.66 ms. for achieving a proper reset calibration, the f adc prescaler value must satisfy the condition f adc max 2 mhz. if this condition is not met at a specific oscillator frequency with the default prescaler value after reset, the f adc prescaler must be adjusted immediately after reset by setting bits adcl1 and adcl0 in sfr adcon1 to a suitable value. proper voltages (see the dc specifications of the data sheet) should be applied at the v aref and v agnd pins before the reset calibration has started. after the reset calibration phase, the adc is calibrated according to its dc characteristics (refer to data sheet). nevertheless, single or continuous a/d conversion can be executed during the reset calibration phase. in this case, the reset calibration is interrupted and continued after the end of the a/d conversion. therefore, interrupting the reset calibration phase by a/d conversions extends the total reset calibration time. if the specified total unadjusted error (tue) is to be valid for an a/d conversion, the first a/d conversion should start after reset when the reset calibration phase is finished. depending on the oscillator frequency used, the reset calibration phase can be shortened by setting adcl1 and adcl0 (prescaler value) to its final value immediately after reset. after the reset calibration, a second calibration mechanism is initiated. this calibration is coupled to each a/d conversion . with this second calibration mechanism, offset and linearity calibration values stored in the calibration ram, are always checked when an a/d conversion is executed. these values are corrected, if required. user ? s manual 6-92 10.99 on-chip peripheral components C505L 6.6.6 a/d converter analog input selection the analog inputs are located at port 1. the corresponding pins have a port structure, which allows them to be used as either digital i/o pins or as analog inputs (see section 6.1.3.2 ). the analog input function of these digital/analog port lines are selected via the register p1ana. this register lies in the mapped sfr area, and can be accessed if bit rmap in sfr syscon is set when writing to its address (90 h ). if a specific bit location of p1ana is set, the corresponding port line is configured as a digital i/o. with a 0 in the bit location, the port line operates as an analog port. special function registers p1ana (address 90 h ) reset value: ff h bit function ean7 - ean0 enable analog port 1 inputs if eanx (x = 7-0) is cleared, port pin p1.x is enabled for operation as an analog input. if eanx is set, port pin p1.x is enabled for digital i/o function (default after reset). 76543210 90 h p1ana bit no. msb lsb ean7 ean6 ean5 ean4 ean3 ean2 ean1 ean0 interrupt system C505L user ? s manual 7-1 10.99 7 interrupt system the C505L provides 12 interrupt vectors with four priority levels. five interrupt requests can be generated by the on-chip peripherals (timer 0, timer 1, timer 2, serial interface, a/d converter) and six interrupts may be triggered externally (p3.2/int0 , p3.3/int1 , p1.0/an0/int3 /cc0, p1.1/an1/ int4/cc1, p1.2/an2/int5/cc2, p1.3/an3/int6/cc3). additionally, the p1.5/an5/t2ex can trigger an interrupt. there is one software-generated interrupt (bit swi in sfr ien1) in addition to the above interrupts. the wake-up from power-down mode interrupt has a special functionality which allows an exit from the software power-down mode by a short low pulse at either pin p3.2/ int0 or by the real-time clock interrupt (please refer to chapter 9 for further details). the four external interrupts (int3 , int4, int5 and int6) can also be generated by the timer 2 in capture/compare mode. this chapter shows the interrupt structure, the interrupt vectors and the interrupt related special function registers (sfrs). figure 7-1 to 7-3 give a general overview of the interrupt sources and illustrate the request and the control flags that are described in the next sections. user ? s manual 7-2 10.99 interrupt system C505L figure 7-1 interrupt structure, overview part 1 ea et0 ip1.1 ip0.1 iadc eadc ex0 ip1.0 ip0.0 ie0 ien0.0 tcon.1 0003 h h 0043 h 000b h 004b ien1.0 ircon.0 ien1.1 ien0.1 a / d converter ien0.7 highest priority level lowest priority level p o l l i n g s e q u e n c e mcb03869 it0 tcon.5 tf0 tcon.0 p3.2 / int0 overflow timer 0 bit addressable request flag is cleared by hardware ircon.1 eswi swi software interrupt interrupt system C505L user ? s manual 7-3 10.99 figure 7-2 interrupt structure, overview part 2 ea et1 iex3 ex3 ex1 ip1.2 ip0.2 ie1 ien0.2 tcon.3 0013 h h 0053 h 001b h 005b ien1.2 ircon.2 ien1.3 ien0.3 ien0.7 highest priority level lowest priority level p o l l i n g s e q u e n c e mcb03304 it1 tcon.7 tf1 tcon.2 p3.3 / int1 overflow timer 1 bit addressable request flag is cleared by hardware an0 / int3 / t2con.6 i3fr p1.0 / cc0 ip0.3 ip1.3 ircon.3 iex4 an1 / p1.1 / int4 / cc1 ex4 user ? s manual 7-4 10.99 interrupt system C505L figure 7-3 interrupt structure, overview part 3 ea et2 iex5 ex5 es ip1.4 ip0.4 ri ien0.4 scon.0 0023 h h 0063 h 002b h 006b ien1.4 ircon.4 ien1.5 ien0.5 ien0.7 highest priority level lowest priority level p o l l i n g s e q u e n c e mcb03305 usart overflow timer 2 bit addressable request flag is cleared by hardware ip0.5 ip1.5 ircon.5 iex6 an2 / p1.2 / int5 / cc2 ex6 ti scon.1 >1 cc3 int6 / p1.3 / ircon.7 exf2 tf2 ircon.6 >1 ien1.7 exen2 an5 / t2ex p1.5 / interrupt system C505L user ? s manual 7-5 10.99 7.1 interrupt registers 7.1.1 interrupt enable registers each interrupt vector can be individually enabled or disabled by setting or clearing the corresponding bit in the interrupt enable registers ien0 and ien1. register ien0 also contains the global disable bit (ea), which can be cleared to disable all interrupts at once. generally, after reset all interrupt enable bits are set to 0. that means that the corresponding interrupts are disabled. the ien0 register contains the general enable/disable flags of the external interrupts 0 and 1, the timer interrupts, and the usart interrupt. special function register ien0 (address a8 h ) reset value: 00 h bit function ea enable/disable all interrupts. if ea = 0, no interrupt will be acknowledged. if ea = 1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit. et2 timer 2 overflow/external reload interrupt enable. if et2 = 0, the timer 2 interrupt is disabled. if et2 = 1, the timer 2 interrupt is enabled. es serial channel (usart) interrupt enable if es = 0, the serial channel interrupt 0 is disabled. if es = 1, the serial channel interrupt 0 is enabled. et1 timer 1 overflow interrupt enable. if et1 = 0, the timer 1 interrupt is disabled. if et1 = 1, the timer 1 interrupt is enabled. ex1 external interrupt 1 enable. if ex1 = 0, the external interrupt 1 is disabled. if ex1 = 1, the external interrupt 1 is enabled. et0 timer 0 overflow interrupt enable. if et0 = 0, the timer 0 interrupt is disabled. if et0 = 1, the timer 0 interrupt is enabled. ex0 external interrupt 0 enable. if ex0 = 0, the external interrupt 0 is disabled. if ex0 = 1, the external interrupt 0 is enabled. ea wdt et2 es a8 h ien0 bit no. af h msb lsb et1 ex1 et0 ex0 ae h ad h ac h ab h aa h a9 h a8 h the shaded bits are not used for interrupt control. user ? s manual 7-6 10.99 interrupt system C505L the ien1 register contains enable/disable flags of the timer 2 external timer reload interrupt, the external interrupts 2 and 3, the software interrupt, and the a/d converter (adc) interrupt. special function register ien1 (address b8 h ) reset value: 00 h bit function exen2 timer 2 external reload interrupt enable if exen2 = 0, the timer 2 external reload interrupt is disabled. if exen2 = 1, the timer 2 external reload interrupt is enabled. the external reload function is not affected by exen2. ex6 external interrupt 6/capture/compare interrupt 3 enable if ex6 = 0, external interrupt 6 is disabled. if ex6 = 1, external interrupt 6 is enabled. ex5 external interrupt 5/capture/compare interrupt 2 enable if ex5 = 0, external interrupt 5 is disabled. if ex5 = 1, external interrupt 5 is enabled. ex4 external interrupt 4/capture/compare interrupt 1 enable if ex4 = 0, external interrupt 4 is disabled. if ex4 = 1, external interrupt 4 is enabled. ex3 external interrupt 3/capture/compare interrupt 0 enable if ex3 = 0, external interrupt 3 is disabled. if ex3 = 1, external interrupt 3 is enabled. eswi software interrupt enable if eswi = 0, the software interrupt is disabled. if eswi = 1, the software interrupt is enabled. this bit must be set in order to enable the software interrupt at bit swi (ircon.1) eadc adc interrupt enable if eadc = 0, the a/d converter interrupt is disabled. if eadc = 1, the a/d converter interrupt is enabled. exen2 swdt ex6 ex5 b8 h ien1 bit no. bf h msb lsb ex4 ex3 eswi eadc be h bd h bc h bb h ba h b9 h b8 h the shaded bits are not used for interrupt control. interrupt system C505L user ? s manual 7-7 10.99 7.1.2 interrupt request / control flags special function register tcon (address 88 h ) reset value: 00 h the external interrupts 0 and 1 (int0 and int1 ) can each be either level-activated or negative transition-activated, depending on bits it0 and it1 in register tcon. the flags that actually generate these interrupts are bits ie0 and le1 in tcon. when an external interrupt is generated, the flag that generated this interrupt is cleared by the hardware when the service routine is vectored to, but only if the interrupt was transition-activated. if the interrupt was level-activated, then the requesting external source directly controls the request flag, rather than the on-chip hardware. the timer 0 and timer 1 interrupts are generated by tf0 and tf1 in register tcon, which are set by a rollover in their respective timer/counter registers. when a timer interrupt is generated, the flag that generated it is cleared by the on-chip hardware when vectoring to the service routine. bit function tf1 timer 1 overflow flag set by hardware on timer/counter 1 overflow. cleared by hardware when processor vectors to interrupt routine. tf0 timer 0 overflow flag set by hardware on timer/counter 0 overflow. cleared by hardware when processor vectors to interrupt routine. ie1 external interrupt 1 request flag set by hardware when external interrupt 1 edge is detected. cleared by hardware when processor vectors to interrupt routine. it1 external interrupt 1 level/edge trigger control flag if it1 = 0, low-level-triggered external interrupt 1 is selected. if it1 = 1, falling-edge-triggered external interrupt 1 is selected. ie0 external interrupt 0 request flag set by hardware when external interrupt 0 edge is detected. cleared by hardware when processor vectors to interrupt routine. it0 external interrupt 0 level/edge trigger control flag if it0 = 0, low level triggered external interrupt 0 is selected. if it0 = 1, falling edge triggered external interrupt 0 is selected. tf1 tr1 tf0 tr0 88 h tcon bit no. 8f h msb lsb ie1 it1 ie0 it0 8e h 8d h 8c h 8b h 8a h 89 h 88 h the shaded bits are not used for interrupt control. user ? s manual 7-8 10.99 interrupt system C505L special function register t2con (address c8 h ) reset value: 00x00000 b the external interrupt 3 (int3 ) can be activated by either a positive or negative transition, depending on bit i3fr in register t2con. the flag that actually generates this interrupt is bit iex3 in register ircon. in addition, this flag will be set if a compare event occurs at pin p1.0/an0/int3 / cc0, regardless of the compare mode established and the transition at the respective pin. the flag iex3 is cleared by hardware when vectoring to the service routine. bit function i3fr external interrupt 3 falling/rising edge control flag if i3fr = 0, external interrupt 3 is activated by a falling edge at p1.0/an0/int3 / cc0. if i3fr = 1, external interrupt 3 is activated by a rising edge at p1.0/an0/int3 / cc0. ? this bit has no effect in the C505L. t2ps i3fr ? t2r1 c8 h t2con bit no. cf h msb lsb t2r0 t2cm t2i1 t2i0 ce h cd h cc h cb h ca h c9 h c8 h the shaded bits are not used for interrupt control. interrupt system C505L user ? s manual 7-9 10.99 special function register ircon (address c0 h ) reset value: 00 h bit function exf2 timer 2 external reload flag exf2 is set when a reload is caused by a falling edge on pin t2ex while exen2 = 1. if et2 in ien0 is set (timer 2 interrupt enabled), exf2 = 1 will cause an interrupt. exf2 can be used as an additional external interrupt when the reload function is not used. exf2 must be cleared by software. tf2 timer 2 overflow flag set by a timer 2 overflow and must be cleared by software. if the timer 2 interrupt is enabled, tf2 = 1 will cause an interrupt. iex6 external interrupt 6 edge flag set by hardware when external interrupt edge was detected or when a compare event occurred at p1.3/an3/int6/cc3. cleared by hardware when processor vectors to interrupt routine. iex5 external interrupt 5 edge flag set by hardware when external interrupt edge was detected or when a compare event occurred at p1.2/an2/int5/cc2. cleared by hardware when processor vectors to interrupt routine. iex4 external interrupt 4 edge flag set by hardware when external interrupt edge was detected or when a compare event occurred at p1.1/an1/int4/cc1. cleared by hardware when processor vectors to interrupt routine. iex3 external interrupt 3 edge flag set by hardware when external interrupt edge was detected or when a compare event occurred at p1.0/an0/int3 /cc0. cleared by hardware when processor vectors to interrupt routine. swi software interrupt flag this bit must be set by software to generate an interrupt. cleared by hardware when processor vectors to interrupt routine. iadc adc interrupt request flag set by hardware at the end of an a/d conversion. must be cleared by software. exf2 tf2 iex6 iex5 c0 h ircon bit no. c7 h msb lsb iex4 iex3 swi iadc c6 h c5 h c4 h c3 h c2 h c1 h c0 h user ? s manual 7-10 10.99 interrupt system C505L the timer 2 interrupt is generated by the logical or of bits tf2 and exf2 in register ircon. neither of these flags is cleared by hardware when vectoring to the service routine. in fact, the service routine may have to determine whether it was tf2 or exf2 that generated the interrupt, and the bit will have to be cleared by software. the adc interrupt is generated by iadc bit in register ircon. if an interrupt is generated, in any case the converted result in addat is valid on the first instruction of the interrupt service routine. if continuous conversion is established, iadc is set once during each conversion. if an adc interrupt is generated, flag iadc will have to be cleared by software. the external interrupts 4 to 6 (int4, int5 and int6) are activated by a positive transition. the flags that actually generate these interrupts are bits iex4, iex5 and iex6 in register ircon. in addition, these flags will be set if a compare event occurs at the corresponding output pin p1.3/an3/ int6/cc3, p1.2/an2/int5/cc2, and p1.1/an1/int4/cc1, regardless of the compare mode established and the transition at the respective pin. when an interrupt is generated, the flag that generated it is cleared by the on-chip hardware when vectoring to the service routine. all of these interrupt request bits that generate interrupts can be set or cleared by software, with the same result as if they had been set or cleared by hardware. that is, interrupts can be generated or pending interrupts can be cancelled by software. the only exceptions are the request flags ie0 and le1. if the external interrupts 0 and 1 are programmed to be level-activated, ie0 and le1 are controlled by the external source via pin int0 and int1 , respectively. thus, writing a one to these bits will not set the request flag ie0 and/or le1. in this mode, interrupts 0 and 1 can only be generated by software and by writing a 0 to the corresponding pins int0 (p3.2) and int1 (p3.3), provided that this will not affect any peripheral circuit connected to the pins. the bit swi (ircon.1) can be set by software to vector to location 004b h . prior to setting this bit, the bit ien1.1 should be set to enable this software interrupt. care should be taken to avoid any erroneous interrupt generation while manipulating this bit. interrupt system C505L user ? s manual 7-11 10.99 special function register scon (address. 98 h ) reset value: 00 h the serial port interrupt is generated by a logical or of flag ri and ti in sfr scon. neither of these flags is cleared by hardware when vectoring to the service routine. in fact, the service routine will normally have to determine whether it was the receive interrupt flag or the transmission interrupt flag that generated the interrupt, and the corresponding bit will have to be cleared by software. bit function ti serial interface transmitter interrupt flag set by hardware at the end of a serial data transmission. must be cleared by software. ri serial interface receiver interrupt flag set by hardware if a serial data byte has been received. must be cleared by software. sm0 sm1 sm2 ren 98 h scon bit no. 9f h msb lsb tb8 rb8 ti ri 9e h 9d h 9c h 9b h 9a h 99 h 98 h the shaded bits are not used for interrupt control. user ? s manual 7-12 10.99 interrupt system C505L 7.1.3 interrupt priority registers the lower six bits of these two registers are used to define the interrupt priority level of the interrupt groups as they are defined in table 7-1 in the next section. special function register ip0 (address a9 h ) reset value: 00 h special function register ip1 (address b9 h ) reset value: xx000000 b bit function ip1.x ip0.x interrupt group priority level bits (x = 0 - 5, see table 7-1 ) ? reserved bits for future use. read by cpu returns undefined values. owds wdts ip0.5 ip0.4 a9 h ip0 ip0.3 ip0.2 ip0.1 ip0.0 bit no.76543210 msb lsb ?? ip1.5 ip1.4 b9 h ip1 ip1.3 ip1.2 ip1.1 ip1.0 bit no.76543210 the shaded bits are not used for interrupt control. ip1.x ip0.x function 0 0 interrupt group x is set to priority level 0 (lowest) 0 1 interrupt group x is set to priority level 1 1 0 interrupt group x is set to priority level 2 1 1 interrupt group x is set to priority level 3 (highest) interrupt system C505L user ? s manual 7-13 10.99 7.2 interrupt priority level structure the following table shows the interrupt grouping of the C505L interrupt sources. each pair of interrupt sources can be programmed individually to one of four priority levels by setting or clearing one bit in the sfr ip0 and one in ip1. a low-priority interrupt can be interrupted by a high-priority interrupt, but not by another interrupt of the same or a lower priority. an interrupt of the highest priority level cannot be interrupted by another interrupt source. if two or more requests of different priority levels are received simultaneously, the request of the highest priority is serviced first. if requests of the same priority level are received simultaneously, an internal polling sequence determines which request is to be serviced first. thus, within each priority level, there is a second priority structure determined by the following polling sequence: ? within one interrupt group the ? left ? interrupt is serviced first, and ? the interrupt groups are serviced from top to bottom of the table. table 7-1 interrupt source structure interrupt group associated interrupts high priority low priority priority 1 external interrupt 0 adc interrupt high low 2 timer 0 overflow software interrupt (swi) 3 external interrupt 1 external interrupt 3 4 timer 1 overflow external interrupt 4 5 serial channel interrupt external interrupt 5 6 timer 2 interrupt external interrupt 6 user ? s manual 7-14 10.99 interrupt system C505L 7.3 how interrupts are handled the interrupt flags are sampled at s5p2 in each machine cycle. the sampled flags are polled during the following machine cycle. if one of the flags was in a set condition at s5p2 of the preceding cycle, the polling cycle will find it and the interrupt system will generate a lcall to the appropriate service routine, provided this hardware-generated lcall is not blocked by any of the following conditions: 1. an interrupt of equal or higher priority is already in progress. 2. the current (polling) cycle is not in the final cycle of the instruction in progress. 3. the instruction in progress is reti or any write access to registers ien0/ien1 or ip0/ip1. any of these three conditions will block the generation of the lcall to the interrupt service routine. condition 2 ensures that the instruction in progress is completed before vectoring to any service routine. condition 3 ensures that if the instruction in progress is reti or any write access to registers ien0/ien1 or ip0/ip1, then at least one more instruction will be executed before vectoring to any interrupt; this delay guarantees that changes in the interrupt status can be observed by the cpu. the polling cycle is repeated with each machine cycle, and the values polled are the values that were present at s5p2 of the previous machine cycle. note that if any interrupt flag is active but not being responded to for one of the conditions already mentioned, or if the flag is no longer active when the blocking condition is removed, the denied interrupt will not be serviced. in other words, the fact that the interrupt flag was once active but not serviced is not remembered. every polling cycle interrogates only the pending interrupt requests. the polling cycle/lcall sequence is illustrated in figure 7-4 . figure 7-4 interrupt response timing diagram mct01920 s5p2 interrupt is latched interrupts are polled vector address long call to interrupt routine interrupt c2 c1 c3 c4 c5 interrupt system C505L user ? s manual 7-15 10.99 note that if an interrupt of a higher priority level goes active prior to s5p2 in the machine cycle labeled c3 in figure 7-4 , then in accordance with the above rules it will be vectored to during c5 and c6 without any instruction for the lower priority routine to be executed. thus, the processor acknowledges an interrupt request by executing a hardware-generated lcall to the appropriate servicing routine. in some cases, it also clears the flag that generated the interrupt, while in other cases it does not. if the latter occurs, the flag must be cleared by the user's software. the hardware clears the external interrupt flags ie0 and ie1 only if they were transition-activated. the hardware-generated lcall pushes the contents of the program counter onto the stack (but it does not save the program status word, psw) and reloads the program counter with an address that depends on the source of the interrupt being vectored to, as shown in the following table 7-2 . execution proceeds from that location until the reti instruction is encountered. the reti instruction informs the processor that the interrupt routine is no longer in progress, then pops the two top bytes from the stack and reloads the program counter. execution of the interrupted program continues from the point where it was stopped. note that the reti instruction is very important because it informs the processor that the program has left the current interrupt priority level. a simple ret instruction would also have returned execution to the interrupted program, but without clearing the internal interrupt status of that particular interrupt. in this case, no interrupt of the same or lower priority level would be acknowledged. table 7-2 interrupt source and vectors interrupt source interrupt vector address interrupt request flags external interrupt 0 0003 h ie0 timer 0 overflow 000b h tf0 external interrupt 1 0013 h ie1 timer 1 overflow 001b h tf1 serial channel 0023 h ri/ti timer 2 overflow/ext. reload 002b h tf2/exf2 a/d converter 0043 h iadc software interrupt 004b h swi external interrupt 3 0053 h iex3 external interrupt 4 005b h iex4 external interrupt 5 0063 h iex5 external interrupt 6 006b h iex6 wake-up from power-down mode 007b h irtc (real-time clock wake-up only) user ? s manual 7-16 10.99 interrupt system C505L 7.4 external interrupts external interrupts 0 and 1 can be programmed to be level-activated or negative-transition activated by setting or clearing bit itx (x = 0 or 1), respectively, in register tcon. if itx = 0, external interrupt x is triggered by a low level detected at the intx pin. if itx = 1, external interrupt x is negative edge-triggered. in this mode, if successive samples of the intx pin show a high in one cycle and a low in the next cycle, interrupt request flag iex in tcon is set. flag bit iex = 1 then requests the interrupt. if the external interrupt 0 or 1 is level-activated, the external source has to hold the request active until the requested interrupt is actually generated. then it has to deactivate the request before the interrupt service routine is completed, or else another interrupt will be generated. the external interrupts 4, 5 and 6 are activated only by a positive transition. the external timer 2 reload trigger interrupt request flag exf2 is activated by a negative transition at pin p1.5/an5/t2ex only if bit exen2 is set. since the external interrupt pins (int4, int5 and int6) are sampled once in each machine cycle, an input high or low should be held for at least 6 oscillator periods to ensure sampling. lf the external interrupt is transition-activated, the external source has to hold the request pin low for at least one cycle, and then hold it high for at least one cycle. this will ensure that the transition is recognized, so that the corresponding interrupt request flag will be set (see figure 7-5 ). the external interrupt request flags will be cleared automatically by the cpu when the service routine is called. figure 7-5 external interrupt detection mct01921 level-activated interrupt p3.x/intx e.g. p3.x/intx transition-activated interrupt > 1 machine cycle low-level threshold > 1 machine cycle > 1 machine cycle transition to be detected high-level threshold low-level threshold b) a) interrupt system C505L user ? s manual 7-17 10.99 7.5 interrupt response time if an external interrupt is recognized, its corresponding request flag is set at s5p2 in every machine cycle. the value is not polled by the circuitry until the next machine cycle. if the request is active and conditions are right for it to be acknowledged, a hardware subroutine call to the requested service routine will be the next instruction to be executed. the call itself takes two cycles. thus a minimum of three complete machine cycles will elapse between activation and external interrupt request and the beginning of execution of the first instruction of the service routine. a longer response time would be obtained if the request was blocked by one of the three previously listed conditions. if an interrupt of equal or higher priority is already in progress, the additional wait time obviously depends on the nature of the other interrupt ? s service routine. if the instruction in progress is not in its final cycle, the additional wait time cannot be more than 3 cycles because the longest instructions (mul and div) are only 4 cycles long. if the instruction in progress is reti or a write access to registers ien0, ien1 or ip0, ip1, the additional wait time cannot be more than 5 cycles (a maximum of one more cycle to complete the instruction in progress, plus 4 cycles to complete the next instruction, if the instruction is mul or div). thus in a single interrupt system, the response time is always more than 3 cycles and less than 9 cycles. user ? s manual 8-1 10.99 fail safe mechanisms C505L 8 fail safe mechanisms the C505L offers enhanced fail save mechanisms, which allow an automatic recovery from software upset or hardware failure: ? a programmable watchdog timer, with variable time-out period from 192 s up to approx. 393.2 ms at 16 mhz (314.5 ms at 20 mhz). ? an oscillator watchdog (owd) unit that monitors the on-chip oscillator and forces the microcontroller into reset state in case the on-chip oscillator fails. the owd also provides the clock for a fast internal reset after power-on. 8.1 programmable watchdog timer to protect the system against software failure, the user ? s program has to clear the watchdog timer within a previously programmed time period. lf the software fails to refresh the watchdog timer periodically, an internal hardware reset will be initiated. the software can be designed so that the watchdog times out if the program does not work properly. lt also times out if a software error is based on hardware-related problems. the watchdog timer in the C505L is a 15-bit timer that is incremented by a count rate of f osc /192 up to f osc /12. the machine clock of the C505L is divided by two prescalers: a divide-by-2, and a divide-by-16 prescaler. for programming of the watchdog timer overflow rate, the upper 7 bits of the watchdog timer can be written. figure 8-1 shows the block diagram of the watchdog timer unit. figure 8-1 block diagram of the programmable watchdog timer mcb03306 ip0 (a9 ) h osc f wdts 2 16 14 07 8 wdtl wdth / 6 external hw reset control logic ien0 (a8 ) h ien1 (b8 ) h 6 70 wdt reset - request wdtpsel wdtrel (86 ) h wdt swdt owds fail safe mechanisms C505L user ? s manual 8-2 10.99 8.1.1 input clock selection the input clock rate of the watchdog timer is derived from the system clock of the C505L. there is a prescaler available, which is software selectable and defines the input clock rate. this prescaler is controlled by bit wdtpsel in the sfr wdtrel. table 8-1 shows resulting time-out periods at f osc = 12 and 16 mhz. special function register wdtrel (address 86 h ) reset value: 00 h bit function wdtpsel watchdog timer prescaler select bit. when set, the watchdog timer is clocked through an additional divide-by-16 prescaler. wdtrel.6 - 0 seven bit reload value for the high-byte of the watchdog timer. this value is loaded to wdth when a refresh is triggered by a consecutive setting of bits wdt and swdt. table 8-1 watchdog timer time-out periods wdtrel time-out period comments f osc = 12 mhz f osc = 16 mhz 00 h 32.768 ms 24.576 ms this is the default value 80 h 524.2 ms 393.2 ms maximum time period 7f h 256 s 192 s minimum time period msb lsb bit no. wdt 86 h wdtrel 76543210 psel reload value user ? s manual 8-3 10.99 fail safe mechanisms C505L 8.1.2 watchdog timer control / status flags the watchdog timer is controlled by two control flags, wdt and swdt (located in sfr ien0 and ien1), and one status flag, wdts (located in sfr ip0). special function register ien0 (address a8 h ) reset value: 00 h special function register ien1 (address b8 h ) reset value: 00 h special function register ip0 (address a9 h ) reset value: 00 h immediately after start, the watchdog timer is initialized to the reload value programmed in wdtrel.0-wdtrel.6. after an external hardware reset, an owd power-on reset, or a watchdog timer reset, register wdtrel is cleared to 00 h . the lower seven bits of wdtrel can be loaded by software at any time. bit function wdt watchdog timer refresh flag. set to initiate a refresh of the watchdog timer. must be set directly before swdt is set to prevent an unintentional refresh of the watchdog timer. swdt watchdog timer start flag. set to activate the watchdog timer. when directly set after setting wdt, a watchdog timer refresh is performed. wdts watchdog timer status flag. set by hardware when a watchdog timer reset occurred. can be cleared and set by software. eal wdt et2 es a8 h ien0 af h msb lsb et1 ex1 et0 ex0 ae h ad h ac h ab h aa h a9 h a8 h exen2 swdt ex6 ex5 b8 h ien1 bf h ex4 ex3 ecan eadc be h bd h bc h bb h ba h b9 h b8 h owds wdts ip0.5 ip0.4 a9 h ip0 ip0.3 ip0.2 ip0.1 ip0.0 bit no.76543210 the shaded bits are not used for watchdog timer control. fail safe mechanisms C505L user ? s manual 8-4 10.99 8.1.3 starting the watchdog timer the watchdog timer can be started by software (bit swdt in sfr ien1), but it cannot be stopped during active mode of the device. if the software fails to clear the watchdog timer, an internal reset will be initiated. the reset cause (external reset or reset caused by the watchdog) can be examined by software (status flag wdts in ip0 is set). a refresh of the watchdog timer is done by setting bits wdt (sfr ien0) and swdt consecutively. this double instruction sequence has been implemented to increase system security. it must be noted, however, that the watchdog timer is halted during the idle mode and power-down mode of the processor (see chapter 9 ). therefore, the watchdog timer cannot reset the device when one of the power saving modes has been entered. user ? s manual 8-5 10.99 fail safe mechanisms C505L 8.1.4 refreshing the watchdog timer at the same time the watchdog timer is started, the 7-bit register wdth is preset by the contents of wdtrel.0 to wdtrel.6. once started, the watchdog cannot be stopped by software but can only be refreshed to the reload value by first setting bit wdt (ien0.6) and by the next instruction setting swdt (ien1.6). bit wdt will be cleared automatically during the second machine cycle after having been set. for this reason, setting swdt bit has to be a one-cycle instruction (e.g. setb swdt). this double-instruction refresh of the watchdog timer is implemented to minimize the chance of an unintentional reset of the watchdog. when the watchdog timer is started or refreshed its lower 8 bits, stored in wdtl (see figure 8-1 ), are reset to 00 h . the reload register wdtrel can be written to at any time. therefore, a periodical refresh of wdtrel can be added to the starting procedure mentioned above for the watchdog timer. thus, a wrong reload value caused by an error during the write operation to the wdtrel can be corrected by software. 8.1.5 watchdog reset and watchdog status flag lf the software fails to refresh the watchdog in time, an internally-generated watchdog reset is entered at the counter state 7ffc h . the duration of the reset signal then depends on the prescaler selection (either 8 cycles or 128 cycles). this internal reset differs from an external one only in so far as the watchdog timer is not disabled, and bit wdts (watchdog timer status, bit 6 in sfr ip0) is set. figure 8-2 shows a block diagram of all reset requests in the C505L, and the function of the watchdog status flags. the wdts flag is a flip-flop that is set by a watchdog timer reset and cleared by an external hardware reset. bit wdts allows the software to examine which source activated the reset. the watchdog timer status flag can also be cleared by software. figure 8-2 watchdog timer status flags and reset requests owds wdts owd reset request wdt reset request set set ip0 (a9 ) h internal bus external hw reset request >1 synchro- nization internal reset reset mct03307 clear fail safe mechanisms C505L user ? s manual 8-6 10.99 8.2 oscillator watchdog unit the oscillator watchdog serves three functions: ? monitoring the on-chip oscillator ? s function the watchdog supervises the on-chip oscillator ? s frequency. if it is lower than the frequency of the auxiliary rc oscillator in the watchdog unit, the internal clock is supplied by the rc oscillator and the device is brought into reset. if the failure condition disappears (i.e., the on-chip oscillator has a higher frequency than the rc oscillator), the device executes a final reset phase of typ. 1 ms in order to allow the oscillator to stabilize. then the oscillator watchdog reset is released and the device starts program execution from address 0000 h again. ? fast internal reset after power-on the oscillator watchdog unit provides a clock supply for the reset before the on-chip oscillator has started. the oscillator watchdog unit and the monitoring function also work identically. ? control of wake-up from software power-down mode when the power-down mode is left by a low level signal at the p3.2/int0 pin or an active real time clock interrupt request flag irtc, the oscillator watchdog unit ensures that the microcontroller resumes operation (execution of the power-down wake-up interrupt) with the nominal clock rate. in the power-down mode, the rc oscillator and the on-chip oscillator are stopped. both oscillators are started again when power-down mode is released. when the on-chip oscillator has a higher frequency than the rc oscillator, the microcontroller starts program execution by processing a power down interrupt after a final delay (typ. 1 ms) in order to allow the on-chip oscillator to stabilize. note: the oscillator watchdog unit is always enabled. special function register ip0 (address a9 h ) reset value: 00 h the shaded bits are not used for fail-safe control. bit function owds oscillator watchdog status flag. set by hardware when an oscillator watchdog reset occurred. can be set and cleared by software. owds wdts ip0.5 ip0.4 a9 h ip0 ip0.3 ip0.2 ip0.1 ip0.0 msb lsb bit no. 76543210 user ? s manual 8-7 10.99 fail safe mechanisms C505L 8.2.1 detailed description of the oscillator watchdog unit figure 8-2 is a block diagram of the oscillator watchdog unit. the oscillator watchdog consists of an internal rc oscillator that provides the reference frequency for the comparison with the frequency of the on-chip oscillator. figure 8-3 also shows the additional provisions for integration of the wake-up from power-down mode. figure 8-3 functional block diagram of the oscillator watchdog the frequency of the rc oscillator is divided by 10 and compared with the on-chip oscillator ? s frequency. if the frequency of the on-chip oscillator is lower than the frequency derived from the rc oscillator the watchdog detects a failure condition. for example, the oscillation at the on-chip oscillator could stop because of crystal damage, etc. in this case, it switches the input of the internal clock system to the output of the rc oscillator. this means that the device is being clocked even if the on-chip oscillator has stopped or has not yet started. at the same time, the watchdog activates the internal reset in order to bring the device to its defined reset state. the reset is performed because a clock signal is available from the rc oscillator. this internal watchdog reset has the same effects as an externally-applied reset signal with the following exceptions: the watchdog timer status flag wdts is not reset (the watchdog timer is, however, stopped); and bit owds is set. this allows the software to examine error conditions detected by the watchdog unit even if meanwhile an oscillator failure occurred. int. clock xtal1 xtal2 owds mcb03870 ip0 (a9 ) h 3 mhz f rc delay 1 f 2 f 2 f 1 f < irtc start / stop start / stop mode activated power - down power - down mode wake - up interrupt internal reset 10 p3.2 / int0 control ws (rtcon.2) ewpd >1 frequency comparator rc on-chip oscillator logic oscillator logic control (pcon1.0) fail safe mechanisms C505L user ? s manual 8-8 10.99 the oscillator watchdog is able to detect a recovery of the on-chip oscillator after a failure. if the frequency derived from the on-chip oscillator is again higher than the reference, the watchdog starts a final reset sequence which takes 1 ms. within that time, the clock is still supplied by the rc oscillator and the device is held in reset. this allows a reliable stabilization of the on-chip oscillator. after that, the watchdog switches the clock supply back to the on-chip oscillator and releases the oscillator watchdog reset. if no other reset is applied at this time, the device will start program execution. if an external reset or a watchdog timer reset is active, however, the device will retain the reset state until the other reset request disappears. furthermore, the status flag owds is set if the oscillator watchdog was active. the status flag can be evaluated by software to detect that a reset was caused by the oscillator watchdog. the flag owds can be set or cleared by software. an external reset request, however, also resets owds (and wdts). if software power-down mode is activated, the rc oscillator and the on-chip oscillator are stopped. both oscillators are again started in power-down mode when a low level signal is detected at either the p3.2/int0 input pin or the real-time clock interrupt flag (irtc), when bit ewpd in sfr pcon1 is set (wake-up from power-down mode enabled). the wake-up source is chosen from one of p3.2/ int0 and irtc (rtcon.3) by bit ws in sfr pcon1. in this case, the oscillator watchdog does not execute an internal reset during start-up of the on-chip oscillator. after the start-up phase of the on-chip oscillator, the watchdog generates a power-down mode wake-up interrupt. detailed description of the wake-up from software power-down mode is given in section 9.4.2 . 8.2.2 fast internal reset after power-on the C505L can use the oscillator watchdog unit for a fast internal reset procedure after power-on. normally, the members of the 8051 family (e. g. sab 80c52) do not enter their default reset state before the on-chip oscillator starts. the reason is that the external reset signal must be internally synchronized and processed in order to bring the device into the correct reset state. in particular, the start up time of the oscillator is relatively long (typ. 1 ms) if a crystal is used. during this time period, the pins are in an undefined state that could have severe effects, e.g., on actuators connected to port pins. in the C505L, the oscillator watchdog unit avoids this situation. after power-on, the oscillator watchdog's rc oscillator starts working within a very short start-up time (typically less than 2 s). then the watchdog circuitry detects a failure condition for the on-chip oscillator because it has not yet started. a failure is always recognized if the watchdog ? s rc oscillator runs faster than the on-chip oscillator. as long as this condition is valid the watchdog uses the rc oscillator output as clock source for the chip. this allows correct resetting of the device and brings all ports to the defined state (see also chapter 5 of this manual). user ? s manual 9-1 10.99 power saving modes C505L 9 power saving modes the C505L provides three basic power-saving modes, the idle mode, the slow-down mode and the power-down mode. 9.1 power-saving mode control registers the functions of the power-saving modes are controlled by bits in the special function registers (sfrs) pcon and pcon1. the sfr pcon is located at sfr address 87 h . pcon1 is located in the mapped sfr area (rmap = 1) at sfr address 88 h . bit rmap, which controls the access to the mapped sfr area, is located in sfr syscon (b1 h ). the bits pde, pds and idle, idls located in sfr pcon select the power-down mode or the idle mode, respectively. if the power-down mode and the idle mode are set at the same time, power-down takes precedence. the slow-down mode is controlled by the bit sd located in sfr pcon. furthermore, sfr pcon contains two general-purpose flags. for example, the flag bits gf0 and gf1 can be used to indicate whether an interrupt occurred during normal operation or during idle mode. for that function, an instruction that activates idle mode can also set one or both flag bits. when idle mode is terminated by an interrupt, the interrupt service routine can examine the flag bits. special function register pcon (address 87 h ) reset value: 00 h symbol function pds power-down start bit the instruction that sets the pds flag bit is the last instruction before entering the power-down mode idls idle start bit the instruction that sets the idls flag bit is the last instruction before entering the idle mode. sd slow-down mode bit when set, the slow-down mode is enabled gf1 general-purpose flag gf0 general-purpose flag pde power-down enable bit when set, starting of the power-down is enabled idle idle mode enable bit when set, starting of the idle mode is enabled msb lsb 87 h pcon smod pds idls sd gf1 gf0 pde idle 76543210 bit no. the function of the shaded bit is not described in this section. power saving modes C505L user ? s manual 9-2 10.99 register lcon (address f3dd h ) reset value: 00 h register rtcon (address f3f0 h ) reset value: 00 h registers lcon and rtcon are used for controlling the power-down modes of the lcd controller and the real-time clock, respectively. please refer to section 9.4 for further details. bit function lcen enables lcd controller lcen = 0: lcd controller is disabled (default after reset). lcen = 1: lcd controller is enabled. csel lcd input clock selection csel = 1: use rtc clock input (32.768 khz) for f lcdin csel = 0: use system clock ( f osc ) for f lcdin bit function rtpd real-time clock power-down enable rtpd = 0: real-time clock is in operation rtpd = 1: real-time clock is powered down real-time clock is in operation by default after reset. the functions of the shaded bits are not described in this section. dsb1 dsb0 0 0 f3dd h lcon bit no. 76543210 msb lsb 00csellcen the functions of the shaded bits are not described in this section. 0000 f3f0 h rtcon bit no. 76543210 msb lsb rtpd irtc ertc rtcs user ? s manual 9-3 10.99 power saving modes C505L special function register pcon1 (mapped address 88 h ) reset value: 0xx0xxxx b symbol function ewpd external wake-up from power-down enable bit setting ewpd before entering power-down mode, enables wake-up from power-down mode capability. ws wake-up from power-down source select ws = 0: wake-up via p3.2/int0 (external wake-up) ws = 1: wake-up via real-time clock interrupt ? reserved bits for future use. read by cpu returns undefined values. msb lsb 88 h pcon1 ewpd ?? ws ???? 76543210 bit no. power saving modes C505L user ? s manual 9-4 10.99 9.2 idle mode in the idle mode, the C505L ? s oscillator continues to run, but the cpu is gated off from the clock signal. however, the interrupt system, the serial port, the a/d converter (adc), the lcd controller, the real-time clock, and all timers with the exception of the watchdog timer are further provided with the clock. the cpu status is preserved in its entirety: the stack pointer, program counter, program status word (psw), accumulator, and all other registers maintain their data during idle mode. the reduction of power consumption which can be achieved in the idle mode depends on the number of peripherals running. if all timers are stopped, and the adc and the serial interfaces are not running, the maximum power reduction can be achieved. this state is also the test condition for the idle mode current ( i dd ). thus, the user has to take care as to which peripheral(s) should continue to run and which has to be stopped during idle mode. also, the state of all port pins ? either the pins controlled by their latches or controlled by their secondary functions ? depends on the status of the controller when entering idle mode. normally, the port pins hold the logical state they had at that time when the idle mode was activated. if some pins are programmed to serve as alternate functions they still continue to output during idle mode if the assigned function is on. this applies especially to the serial interface in case it cannot finish reception or transmission during normal operation. the control signals ale and psen are held at logic high levels. as in normal operation mode, the ports can be used as inputs during idle mode. thus a capture or reload operation can be triggered, the timers can be used to count external events, and external interrupts will be detected. the idle mode is a useful feature that makes it possible to ? freeze ? the processor ? s status, either for a predefined time, or until an external event causes the controller to revert to normal operation, as discussed below. the watchdog timer is the only peripheral which is stopped automatically during idle mode. user ? s manual 9-5 10.99 power saving modes C505L the idle mode is entered by two consecutive instructions. the first instruction sets the flag bit idle (pcon.0) and must not set bit idls (pcon.5). the subsequent instruction sets the start bit idls (pcon.5) and must not set bit idle (pcon.0). the hardware ensures that a concurrent setting of both bits, idle and idls, does not initiate the idle mode. bits idle and idls will be cleared automatically after being set. if one of these register bits is read, the value that appears is 0. this double instruction is implemented to minimize the chance of entering the idle mode unintentionally, which would leave the watchdog timer unable to protect the system. note pcon is not a bit-addressable register, so the sequence mentioned above for entering the idle mode is accomplished by byte-handling instructions, as shown in the following example: orl pcon,#00000001b ;set bit idle, bit idls must not be set orl pcon,#00100000b ;set bit idls, bit idle must not be set the instruction that sets bit idls is the last instruction executed before going into idle mode. there are two ways to terminate the idle mode: ? the idle mode can be terminated by activating any enabled interrupt. the cpu operation is resumed, the interrupt will be serviced, and the next instruction to be executed after the reti instruction will be the one following the instruction that had set the bit idls. ? the other way to terminate the idle mode is a hardware reset. since the oscillator is still running, the hardware reset must be held active for only two machine cycles for a complete reset. power saving modes C505L user ? s manual 9-6 10.99 9.3 slow-down mode operation in some applications where power consumption and dissipation are critical, the controller might run for a certain time at reduced speed (e.g. if the controller is waiting for an input signal). since in cmos devices there is an almost linear dependency between the operating frequency and the power supply current, a reduction of the operating frequency results in reduced power consumption. in the slow-down mode, all signal frequencies that are derived from the oscillator clock are divided by 32. the slow-down mode is activated by setting the bit sd in sfr pcon. if the slow-down mode is enabled, the clock signals for the cpu and the peripheral units are reduced to 1/32 of the nominal clock rate. the controller actually enters the slow-down mode after a short synchronization period (max. two machine cycles). the slow-down mode is terminated by clearing bit sd. the slow-down mode can be combined with the idle mode by performing the following double instruction sequence: orl pcon,#00000001b ; preparing idle mode: set bit idle (idls not set) orl pcon,#00110000b ; entering idle mode combined with the slow-down mode: ; (idls and sd set) there are two ways to terminate the combined idle and slow-down mode: ? the idle mode can be terminated by activation of any enabled interrupt. the cpu operation is resumed, the interrupt will be serviced, and the next instruction to be executed after the reti instruction will be the one following the instruction that had set the bits idls and sd. nevertheless the slow-down mode remains enabled, and if it is necessary to terminate this mode, that can be accomplished by clearing the bit sd in the corresponding interrupt service routine or at any point in the program where the user no longer requires the slow-down mode. ? the combined idle and slow-down mode can also be terminated by a hardware reset. since the oscillator is still running, the hardware reset has to be held active for only two machine cycles for a complete reset. user ? s manual 9-7 10.99 power saving modes C505L 9.4 software power-down modes in order to achieve different levels of power-saving, the C505L has three major software power-down modes as described below: ? software power-down mode 1 , in which all the peripheral blocks and the cpu are stopped. in this mode, the rc oscillator and the on-chip oscillator that operates with the xtal1 and xtal2 pins are stopped. therefore, all functions of the microcontroller are stopped and only the contents of the on-chip ram, xram and the sfrs are maintained. the port pins, which are controlled by their port latches, output the values that are held by their sfrs. the port pins that serve the alternate output functions show the values they had at the end of the last cycle of the instruction which initiated the power-down mode. ale and psen are held at logic low level (see table 9-1 ). ? software power-down mode 2 , in which only the real-time clock and lcd controller are operating. in this mode, the cpu and the rest of the peripherals are stopped. the rc oscillator and the on-chip oscillator are stopped, the real-time clock oscillator that operates with the xtal3 and xtal4 pins is still running and the real-time count is maintained in this mode. ? software power-down mode 3 , in which only the real-time clock is operating. in this mode, the clock input into the cpu, lcd controller and the rest of the peripherals are stopped. the only difference between this mode and mode 2 is that the lcd controller is also stopped in this mode. the lcd controller output pins are inactive in this stage and should not be used for any input function. in both software power-down modes 2 and 3, all the functions of the microcontroller other than those described above are stopped, and the contents of the on-chip ram, xram and sfrs are maintained. the unused pins in these modes have the behavior as in the software power-down mode 1. in all the software power-down modes, v dd can be reduced to minimize power consumption. in the case of the software power-down mode 3, v dd can be reduced to 3 v (lower specification limit). it must be ensured, however, that v dd is not reduced before any of the power-down modes is invoked, and that v dd is restored to its normal operating level before leaving the power-down mode. any of these software power-down modes can be exited either by an active reset signal or by a wake-up request. using reset to leave power-down mode puts the microcontroller with its sfrs into the reset state. program execution then starts from the address 0000 h . using a wake-up request to exit the power-down mode starts the rc oscillator and the on-chip oscillator and maintains the state of the sfrs, which were frozen when power-down mode was entered. when the C505L is in software power-down mode 1, a wake-up operation is possible only through p3.2/int0 . there are two ways to use a wake-up request to exit power-down modes 2 and 3: - wake-up via p3.2/int0 pin when bit ws in sfr pcon1 is cleared, and - wake-up via the real-time clock interrupt when bit ws in sfr pcon1 is set power saving modes C505L user ? s manual 9-8 10.99 9.4.1 invoking software power-down modes the C505L ? s software power-down modes can be entered as shown below: software power-down mode 1 - this mode is entered by first ensuring that both the lcd controller and the real-time clock are disabled. this is done by clearing bit lcen (lcon.0) and setting bit rtpd (rtcon.3). once these conditions are fulfilled, software power-down mode 1 is entered by two consecutive instructions. the first instruction has to set the flag bit pde (pcon.1) and must not set bit pds (pcon.6). the subsequent instruction has to set the start bit pds (pcon.6) and must not set bit pde (pcon.1). the hardware ensures that a concurrent setting of both bits, pde and pds, does not initiate the power-down mode. bits pde and pds will be cleared automatically after having been set, and the value shown by reading one of these bits is always 0. the double instruction is implemented to minimize the chance of entering the power-down mode unintentionally, which could possibly ? freeze ? the chip ? s activity in an undesired status. pcon is not a bit-addressable register, so the above mentioned sequence for entering the power-down mode can be accomplished by byte-handling instructions, as shown in the following example: orl pcon,#00000010b ;set bit pde, bit pds must not be set orl pcon,#01000000b ;set bit pds, bit pde must not be set, enter power-down software power-down mode 2 - this mode is entered by first ensuring that both the lcd controller and the real-time clock are enabled. the following conditions should be met: ? bit lcen (lcon.0) is set, ? bit csel (lcon.1) is set, and ? bit rtpd (rtcon.3) is cleared. once these conditions are fulfilled, the C505L can enter software power-down mode 2 with the two instruction sequence as in mode 1. software power-down mode 3 - this mode is entered by first ensuring that the real-time clock is enabled and the lcd controller is disabled. the following conditions should be met: ? bit rtpd (rtcon.3) is cleared, and ? bit lcen (lcon.0) is cleared. once these conditions are fulfilled, the C505L can enter software power-down mode 3 with the two instruction sequence as in mode 1. in any of the above modes, the instruction that sets bit pds is the last instruction executed before going into power-down mode. note: before entering the power-down mode, any a/d conversion in progress must be stopped. user ? s manual 9-9 10.99 power saving modes C505L 9.4.2 exit from software power-down mode the C505L can exit the software power-down modes in one of the following 2 ways: ? hardware reset ? wake-up from power-down mode through pin p3.2/ int0 or real-time clock interrupt if the bit ewpd in sfr pcon1 is 0 during power-down entry, the only way to exit from the power-down mode is a hardware reset. this reset will redefine all the sfrs but will not change the contents of the internal ram and xram. the reset signal that terminates the power-down mode also restarts the rc oscillator and the on-chip oscillator. the reset operation should not be activated before v dd is restored to its normal operating level and must be held active long enough to allow the oscillator to restart and stabilize (similar to power-on reset). if the wake-up from power-down capability is used, this function must be enabled using the following instruction sequence prior to entering the power-down mode. orl syscon,#00010000b ;set rmap orl pcon1,#80h ;enable external wake-up from power-down by setting ewpd anl syscon,#11101111b ;reset rmap (for future sfr accesses) power saving modes C505L user ? s manual 9-10 10.99 figure 9-1 shows the procedure which must be executed when power-down modes are exited via the p3.2/int0 wake-up request capability. figure 9-1 wake-up from power-down mode procedure when the power-down mode wake-up capability has been enabled (bit ewpd in sfr pcon1 set) prior to entering power-down mode, and bit ws in sfr pcon1 is cleared, the power-down mode can be exited via int0 while executing the following procedure: 1. in power-down mode, pin p3.2/int0 must be held at high level. 2. power-down mode is exited when p3.2/int0 goes low for at least 10 s (latch phase). after this delay, the internal rc oscillator, and the on-chip oscillator are started, the state of pin p3.2/int0 is internally latched, and p3.2/int0 can be set again to a high level if required. thereafter, the oscillator watchdog unit controls the wake-up procedure in its start-up phase. 3. the oscillator watchdog unit starts operation. when the on-chip oscillator clock ? s stable nominal frequency has been detected, the microcontroller starts again and initiates the power-down wake-up interrupt. the interrupt address of the first instruction to be executed after wake-up is 007b h . ale and psen are in their power-down state up to this time. at the end of phase 3, the cpu processes the interrupt call and during these two machine cycles, ale and psen behave as shown in figure 9-1 (i.e., at the beginning of phase 4). instruction fetches during the interrupt call are discarded, however. mct02597 ale psen p2 p0 00 h h 7b 1st. instr. of isr detailed timing of beginning of phase 4 int0 p3.2/ power down mode 1) latch phase 2) 10 min. s 5 ms typ. oscillator start-up phase watchdog circuit 3) 4) interrupt at execution of 007b h reti instruction invalid address invalid address/data ~ ~ ~ ~ user ? s manual 9-11 10.99 power saving modes C505L 4. after the reti instruction of the power-down wake-up interrupt routine has been executed, the instruction that follows the double instruction sequence that initiates the power-down mode will be executed. the peripheral units timer 0/1/2 and watchdog timer are frozen until the end of phase 4. all of the C505L ? s interrupts are disabled from phase 2 until the end of phase 4. other interrupts can be handled first after the reti instruction of the wake-up interrupt routine. note: to avoid any unintentional external interrupt request, the user should ensure that p3.2/int0 is set back to high level, after a wake-up request, prior to completion of the wake-up sequence. prior to entering the software power-down mode, the port latch of sfr p3.2 (p3.2/int0 pin) should contain a ? 1 ? . otherwise, the wake-up sequence described above will be started immediately after the power-down mode has been entered. the wake-up routine initiated by the real-time clock interrupt is similar to the wake-up from p3.2/ int0 , and can be used to wake-up from power-down modes 2 and 3. for this to occur, it is necessary to enable both the wake-up capability (bit ewpd in sfr pcon1 should be set) and the real-time clock interrupt have to be enabled (bit ertc in rtcon). additionally, the real-time clock should be selected as the source of the wake-up request (bit ws in sfr pcon1 must be set). an interrupt can then be generated by the real-time clock at a predetermined time, depending on the setting of the rtint register. this interrupt will then be used as a wake-up request. the flag irtc is set by hardware and has to be cleared by software. the handling of such a wake-up request is, however, identical to the handling of the wake-up through p3.2/int0 . the real-time clock wake-up interrupt has no effect on the device, unless the C505L has entered the power-down mode. power saving modes C505L user ? s manual 9-12 10.99 9.5 state of pins in software-initiated power-saving mode in the idle mode and in the software power-down mode 1, the port pins of the C505L have a well-defined status which is listed in the following table 9-1 . this state of some pins also depends on the location of the code memory (internal or external). in software power-down mode 2, all the port pins are in the states as shown in table 9-1 , except for the enabled lcd output pins at ports 3, 4 and 5. these pins output values corresponding to their digit registers. in the software power-down mode 3, all the port pins are in the states as shown in table 9-1 . table 9-1 status of external pins during idle and software power-down mode 1 outputs last instruction executed from internal code memory last instruction executed from external code memory idle power-down idle power-down ale high low high low psen high low high low port 0 data data float float port 2 data data address data port 1, 3, 4 and 5 data/alternate outputs data/last output data/alternate outputs data/last output user ? s manual 10-1 10.99 otp memory operation C505L 10 otp memory operation the C505L is the one-time programmable (otp) version of the C505L microcontroller with a 32-kbyte otp program memory. the C505L has fast programming cycles (1 byte per 100 s). also, several levels of otp memory protection can be selected. 10.1 programming configuration to program the device, the C505L must be put into the programming mode. typically, this is done not ? in-system ? but with special programming hardware instead. in the programming mode, the C505L operates as a slave device similar to an eprom stand-alone memory device, and must be controlled with address/data information, control lines, and an external 11.5 v programming voltage. in the programming mode, port 0 provides the bidirectional data lines and port 2 is used for the multiplexed address inputs. the upper address information at port 2 is latched with the signal pale. the inputs reset, psen , ea / v pp , ale and pmsel1/0 and psel are used for basic programming mode selection. furthermore, the inputs pmsel1,0 are required to select the access types (e.g., program/verify data, write lock-bits, and so forth) in the programming mode. v dd / v ss and a clock signal at the xtal pins must be applied to the C505L in the programming mode. the 11.5 v external programming voltage is input through the ea / v pp pin. figure 10-1 shows the pins of the C505L that are required for controlling of the otp programming mode. figure 10-1 programming mode configuration pmsel1 pmsel0 xtal2 xtal1 p0.0 - 7 v ss v dd C505L mcs03876 p2.0 - 7 pa l e ea / prog prd reset psen psel v pp port 2 port 0 otp memory operation C505L user ? s manual 10-2 10.99 10.2 pin configuration figure 10-2 shows the detailed pin configuration of the C505L in programming mode. figure 10-2 otp programming mode pin configuration (top view) n.c. n.c. n.c. n.c. mcp03877 n.c. n.c. n.c. n.c. n.c. C505L 60 61 80 21 40 70 30 41 50 20 10 1 n.c. n.c. n.c. n.c. 5 15 25 35 45 55 65 75 n.c. n.c. n.c. n.c. n.c. n.c. d0 d3 n.c. n.c. n.c. n.c. n.c. n.c. n.c. d4 d2 d6 d7 d5 d1 n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. n.c. prd psel pale dd ss v v a1 / a9 a3 / a11 a2 / a10 n.c. prog psen xtal2 ea / xtal1 a5 / a13 a6 / a14 pmsel0 reset v ss pmsel1 dd v a4 / a12 a7 a0 / a8 n.c. pp v p - mqfp - 80 package user ? s manual 10-3 10.99 otp memory operation C505L 10.3 pin definitions table 10-2 is a functional description of all C505L pins that are required for otp memory programming. table 10-2 pin definitions and functions of the C505L in programming mode symbol pin number i/o *) function p-mqfp-80 reset 43 i reset this input must be at static ? 1 ? (active) level during the whole programming mode. pmsel0 pmsel1 42 41 i i programming mode selection pins these pins are used to select the different access modes in programming mode. pmsel1,0 must satisfy a setup time to the rising edge of pale. when the logic level of pmsel1,0 is changed, pale must be at low level. psel 40 i basic programming mode select this input is used for the basic programming mode selection and must be switched according to figure 10-3 . prd 39 i programming mode read strobe this input is used for read access control for otp memory read, version byte read, and lock-bit read operations. pale 38 i programming address latch enable pale is used to latch the high address lines. the high address lines must satisfy a setup and hold time to/from the falling edge of pale. pale must be at a low level when the logic level of pmsel1,0 is changed. xtal2 47 o xtal2 output of the inverting oscillator amplifier. xtal1 48 i xtal1 input to the oscillator amplifier. *) i = input o = output pmsel1 pmsel0 access mode 00reserved 0 1 read signature bytes 1 0 program/read lock-bits 1 1 program/read otp memory byte otp memory operation C505L user ? s manual 10-4 10.99 v ss 49, 70 ? circuit ground potential must be applied in programming mode. v dd 50, 69 ? power supply terminal must be applied in programming mode. p2.0-7 60-53 i address lines p2.0-7 are used as multiplexed address input lines a0-a7 and a8-a14. a8-a14 must be latched with pale. psen 44 i program store enable this input must be at static ? 0 ? level during the whole programming mode. prog 45 i programming mode write strobe this input is used in programming mode as a write strobe for otp memory program, and lock-bit write operations. during basic programming mode selection a low level must be applied to prog . ea / v pp 46 ? programming voltage this pin must be at 11.5 v ( v pp ) voltage level during programming of an otp memory byte or lock-bit. during an otp memory read operation, this pin must be at v ih high level. this pin is also used for basic programming mode selection. at basic programming mode selection a low level must be applied to ea / v pp . p0.7-0 68-61 i/o data lines 0-7 during programming mode, data bytes are transferred via the bidirectional d7-0 lines that are located at port 0. n.c. 1-37, 51-52, 71-80 ? not connected these pins should not be connected in programming mode. *) i = input o = output table 10-2 pin definitions and functions of the C505L in programming mode (cont ? d) symbol pin number i/o *) function p-mqfp-80 user ? s manual 10-5 10.99 otp memory operation C505L 10.4 programming mode selection the selection of the otp programming mode can be separated into two different parts: ? basic programming mode selection ? access mode selection with basic programming mode selection, the device is put into the mode in which it is possible to access the otp memory through the programming interface logic. after selection of the basic programming mode, otp memory accesses are executed by using one of the access modes. these access modes include otp memory byte program/read, version byte read, and program/ read lock byte operations. 10.4.1 basic programming mode selection the basic programming mode selection scheme is shown in figure 10-3 . figure 10-3 basic programming mode selection clock (xtal1 / xtal2) reset psen pmsel1,0 prog prd psel pale ea / v pp v dd 5 v v pp ih2 v "1" "0" 0,1 "0" "1" "0" 0 v ready for access mode selection during this period signals are not actively driven mcs03878 stable otp memory operation C505L user ? s manual 10-6 10.99 the basic programming mode is selected by executing the following steps: ? with a stable v dd a clock signal is applied to the xtal pins; the reset pin is set to ? 1 ? level and the psen pin is set to ? 0 ? level. ? prog , pale, pmsel1 and ea / v pp are set to ? 0 ? level; prd , psel , and pmsel0 are set to ? 1 ? level. ? psel is switched from ? 1 ? to ? 0 ? level and thereafter prog is switched to ? 1 ? level. ? pmsel1,0 can now be changed; after ea / v pp has been set to v ih high level or to v pp the otp memory is ready for access. the pins reset and psen must stay at static signal levels ? 1 ? and ? 0 ? , respectively, during the whole programming mode. with a falling edge of psel , the logic state of prog and ea / v pp is latched internally. these two signals are now used as programming write-pulse signal (prog ) and as programming voltage for input pin v pp . after the falling edge of psel , psel must stay at ? 0 ? state during all programming operations. note: if protection level 1 to 3 has been programmed (see section 10.6 ) and the programming mode has been left, it is no longer possible to enter the programming mode! 10.4.2 otp memory access mode selection when the C505L has been put into the programming mode using the basic programming mode selection, several access modes of the otp memory programming interface are available. the conditions for the different control signals of these access modes are listed in table 10-3 . the access modes shown above are selected by setting the two pmsel1,0 lines to the required logic level. the prog and prd signal are the write and read strobe signal. data is transferred via port 0 and addresses are applied to port 2. the following sections describe the various access modes. table 10-3 access modes selection access mode ea / v pp prog prd pmsel address (port 2) data (port 0) 10 program otp memory byte v pp hhh a0-7 a8-14 d0-7 read otp memory byte v ih h program otp lock-bits v pp hhl ? d1, d0 see table 10-4 read otp lock-bits v ih h read otp version byte v ih h l h byte addr. of version byte d0-7 user ? s manual 10-7 10.99 otp memory operation C505L 10.5 program/read otp memory bytes the program/read otp memory byte access mode is defined by pmsel1,0 = 1,1. it is initiated when the pmsel1,0 = 1,1 is valid at the rising edge of pale. with the falling edge of pale, the upper addresses a8-a14 of the 15-bit otp memory address are latched. after a8-a14 has been latched, a0-a7 is put on the address bus (port 2). a0-a7 must be stable when prog is low or prd is low. if subsequent otp address locations are accessed with constant address information at the high address lines a8-a14, a8-a14 must be latched only once (page address mechanism). figure 10-4 shows a typical basic otp memory programming cycle with a subsequent otp memory read operation. in this example a8-a14 of the read operation are identical to a8-a14 of the proceeding programming operation. figure 10-4 programming/verify otp memory access waveform if the address lines a8-a14 must be updated, pale must be activated to latch the new a8-a14 value. control, address, and data information must only be switched when the prog and prd signals are at a high level. the pale high pulse must always be executed if a different access mode has been used prior to the actual access mode. d0 - d7 min. 100 s d0 - d7 a8-a14 a0-a7 1,1 pmsel1,0 port 2 pale port 0 prog prd mcs03879 min. 100 ns otp memory operation C505L user ? s manual 10-8 10.99 figure 10-5 shows a waveform example of the program/read mode access for several otp memory bytes. in this example, otp memory locations 3fd h to 400 h are programmed. thereafter, otp memory locations 400 h and 3fd h are read. figure 10-5 typical otp memory programming/verify access waveform mct03364 pmsel1, 0 pa l e port 2 port 0 prog prd 1, 1 3fd 3fe 3ff 400 400 3fd 03 fd fe ff 04 00 00 03 fd data 1 data 2 data 3 data 4 data 1 data 4 user ? s manual 10-9 10.99 otp memory operation C505L 10.6 programming and reading lock bits the C505L has two programmable lock-bits that, when programmed according to table 10-4 , provide four levels of protection for the on-chip otp code memory. note: a ? 1 ? means that the lock-bit is unprogrammed. ? 0 ? means that lock-bit is programmed. for an otp verify operation at protection level 1, the C505L must be put into the otp verification mode. if a device is programmed with protection level 2 or 3, it is no longer possible to verify the otp content of a customer rejected (far) otp device. when a protection level has been activated by programming the lock-bits, the basic programming mode must be exited in order to activate the protection mechanisms. this means that after the activation of a protection level, further otp program/verify operations are still possible if the basic programming mode is maintained. the state of the lock-bits can always be read if protection level 0 is selected. if protection level 1 to 3 has been programmed and the programming mode has been exited, it is not possible to re-enter the programming mode. in this case, the lock-bits cannot be read anymore. figure 10-6 shows the waveform of a lock-bit write/read access. for a simple drawing, the prog pulse is shortened. in practice, a 100 s prog low pulse must be applied for lock-bit programming. table 10-4 lock bit protection types lock bits at d1, d0 protection level protection type d1 d0 1 1 level 0 the otp lock feature is disabled. during normal operation of the C505L, the state of the ea pin is not latched on reset. 1 0 level 1 during normal operation of the C505L, movc instructions executed from external program memory are prevented from fetching code bytes from internal memory. ea is sampled and latched on reset. an otp memory read operation is only possible in the otp verification mode. further programming of the otp memory is disabled (reprogramming security). 0 1 level 2 same as level 1, but otp memory read operation using otp verification mode is disabled. 0 0 level 3 same as level 2, but external code execution by setting ea = low during normal operation of the C505L is not possible. external code execution, which is initiated by an internal program (e.g. by an internal jump instruction above the otp memory boundary), is still possible. otp memory operation C505L user ? s manual 10-10 10.99 figure 10-6 write/read lock bit waveform mct03365 pmsel1,0 pale prog prd 1,0 1,0 1,0 port 0 (d1, d0) the example shows the programming and reading of a protection level 1. user ? s manual 10-11 10.99 otp memory operation C505L 10.6.1access of version bytes the C505L provides 3 version bytes at address locations fc h , fd h , and fe h . the information stored in the version bytes, is defined by the mask of each microcontroller step. therefore, the version bytes can be read but not written. the three version registers hold information such as manufacturer ? s code, device type, and stepping code. to read the version bytes the control lines must be used according to table 10-3 and figure 10-7 . the address of the version byte must be applied to the port 2 address lines. pale must not be activated. figure 10-7 read version register(s) waveform version bytes are typically used by programming systems for adapting the programming firmware to specific device characteristics such as otp size etc. note: the 3 version bytes are implemented in a way that allows them be read during normal program execution mode as a mapped register with bit rmap in special function register (sfr) syscon set. the addresses of the version bytes in normal mode and programming mode are identical and therefore they are located in the sfr address range. the steppings of the C505L versions will contain the following version register/byte information: note: future steppings of C505L would have a different version byte 2 content. stepping version byte 0 = vr0 (mapped addr. fc h ) version byte 1 = vr1 (mapped addr. fd h ) version byte 2 = vr2 (mapped addr. fe h ) C505L es-aa-step c5 h 85 h 01 h mct03366 pmsel 1,0 pale port 2 port 0 prog prd 0,1 fd fc fe ver. 0 ver. 1 ver. 2 otp memory operation C505L user ? s manual 10-12 10.99 10.7 otp verification mode the otp verification mode shown in figure 10-8 is used to verify the contents of the otp when the protection level 1 has been set. the detailed timing characteristics of the otp verification mode are shown in the ac specifications (refer to data sheet). figure 10-8 otp verification mode otp verification mode is selected if the inputs psen , ea , and ale are set at the specified logic levels. with reset going inactive, the otp verification mode sequence is started. the C505L outputs an ale signal with a period of 3 clock periods (clp) and expects data bytes at port 0. the data bytes at port 0 are assigned to the otp addresses in the following way: 1. data byte = content of otp address 0000 h 2. data byte = content of otp address 0001 h 3. data byte = content of otp address 0002 h : 16. data byte = content of otp address 000f h : the C505L does not output any address information during the otp verification mode. the first data byte to be verified is always the byte that is assigned to the otp address 0000 h , and it must be put onto the data bus with the falling edge of reset. with each following ale pulse, the otp address pointer is internally incremented and the expected data byte for the next otp address must be delivered externally. reset ale port 0 p3.5 6 clp 3 clp latch latch latch latch data for addr. 0 data for addr. x 16 data for addr. x 16 + 1 data for ad. x 16 - 1 data for addr. 1 inputs : ale = psen = v reset = v ss ih mct03289 1. ale pulse after reset low: verify error high: verify ok , ea = v ih2 user ? s manual 10-13 10.99 otp memory operation C505L between two ale pulses the data at port 0 is latched (at 3 clp after ale rising edge) and compared internally with the otp content of the actual address. if a verify error is detected, the error condition is stored internally. after each 16th data byte, the cumulated verify result (pass or fail) of the last 16 verify operations is output at p3.5. this means that p3.5 stays at static level (low for fail and high for pass) during the time when the subsequent 16 bytes are checked. in otp verification mode, the C505L must be provided with a system clock at the xtal pins. figure 10-9 shows an application example of an external circuitry that allows verification of the otp, with protection level 1, inside the C505L in the otp verification mode. when reset goes inactive, the C505L starts the otp verify sequence. its ale is clocking a 15-bit address counter. this counter generates the addresses for an external eprom that is programmed with the contents of the otp. the verify detect logic typically displays the pass/fail information of the verify operation. p3.5 can be latched with the falling edge of ale. when the last byte of the otp has been handled, the C505L starts generating a psen signal. this signal or the cy signal of the address counter indicate to the verify detect logic the end of the otp verification. otp memory operation C505L user ? s manual 10-14 10.99 figure 10-9 otp verification mode - external circuitry example verify detect logic carry clk 15 - bit address counter s compare code rom cs oe d0 - d7 a0 - a14 v dd & & dd v port 0 reset ea psen ale p3.5 2k C505L mcs03880 user ? s manual 11-1 10.99 index C505L 11 index a a/d converter . . . . . . . . . . . . . . . 6-80 ? 6-92 analog input pin selection . . . . . . . . 6-92 block diagram . . . . . . . . . . . . . . . . . 6-81 calibration mechanisms . . . . . . . . . 6-91 clock selection . . . . . . . . . . . . . . . . . 6-86 conversion time calculation . . . . . . . 6-89 conversion timing . . . . . . . . . . . . . . 6-87 general operation . . . . . . . . . . . . . . 6-80 registers . . . . . . . . . . . . . . . . . 6-82 ? 6-86 system clock relationship . . . . . . . . 6-88 ac . . . . . . . . . . . . . . . . . . . . . . . . .2-4, 3-16 acc . . . . . . . . . . . . . . . . . . . 2-3, 3-12, 3-17 adcl1 . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 adcon0 . . . . . . . . . . 3-13, 3-16, 5-8, 6-48 adcon02 . . . . . . . . . . . . . . . . . . . . . . 3-12 adcon1 . . . . . . . . . . . . . . . . . . . 3-12, 3-17 addath . . . . . . . . . . . . . . . . . . . 3-12, 3-16 addatl . . . . . . . . . . . . . . . . . . . 3-12, 3-16 adm . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 ale signal . . . . . . . . . . . . . . . . . . . . . . . 4-4 b b . . . . . . . . . . . . . . . . . . . . . 2-4, 3-12, 3-17 basic cpu timing . . . . . . . . . . . . . . . . . 2-5 bd . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 block diagram . . . . . . . . . . . . . . . . . . . . 2-2 bsy . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 c c/t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ccen . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 cch1 . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 cch2 . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 cch3 . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 ccl1 . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 ccl2 . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 ccl3 . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 clk . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 clkout . . . . . . . . . . . . . . . . . . . . . . . 3-15 clreg0 . . . . . . . . . . . . . . . . . . . 3-14, 3-18 clreg1 . . . . . . . . . . . . . . . . . . . 3-14, 3-18 clreg2 . . . . . . . . . . . . . . . . . . . 3-14, 3-18 clreg3 . . . . . . . . . . . . . . . . . . . 3-14, 3-18 clreg4 . . . . . . . . . . . . . . . . . . . 3-14, 3-18 cocah0 . . . . . . . . . . . . . . . . . . . . . . . 3-16 cocah1 . . . . . . . . . . . . . . . . . . . . . . . 3-16 cocah2 . . . . . . . . . . . . . . . . . . . . . . . .3-16 cocah3 . . . . . . . . . . . . . . . . . . . . . . . .3-16 cocal0 . . . . . . . . . . . . . . . . . . . . . . . .3-16 cocal1 . . . . . . . . . . . . . . . . . . . . . . . .3-16 cocal2 . . . . . . . . . . . . . . . . . . . . . . . .3-16 cocal3 . . . . . . . . . . . . . . . . . . . . . . . .3-16 cpu accumulator . . . . . . . . . . . . . . . . . . . .2-3 b register . . . . . . . . . . . . . . . . . . . . . . .2-4 basic timing . . . . . . . . . . . . . . . . . . . . .2-5 fetch/execute diagram . . . . . . . . . . . .2-6 functionality . . . . . . . . . . . . . . . . . . . .2-3 program status word . . . . . . . . . . . . . .2-3 stack pointer . . . . . . . . . . . . . . . . . . . .2-4 cpu timing . . . . . . . . . . . . . . . . . . . . . . .2-6 crch . . . . . . . . . . . . . . . . . . . . . . . . . .3-13 crcl . . . . . . . . . . . . . . . . . . . . . . . . . .3-13 cy . . . . . . . . . . . . . . . . . . . . . . . . . 2-4, 3-16 d dac0 . . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 datapointers . . . . . . . . . . . . . . . . . . 4-6 ? 4-9 application examples . . . . . . . . . 4-7 ? 4-9 dpsel register . . . . . . . . . . . . . . . . . .4-6 functionality . . . . . . . . . . . . . . . . . . . .4-6 dign1 . . . . . . . . . . . . . . . . . . . . . . . . . .3-18 dign5 . . . . . . . . . . . . . . . . . . . . . . . . . .3-14 dph . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 dpl . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 dpsel . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 e ea . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 eadc . . . . . . . . . . . . . . . . . . . . . . 3-16, 7-6 eale . . . . . . . . . . . . . . . . . . . . . . . 1-8, 3-16 ean0 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean1 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean2 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean3 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean4 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean5 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean6 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean7 . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 ean7-0 . . . . . . . . . . . . . . . . . . . . . . . . .6-92 emulation concept . . . . . . . . . . . . . . . . .4-5 ertc . . . . . . . . . . . . . . . . . . . . . . . . . .3-18 es . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 eswi . . . . . . . . . . . . . . . . . . . . . . . 3-16, 7-6 et0 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 user ? s manual 11-2 10.99 index C505L et1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 et2 . . . . . . . . . . . . . . . . . . . . . . . .3-15, 7-5 ewpd . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ex0 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ex1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ex3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 ex4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 ex5 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 ex6 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 execution of instructions . . . . . . . . . . . . 2-6 exen2 . . . . . . . . . . . . . . . . . . . . . . 3-16, 7-6 exf2 . . . . . . . . . . . . . . . . . . . . . . .3-16, 7-9 external bus interface . . . . . . . . . . . . . . 4-1 ale signal . . . . . . . . . . . . . . . . . . . . . 4-4 ale switch-off control . . . . . . . . . . . . 4-4 overlapping of data/program memory 4-3 program memory access . . . . . . . . . . 4-3 program/data memory timing . . . . . . 4-2 psen signal . . . . . . . . . . . . . . . . . . . . 4-3 role of p0 and p2 . . . . . . . . . . . . . . . 4-1 f f0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 f1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 fail save mechanisms . . . . . . . . . . .8-1 ? 8-8 fast power-on reset . . . . . . . . . . . .5-3, 8-8 features . . . . . . . . . . . . . . . . . . . . . . . . 1-2 functional units . . . . . . . . . . . . . . . . . . . 1-1 fundamental structure . . . . . . . . . . . . . 2-1 g gate . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 gf0 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 gf1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 h hardware reset . . . . . . . . . . . . . . . . . . . 5-1 i i/o ports . . . . . . . . . . . . . . . . . . . . .6-1 ? 6-17 i3fr . . . . . . . . . . . . . . . . . . . . . . . .3-16, 7-8 iadc . . . . . . . . . . . . . . . . . . 3-16, 6-85, 7-9 idle . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 idle mode . . . . . . . . . . . . . . . . . . . . .9-4 ? 9-5 idls . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ie0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ie1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 ien0 . . . . . . . . . . . . . . . . . . 3-15, 6-31, 8-3 ien02 . . . . . . . . . . . . . . . . . . . . . 3-12, 3-13 ien1 . . . . . . . . . . . . . 3-16, 6-31, 6-85, 8-3 ien12 . . . . . . . . . . . . . . . . . . . . . 3-12, 3-13 iex3 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 iex4 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 iex5 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 iex6 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 int0 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 int1 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 int4 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 int5 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 interrupt system . . . . . . . . . . . . . . 7-1 ? 7-17 interrupts block diagram . . . . . . . . . . . . . . . 7-2 ? 7-4 enable registers . . . . . . . . . . . . . 7-5 ? 7-9 external interrupts . . . . . . . . . . . . . . .7-16 handling procedure . . . . . . . . . . . . . .7-14 priority registers . . . . . . . . . . . . . . . .7-12 priority within level structure . . . . . . .7-13 request flags . . . . . . . . . . . . . . 7-7 ? 7-11 response time . . . . . . . . . . . . . . . . .7-17 sources and vector addresses . . . . .7-15 introduction . . . . . . . . . . . . . . . . . . . . . . .1-1 ip0 . . . . . . . . . . . . . . . . . . . . 3-15, 8-3, 8-6 ip02 . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-13 ip1 . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-16 ircon . . . . . . . . . . . 3-12, 3-16, 6-31, 6-85 irtc . . . . . . . . . . . . . . . . . . . . . . . . . . .3-18 it0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 it1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 l lcd controller . . . . . . . . . . . . . . 6-62 ? 6-72 clocking . . . . . . . . . . . . . . . . . 6-65 ? 6-66 block diagram . . . . . . . . . . . . . . . .6-66 frequency . . . . . . . . . . . . . . . . . . .6-65 column singals . . . . . . . . . . . . . . . . .6-68 display voltage . . . . . . . . . . . . . . . . .6-72 d/a converter . . . . . . . . . . . . . . . .6-72 lcd cell organization . . . . . . . . . . .6-62 power saving mode . . . . . . . . . . . . .6-72 registers . . . . . . . . . . . . . . . . . . . . . .6-63 control register . . . . . . . . . . . . . . .6-63 digit registers . . . . . . . . . . . . . . . . .6-64 row signals . . . . . . . . . . . . . . . . . . . .6-67 lcd controller/rtc access control . . . . . . . . . . . . . . . . . . .3-3 lcon . . . . . . . . . . . . . . . . . 3-14, 3-18, 9-2 lcrh . . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 lcrl . . . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 user ? s manual 11-3 10.99 index C505L logic symbol . . . . . . . . . . . . . . . . . . . . . 1-3 m m0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 m1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 memory organization . . . . . . . . . . . . . . . 3-1 data memory . . . . . . . . . . . . . . . . . . . 3-2 general purpose registers . . . . . . . . . 3-2 memory map . . . . . . . . . . . . . . . . . . . 3-1 program memory . . . . . . . . . . . . . . . . 3-2 mx0 . . . . . . . . . . . . . . . . . . . . . . . 3-16, 3-17 mx1 . . . . . . . . . . . . . . . . . . . . . . . 3-16, 3-17 mx2 . . . . . . . . . . . . . . . . . . . . . . . 3-16, 3-17 o oscillator operation . . . . . . . . . . . . .5-6 ? 5-7 external clock source . . . . . . . . . . . . . 5-7 on-chip oscillator circuitry . . . . . . . . . 5-7 recommended oscillator circuit . . . . . 5-6 oscillator watchdog . . . . . . . . . . . . .8-6 ? 8-8 behaviour at reset . . . . . . . . . . . . . . . 5-3 block diagram . . . . . . . . . . . . . . . . . . 8-7 otp memory . . . . . . . . . . . . . . . 10-1 ? 10-14 access of version bytes . . . . . . . . 10-11 basic mode selection . . . . . . . . . . . 10-5 pin configuration . . . . . . . . . . . . . . . 10-1 program/read operation . . . . . . . . . . 10-7 verification example . . . . . . . . . . . 10-14 verification mode . . . . . . . . . . . . . . 10-12 verification mode timing . . . . . . . . 10-12 ov . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 owds . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 p p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 p0 . . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 p1 . . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 p1ana . . . . . . . . . . . . . . . . . 3-12, 3-15, 6-2 p2 . . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 p3 . . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-16 p4 . . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-17 p5 . . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-17 parallel i/o . . . . . . . . . . . . . . . . . . .6-1 ? 6-17 pcon . . . . . . . . . . . . . . . . 3-13, 3-15, 6-48 pcon1 . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 pde . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 pds . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 pin configuration . . . . . . . . . . . . . . . . . . 1-4 pin definitions and functions . . . . . . . . . 1-5 pin definitions and functions (otp mode) . . . . . . . . . . . . . . 10-3 ? 10-4 ports . . . . . . . . . . . . . . . . . . . . . . . 6-1 ? 6-17 alternate functions . . . . . . . . . . . . . . .6-3 loading and interfacing . . . . . . . . . . .6-16 output drivers circuitry . . . . . . . . . . .6-10 mixed digital/analog i/o pins . . . . .6-12 multifunctional digital i/o pins . . . .6-10 output/input sample timing . . . . . . . .6-15 read-modify-write operation . . . . . . .6-17 types and structures . . . . . . . . . . . . . .6-1 port 0 circuitry . . . . . . . . . . . . . . . . .6-6 port 1/3/4 circuitry . . . . . . . . . . . . . .6-7 port 2 circuitry . . . . . . . . . . . . . . . . .6-8 standard i/o port circuitry . . . . 6-4 ? 6-5 power saving modes . . . . . . . . . . 9-1 ? 9-12 control registers . . . . . . . . . . . . . 9-1 ? 9-3 idle mode . . . . . . . . . . . . . . . . . . 9-4 ? 9-5 slow down mode . . . . . . . . . . . . . . . . .9-6 software power down mode entry procedure . . . . . . . . . . . . . . . .9-8 exit (wake-up) procedure . . . . . . . .9-9 software power down modes . . 9-7 ? 9-11 state of pins . . . . . . . . . . . . . . . . . . .9-12 psen signal . . . . . . . . . . . . . . . . . . . . . .4-3 psw . . . . . . . . . . . . . . . . . . 2-3, 3-12, 3-16 r rb8 . . . . . . . . . . . . . . . . . . . . . . . 3-15, 6-46 rd . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 real-time clock . . . . . . . . . . . . . 6-73 ? 6-79 control register . . . . . . . . . . . . . . . .6-74 functionality . . . . . . . . . . . . . . . . . . .6-77 oscillator . . . . . . . . . . . . . . . . . . . . . .6-73 wake-up interrupt . . . . . . . . . . . . . . .6-78 ren . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 reset . . . . . . . . . . . . . . . . . . . . . . . . . . .5-1 fast power-on reset . . . . . . . . . . . . . .5-3 hardware reset timing . . . . . . . . . . . . .5-5 power-on reset timing . . . . . . . . . . . . .5-4 reset circuitries . . . . . . . . . . . . . . . . . .5-2 ri . . . . . . . . . . . . . . . . . . . 3-15, 6-46, 7-11 rmap . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 rs0 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 rs1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 rtcon . . . . . . . . . . . . . . . . 3-14, 3-18, 9-2 rtcr0 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtcr1 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 user ? s manual 11-4 10.99 index C505L rtcr2 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtcr3 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtcr4 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtcs . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18 rtint0 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtint1 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtint2 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtint3 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtint4 . . . . . . . . . . . . . . . . . . . . 3-14, 3-18 rtpd . . . . . . . . . . . . . . . . . . . . . . .3-18, 9-2 rxd . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 s sbuf . . . . . . . . . . . . . . . . . 3-13, 3-15, 6-46 scon . . . . . . . . . . . 3-13, 3-15, 6-46, 7-11 scon2 . . . . . . . . . . . . . . . . . . . . . . . . 3-12 sd . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 serial interface (usart) . . . . . . . 6-45 ? 6-61 baudrate generation . . . . . . . . . . . . 6-48 with internal baud rate generator . 6-50 with timer 1 . . . . . . . . . . . . . . . . . . 6-52 multiprocessor communication . . . . 6-46 operating mode 0 . . . . . . . . . . 6-53 ? 6-55 operating mode 1 . . . . . . . . . . 6-56 ? 6-58 operating mode 2 and 3 . . . . . 6-59 ? 6-61 registers . . . . . . . . . . . . . . . . . . . . . 6-46 sm0 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 sm1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 sm2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 smod . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 sp . . . . . . . . . . . . . . . . . . . . 2-4, 3-12, 3-15 special function registers . . . . . . . . . 3-11 access with rmap . . . . . . . . . . . . . 3-11 table - address ordered . . . . . 3-15 ? 3-18 table - functional order . . . . . . 3-12 ? 3-14 srelh . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 srell . . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 swdt . . . . . . . . . . . . . . . . . . . . . . 3-16, 8-3 swi . . . . . . . . . . . . . . . . . . . . . . . .3-16, 7-9 syscon . . . . . . . 3-3, 3-11, 3-12, 3-16, 4-4 system clock output . . . . . . . . . . . .5-8 ? 5-9 t t0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 t1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 t2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 t2cm . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 t2con . . . . . . . . . . . . . . . . 3-13, 3-16, 7-8 t2con2 . . . . . . . . . . . . . . . . . . . . . . . 3-12 t2ex . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 t2i0 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 t2i1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 t2ps . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 t2r0 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 t2r1 . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 tb8 . . . . . . . . . . . . . . . . . . . . . . . 3-15, 6-46 tcon . . . . . . . . . . . . . . . . . 3-13, 3-15, 7-7 tcon2 . . . . . . . . . . . . . . . . . . . . . . . . .3-12 tf0 . . . . . . . . . . . . . . . . . . . . . . . . 3-15, 7-7 tf1 . . . . . . . . . . . . . . . . . . . . . . . . 3-15, 7-7 tf2 . . . . . . . . . . . . . . . . . . . . . . . . 3-16, 7-9 th0 . . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 th1 . . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 th2 . . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 ti . . . . . . . . . . . . . . . . . . . . 3-15, 6-46, 7-11 timer/counter . . . . . . . . . . . . . . . . . . . .6-18 timer/counter 0 and 1 . . . . . . . 6-18 ? 6-25 mode 0, 13-bit timer/counter . . . . .6-22 mode 1, 16-bit timer/counter . . . . .6-23 mode 2, 8-bit rel. timer/counter . . .6-24 mode 3, two 8-bit timer/counter . . .6-25 registers . . . . . . . . . . . . . . . 6-19 ? 6-21 timer/counter 2 . . . . . . . . . . . . 6-26 ? 6-45 block diagram . . . . . . . . . . . . . . . .6-27 capture function . . . . . . . . . 6-43 ? 6-45 compare function . . . . . . . . 6-35 ? 6-40 compare mode 0 . . . . . . . . . 6-35 ? 6-38 compare mode 1 . . . . . . . . . 6-39 ? 6-40 compare mode interrupts . . . . . . .6-41 general operation . . . . . . . . . . . . .6-33 port functions . . . . . . . . . . . . . . . . .6-26 registers . . . . . . . . . . . . . . . 6-28 ? 6-32 reload configuration . . . . . . . . . . .6-34 tl0 . . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 tl1 . . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 tl2 . . . . . . . . . . . . . . . . . . . . . . . 3-13, 3-16 tmod . . . . . . . . . . . . . . . . . . . . . 3-13, 3-15 tr0 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 tr1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-15 txd . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16 v vr0 . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-17 vr1 . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-17 vr2 . . . . . . . . . . . . . . . . . . . . . . . 3-12, 3-17 w watchdog timer . . . . . . . . . . . . . . . . 8-1 ? 8-5 user ? s manual 11-5 10.99 index C505L block diagram . . . . . . . . . . . . . . . . . . 8-1 control/status flags . . . . . . . . . . . . . . 8-3 input clock selection . . . . . . . . . . . . . 8-2 refreshing of the wdt . . . . . . . . . . . 8-5 reset operation . . . . . . . . . . . . . . . . . 8-5 starting of the wdt . . . . . . . . . . . . . . 8-4 time-out periods . . . . . . . . . . . . . . . . 8-2 wdt . . . . . . . . . . . . . . . . . . . . . . .3-15, 8-3 wdtpsel . . . . . . . . . . . . . . . . . . . . . . 3-15 wdtrel . . . . . . . . . . . . . . . . . . . 3-13, 3-15 wdts . . . . . . . . . . . . . . . . . . . . . . . . . 3-15 wr . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 ws . . . . . . . . . . . . . . . . . . . . . . . . .3-15, 9-3 x xmap0 . . . . . . . . . . . . . . . . . . . . . . . . 3-16 xmap1 . . . . . . . . . . . . . . . . . . . . . . . . 3-16 xpage . . . . . . . . . . . . . . . . . . . . 3-12, 3-15 xram operation . . . . . . . . . . . . . . . . . . 3-3 access control . . . . . . . . . . . . . . . . . . 3-3 accessing through dptr . . . . . . . . . 3-5 accessing through r0/r1 . . . . . . . . . 3-5 behaviour of p2/p0 . . . . . . . . . . . . . . 3-9 reset operation . . . . . . . . . . . . . . . . . 3-9 xpage register . . . . . . . . . . . . . . . . . 3-5 use of p2 as i/o port . . . . . . . . . . . 3-8 write page address to p2 . . . . . . . . 3-6 write page address to xpage . . . . 3-7 infineon goes for business excellence ? business excellence means intelligent approaches and clearly defined processes, which are both constantly under review and ultimately lead to good operating results. better operating results and business excellence mean less idleness and wastefulness for all of us, more professional success, more accurate information, a better overview and, thereby, less frustration and more satisfaction. ? dr. ulrich schumacher http://www.infineon.com published by infineon technologies ag |
Price & Availability of C505L |
|
|
All Rights Reserved © IC-ON-LINE 2003 - 2022 |
[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy] |
Mirror Sites : [www.datasheet.hk]
[www.maxim4u.com] [www.ic-on-line.cn]
[www.ic-on-line.com] [www.ic-on-line.net]
[www.alldatasheet.com.cn]
[www.gdcy.com]
[www.gdcy.net] |