![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
user 's manual 05.94 microcomputer components sab 80c517 / 8 0 c5 3 7 8-bit cmos single-chip microcontroller
edition 05.95 this edition was realized using the software system framemaker a . published by siemens ag, bereich halbleiter, marketing- kommunikation, balanstra?e 73, 81541 mnchen ? siemens ag 1995. all rights reserved. attention please! as far as patents or other rights of third par- ties are concerned, liability is only assumed for components, not for applications, pro- cesses and circuits implemented within com- ponents or assemblies. the information describes the type of compo- nent and shall not be considered as assured characteristics. terms of delivery and rights to change design reserved. for questions on technology, delivery and prices please contact the semiconductor group offices in germany or the siemens companies and representatives worldwide (see address list). due to technical requirements components may contain dangerous substances. for in- formation on the types in question please contact your nearest siemens office, semi- conductor group. siemens ag is an approved cecc manufac- turer. packing please use the recycling operators known to you. we can also help you C get in touch with your nearest sales office. by agreement we will take packing material back, if it is sorted. you must bear the costs of transport. for packing material that is returned to us un- sorted or which we are not obliged to accept, we shall have to invoice you for any costs in- curred. components used in life-support devices or systems must be expressly authorized for such purpose! critical components 1 of the semiconductor group of siemens ag, may only be used in life-support devices or systems 2 with the ex- press written approval of the semiconductor group of siemens ag. 1 a critical component is a component used in a life-support device or system whose failure can reasonably be expected to cause the failure of that life-support de- vice or system, or to affect its safety or ef- fectiveness of that device or system. 2 life support devices or systems are in- tended (a) to be implanted in the human body, or (b) to support and/or maintain and sustain human life. if they fail, it is reasonable to assume that the health of the user may be endangered. semiconductor group 4 sab 80c517/80c537 users manual revision history: 04.95 previous releases: 06.91/10.92/08.93/04.94 page subjects (changes since last revision) 119 133 141 167 188 360 figure 7-33, writing error corrected pin assignment table 7-10 corrected page number reference number corrected software watchdog timer start: extended description description of ctf flag modified rom verification timing: text added revision history 80c517/80c537 semiconductor group 5 table of contents page 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 2 fundamental structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 3 central processing unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 3.1 general description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 3.2 cpu timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 4 memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 4.1 program memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 4.2 data memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16 4.3 general purpose registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 4.4 special function registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 5 external bus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 5.1 accessing external memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 5.2 eight datapointers for faster external bus access . . . . . . . . . . . . . . . . . . . .29 5.3 psen , program store enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33 5.4 ale, address latch enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33 5.5 overlapping external data and program memory spaces . . . . . . . . . . . . . .33 6 system reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 6.1 hardware reset and power-up reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 6.1.1 reset function and circuitries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 6.1.2 hardware reset timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38 6.2 reset output pin (ro ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39 7 on-chip peripheral components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 7.1 parallel i/o . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 7.1.1 port structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 7.1.2 port 0 and port 2 used as address/data bus . . . . . . . . . . . . . . . . . . . . . . . .45 7.1.3 alternate functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46 7.1.4 port handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 7.1.4.1 port timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 7.1.4.2 port loading and interfacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49 7.1.4.3 read-modify-write feature of ports 0 through 6 . . . . . . . . . . . . . . . . . . . . . .49 7.2 serial interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51 7.2.1 serial interface 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51 7.2.1.1 operating modes of serial interface 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51 7.2.1.2 multiprocessor communication feature . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 7.2.1.3 baud rates of serial channel 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54 7.2.1.4 new baud rate generator for serial channel 0 . . . . . . . . . . . . . . . . . . . . . .58 7.2.2 serial interface 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61 7.2.2.1 operating modes of serial interface 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61 80c517/80c537 semiconductor group 6 table of contents page 7.2.2.2 multiprocessor communication feature . . . . . . . . . . . . . . . . . . . . . . . . . . . .63 7.2.2.3 baud rates of serial channel 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63 7.2.2.4 new baud rate generator for serial channel 1 . . . . . . . . . . . . . . . . . . . . . .64 7.2.3 detailed description of the operating modes . . . . . . . . . . . . . . . . . . . . . . . .66 7.2.3.1 mode 0, synchronous mode (serial interface 0) . . . . . . . . . . . . . . . . . . . . . .66 7.2.3.2 mode 1/mode b, 8-bit uart (serial interfaces 0 and 1) . . . . . . . . . . . . . . . .67 7.2.3.3 mode 2, 9-bit uart (serial interface 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . .68 7.2.3.4 mode 3 / mode a, 9-bit uart (serial interfaces 0 and 1) . . . . . . . . . . . . . . .68 7.3 timer 0 and timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76 7.3.1 mode 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79 7.3.2 mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80 7.3.3 mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81 7.3.4 mode 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82 7.4 a/d converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83 7.4.1 function and control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83 7.4.1.1 lnitialization and input channel selection . . . . . . . . . . . . . . . . . . . . . . . . . . .83 7.4.1.2 start of conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87 7.4.2 reference voltages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87 7.4.3 a/d converter timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91 7.5 the compare/capture unit (ccu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93 7.5.1 timer 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97 7.5.2 the compare timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101 7.5.3 compare function in the ccu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103 7.5.4 compare modes of the ccu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .103 7.5.4.1 compare mode 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104 7.5.4.2 compare mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106 7.5.5 timer/compare register configurations in the ccu . . . . . . . . . . . . . . . . . .107 7.5.5.1 compare function of timer 2 with registers crc, cc1 to cc4 . . . . . . . . .108 7.5.5.2 compare function of registers cm0 to cm7 . . . . . . . . . . . . . . . . . . . . . . .116 7.5.6 capture function in the ccu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .123 7.6 arithmetic unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126 7.6.1 programming the mdu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126 7.6.2 multiplication/division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128 7.6.3 normalize and shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129 7.6.4 the overflow flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132 7.6.5 the error flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132 7.7 power saving modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134 7.7.1 idle mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .136 7.7.2 power-down mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139 7.7.3 slow-down mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140 7.8 fail save mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141 80c517/80c537 semiconductor group 7 table of contents page 7.8.1 programmable watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141 7.8.2 oscillator watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146 7.9 oscillator and clock circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148 7.10 system clock output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .150 8 interrupt system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152 8.1 interrupt structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .152 8.2 priority level structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .162 8.3 how interrupts are handled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .164 8.4 external interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167 8.5 response time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168 9 instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169 9.1 addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169 9.2 introduction to the instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171 9.2.1 data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .171 9.2.2 arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .172 9.2.3 logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174 9.2.4 control transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174 9.3 instruction definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .176 10 application examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .256 10.1 application examples for the compare functions . . . . . . . . . . . . . . . . . . . .256 10.1.1 generation of two different pwm signals with "additive compare" using the "ccx registers" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .256 10.1.2 sine-wave generation with a cmx registers/compare timer configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .258 10.2 using an sab 80c537 with external program memory and additional external data memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .263 11 device specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .265 semiconductor group 8 introduction 1 introduction the sab 80c517/80c537 is a high-end microcontroller in the siemens sab 8051 8-bit microcontroller family. lt is based on the well-known industry standard 8051 architecture; a great number of enhancements and new peripheral features extend its capabilities to meet the extensive requirements of new applications. nevertheless, the sab 80c517 maintains compatibility within the siemens sab 8051 family; in fact, the sab 80c517 is a superset of the siemens sab 80c515/ 80c535 microcontroller thus offering an easy upgrade path for sab 80(c)515/80(c)535 users. in addition to all features of the sab 80c515, there are several enhancements for higher performance. the sab 80c517 has been expanded e.g. in its arithmetic characteristics, fail save mechanisms, analog signal processing facilities and timer capabilities. listed below is a summary of the main features of the sab 80c517/80c537: l 8 kbyte on-chip program memory (sab 80c517 only) l romiess version also available (sab 80c537) l full compatibility with sab 80c515/80c535 l 256 byte on-chip ram l 256 directly addressable bits l 1 microsecond instruction cycle at 12-mhz oscillator frequency l 64 of 111 instructions are executed in one instruction cycle l external program and data memory expandable up to 64 kbyte each l 8-bit a/d converter C 12 multiplexed inputs C programmable reference voltages C external/internal start of conversion l two 16-bit timers/counters (8051 compatible) l powerful compare/capture unit (ccu) based on a 16-bit timer/counter and a high-speed 16-bit timer for fast compare functions C one 16-bit reload/compare/capture register C four 16-bit compare/capture registers, one of which serves up to nine compare channels (concurrent compare) l eight fast 16-bit compare registers l arithmetic unit for division, multiplication, shift and normalize operations l eight datapointers instead of one for indirect addressing of program and external data memory l extended watchdog facilities C 16-bit programmable watchdog timer C oscillator watchdog semiconductor group 9 introduction l nine ports C seven bidirectional 8-bit ports C one 8-bit and one 4-bit input port for analog and digital input signals l two full-duplex serial interfaces with own baud rate generators l four priority level interrupt systems, 14 interrupt vectors l three power saving modes C slow-down mode C idle mode C power-down mode l siemens high-performance acmos technology l p-lcc-84 package the romiess version sab 80c537 is identical with the sab 80c517 except for the fact that it lacks the on-chip program memory; the sab 80c537 is designed for applications with external program memory. in this manual, any reference made to the sab 80c517 applies to both versions, the sab 80c517 and the sab 80c537, unless otherwise noted. figure 1-1 shows the logic symbol of the sab 80c517: figure 1-1 logic symbol semiconductor group 10 fundamental structure 2 fundamental structure the sab 80c517 is a totally 8051-compatible microcontroller while its peripheral performance has been increased significantly. lt includes the complete sab 80(c)515, providing 100% upward compatibility. this means that all existing 80515 programs or users program libraries can be used further on without restriction and may be easily extended to the new sab 80c517. the sab 80c517 is in the siemens line of highly integrated microcontrollers for control applications. some of the various on-chip peripherals have been added to support the 8-bit core in case of stringent real-time requirements. the 32-bit/16-bit arithmetic unit, the improved 4-level interrupt structure and the increased number of eight 16-bit datapointers are meant to give such a cpu support. but strict compatibility to the 8051 architecture is a principle of the sab 80c517s design. furthermore, the sab 80c517 contains three additional 8-bit i/o ports and twelve general input lines. the additional serial channel is compatible to an 8051-uart and provided with an independent and freely programmable baud rate generator. an 8-bit resolution a/d-converter with software-adjustable reference voltages has been integrated to allow analog signal processing. as a counterpart to the a/d converter, the sab 80c517 includes a powerful compare/capture unit with two 16-bit timers for all kinds of digital signal processing. the controller has been completed with well considered provisions for "fail-safe" reaction in critical applications and offers all cmos features like low power consumption as well as an idle, power-down and slow-down mode. figure 2-1 shows a block diagram of the sab 80c517. readers who are familiar with the sab 8051 or sab 80515 may concentrate on chapters 6 and 7 where the reset conditions and the new peripheral components are described. chapter 8 (interrupt system) has a special section for 80515 professionals where enhancements of the interrupt structure compared to the sab 80515 are summarized. for readers, however, who are newcomers to the 8051 family of microcontrollers, the following section may give a general view of the basic characteristics of the sab 80c517. the details of operation are described later in chapters 3 and 4. semiconductor group 11 fundamental structure figure 2-1 functional block diagram semiconductor group 12 fundamental structure central processing unit the cpu is designed to operate on bits and bytes. the instructions, which consist of up to 3 bytes, are performed in one, two or four machine cycles. one machine cycle requires twelve oscillator cycles. the instruction set has extensive facilities for data transfer, logic and arithmetic instructions. the boolean processor has its own full-featured and bit-based instructions within the instruction set. the sab 80c517 uses five addressing modes: direct access, immediate, register, register indirect access, and for accessing the external data or program memory portions a base register plus index- register indirect addressing. memory organization the sab 80c517 has an internal rom of 8 kbyte. the program memory can externally be expanded up to 64 kbyte (see bus expansion control). the internal ram consists of 256 bytes. within this address space there are 128 bit-addressable locations and four register banks, each with 8 general purpose registers. in addition to the internal ram there is a further 128-byte address space for the special function registers, which are described in sections to follow. because of its harvard architecture, the sab 80c517 distinguishes between an external program memory portion (as mentioned above) and up to 64 kbyte external data memory accessed by a set of special instructions. as an important improvement of the 8051 architecture, the sab 80c517 contains eight datapointers (instead of one in the 8051) which speed up external data access. bus expansion control the external bus interface of the sab 80c517 consists of an 8-bit data bus (port 0), a 16-bit address bus (port 0 and port 2) and five control lines. the address latch enable signal (ale) is used to demultiplex address and data of port 0. the program memory is accessed by the program store enable signal (psen ) twice a machine cycle. a separate external access line (ea ) is used to inform the controller while executing out of the lower 8 kbyte of the program memory, whether to operate out of the internal or external program memory. the read or write strobe (rd , wr ) is used for accessing the external data memory. peripheral control all on-chip peripheral components - i/o ports, serial interfaces, timers, compare/capture registers, the interrupt controller and the a/d converter - are handled and controlled by the so-called special function registers. these registers constitute the easy-to-handle interface with the peripherals. this peripheral control concept, as implemented in the sab 8051, provides the high flexibility for further expansion as done in the sab 80c517. moreover some of the special function registers, like accumulator, bregister, program status word (psw), stack pointer (sp) and the data pointers (dptr) are used by the cpu and maintain the machine status. semiconductor group 13 central processing unit 3 central processing unit 3.1 general description the cpu (central processing unit) of the sab 80c517 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. they 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 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, bcd-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 of set, clear, complement, 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 a, b and psw registers are described in section 4.4. 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 pc is manipulated by the control transfer instructions listed in the chapter "instruction set". the conditional branch logic enables internal and external events to the processor to cause a change in the program execution sequence. semiconductor group 14 central processing unit 3.2 cpu timing a machine cycle consists of 6 states (12 oscillator periods). each state is divided into a phase 1 half, during which the phase 1 clock is active, and a phase 2 half, during which the phase 2 clock is active. thus, a machine cycle consists of 12 oscillator periods, numbered s1p1 (state 1, phase 1) through s6p2 (state 6, phase 2). each state lasts for two oscillator periods. typically, arithmetic and logical operations take place during phase 1 and internal register-to-register transfers take place during phase 2. the diagrams in figure 3-1 show the fetch/execute timing related to the internal states and phases. since these internal clock signals are not user-accessible, the xtal2 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 op-code is latched into the instruction register. lf it is a two-byte instruction, the second is read during s4 of the same machine cycle. lf it is a one-byte instruction, there is still a fetch at s4, but the byte read (which would be the next op- code) is ignored, and the program counter is not incremented. in any case, execution is completed at the end of s6p2. figures 3-1 a) and b) show the timing of a 1-byte, 1-cycle instruction and for a 2-byte, 1-cycle instruction. most sab 80c517 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 one-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. figures 3-1 c) and d) show the timing for a normal 1-byte, 2-cycle instruction and for a movx instruction. semiconductor group 15 central processing unit figure 3-1 fetch/execute sequence semiconductor group 16 memory organization 4 memory organization the sab 80c517 cpu manipulates operands in the following four address spaces: C up to 64 kbyte of program memory C up to 64 kbyte of external data memory C 256 bytes of internal data memory C a 128-byte special function register area 4.1 program memory the program memory of the sab 80c517 consists of an internal and an external memory portion ( see figure 4-1 ). 8 kbytes of program memory may reside on-chip (sab 80c517 only), while the sab 80c537 has no internal rom. the program memory can be externally expanded up to 64 kbyte. lf the ea pin is held high, the sab 80c517 executes out of the internal program memory unless the address exceeds 1 fff h . locations 2000 h through 0ffff h are then fetched from the external program memory. lf the ea pin is held low, the sab 80c517 fetches all instructions from the external program memory. since the sab 80c537 has no internal program memory, pin ea must be tied low when using this device. in either case, the 16-bit program counter is the addressing mechanism. locations 03 h through 93 h in the program memory are used by interrupt service routines. 4.2 data memory the data memory address space consists of an internal and an external memory portion. internal data memory the internal data memory address space is divided into three physically separate and distinct blocks: the lower 128 byte of ram, the upper ram area, and the 128-byte special function register (sfr) area ( see figure 4-2 ). while the latter sfr area and the upper ram area share the same address locations, they must be accessed through different addressing modes. the map in figure 4-2 and the following table show the addressing modes used for the different ram/sfr spaces. semiconductor group 17 memory organization for details about the addressing modes see chapter 9.1. figure 4-1 program memory address space the lower 128 bytes of the internal ram are again grouped in three address spaces ( see figure 4-3 ): 1) a general purpose register area occupies locations 0 trough 1f h (see also section 4.3). 2) the next 16 bytes, locations 20 h through 2f h , contain 128 directly addressable bits. (programming information: these bits can be referred to in two ways, both of which are acceptable for the asm51. one way is to refer to their addresses, i.e. 0 to 7f h . the other way is with reference to bytes 20 h to 2f h . thus bits 0 to 7 can also be referred to as bits 20.0-20.7, and bits 8-0f h are the same as 21.0-21.7 and so on. each of the 16 bytes in this segment may also be addressed as a byte.) 3) locations 30 h to 7f h can be used as a scratch pad area. address space locations addressing mode lower 128 bytes of ram 00 h to 7f h direct/indirect upper 128 bytes of ram 80 h to 0ff h indirect special function registers 80 h to 0ff h direct semiconductor group 18 memory organization using the stack pointer (sp) - a special function register described in section 4.4 - the stack can be located anywhere in the whole internal data memory address space. the stack depth is limited only by the internal ram available (256 byte maximum). however, pay attention to the fact that the stack is not overwritten by other data, and vice versa. external data memory figure 4-2 and 4-3 contain memory maps which illustrate the internal/external data memory. to address data memory external to the chip, the "movx" instructions in combination with a 16-bit datapointer or an 8-bit general purpose register are used. refer to chapter 9 (instruction set) or 5 (external bus interface) for detailed descriptions of these operations. a maximum of 64 kbytes of external data memory can be accessed by instructions using a 16-bit address. the datapointer structure in the sab 80c517 deserves special attention, since it consists of eight 16-bit registers which can be alternatively selected as datapointers. see section 4.4 and chapter 5 for further details. figure 4-2 data memory / sfr address spaces semiconductor group 19 memory organization figure 4-3 mapping of the lower portion of the internal data memory semiconductor group 20 memory organization 4.3 general purpose registers the lower 32 locations of the internal ram are assigned to four banks with eight general purpose registers (gprs) each. only one of these banks may be enabled at a time. two bits in the program status word, psw.3 and psw.4, select the active register bank (see description of the psw). this allows fast context switching, which is useful when entering subroutines or interrupt service routines. asm51 and the device sab 80c517 default to register bank 0. the 8 general purpose registers of the selected register bank may be accessed by register addressing. with register addressing the instruction of code 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 which is not used for data storage. 4.4 special function registers the special function register (sfr) area has two important functions. firstly, all cpu registers except the program counter and the four register banks reside here. the cpu registers are the arithmetic registers like a, b, psw and pointers like sp, dphx and dplx. secondly, a number of registers constitute the interface between the cpu and all on-chip peripherals. that means, all control and data transfers from and to the peripherals use this register interface exclusively. the special function register area is located in the address space above the internal ram from addresses 80 h to ff h . all 81 special function registers of the sab 80c517 reside here. sixteen sfrs, that are located on addresses dividable by eight, are bit-addressable, thus allowing 128 bit-addressable locations within the sfr area. since the sfr area is memory mapped, access to the special function registers is as easy as with the internal ram, and they may be processed with most instructions. in addition, if the special functions are not used, some of them may be used as general scratch pad registers. note, however, all sfrs can be accessed by direct addressing only. the special function registers are listed in the following tables where they are organized in functional groups which refer to the functional blocks of the sab 80c517. block names and symbols are listed in alphabetical order. bit addressable special function registers are marked with a dot in the fifth column. special function registers with bits belonging to more then one functional block are marked with an asterisk at the symbol name. semiconductor group 21 memory organization 1) bit-addressable special function registers. 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate. special function registers of the sab 80c517 block symbol name address contents after reset cpu acc b dph dpl dpsel psw sp accumulator b-register data pointer, high byte data pointer, low byte data pointer select register program status word register stack pointer 0e0 h 1) 0f0 h 1) 83 h 82 h 92 h 0d0 h 1) 81 h 00 h 00 h 00 h 00 h xxxx.x000 b 3) 00 h 07 h a/d- converter adcon0 adcon1 addat dapr a/d converter control register 0 a/d converter control register 1 a/d converter data register d/a converter program register 0d8 h 1) 0dc h 0d9 h 0da h 00 h xxxx.0000 b 3) 00 h 00 h interrupt system ien0 ctcon 2) ien1 ien2 ip0 ip1 ircon tcon 2) t2con 2) interrupt enable register 0 com. timer control register interrupt enable register 1 interrupt enable register 2 interrupt priority register 0 interrupt priority register 1 interrupt request control register timer control register timer 2 control register 0a8 h 1) 0e1 h 0b8 h 1) 9a h 0a9 h 0b9 h 0c0 h 1) 88 h 1) 0c8 h 1) 00 h 0xxx.0000 b 3) 00 h xxxx.00x0 b 3) 00 h xx00.0000 b 3) 00 h 00 h 00 h mul/div unit arcon md0 md1 md2 md3 md4 md5 arithmetic control register multiplication/division register 0 multiplication/division register 1 multiplication/division register 2 multiplication/division register 3 multiplication/division register 4 multiplication/division register 5 0ef h 0e9 h 0ea h 0eb h 0ec h 0ed h 0ee h 0xxx.xxxx b 3) xx h 3) xx h 3) xx h 3) xx h 3) xx h 3) xx h 3) semiconductor group 22 memory organization 1) bit-addressable special function registers. 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate. special function registers of the sab 80c517 (contd) block symbol name address contents after reset compare/ capture unit (ccu) ccen cc4en cch1 cch2 cch3 cch4 ccl1 ccl2 ccl3 ccl4 cmen cmh0 cmh1 cmh2 cmh3 cmh4 cmh5 cmh6 cmh7 cml0 cml1 cml2 cml3 cml4 cml5 cml6 cml7 cmsel crch crcl ctcon ctrelh ctrell th2 tl2 t2con compare/capture enable register compare/capture 4 enable register compare/capture register 1, high byte compare/capture register 2, high byte compare/capture register 3, high byte compare/capture register 4, high byte compare/capture register 1, low byte compare/capture register 2, low byte compare/capture register 3, low byte compare/capture register 4, low byte compare enable register compare register 0, high byte compare register 1, high byte compare register 2, high byte compare register 3, high byte compare register 4, high byte compare register 5, high byte compare register 6, high byte compare register 7, high byte compare register 0, low byte compare register 1, low byte compare register 2, low byte compare register 3, low byte compare register 4, low byte compare register 5, low byte compare register 6, low byte compare register 7, low byte compare input select com./rel./capt. register, high byte com./rel./capt. register, low byte com. timer control register com. timer rel. register, high byte com. timer rel. register, low byte timer 2, high byte timer 2, low byte timer 2 control register 0c1 h 0c9 h 0c3 h 0c5 h 0c7 h 0cf h 0c2 h 0c4 h 0c6 h 0ce h 0f6 h 0d3 h 0d5 h 0d7 h 0e3 h 0e5 h 0e7 h 0f3 h 0f5 h 0d2 h 0d4 h 0d6 h 0e2 h 0e4 h 0e6 h 0f2 h 0f4 h 0f7 h 0cb h 0ca h 0e1 h 0df h 0de h 0cd h 0cc h 0c8 h 1) 00 h x000.0000 b 3) 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 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 0xxx.0000 b 3) 00 h 00 h 00 h 00 h 00 h semiconductor group 23 memory organization 1) bit-addressable special function registers. 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate. 4) these registers are available in the ca step and later steps. special function registers of the sab 80c517 (contd) block symbol name address contents after reset ports p0 p1 p2 p3 p4 p5 p6 p7 p8 port 0 port 1 port 2 port 3 port 4 port 5 port 6 port 7, analog/digital input port 8, analog/digital input, 4bit 80 h 1) 90 h 1) 0a0 h 1 ) 0b0 h 1) 0e8 h 1) 0f8 h 1) 0fa h 0db h 0dd h ff h ff h ff h ff h ff h ff h ff h xx h 3) xx h 3) pow. sav.m pcon power control register 87 h 00 h serial channels adcon0 2) pcon 2) s0buf s0con s0rell 4) s0relh 4) s1buf s1con s1rel s1relh 4) a/d converter control register power control register serial channel 0, buffer register serial channel 0 control register serial channel 0, reload reg., low byte serial channel 0, reload reg., high byte serial channel 1, buffer register serial channel 1, control register serial channel 1, reload register serial channel 1, reload reg., high byte 0d8 h 1) 87 h 99 h 98h 1) 0aa h 0ba h 9c h 9b h 9d h obb h 00 h 00 h xx h 3) 00 h 0d9 h xxxx.xx11 b 3) xx h 3) 0x00.0000 b 3) 00 h xxxx.xx11b 3) timer0/ timer1 tcon th0 th1 tl0 tl1 tmod timer 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 watchdog ien0 2) ien1 2) ip0 2) ip1 2) wdtrel interrupt enable register 0 interrupt enable register 1 interrupt priority register 0 interrupt priority register 1 watchdog timer reload register 0a8 h 1) 0b8 h 1) 0a9 h 0b9 h 86 h 00 h 00 h 00 h xx00.0000 b 3) 00 h semiconductor group 24 memory organization the following paragraphs give a general overview of the special function registers and refer to sections where a more detailed description can be found. accumulator, sfr address 0e0 h acc is the symbol for the accumulator register. the mnemonics for accumulator-specific instructions, however, refer to the accumulator simply as a. program status word register (psw), sfr address 0d0 h the psw register contains program status information. b register, sfr address 0f0 h 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. bit function cy carry flag ac auxiliary carry flag (for bcd operations) f0 general purpose user flag 0 rs1 rs0 00 01 10 11 register bank select control bits bank 0 selected, data address 00 h -07 h bank 1 selected, data address 08 h -0f h bank 2 selected, data address 10 h -17 h bank 3 selected, data address 18 h -1f h ov overflow flag f1 general purpose user flag 1 p parity flag. set/cleared by hardware each instruction cycle to indicate an odd/even number of "one" bits in the accumulator, i.e. even parity. 0d7 h 0d6 h 0d5 h 0d4 h 0d3 h 0d2 h 0d1 h 0d0 h cy ac f0 rs1 rs0 ov f1 p 0d0 h psw semiconductor group 25 memory organization stack pointer, sfr address 081 h the stack pointer (sp) register is 8 bits wide. lt 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 on-chip ram, the stack pointer is initialized to 07 h after a reset. this causes the stack to begin at location 08 h above register bank zero. the sp can be read or written under software control. datapointer, sfr address 082 h and 083 h datapointer select register, sfr address 092 h as a functional enhancement to standard 8051 controllers, the sab 80c517 contains eight 16-bit registers which can be used as datapointers. to be compatible with 8051 architecture, the instruction set uses just one of these datapointers at a time. the selection of the actual datapointer is done in special function register dpsel (datapointer select register, address 92 h ). each 16-bit datapointer (dptrx) register is a concatenation of registers dphx (data pointers high order byte) and dplx (data pointers low order byte). these pointers are used in register-indirect addressing to move program memory constants and external data memory variables, as well as to branch within the 64-kbyte program memory address space. since the datapointers are mainly used to access the external world, they are described in more detail in section 5.2. ports 0 to 8 p0 to p8 are the sfr latches to port 0 to 8, respectively. the port sfrs 0 to 5 are bit-addressable. ports 0 to 6 are 8-bit i/o ports (that is in total 56 i/o lines) which may be used as general purpose ports and which provide alternate output functions dedicated to the on-chip peripherals of the sab 80c517. port 7 (8-bit) and port 8 (4-bit) are general purpose input ports and have no internal latch. that means, these port lines are used for the 12 multiplexed input lines of the a/d converter but can also be used as digital inputs. p7/p8 are the associated sfrs when the digital value is to be read by the cpu. both ports can be read only. you can find more about the ports in section 7.1 (parallel i/o). semiconductor group 26 memory organization peripheral control, data and status registers most of the special function registers are used as control, status and data registers to handle the on-chip peripherals. in the special function register table the register names are organized in groups and each of these groups refer to one peripheral unit. more details on how to program these registers are given in the descriptions of the following peripheral units: unit symbol section ports C7.1 serial channels C 7.2 timer 0/1 C 7.3 a/d converter adc 7.4 compare/capture unit ccu 7.5 arithmetic unit (mul/div unit) mdu 7.6 power saving control unit C 7.7 watchdog unit wdt/owd 7.8 interrupt system C 8 semiconductor group 27 external bus interface 5 external bus interface the sab 80c517 allows for external memory expansion. to accomplish this, the external bus interface common to most 8051-based controllers is employed. to speed up external bus accesses, the sab 80c517 contains eight 16-bit registers used as datapointers. this enhancement to the 8051 architecture is described in section 5.2. 5.1 accessing external memory lt is possible to distinguish between accesses to external program memory and external data memory or 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, see section 7.1.). 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 (for further details see chapter 7.1). 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). 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 0ff 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 special function register). thus the port 2 latch does not have to contain 1s, and the contents of the port 2 sfr are not modified. lf 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. lt 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. semiconductor group 28 external bus interface timing the timing of the external bus interface, in particular the relationship between the control signals ale, psen , rd /wr and information on port 0 and port 2, is illustrated in figure 5-2 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. for further information see section 5.3. external program memory access the external program memory is accessed under two conditions: C whenever signal ea is active; or C whenever the program counter (pc) contains a number that is larger than 01fff h this requires the romiess version sab 80c537 to have ea wired low to allow the lower 8 k program bytes to be fetched from external memory. when the cpu is executing out of external program memory, all 8 bits of port 2 are dedicated to an output function and may not be used for general-purpose i/o. the contents of the port 2 sfr however is not affected. during external program memory fetches port 2 lines output the high byte of the pc, and 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). since the sab 80c537 has no internal program memory, accesses to program memory are always external, and port 2 is at all times dedicated to output the high-order address byte. this means that port 0 and port 2 of the sab 80c537 can never be used as general-purpose i/o. this also applies to the sab 80c517 when it is operated with only an external program memory. semiconductor group 29 external bus interface 5.2 eight datapointers for faster external bus access 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 to be done byte by byte. for complex applications with numerous external peripherals or extended data storage capacity this turned out to be a "bottle neck" for the 8051s communication to the external world. especially programming in high-level languages (plm51, "c", 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. how the eight datapointers of the sab 80c517 are realized simply adding more datapointers is not suitable because of the need to keep up 100% compatibility to the 8051 instruction set. this instruction set, however, 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 to 8051 architecture) the sab 80c517 contains a set of eight 16-bit registers from which the actual datapointer can be selected. this means that the users 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 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 sab 80c517 which handle the datapointer therefore affect only one of the eight pointers which is addressed by dpsel at that very moment. figure 5-1 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. semiconductor group 30 external bus interface figure 5-1 accessing of external data memory via multiple datapointers advantages of multiple datapointers using the above addressing mechanism 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 single instruction, which 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 not only takes more time, it also requires additional space in the internal ram. application example and performance analysis the following example shall demonstrate the involvement 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 semiconductor group 31 external bus interface 1) using only one datapointer (code for an 8051) initialization routine table look-up routine under real time conditions action code initialize shadow_variables with source_pointer mov low(src_ptr), #0ffh mov high(src_ptr), #1fh initialize shadow_variables with destination_pointer mov low(des_ptr), #0a0h mov high(des_ptr), #2fh action code machine cycles save old datapointer push dpl push dph 2 2 load source pointer mov dpl, low(src_ptr) mov dph, high(src_ptr) 2 2 increment and check for end of table (execution time not relevant for this consideration) inc dptr cjne C C C fetch source data byte from rom table movc a,@dptr 2 save source_pointer and load destination_pointer mov low(src_ptr), dpl mov high(src_ptr), dph mov dpl, low(des_ptr) mov dph, high(des_ptr) 2 2 2 2 increment destination_pointer (ex. time not relevant) inc dptr C transfer byte to destination address movx @dptr, a 2 save destination_pointer mov low(des_ptr), dpl mov high(des_ptr),dph 2 2 restore old datapointer pop dph pop dpl 2 2 total execution time (machine cycles) C 28 semiconductor group 32 external bus interface 2) using two datapointers (code for an sab 80c517) initialization routine table look-up routine under real time conditions the above example shows that utilization of the sab 80c517s 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. this means for some applications where all eight datapointers are employed that an sab 80c517 program has up to 24 byte (16 variables and 8 stack bytes) of the internal ram free for other use. action code initialize dptr6 with source pointer mov dpsel, #06h mov dptr, #1fffh initialize dptr7 with destination pointer mov dpsel, #07h mov dptr, #2fa0h action code machine cycles save old source pointer push dpsel 2 load source pointer mov dpsel, #06h 2 increment and check for end of table (execution time not relevant for this consideration) inc dptr cjne C C C fetch source data byte from rom table movc a,@dptr 2 save source_pointer and load destination_pointer mov dpsel, #07h 2 transfer byte to destination address movx @dptr, a 2 save destination pointer and restore old datapointer pop dpsel 2 total execution time (machine cycles) C 12 semiconductor group 33 external bus interface 5.3 psen , program store enable the read strobe for external fetches is psen . psen is not activated for internal fetches. when the cpu is accessing external program memory, psen is activated twice every cycle (except during a movx instruction) no matter 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 12 osillator periods. a complete psen cycle, including activation and deactivation of ale and psen takes 6 oscillator periods. the execution sequence for these two types of read cycles is shown in figure 5-2 a) and b) . 5.4 ale, address latch enable the main function of ale is to provide a properly timed signal to latch the low byte of an address from p0 into an external latch during fetches from external memory. the address byte is valid at the negative transition of ale. for that purpose, ale is activated twice every machine cycle. this activation takes place even if the cycle involves no external fetch. the only time no ale pulse comes out is during an access to external data memory when rd /wr signals are active. the first ale of the second cycle of a movx instruction is missing ( see figure 5-2 b) ). consequently, in any system that does not use data memory, ale is activated at a constant rate of 1/6 of the oscillator frequency and can be used for external clocking or timing purposes. 5.5 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 sab 80c517, the external program and data memory spaces can be combined by and-ing psen and rd . a positive logic and of these two signals produces an active low 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. semiconductor group 34 external bus interface figure 5-2 a) and b) external program memory execution semiconductor group 35 system reset 6 system reset 6.1 hardware reset and power-up reset 6.1.1 reset function and circuitries the hardware reset function incorporated in the sab 80c517 allows for an easy automatic start-up at 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 particularly done when the power-down mode (see section 7.7) is to be terminated. additionally to the hardware reset, which is applied externally to the sab 80c517, there are two internal reset sources, the watchdog timer and the oscillator watchdog. they are described in detail in section 7.8 "fail-save mechanisms". the chapter at hand only deals with the external hardware reset. the reset input is an active low input at pin 10 (reset ). an internal schmitt trigger is used at the input for noise rejection. since the reset is synchronized internally, the reset pin must be held low for at least two machine cycles (24 oscillator periods) while the oscillator is running. with the oscillator running the internal reset is executed during the second machine cycle in which reset is low and is repeated every cycle until reset goes high 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 which are reserved for test purposes. this in turn may cause unpredictable output operations at several port pins). a pullup resistor is internally connected to v cc to allow a power-up reset with an external capacitor only. an automatic reset can be obtained when v cc is applied by connecting the reset pin to v ss via a capacitor as shown in figure 6-1 a) and c) . after v cc has been turned on, the capacitor must hold the voltage level at the reset pin for a specified time below the upper threshold of the schmitt trigger to effect a complete reset. semiconductor group 36 system reset the time required 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 usually met using a capacitor of 4.7 to 10 microfarad. the same considerations apply if the reset signal is generated externally ( figure 6-1 b ). in each case it must be assured that the oscillator has started up properly and that at least two machine cycles have passed before the reset signal goes inactive. figure 6-1 reset circuitries a correct reset leaves the processor in a defined state. the program execution starts at location 0000 h . the default values of the special function registers (sfr) to which they are forced during reset are listed in table 6-1 . after reset is internally accomplished the port latches of ports 0 to 6 default in 0ff 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 through 6) output a one (1). ports 7 and 8, which are input-only ports, have no internal latch and therefore the contents of the special function registers p7 and p8 depend on the levels applied to ports 7 and 8. the contents of the internal ram of the sab 80c517 is not affected by a reset. after power-up the contents is undefined, while it remains unchanged during a reset it the power supply is not turned off. semiconductor group 37 system reset table 6-1 register contents register contents pc 0000 h ien0, ien1 00 h acc 00 h ien2 xxxx 00x0 b adcon0 00 h ip0 ip1 00 h xx00.0000 b adcon1 xxxx 0000 b ircon 00 h addat 00 h md0-5 xx h arcon 0xxx xxxx b p0-p6 0ff h b00 h pcon 00 h ccl1-4 00 h psw 00 h cch1-4 00 h s0buf, s1buf 0xx h ccen 00 h s0con 00 h cc4en 00 h s1con 0x00 0000 b cmen 00 h s1rel 00 h cml0-7 00 h sp 07 h cmh0-7 00 h tcon 00 h cmsel 00 h tl0, th0 00 h crcl, crch 00 h tl1, th1 00 h ctcon 0xxx 0000 b tl2, th2 00 h ctrell, ctrelh 00 h tmod 00 h dapr 00 h t2con 00 h dpsel xxxx x000 b wdtrel 00 h dptr0-7 0000 h CC semiconductor group 38 system reset 6.1.2 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 to the internal cpu timing. when the reset is found active (low level at pin 10) the internal reset procedure is started. lt needs two complete machine cycles to put the complete device to its correct reset state, i.e. all special function registers contain their default values, the port latches contain 1s etc. note that this reset procedure is not performed if there is no clock available at the device (this can be avoided using the oscillator watchdog, which provides an auxiliary clock for performing a correct reset without clock at the xtal1 and xtal2 pins. see section 7.8 for further details). the reset signal must be active for at least two machine cycles; after this time the sab 80c517 remains in its reset state as long as the signal is active. when the signal goes inactive this transition is recognized in the following state 5 phase 2 of the machine cycle. then the processor starts its address output (when configured for external rom) in the following state 5 phase 1. one phase later (state 5 phase 2) the first falling edge at pin ale occurs. figure 6-2 shows this timing for a configuration with ea = 0 (external program memory). thus, between the release of the reset signal and the first falling edge at ale there is a time period of at least one machine cycle but less than two machine cycles. figure 6-2 cpu timing after reset semiconductor group 39 system reset 6.2 reset output pin (ro ) as mentioned before the sab 80c517 internally synchronizes an external reset signal at pin reset in order to perform a reset procedure. additionally, the sab 80c517 provides several "fail- save" mechanisms, e.g. watchdog timer and oscillator watchdog, which can internally generate a reset, too. thus, it is often important to inform also the peripherals external to the chip that a reset is being performed and that the controller will soon start its program again. for that purpose, the sab 80c517 has a pin dedicated to output the internal reset request. this reset output (ro ) at pin 82 shows the internal (and already synchronized) reset signal requested by any of the three possible sources in the sab 80c517: external hardware reset, watchdog timer reset, oscillator watchdog reset. the duration of the active low signal of the reset output depends on the source which requests it. in the case of the external hardware reset it is the synchronized external reset signal at pin reset . in the case of a watchdog timer reset or oscillator watchdog reset the reset out signal takes at least two machine cycles, which is the minimal duration for a reset request allowed. for details - how the reset requests are or-ed together and how long they last - see also chapter 7.8 "fail-save mechanisms". semiconductor group 40 on-chip peripheral components 7 on-chip peripheral components this chapter gives detailed information about all on-chip peripherals of the sab 80c517 except for the integrated interrupt controller, which is described separately in chapter 8. sections 7.1 and 7.2 are associated with the general parallel and serial i/o facilities while the remaining sections describe the miscellaneous functions such as the timers, a/d converter, compare/capture unit, multiplication/division unit, power saving modes, "fail-save" mechanisms, oscillator and clock circuitries and system clock output. 7.1 parallel i/o 7.1.1 port structures digital i/o the sab 80c517 allows for digital i/o on 56 lines grouped into 7 bidirectional 8-bit 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 through p6 are performed via their corresponding special function registers p0 to p6. 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 sfr contents (see also chapter 7.1.2 and chapter 5 for more details about the external bus interface). digital/analog input ports ports 7 and 8 are available as input ports only and provide for two functions. when used as digital inputs, the corresponding sfrs p7 and p8 contain the digital value applied to port 7 and port 8 lines. when used for analog inputs the desired analog channel is selected by a three-bit field in sfr adcon0 or a four-bit field in sfr adcon1, as described in section 7.4. of course, it makes no sense to output a value to these input-only ports by writing to the sfrs p7 or p8; this will have no effect. lf a digital value is to be read, the voltage levels are to be held within the input voltage specifications ( v il / v ih ). since p7 and p8 are not bit-addressable registers, all input lines of p7 or p8 are read at the same time by byte instructions. semiconductor group 41 on-chip peripheral components nevertheless, it is possible to use ports 7 and 8 simultaneously for analog and digital input. however, care must be taken that all bits of p7 or p8 that have an undetermined value caused by their analog function are masked. in order to guarantee a high-quality a/d conversion, digital input lines of port 7 and port 8 should not toggle while a neighbouring port pin is executing an a/d conversion. this could produce crosstalk to the analog signal. digital i/o port circuitry figure 7-1 shows a functional diagram of a typical bit latch and i/o buffer, which is the core of each of the 7 i/o-ports. the bit latch (one bit in the ports sfr) is represented as a type-d flip-flop, which 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 self 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 p6) activate the "read-latch" signal, while others activate the "read-pin" signal (see section 7.1.4.3). figure 7-1 basic structure of a port circuitry mcs01822 d clk port latch q q port read latch to latch read pin write int. bus port driver circuit pin semiconductor group 42 on-chip peripheral components port 1 through 6 output drivers have internal pullup fets ( see figure 7-2 ). each i/o line can be used independently as an input or output. to be used as an input, the port bit must contain a one (1) (that means for figure 7-2 : q = 0), which turns off the output driver fet n1. then, for ports 1 through 6, the pin is pulled high by the internal pullups, 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 sometimes called "quasi-bidirectional". figure 7-2 basic output driver circuit of ports 1 through 6 in fact, the pullups mentioned before and included in figure 7-2 are pullup arrangements as shown in figure 7-3 . one n-channel pulldown fet and three pullup fets are used: C the pulldown fet n1 is of n-channel type. lt is a very strong driver transistor which is capable of sinking high currents ( i ol ); it is only activated if a "0" is programmed to the port pin. a short circuit to v cc must be avoided if the transistor is turned on, since the high current might destroy the fet. C the pullup fet p1 is of p-channel type. lt 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 pullup can drive a similar current as the pulldown fet n1. this provides a fast transition of the logic levels at the pin. mcs01823 d clk bit latch q q internal pull up arrangement pin read latch to latch read pin write v cc int. bus n1 semiconductor group 43 on-chip peripheral components Cthe pullup fet p2 is of p-channel type. lt is always activated when a "1" is in the port latch, thus providing the logic high output level. this pullup 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. Cthe pullup fet p3 is of p-channel type. lt is only activated if the voltage at the port pin is higher than approximately 1.0 to 1.5 v. this provides an additional pullup current if a logic high level shall be output at the pin (and the voltage is not forced lower than approximately 1.0 to 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 pullup fet p2 is active, which sources the current i il . lf, in addition, the pullup fet p3 is activated, a higher current can be sourced ( i tl ). thus, an additional power consumption can be avoided if port pins are used as inputs with a low level applied. however, the driving cabability is stronger if a logic high level is output. figure 7-3 output driver circiut of ports 1 through 6 the described activating and deactivating of the four different transistors translates into four states the pins can be: C input low state (il), p2 active only C input high state (ih) = steady output high state (soh), p2 and p3 active C forced output high state (foh), p1, p2 and p3 active C output low state (ol), n1 active semiconductor group 44 on-chip peripheral components 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 p3s 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, 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 this 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. port 0, in contrast to ports 1 through 6, is considered as "true" bidirectional, because the port 0 pins float when configured as inputs. thus, this port differs in not having internal pullups. the pullup fet in the p0 output driver ( see figure 7-4 a ) is used only when the port is emitting 1s during the external memory accesses. otherwise, the pullup is always off. consequently, p0 lines that are used as output port lines are open drain lines. writing a "1" to th port latch leaves both output fets off and the pin floats. in that condition it can be used as high-impedance input. lf port 0 is configured as general i/o port and has to emit logic high level (1), external pullups are required. figure 7-4 a) port 0 circuitry semiconductor group 45 on-chip peripheral components 7.1.2 port 0 and port 2 used as address/data bus as shown in figures 7-4 a) and 7-4 b) , 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 they 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. lf the ports are configured as an address/data bus, the port latches are disconnected from the driver circuit. during this time, the p2 sfr remains unchanged while the p0 sfr has 1s written to it. being an address/data bus, port 0 uses a pullup fet as shown in figure 7-4 a) . when a 16-bit address is used, port 2 uses the additional strong pullups p1 to emit 1s for the entire external memory cycle instead of the weak ones (p2 and p3) used during normal port activity. figure 7-4 b) port 2 circuitry semiconductor group 46 on-chip peripheral components 7.1.3 alternate functions several pins of ports 1, 3, 4, 5 and 6 are multifunctional. they are port pins and also serve to implement special features as listed in table 7-1 . figure 7-5 shows 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 one (1); otherwise the pull-down fet is on and the port pin is stuck at 0. (this does not apply to ports 1.0 to 1.4 and ports 5.0 to 5.7 when operated in compare output mode; refer to section 7.5.3 for details). after reset all port latches contain ones (1). figure 7-5 circuitry of ports 1, 3, 4, 5 and 6.0 through 6.2 ports 6.3 through 6.7 have no alternate functions as discribed above. therefore, the port circuitry can do without the switching capability between alternate function and normal i/o operation. this more simple circuitry is shown as basic port structure in figures 7-1 and 7-2 . mcs01827 d clk bit latch q q internal pull up arrangement pin read latch to latch read pin write v cc int. bus alternate output function alternate input function & semiconductor group 47 on-chip peripheral components table 7-1 alternate functions of port pins port pin alternate function p1.0 p1.1 p1.2 p1.3 p1.4 p1.5 p1.6 p1.7 int3 /cc0 int4/cc1 int5/cc2 int6/cc3 int2 /cc4 t2ex clkout t2 ext. interrupt 3/capture 0/compare 0 ext. interrupt 4/capture 1/compare 1 ext. interrupt 5/capture 2/compare 2 ext. interrupt 6/capture 3/compare 3 ext. interrupt 2/capture 4/compare 4 timer 2 ext. reload trigger input system clock output timer 2 external count input p3.0 p3.1 p3.2 p3.3 p3.4 p3.5 p3.6 p3.7 rxd0 txd0 int0 int1 t0 t1 wr rd serial input channel 0 serial output channel 0 ext. interrupt 0 ext. interrupt 1 timer 0 external count input timer 1 external count input external data memory write strobe external data memory read strobe p4.0 p4.1 p4.2 p4.3 p4.4 p4.5 p4.6 p4.7 cm0 cm1 cm2 cm3 cm4 cm5 cm6 cm7 compare 0 of compare unit cm0-7 compare 1 of compare unit cm0-7 compare 2 of compare unit cm0-7 compare 3 of compare unit cm0-7 compare 4 of compare unit cm0-7 compare 5 of compare unit cm0-7 compare 6 of compare unit cm0-7 compare 7 of compare unit cm0-7 p5.0 p5.1 p5.2 p5.3 p5.4 p5.5 p5.6 p5.7 ccm0 ccm1 ccm2 ccm3 ccm4 ccm5 ccm6 ccm7 concurrent compare 0 concurrent compare 1 concurrent compare 2 concurrent compare 3 concurrent compare 4 concurrent compare 5 concurrent compare 6 concurrent compare 7 p6.0 p6.1 p6.2 adst rxd1 txd1 ext. a/d converter start serial input channel 1 serial output channel 1 semiconductor group 48 on-chip peripheral components 7.1.4 port handling 7.1.4.1 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 7-6 illustrates this port timing. lt 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, there must be met certain requirements on the pulse length of signals in order to avoid signal "edges" not being 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 7-6 port timing semiconductor group 49 on-chip peripheral components 7.1.4.2 port loading and interfacing the output buffers of ports 1 through 6 can drive ttl inputs directly. the maximum port load which still guarantees correct logic output levels can be looked up in the dc characteristics in the data sheet of the sab 80c517. the corresponding parameters are v ol and v oh . the same applies to port 0 output buffers. they do, however, require external pullups to drive floating inputs, except when being used as the address/data bus. when used as inputs it must be noted that the ports 1 through 6 are not floating but have internal pullup transistors. the driving devices must be capable of sinking a sufficient current if a logic low level shall be applied to the port pin (the parameters i tl and i il in the dc characteristics specify these currents). port 0 as well as the input only ports 7 and 8, however, have floating inputs when used for digital input. 7.1.4.3 read-modify-write feature of ports 0 through 6 some port-reading instructions read the latch and others read the pin ( see figure 7-1 ). the instructions reading the latch rather than the pin read a value, possibly change it, and then rewrite it to the latch. these are called "read-modify-write" instructions, which are listed in table 7-2 . lf the destination is a port or a port bit, these instructions read the latch rather than the pin. note that all other instructions which can be used to read a port, exclusively read the port pin. in any case, reading from latch or pin, resp., is performed by reading the sfr p0 to p6; for example, "mov a, p3" reads the value from port 3 pins, while "anl p4, #0aah" reads from the latch, modifies the value and writes it back to the latch. lt is not obvious that the last three instructions in this list are read-modify-write instructions, but they are. the reason is that they read the port byte, all 8 bits, modify the addressed bit, then write the complete byte back to the latch. semiconductor group 50 on-chip peripheral components table 7-2 read-modify-write instructions the reason why read-modify-write instructions are directed to the latch rather than the pin is 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. lf 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 above mentioned configuration 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". 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 semiconductor group 51 on-chip peripheral components 7.2 serial interfaces the sab 80c517 has two serial interfaces which are functionally nearly identical concerning the asynchronous modes of operation. the two channels are full-duplex, meaning they can transmit and receive simultaneously. they are also receive buffered, meaning they 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 has not been read by the time reception of the second byte is complete, the last received byte will be lost). the serial channel 0 is completely compatible with the serial channel of the sab 80(c)51. serial channel 1 has the same functionality in its asynchronous modes, but the synchronous mode is lacking. 7.2.1 serial interface 0 7.2.1.1 operating modes of serial interface 0 the serial interface 0 can operate in four modes (one synchronous mode, three asynchronous modes). the baud rate clock for this interface is derived from the oscillator frequency (mode 0, 2) or generated either by timer 1 or by a dedicated baud rate generator (mode 1, 3). a more detailed description of how to set the baud rate will follow in section 7.2.1.3. mode 0: shift register (synchronous) mode: serial data enters and exits through rxd0. txd0 outputs the shift clock. 8 data bits are transmitted/ received (lsb first). the baud rate is fixed at 1/12 of the oscillator frequency. mode 1: 8-bit uart, variable baud rate: 10 bits are transmitted (through txd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on reception, the stop bit goes into rb80 in special function register s0con. the baud rate is variable. mode 2: 9-bit uart, fixed baud rate: 11 bits are transmitted (through txd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), a programmable 9th bit, and a stop bit (1). on transmission, the 9th data bit (tb80 in s0con) can be assigned to the value of 0 or 1. for example, the parity bit (p in the psw) could be moved into tb80 or a second stop bit by setting tb80 to 1. on reception the 9th data bit goes into rb80 in special function register s0con, while the stop bit is ignored. the baud rate is programmable to either 1/32 or 1/64 of the oscillator frequency. semiconductor group 52 on-chip peripheral components mode 3: 9-bit uart, variable baud rate: 11 bits are transmitted (through txd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), a programmable 9th bit, and a stop bit (1). on transmission, the 9th data bit (tb80 in s0con) can be assigned to the value of 0 or 1. for example, the parity bit (p in the psw) could be moved into tb80 or a second stop bit by setting tb80 to 1. on reception, the 9th data bit goes into rb80 in special function register s0con, while the stop bit is ignored. in fact, mode 3 is the same as mode 2 in all respects except the baud rate. the baud rate in mode 3 is variable. in all four modes, transmission is initiated by any instruction that uses s0buf as a destination register. reception is initiated in mode 0 by the condition ri0 = 0 and ren0 = 1. reception is initiated in the other modes by the incoming start bit if ren0 = 1. the serial interfaces also provide interrupt requests when a transmission or a reception of a frame has completed. the corresponding interrupt request flags for serial interface 0 are ti0 or ri0, resp. see section 8 for more details about the interrupt structure. the interrupt request flags ti0 and ri0 can also be used for polling the serial interface 0 if the serial interrupt is not to be used (i.e. serial interrupt 0 not enabled). the control and status bits of the serial channel 0 in special function register s0con are illustrated in figure 7-8 . figure 7-7 shows the special function register s0buf which is the data register for receive and transmit. the following table summarizes the operating modes of serial interface 0. serial interface 0, mode selection figure 7-7 special function register s0buf (address 99 h ) receive and transmit buffer of serial interface 0. writing to s0buf loads the transmit register and initiates transmission. reading out s0buf accesses a physically separate receive register. sm0 sm1 mode descriptions baud rate 0 0 0 shift register f osc /12 0 1 1 8-bit uart variable 1 0 2 9-bit uart f osc /64 or f osc /32 1 1 3 9-bit uart variable serial interface 0 buffer register s0buf 99 h semiconductor group 53 on-chip peripheral components figure 7-8 special function register s0con (address 98 h ) bit symbol sm0 sm1 00 01 10 11 serial mode 0: shift register mode, fixed baud rate serial mode 1: 8-bit uart, variable baud rate serial mode 2: 9-bit uart, fixed baud rate serial mode 3: 9-bit uart, variable baud rate sm20 enables the multiprocessor communication feature in modes 2 and 3. in mode 2 or 3 and sm20 being set to 1, ri0 will not be activated if the received 9th data bit (rb80) is 0. in mode 1 and sm20 = 1, ri0 will not be activated if a valid stop bit has not been received. in mode 0, sm20 should be 0. ren0 receiver enable. enables serial reception. set by software to enable reception. cleared by software to disable reception. tb80 transmitter bit 8. is the 9th data bit that will be transmitted in modes 2 and 3. set or cleared by software as desired. rb80 receiver bit 8. in modes 2 and 3 it is the 9th bit that was received. in mode 1, if sm20 = 0, rb80 is the stop bit that was received. in mode 0, rb80 is not used. ti0 transmitter interrupt. is the transmit interrupt flag. 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. must by cleared by software. ri0 receiver interrupt. is the receive interrupt flag. set by hardware at the end of the 8th bit time in mode 0, or during the stop bit time in the other modes, in any serial reception. must be cleared by software. 9f h 9e h 9d h 9c h 9b h 9a h 99 h 98 h sm0 sm20 ren0 tb80 rb80 ti0 ri0 98 h s0con sm1 semiconductor group 54 on-chip peripheral components 7.2.1.2 multiprocessor communication feature modes 2 and 3 of the serial interface 0 have a special provision for multi-processor communication. in these modes, 9 data bits are received. the 9th bit goes into rb80. then a stop bit follows. the port can be programmed such that when the stop bit is received, the serial port 0 interrupt will be activated (i.e. the request flag ri0 is set) only if rb80 = 1. this feature is enabled by setting bit sm20 in s0con. a way to use this feature in multiprocessor communications is as follows. lf the master processor wants to transmit a block of data to one of the 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 sm20 = 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 sm20 bit and prepare to receive the data bytes that will be coming. after having received a complete message, the slave sets sm20 again. the slaves that were not addressed leave their sm20 set and go on about their business, ignoring the incoming data bytes. sm20 has no effect in mode 0. in mode 1 sm20 can be used to check the validity of the stop bit. lf sm20 = 1 in mode 1, the receive interrupt will not be activated unless a valid stop bit is received. 7.2.1.3 baud rates of serial channel 0 as already mentioned there are several possibilities to generate the baud rate clock for the serial interface 0 depending on the mode in which it is operated. to clarify the terminology, something should be said about the difference between "baud rate clock" and "baud rate". the serial interface requires a clock rate which is 16 times the baud rate for internal synchronization, as mentioned in the detailed description of the various operating modes in section 7.2.3. therefore, the baud rate generators have to provide a "baud rate clock" to the serial interface which - there divided by 16 - results in the actual "baud rate". however, all formulas given in the following section already include the factor and calculate the final baud rate. semiconductor group 55 on-chip peripheral components mode 0 the baud rate in mode 0 is fixed: mode 2 the baud rate in mode 2 depends on the value of bit smod in special function register pcon ( see figure 7-9 ). if smod = 0 (which is the value after reset), the baud rate is 1/64 of the oscillator frequency. if smod = 1, the baud rate is 1/32 of the oscillator frequency. figure 7-9 special function register pcon (address 87 h ) modes 1 and 3 in these modes the baud rate is variable and can be generated alternatively by a dedicated baud rate generator or by timer 1. using the baud rate generator: in modes 1 and 3, the sab 80c517 can use the internal baud rate generator for serial interface 0. to enable this feature, bit bd (bit 7 of special function register adcon0) must be set ( see figure 7-10 ). this baud rate generator divides the oscillator frequency by 2496. bit smod (pcon.7) also can be used to enable a multiply-by-two prescaler ( see figure 7-9 ). at 12-mhz oscillator frequency, the commonly used baud rates 4800 baud (smod = 0) and 9600 baud (smod = 1) are available (with 0.16 % deviation). the baud rate is determined by smod and the oscillator frequency as follows: bit function smod when set, the baud rate of serial interface 0 in modes 1, 2, 3 is doubled. mode 0 baud rate = oscillator frequency 12 mode 2 baud rate = oscillator frequency 64 2 smod x smod pds idls sd gf1 gf0 pde idle 87 h pcon these bits are not used in controlling serial interface 0. semiconductor group 56 on-chip peripheral components figure 7-10 special function register adcon0 (address 0d8 h ) using timer 1 to generate baud rates: in mode 1 and 3 of serial channel 0 timer 1 can be used for generating baud rates. then the baud rate 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. the timer itself can be configured for either "timer" or "counter" operation, and in any of its operating modes. in the most typical applications, it is configured for "timer" operation in the auto-reload mode (high nibble of tmod = 0010 b ). in the case, the baud rate is given by the formula: one can achieve very low baud rates 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. table 7-4 lists various commonly used baud rates and shows how they can be obtained from timer 1. bit function bd baud rate enable. when set, the baud rate in modes 1 and 3 of serial interface 0 is taken from a dedicated prescaler. standard baud rates 4800 and 9600 baud at 12-mhz oscillator frequency can be achieved. mode 1, 3 baud rate = oscillator frequency 2496 2 smod x bd clk adex bsy adm mx2 mx1 mx0 0d8 h adcon these bits are not used in controlling serial interface 0. 0df h 0de h 0dd h 0dc h 0db h 0da h 0d9 h 0d8 h mode 1, 3 baud rate = (timer 1 overflow rate) 32 2 smod x mode 1, 3 baud rate = 32 x 12 x (256 C (th1)) 2 smod x oscillator frequency semiconductor group 57 on-chip peripheral components table 7-4 timer 1 generated commonly used baud rates figure 7-11 shows the mechanisms for baud rate generation of serial channel 0, while table 7-5 summarizes the baud rate formulas for all usual configurations. figure 7-11 generation of baud rates for serial channel 0 baud rate f osc (mhz) smod timer 1 c/t mode reload value mode 1, 3:62.5 kbaud 19.2 kbaud 9.6 kbaud 4.8 kbaud 2.4 kbaud 1.2 kbaud 110 baud 110 baud 12.0 11.059 11.059 11.059 11.059 11.059 6.0 12.0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 1 ff h fd h fd h fa h f4 h e8 h 72 h feeb h semiconductor group 58 on-chip peripheral components table 7-5 baud rates of serial interface 0 7.2.1.4 new baud rate generator for serial channel 0 the sab 80c517 devices with stepping code "ca" or later have a new baud rate generator for serial channel 0 which provides greater flexibility and better resolution. it substitutes the 80c517s baud rate generator at serial channel 0 which provides only 4.8 kbaud or 9.6 kbaud at 12 mhz crystal frequency. since the new generator offers greater flexibility it is often possible to use it instead of timer1 which is then free for other tasks. figure 7-11a shows a block diagram of the new baud rate generator for serial channel 0. it consists of a free running 10-bit timer with f osc /2 input frequency. on overflow of this timer there is an automatic reload from the registers s0rell (address aa h ) and s0relh (address ba h ). the lower 8 bits of the timer are reloaded from s0rell, while the upper two bits are reloaded from bit 0 and 1 of register s0relh. the baud rate timer is reloaded by writing to s0rell. baud rate derived from interface mode baud rate timer 1 in mode 1 ( see table 7-4 ) 1, 3 timer 1 in mode 2 ( see table 7-4 ) 1, 3 oscillator 2 bd 1, 3 x (timer 1 overflow rate) 2 smod 1 16 x 2 2 smod 1 16 x 2 x f osc 12 x (256 C (th1)) 2 smod 1 16 x 2 x f osc 2 2 smod 1 16 x 2 x f osc 1248 semiconductor group 59 on-chip peripheral components figure 7-11a baud rate generator for serial interface 0 the default value after reset of s0rell is 0d9 h , s0relh contains xxxx xx11 b special function register s0relh, s0rell reset value of s0rell is 0d9 h , s0relh contains xxxx xx11 b . bit function s0relh.0-1 reload value. upper two bits of the timer reload value. s0rell.0-7 reload value. lower 8 bit of timer reload value. addr. 0aa h s0rell shaded areas are not used for programming the baudrate timer 76543210 msb lsb bit no. addr. 0ba h s0relh 76543210 msb lsb bit no. msb lsb semiconductor group 60 on-chip peripheral components figure 7-11b shows a block diagram of the options available for baud rate generation of serial channel 0. it is a fully compatible superset of the functionality of older sab 80c517 steppings. the new baud rate generator can be used in modes 1 and 3 of the serial channel 0. it is activated by setting bit bd (adcon0.7). this also starts the baud rate timer. when timer1 shall be used for baud rate generation, bit bd must be cleared. in any case, bit smod (pcon.7) selects an additional divider by two. the default values after reset in registers s0rell and s0relh provide a baud rate of 4.8 kbaud (with smod = 0) or 9.6 kbaud (with smod = 1) at 12 mhz oscillator frequency. this guarantees full compatibility to older steppings of the sab 80c517. figure 7-11b block diagram of baud rate generation for serial interface 0 if the new baud rate generator is used the baud rate of serial channel 0 in mode 1 and 3 can be determined as follows: mode 1, 3 baud rate = 64 x (2 10 C s0rel) 2 smod x oscillator frequency with s0rel = s0relh.1 C 0, s0rell.7 C 0 semiconductor group 61 on-chip peripheral components 7.2.2 serial interface 1 7.2.2.1 operating modes of serial interface 1 the serial interface 1 is an asynchronous channel only and is able to operate in two modes, as an 8-bit or 9-bit uart. these modes, however, correspond to the above mentioned modes 1, 2 and 3 of serial interface 0. the multiprocessor communication feature is identical with this feature in serial interface 0. the serial interface 1 has its own interrupt request flags rl1 and tl1 which have a dedicated interrupt vector location (see section 8 for more details about the interrupts). the baud rate clock for this interface is generated by a dedicated baud rate generator. a more detailed description how to set the baud rate follows in section 7.2.2.3 and 7.2.2.4. mode a: 9-bit uart, variable baud rate: 11 bits are transmitted (through txd1) or received (through rxd1): a start bit (0), 8 data bits (lsb first), a programmable 9th bit, and a stop bit (1). on transmission, the 9th data bit (tb81 in s1con) can be assigned to the value of 0 or 1. for example, the parity bit (p in the psw) could be moved into tb81 or a second stop bit by setting tb81 to 1. on reception the 9th data bit goes into rb81 in special function register s0con, while the stop bit is ignored. in fact, mode a of serial interface 1 is identical with mode 2 or 3 of serial interface 0 in all respects except the baud rate generation (see section 7.2.2.3). mode b: 8-bit uart, variable baud rate: 10 bits are transmitted (through txd1) or received (through rxd1): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on reception, the stop bit goes into rb81 in special function register s1con. in fact, mode b of serial interface 1 is identical with mode 1 of serial interface 0 in all respects except for the baud rate generation (see section 7.2.2.3). in both modes, transmission is initiated by any instruction that uses s1buf as a destination register. reception is initiated by the incoming start bit if ren1 = 1. the serial interfaces also provide interrupt requests when a transmission or a reception of a frame has completed. the corresponding interrupt request flags for serial interface 1 are tl1 or rl1, resp. see section 8 for more details about the interrupt structure. the interrupt request flags tl1 and rl1 can also be used for polling the serial interface 1 if the serial interrupt shall not be used (i.e. serial interrupt 1 not enabled). the control and status bits of the serial channel 1 in special function register s1con are illustrated in figure 7-12 . figure 7-13 shows the special function register s1buf which is the data register for receive and transmit. note that these special function registers are not bit-addressable. due to this fact bit instructions cannot be used for manipulating these registers. this is important especially for s1con where a polling and resetting of the rl1 or tl1 request flag cannot be performed by jnb and clr instructions but must be done by a sequence of byte instructions, e.g.: loop: mov a,s1con jnb acc.0,loop ;testing of ri1 anl s1con,#0feh ;resetting of ri1 semiconductor group 62 on-chip peripheral components figure 7-12 special function register s1con (address 9b h ) figure 7-13 special function register s1buf (address 9c h ) receive and transmit buffer of serial interface 1. writing to s1buf loads the transmit register and initiates transmission. reading out s1buf accesses a physically separate receive register. bit function sm sm = 0: serial mode a; 9-bit uart sm = 1: serial mode b; 8-bit uart sm21 enables the multiprocessor communication feature in mode a. if sm21 is set to 1, ri1 will not be activated if the received 9th data bit (rb81) is 0. in mode b, if sm21 = 1, ri1 will not be activated if a valid stop bit was not received. ren1 receiver enable of interface 1. enables serial reception. set by software to enable reception. cleared by software to disable reception. tb81 transmitter bit 8 of interface 1. is the 9th data bit that will be transmitted in mode a. set or cleared by software as desired. rb81 receiver bit 8 of interface 1. is the 9th data bit that was received in mode a. in mode b, if sm21 = 0, rb81 is the stop bit that was received. ti1 transmitter interrupt of interface 1. is the transmit interrupt flag. set by hardware at the beginning of the stop bit in any serial transmission. must be cleared by software. ri1 receiver interrupt of interface 1. is the receive interrupt flag. set by hardware at the halfway through the stop bit time in any serial reception. must be cleared by software. sm ?C sm21 ren1 tb81 rb81 ti1 ri1 9b h s1con serial interface 1 buffer register s1buf 9c h semiconductor group 63 on-chip peripheral components 7.2.2.2 multiprocessor communication feature mode a of the serial interface 1 has a special provision for multiprocessor communication. in this mode, 9 data bits are received. the 9th bit goes into rb81. then follows a stop bit. the port can be programmed such that when the stop bit is received, the serial port interrupt (i.e. the request flag rl1 is set) will be activated only if rb81 = 1. this feature is enabled by setting bit sm21 in s1con. a way to use this feature in multiprocessor communications is as follows. lf the master processor wants to transmit a block of data to one of the 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 sm21 = 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 sm21 bit and prepare to receive the data bytes that will be coming. after having received a complete message, the slave is setting sm21 again. the slaves that were not addressed leave their sm21 set and go on about their business, ignoring the incoming data bytes. in mode b sm21 can be used to check the validity of the stop bit. lf sm21 = 1 in mode b, the receive interrupt will not be activated unless a valid stop bit is received. 7.2.2.3 baud rates of serial channel 1 as already mentioned serial interface 1 uses its own dedicated baud rate generator for baud rate generation in both operating modes ( see figure 7-14 ). this baud rate generator consists of a free running 8-bit timer with f osc /2 input frequency. the timer is automatically reloaded at overflow by the contents of register s1rel ( see figure 7-15 ). the timer must be started by writing the desired reload value to register s1rel. the baud rate in operating modes a and b can be determined by following formula: at 12-mhz oscillator frequency a baud rate range from about 1.5 kbaud up to 375 kbaud is covered. using the fast baud rates offers the same functionality as the operating mode 2 in serial interface 0 with its fixed baud rates. mode a, b baud rate = oscillator frequency 32 x (256 C s1rel) semiconductor group 64 on-chip peripheral components figure 7-14 baud rate generator for serial interface 1 figure 7-15 special function register s1rel (address 9d h ) 8-bit reload register for baud rate generator of serial interface 1. 7.2.2.4 new baud rate generator for serial channel 1 a new baud rate generator for serial channel 1, which is implemented in sab 80c517 devices with stepping code "ca" or later, now offers a wider range of selectable baud rates. especially a baud rate of 1200 baud can be achieved now. the baud rate generator itself is identical with the one used for serial channel 0. it consists of a free running 10-bit timer with f osc /2 input frequency. on overflow of this timer there is an automatic reload from the registers s1rel (address 9d h ) and s1relh (address bb h ). the lower 8 bits of the timer are reloaded from s0rel, while the upper two bits are reloaded from bit 0 and 1 of register s1relh. the baud rate timer is reloaded by writing to s1rel. the baud rate in mode a and b can be determined by the following formula: serial interface 1 reload register s1rel 9d h mode a, b baud rate = 32 x (2 10 C reload value) oscillator frequency with reload value = s1relh.1 C 0, s1rell.7 C 0 semiconductor group 65 on-chip peripheral components figure 7-15a shows a block diagram of the baud rate generator for serial interface 1. figure 7-15a baud rate generator for serial interface 1 special function register s1relh, s1rell reset value of s1rel is 00 h , s1relh contains xxxx xx11b. bit function s1relh.0-1 reload value. upper two bits of the timer reload value. s1rel.0-7 reload value. lower 8 bit of timer reload value. addr. 09d h s1rel shaded areas are not used for programming the baudrate timer 76543210 msb lsb bit no. addr. 0bb h s1relh 76543210 msb lsb bit no. msb lsb semiconductor group 66 on-chip peripheral components 7.2.3 detailed description of the operating modes the following sections give a more detailed description of the several operating modes of the two serial interfaces. the sections 7.2.3.2. and 7.4.3.4. apply to both of the serial interfaces. the description of the synchronous mode 0 and the asynchronous mode 2 refers only to serial interface 0. 7.2.3.1 mode 0, synchronous mode (serial interface 0) serial data enters and exits through rxd0. txd0 outputs the shift clock. 8 bits are transmitted/ received: 8 data bits (lsb first). the baud rate is fixed at 1/12 of the oscillator frequency. figures 7-16 a) and b) show a simplified functional diagram of the serial port in mode 0, and associated timing. transmission is initiated by any instruction that uses s0buf as a destination register. the "write- to-s0buf" signal at s6p2 also loads a 1 into the 9th bit 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-s0buf" and activation of send. send enables the output of the shift register to the alternate output function line p3.0, and also enables shift clock to the alternate output function line p3.1. shift clock is low during s3, s4, and s5 of every machine cycle, and high during s6, s1, and s2, while the interface is transmitting. before and after transmission shift clock remains high. at s6p2 of every machine cycle in which send is active, the contents of the transmit shift register is shifted one position to the right. as data bits shift to the right, zeros 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 left of the msb, and all positions to the left of that contain zeros. this condition flags the tx control block to do one last shift and then deactivates send and sets ti0. both of these actions occur at s1p1 in the 10th machine cycle after "write-to-s0buf". reception is initiated by the condition ren0 = 1 and ri0 = 0. at s6p2 in 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 in every machine cycle. at s6p2 of every machine cycle in which receive is active, the contents of the receive shift register are shifted one position to the left. the value that comes in from the right is the value that was sampled at the p3.0 pin at s5p2 in the same machine cycle. as data bits come in from the right, 1 s 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 s0buf. at s1p1 in the 10th machine cycle after the write to s0con that cleared ri0, receive is cleared and ri0 is set. semiconductor group 67 on-chip peripheral components 7.2.3.2 mode 1/mode b, 8-bit uart (serial interfaces 0 and 1) ten bits are transmitted (through txd0 or txd1), or received (through rxd0 or rxd1): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on reception through rxd0, the stop bit goes into rb80 (s0con), on reception through rxd1, rb81 (s1c0n) stores the stop bit. the baud rate for serial interface 0 is determined by the timer 1 overflow rate or by the internal baud rate generator of serial interface 0. serial interface 1 receives the baud rate clock from its own baud rate generator. figures 7-17 a) and b) show a simplified functional diagram of both serial channels in mode 1 or mode b, resp. the generation of the baud rate clock by the various timers is described in sections 7.2.1.3 and 7.2.2.3. transmission is initiated by any instruction that uses s0buf/s1buf as a destination register. the "write-to-s0buf/s1buf" signal also loads a 1 into the 9th bit position of the transmit shift register and flags the tx control block that a transmission is requested. transmission actually commences at s1p1 of the machine cycle following the next roll-over in the divide-by-16 counter (thus, the bit times are synchronized to the divide-by-16 counter, not to the "write-to-s0buf/s1buf" signal). the transmission begins with activation of send , which puts the start bit to txd0/txd1. one bit time later, data is activated, which enables the output bit of the transmit shift register to txd0/ txd1. the first shift pulse occurs one bit time after that. as data bits shift out to the right, zeros 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 left of the msb, and all positions to the left of that contain zero. this condition flags the tx control to do one last shift and then deactivate send and set ti0/tl1. this occurs at the 10th divide- by-16 rollover after "write-to-s0buf/s1buf". reception is initiated by a detected 1-to-0 transition at rxd0/rxd1. for this purpose rxd0/rxd1 is sampled at a rate of 16 times whatever baud rate has been established. when a reception is detected, the divide-by-16 counter is immediately reset, and 1 ff h is written into the input shift register. resetting the divide-by-16 counter aligns its rollover with the boundaries of the incoming bit times. the 16 states of the counter divide each bit time into 16 counter states. at the 7th, 8th and 9th counter state of each bit time, the bit detector samples the value of rxd0/rxd1. the value accepted is the value that was seen in at least 2 of the 3 samples. this is done for noise rejection. lf the value accepted during the first bit time is not 0, the receive circuits are reset and the unit goes back looking for another 1-to-0 transition. this is to provide rejection of false start bits. lf 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 in mode 1/b is a 9-bit register), it flags the rx control block to do one last shift. the signal to load s0buf/s1buf and rb80/rb81, and to set ri0/rl1 will be generated if, and only if, the following conditions are met at the time the final shift pulse is generated: 1) ri0/rl1 = 0, and 2) either sm20/sm21 = 0 or the received stop bit = 1 semiconductor group 68 on-chip peripheral components lf either of these two conditions is not met the received frame is irretrievably lost. lf both conditions are met, the stop bit goes into rb80/rb81, the 8 data bits go into s0buf/s1buf, and ri0/rl1 is activated. at this time, no matter whether the above conditions are met or not, the unit goes back to looking for a 1-to-0 transition in rxd0/rxd1. 7.2.3.3 mode 2, 9-bit uart (serial interface 0) mode 2 is functionally identical to mode 3 (see below). the only exception is, that in mode 2 the baud rate can be programmed to two fixed quantities: either 1/32 or 1/64 of the oscillator frequency. note that serial interface 0 cannot achieve this baud rate in mode 3. its baud rate clock is generated by timer 1, which is incremented by a rate of f osc /12. the dedicated baud rate generator of serial interface 1 however is clocked by a f osc /2-signal and so its maximum baud rate is f osc /32. 7.2.3.4 mode 3 / mode a, 9-bit uart (serial interfaces 0 and 1) eleven bits are transmitted (through txd0/txd1), or received (through rxd0/rxd1): 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 (tb80/tb81) can be assigned the value of 0 or 1. on reception the 9th data bit goes into rb80/ rb81 in s0con/s1con. figures 7-18 a) and b) show a functional diagram of the serial interfaces in mode 2 and 3 or mode a, resp. and associated timing. 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. transmission is initiated by any instruction that uses s0buf/s1buf as a destination register. the "write to s0buf/s1buf" signal also loads tb80/tb81 into the 9th bit position of the transmit shift register and flags the tx control unit that a transmission is requested. transmission commences at s1p1 of the machine cycle following the next rollover in the divide-by-16 counter (thus the bit times are synchronized to the divide-by-16 counter, and not to the "write-to-s0buf/s1buf" signal). the transmission begins with the activation of send , which puts the start bit to txd0/txd1. one bit time later, data is activated which enables the output bit of transmit shift register to txd0/txd1. 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 zeros are clocked in. thus, as data shift out to the right, zeros are clocked in from the left. when tb80/tb81 is at the output position of the shift register, then the stop bit is just left of the tb80/tb81, and all positions to the left of that contain zeros. semiconductor group 69 on-chip peripheral components this condition flags the tx control unit to do one last shift and then deactivate send and set ti0/ ti1. this occurs at the 11th divide-by-16 rollover after "write-to-s0buf/s1buf". reception is initiated by a detected 1-to-0 transition at rxd0/rxd1. for this purpose rxd0/rxd1 is sampled of a rate of 16 times whatever baud rate has been established. when a transition is detected, the divide-by-16 counter is immediately reset, and 1f h is written to the input shift register. at the 7th, 8th and 9th counter state of each bit time, the bit detector samples the value of rxd0/ rxd1. the value accepted is the value that was seen in at least 2 of the 3 samples. lf 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. lf 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), it flags the rx control block to do one last shift, load s0buf/s1buf and rb80/ rb81, and set ri0/ri1. the signal to load s0buf/s1buf and rb80/rb81, and to set ri0/ri1, will be generated if, and only if, the following conditions are met at the time the final shift pulse is generated: 1) ri0/ri1 = 0, and 2) either sm20/sm21 = 0 or the received 9th data bit = 1 lf either one of these two conditions is not met, the received frame is irretrievably lost, and ri0/rl1 is not set. lf both conditions are met, the received 9th data bit goes into rb80/rb81, the first 8 data bits go into s0buf/s1buf. one bit time later, no matter whether the above conditions are met or not, the unit goes back to look for a 1-to-0 transition at the rxd0/rxd1 input. note that the value of the received stop bit is irrelevant to s0buf/s1buf, rb80/rb81, or ri0/rl1. semiconductor group 70 on-chip peripheral components figure 7-16 a) functional diagram - serial interface 0, mode 0 semiconductor group 71 on-chip peripheral components figure 7-16 b) timing diagram - serial interface 0, mode 0 semiconductor group 72 on-chip peripheral components figure 7-17 a) functional diagram - serial interfaces 0 and 1, mode 1 / mode b semiconductor group 73 on-chip peripheral components figure 7-17 b) timing diagram - serial interfaces 0 and 1, mode 1 / mode b semiconductor group 74 on-chip peripheral components figure 7-18 a) functional diagram - serial interfaces 0 and 1, modes 2 and 3 / mode a semiconductor group 75 on-chip peripheral components figure 7-18 b) timing diagram - serial interfaces 0 and 1, modes 2 and 3 / mode a semiconductor group 76 on-chip peripheral components 7.3 timer 0 and timer 1 the sab 80c517 has a number of general purpose 16-bit timer/counters: timer 0, timer 1, timer 2 and the compare timer (timer 2 and the compare timer are discussed separately in section 7.5 "compare/capture unit"). timer/counter 0 and 1 are fully compatible with timer/counters 0 and 1 of the sab 8051 and can be used in the same operating modes. timer/counter 0 and 1 which are discussed in this section can be configured to operate either as timers or event counters: C in "timer" function, the register is incremented every machine cycle. thus one can think of it as counting machine cycles. since a machine cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator frequency. C in "counter" function, the register is incremented in response to a 1-to-0 transition (falling edge) at its corresponding external input pin, t0 or t1 (alternate functions of p3.4 and p3.5, resp.). in this function the external input is sampled during s5p2 of every machine cycle. when the samples show a high in one cycle and a low in the next cycle, the count is incremented. the new count value appears in the register during s3p1 of the cycle following the one in which the transition was detected. since it takes two machine cycles (24 oscillator periods) to recognize a 1-to-0 transition, the maximum count rate is 1/24 of the oscillator frequency. there are no restrictions on the duty cycle of the external input signal, but to ensure that a given level is sampled at least once before it changes, it must be held for at least one full machine cycle. in addition to the "timer" and "counter" selection, timer/counters 0 and 1 have four operating modes from which to select. semiconductor group 77 on-chip peripheral components figure 7-19 special function register tcon (address 88 h ) each timer consists of two 8-bit registers (th0 and tl0 for timer/counter 0, th1 and tl1 for timer/ counter 1) which 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 tcon and tmod, shown in figures 7-19 and 7-20 . in the following descriptions the symbols th0 and tl0 are used specify the high-byte and low-byte of timer 0 (th1 and tl1 for timer 1, respectively). the operating modes are described and shown for timer 0. if not explicitly noted, this applies also to timer 1. 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. these bits are not used in controlling timer/counter 0 and 1. 8f h 8e h 8d h 8c h 8b h 8a h 89 h 88 h tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 88 h tcon semiconductor group 78 on-chip peripheral components figure 7-20 special function register tmod (address 89 h ) timer/counter 0/1 mode control register bit symbol gate gating control. when set, timer/counter x is enabled only while intx 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 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. 11timer 0: tl0 is an 8-bit timer/counter controlled by the standard timer 0 control bits. th00 is an 8-bit timer only controlled by timer 1 control bits. 11timer 1: timer/counter 1 stops gate c/t m1 m0 gate c/ t m1 m0 89 h tmod timer 1 timer 0 semiconductor group 79 on-chip peripheral components 7.3.1 mode 0 putting either timer/counter into mode 0 configures it as an 8-bit timer/counter with a divide-by-32 prescaler. figure 7-21 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 0s, it sets the timer overflow flag tf0. the overflow flag tf0 then can be used to request an interrupt (see section 8 for details about the interrupt structure). 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 , to facilitate pulse width measurements). tr0 is a control bit in the special function register tcon; gate is in tmod. the 13-bit register consists of all 8 bits of th1 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 tr1, tf1, th1, tl1, and int1 for the corresponding timer 1 signals in figure 7-21 . there are two different gate bits, one for timer 1 (tmod.7) and one for timer 0 (tmod.3). figure 7-21 timer/counter 0/1, mode 0: 13 bit timer/counter semiconductor group 80 on-chip peripheral components 7.3.2 mode 1 mode 1 is the same as mode 0, except that the timer register is run with all 16 bits. mode 1 is shown in figure 7-22 . figure 7-22 timer/counter 0/1, mode 1: 16-bit timer/counter semiconductor group 81 on-chip peripheral components 7.3.3 mode 2 mode 2 configures the timer register as an 8-bit counter (tl0) with automatic reload, as shown in figure 7-23 . 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 7-23 timer/counter 0/1, mode 2: 8-bit timer/counter with auto-reload semiconductor group 82 on-chip peripheral components 7.3.4 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 7-24 . 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 fact, in any application not requiring an interrupt from timer 1 itself. figure 7-24 timer/counter 0, mode 3: two 8-bit timer/counter semiconductor group 83 on-chip peripheral components 7.4 a/d converter the sab 80c517 provides an a/d converter with the following features: C 12 multiplexed input channels, which can also be used as digital inputs (port 7, port 8) C programmable internal reference voltages (16 steps each) via resistor array C 8-bit resolution within the selected reference voltage range C 13 microseconds conversion time (including sample time) at 12-mhz oscillator frequency C selectable external or internal start-of-conversion trigger C interrupt request generation after each conversion for the conversion, the method of successive approximation via capacitor array is used. the externally applied reference voltage range has to be held on a fixed value within the specifications (see section "a/d converter characteristics" in the data sheet). the internal reference voltages can be varied to reduce the reference voltage range of the a/d converter and thus to achieve a higher resolution. figure 7-25 shows a block diagram of the a/d converter. there are four user-accessible special function registers: adcon0, adcon1 (a/d converter control registers), addat (a/d converter data register) and dapr (d/a converter program register) for the programmable reference voltages. the analog input channels (port 7 and port 8) can also be used for digital input; refer also to section 7.1 "parallel i/o". 7.4.1 function and control 7.4.1.1 lnitialization and input channel selection special function register adcon0 which is illustrated in figure 7-26 is used to set the operating modes, to check the status, and to select one of eight analog input channels. special function register adcon1 ( figure 7-27 ) controls the selection of all twelve input channels. register adcon0 contains two mode bits. bit adm is used to choose the single or continuous conversion mode. in single conversion mode only one conversion is performed after starting, while in continuous conversion mode after the first start a new conversion is automatically started on completion of the previous one. semiconductor group 84 on-chip peripheral components figure 7-25 block diagram of the a/d converter semiconductor group 85 on-chip peripheral components an externally controlled conversion can be achieved by setting the bit adex. in this mode on single conversion is triggered by a 1-to-0 transition at pin p6.0/adst , if adm is 0. p6.0/adst is sampled suring s5p2 of every machine cycle. when the samples show a logic high in one cycle and a logic low in the next cycle the transition is detected and the conversion is started. when adm and adex is set, a continuous conversion is started when pin p6.0/adst sees a low level; the conversion is stopped when the pin p6.0/adst goes back to high. the last commenced conversion during low level will be completed. the busy flag bsy (adcon0.4) is automatically set when a conversion is in progress. after completion of the conversion it is reset by hardware. this flag can be read only, a write has no effect.there is also an interrupt request flag iadc (ircon.0) that is set when a conversion is completed. see section 8 for more details about the interrupt structure. figure 7-26 special function register adcon0 (address 0d8 h ) figure 7-27 special function registeradcon1 (address 0dc h ) a/d converter control register 1. it contains channel selection bits mx0 to mx3. bits mx0 to mx2 can be written or read either in adcon0 or in adcon1. bit function mx0 mx1 mx2 mx3 select 12 input channels of the a/d converter. adm a/d conversion mode. when set, a continuous conversion is selected. if adm = 0, the converter stops after one conversion. bsy busy flag. this flag indicates whether a conversion is in progress (bsy = 1). the flag is cleared by hardware when the conversion is completed. adex internal/external start of conversion. when set, the external start of conversion by p6.0/adst is enabled. these bits are not used in controlling a/d converter functions. 0df h 0de h 0dd h 0dc h 0db h 0da h 0d9 h 0d8 h bd clk adex bsy adm mx2 mx1 mx0 0d8 h adcon0 C C C C mx3 mx2 mx1 mx0 0dc h acon1 semiconductor group 86 on-chip peripheral components table 7-6 selection of the analog input channels *) x means that the value may be 1 or 0. the bits mx0 to mx2 in special function register adcon0 and the bits mx0 to mx3 in adcon1 are used for selection of the analog input channel. table 7-6 lists the selected input channels. the bits mx0 to mx2 are represented in both the registers adcon0 and adcon1; however, these bits are present only once; it has the same effect irrespective of whether they are accessed via adcon0 or adcon1. this is done in order to maintain software compatibility to the sab 80(c)515. in this device there are only eight input channels which are selected by mx0 to mx2 in adcon0. thus, a program written for the sab 80(c)515 selects one of the lower eight input channels (port 7) if the bit mx3 is reset which is the default value after reset. (for clarity: in the sab 80(c)515 the analog input channel is called port 6 or an0 to an7, resp. however, it is found on the same address (0db h ) as the sab 80c517s port 7.) lf all 12 multiplexed input channels are required register adcon1 is to be used. lt contains a four- bit field to select one of all 12 input channels, the eight inputs at port 7 and the four inputs at port 8. thus, there are two methods of selecting a channel of port 7 and it does not matter which is used: 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. lf bit mx3 is set, the additional analog inputs at port 8 are used. mx0 and mx1 then determine which channel of port 8 is being selected ( see table 7-6 ). mx3 mx2 mx1 mx0 selected channel pin 0 000analog i nput 0 p7.0 0 001analog i nput 1 p7.1 0 010analog i nput 2 p7.2 0 011analog i nput 3 p7.3 0 100analog i nput 4 p7.4 0 101analog i nput 5 p7.5 0 110analog i nput 6 p7.6 0 111analog i nput 7 p7.7 1 x *) 0 0 analog input 8 p8.0 1 x 0 1 analog input 9 p8.1 1 x 1 0 analog input 10 p8.2 1 x 1 1 analog input 11 p8.3 semiconductor group 87 on-chip peripheral components ports p7 and p8 are dual purpose input ports. lf the input voltage meets the specified logic levels, they can be used as digital inputs as well regardless of whether the pin levels are sampled by the a/d converter at the same time. the special function register addat ( figure 7-28 ) holds the converted digital 8-bit data result. the data remains in addat until it is overwritten by the next converted data. addat can be read or written under software control. lf the a/d converter of the sab 80c517 is not used, register addat can be used as an additional general purpose register. figure 7-28 special function register addat (address 0d9 h ) this register contains the 8-bit conversion result. 7.4.1.2 start of conversion an internal start of conversion (adex = 0) is triggered by a write-to-dapr instruction. the start procedure itself is independent of the value which is written to dapr. however, the value in dapr determines which internal reference voltages are used for the conversion (see section 7.4.2). when single conversion mode is selected (adm = 0) only one conversion is performed. in continuous mode after completion of a conversion a new conversion is triggered automatically, until bit adm is reset. when external start of conversion is selected a write-to-dapr will not start the conversion; in this case, conversion starts when a falling edge at pin p6.0/adst is detected. in single conversion mode one conversion is performed until the next falling edge at p6.0/adst is recognized. in continuous mode new conversions are started automatically as long as pin p6.0/adst is on low level. this is done until p6.0/adst goes to logic high level; in this case the last commenced conversion is completed. 7.4.2 reference voltages the sab 80c517 has two pins to which a reference voltage range for the on-chip a/d converter is applied (pin v aref for the upper voltage and pin v agnd for the lower voltage). in contrast to conventional a/d converters it is now possible to use not only these externally applied reference voltages for the conversion but also internally generated reference voltages which are derived from the externally applied ones. for this purpose a resistor ladder provides 16 equidistant voltage levels between v aref and v agnd . these steps can individually be assigned as upper and lower reference voltage for the converter itself. these internally generated reference voltages are called v lntaref and v lntagnd . the internal reference voltage programming can be thought of as a programmable "d/a converter" which provides the voltages v intaref and v intagnd for the a/d converter itself. conversion result addat 0d9 h semiconductor group 88 on-chip peripheral components the sfr dapr (see figure 7-29) is provided for programming the internal reference voltages v intaref and v lntagnd . for this purpose the internal reference voltages can be programmed in steps of 1/16 of the external reference voltages ( v aref C v agnd ) by four bits each in register dapr. bits 0 to 3 specify v lntagnd , while bits 4 to 7 specify v intaref . a minimum of 1 v difference is required between the internal reference voltages v lntaref and v intagnd for proper operation of the a/d converter. this means, for example, in the case where v aref is 5 v and v agnd is 0 v, there must be at least four steps difference between the internal reference voltages v intaref and v intagnd . the values of v intagnd and v intaref are given by the formulas: dapr (.3-.0) is the contents of the low-order nibble, and dapr (.7-.4) the contents of the high-order nibble of dapr. figure 7-29 special function register dapr (address da h ) d/a converter program register. each 4-bit nibble is used to program the internal reference voltages. write-access to dapr starts conversion. v intagnd = v agnd + dapr (.3-.0) 16 ( v aref C v agnd ) with dapr (.3-.0) < c h ; v intaref = v agnd + dapr (.7-.4) 16 ( v aref C v agnd ) with dapr (.7-.4) > 3 h ; dapr 0da h programming of v intaref programming of v intagnd v intagnd = v agnd + dapr (.3-.0) 16 ( v aref C v agnd ) with dapr (.3-.0) < 13; v intaref = v agnd + dapr (.7-.4) 16 ( v aref C v agnd ) with dapr (.7-.4) > 3; semiconductor group 89 on-chip peripheral components if dapr (.3-.0) or dapr (.7-.4) = 0, the internal reference voltages correspond to the external reference voltages v agnd and v aref , respectively. if v ainput > v intaref , the conversion result is 0ff h , if v ainput < v intagnd , the conversion result is 00 h ( v ainput is the analog input voltage). if the external reference voltages v agnd = 0 v and v aref = + 5 v (with respect to v ss and v cc ) are applied, then the following internal reference voltages v intagnd and v intaref shown in table 7-7 can be adjusted via the special function register dapr. table 7-7 adjustable internal reference voltages the programmability of the internal reference voltages allows adjusting the internal voltage range to the range of the external analog input voltage or it may be used to increase the resolution of the converted analog input voltage by starting a second conversion with a compressed internal reference voltage range close to the previously measured analog value. figures 7-30 and 7-31 illustrate these applications. step dapr (.3-.0) dapr (.7-.4) v intagnd v intaref 0 0000 0.0 5.0 1 0001 0.3125 C 2 0010 0.625 C 3 0011 0.9375 C 4 0100 1.25 1.25 5 0101 1.5625 1.5625 6 0110 1.875 1.875 7 0111 2.1875 2.1875 8 1000 2.5 2.5 9 1001 2.8125 2.8125 10 1010 3.125 3.125 11 1011 3.4375 3.4375 12 1100 3.75 3.75 13 1101 C 4.0625 14 1110 C 4.375 15 1111 C 4.6875 semiconductor group 90 on-chip peripheral components figure 7-30 adjusting the internal reference voltages to the range of the external analog input voltages figure 7-31 increasing the resolution by a second conversion semiconductor group 91 on-chip peripheral components the external reference voltage supply need only be applied when the a/d converter is used, otherwise the pins v aref and v agnd may be left unconnected. the reference voltage supply has to meet some requirements concerning the level of v agnd and v aref and the output impedance of the supply voltage (see also "a/d converter characteristics" in the data sheet). C the voltage v aref must meet the following specification: v aref = v cc +/C 5 % C the voltage v agnd must meet a similar specification: v agnd = v ss + /C 0.2 v C the differential output impedance of the analog reference supply voltage should be less than 1 k w . lf the above mentioned operating conditions are not met the accuracy of the converter may be decreased. furthermore, the analog input voltage v ainput must not exceed the range from ( v agnd C 0.2 v) to ( v aref + 0.2 v). otherwise, a static input current might result at the corresponding analog input which will also affect the accuracy of the other input channels. 7.4.3 a/d converter timing a conversion is internally started by writing into special function register dapr (adex = 0). a write- to-dapr will start a new conversion even if a conversion is currently in progress. the conversion begins with the next machine cycle and the busy flag bsy will be set. when external start is selected (adex = 1) the conversion starts in the machine cycle following the one where the low level was detected at p6.0/adst . the conversion procedure is divided into three parts: load time ( t l ): during this time the analog input capacitance c i (see data sheet) must be loaded to the analog input voltage level. the external analog source needs to be strong enough to source the current to load the analog input capacitance during the load time. this causes some restrictions for the impedance of the analog source. sample time ( t s ): during this time the internal capacitor array is connected to the selected analog input channel. the sample time includes the load time which is described above. after the load time has passed the selected analog input must be held constant for the rest of the sample time. otherwise the internal calibration of the comparator circuitry could be affected which might result in a reduced accuracy of the converter. however, in typical applications a voltage change of approx. 200 - 300 mv at the inputs during this time has no effect. semiconductor group 92 on-chip peripheral components conversion time ( t c ): the conversion time t c includes the sample and load time. thus, t c is the total time required for one conversion. after the load time and sample time have elapsed, the conversion itself is performed during the rest of t c . in the last machine cycle the converted result is moved to addat; the busy flag (bsy) is cleared before. the a/d converter interrupt is generated by bit iadc in register ircon. iadc is already set some cycles before the result is written to addat. the flag iadc is set before the result is available in addat because the shortest possible interrupt latency time is taken into account in order to ensure optimal performance. thus, the converted result appears at the same time in addat when the first instruction of the interrupt service routine is executed. similar considerations apply to the timing of the flag bsy where usually a "jb bsy,$" instruction is used for polling. lf a continuous conversion is established, the next conversion is automatically started in the machine cycle following the last cycle of the previous conversion. figure 7-32 timing diagram of an a/d converter semiconductor group 93 on-chip peripheral components 7.5 the compare/capture unit (ccu) the compare/capture unit is one of the sab 80c517s most powerful peripheral units for use in all kinds of digital signal generation and event capturing like pulse generation, pulse width modulation, pulse width measuring etc. the ccu consists of two 16-bit timer/counters with automatic reload feature and an array of 13 compare or compare/capture registers. a set of six control registers is used for flexible adapting of the ccu to a wide variety of users applications. the ccu is the ideal peripheral for various automotive control applications (ignition/injection control, anti-lock brakes, etc.) as well as for industrial applications (dc, three-phase ac, and stepper motor control, frequency generation, digital-to-analog conversion, process control, etc.) the detailed description in the following sections refers to the ccus functional blocks as listed below: C timer 2 with f osc /12 input clock, 2-bit prescaler, (4-bit prescaler, in sab 80c517 identification mark "bb" or later), 16-bit reload, counter/gated timer mode and overflow interrupt request. C compare timer with f osc /2 input clock, 8-bit prescaler, 16-bit reload and overflow interrupt request. C compare/(reload/)capture register array consisting of four different kinds of registers: one 16-bit compare/reload/capture register, three 16-bit compare/capture registers, one 16-bit compare/capture register with additional "concurrent compare" feature, eight 16-bit compare registers with timer-overflow controlled loading. altogether the register array may control up to 21 output lines and can request up to 7 independent interrupts. for brevity, in the following text all double-byte compare, compare/capture or compare/reload/ capture registers are called cmx (x = 0 7), ccx (x = 0 4) or crc register, respectively. the block diagram in figure 7-33 shows the general configuration of the ccu. all ccx registers and the crc register are exclusively assigned to timer 2. each of the eight compare registers cm0 through cm7 can either be assigned to timer 2 or to the faster compare timer, e.g. to provide up to 8 pwm channels. the assignment of the cmx registers - which can be done individually for every single register - is combined with an automatic selection of one of the two possible compare modes. semiconductor group 94 on-chip peripheral components port 5, port 4 and seven lines of port 1 have alternate functions dedicated to the ccu. these functions are listed in table 7-8 . normally each register controls one dedicated output line at the ports. register cc4 is an exception as it can manipulate up to nine output lines (one at port 1.4 and the other eight at port 5) concurrently. this feature, the "concurrent compare", is described in section 7.5.5.1. note that for an alternate input function the port-bit latch has to be programmed with a 1. for bit latches of port pins that are used as compare outputs, the value to be written to the bit latches depends on the compare mode established. a list of all special function registers concerned with the ccu is given in table 7-9 . figure 7-33 block diagram of the ccu semiconductor group 95 on-chip peripheral components table 7-8 alternate port functions of the ccu 1) pin numbering refers to the p-lcc-84 package pin symbol pin no. 1) alternate function p5.0/ccm0 p5.1/ccm1 p5.2/ccm2 p5.3/ccm3 p5.4/ccm4 p5.5/ccm5 p5.6/ccm6 p5.7/ccm7 68 67 66 65 64 63 62 61 concurrent compare 0 concurrent compare 1 concurrent compare 2 concurrent compare 3 concurrent compare 4 concurrent compare 5 concurrent compare 6 concurrent compare 7 p4.7/cm7 p4.6/cm6 p4.5/cm5 p4.4/cm4 p4.3/cm3 p4.2/cm2 p4.1/cm1 p4.0/cm0 9 8 7 6 5 3 2 1 comp. output for the cm7 reg. comp. output for the cm6 reg. comp. output for the cm5 reg. comp. output for the cm4 reg. comp. output for the cm3 reg. comp. output for the cm2 reg. comp. output for the cm1 reg. comp. output for the cm0 reg. p1.7/t2 p1.5/t2ex p1.4/int2 /cc4 p1.3/int6/cc3 p1.2/int5/cc2 p1.1/int4/cc1 p1.0/int3 /cc0 29 31 32 33 34 35 36 external count or gate input to timer 2 external reload trigger input comp. output/capture input for cc register 4 comp. output/capture input for cc register 3 comp. output/capture input for cc register 2 comp. output/capture input for cc register 1 comp. output/capture input for crc register semiconductor group 96 on-chip peripheral components table 7-9 special function registers of the ccu symbol description address ccen cc4en cch1 cch2 cch3 cch4 ccl1 ccl2 ccl3 ccl4 cmen cmh0 cmh1 cmh2 cmh3 cmh4 cmh5 cmh6 cmh7 cml0 cml1 cml2 cml3 cml4 cml5 cml6 cml7 cmsel crch crcl ctcon ctrelh ctrell ircon th2 tl2 t2con comp./capture enable reg. comp./capture 4 enable reg. comp./capture reg. 1, high byte comp./capture reg. 2, high byte comp./capture reg. 3, high byte comp./capture reg. 4, high byte comp./capture reg. 1, low byte comp./capture reg. 2, low byte comp./capture reg. 3, low byte comp./capture reg. 4, low byte compare enable register compare reg. 0, high byte compare reg. 1, high byte compare reg. 2, high byte compare reg. 3, high byte compare reg. 4, high byte compare reg. 5, high byte compare reg. 6, high byte compare reg. 7, high byte compare reg. 0, low byte compare reg. 1, low byte compare reg. 2, low byte compare reg. 3, low byte compare reg. 4, low byte compare reg. 5, low byte compare reg. 6, low byte compare reg. 7, low byte compare input select com./rel./capt. reg., high byte com./rel./capt. reg., low byte com. timer control reg. com. timer rel. reg., high byte com. timer rel. reg., low byte interrupt control register timer 2, high byte timer 2, low byte timer 2 control register 0c1 h 0c9 h 0c3 h 0c5 h 0c7 h 0cf h 0c2 h 0c4 h 0c6 h 0ce h 0f6 h 0d3 h 0d5 h 0d7 h 0e3 h 0e5 h 0e7 h 0f3 h 0f5 h 0d2 h 0d4 h 0d6 h 0e2 h 0e4 h 0e6 h 0f2 h 0f4 h 0f7 h 0cb h 0ca h 0e1 h 0df h 0de h 0c0 h 0cd h 0cc h 0c8 h semiconductor group 97 on-chip peripheral components 7.5.1 timer 2 timer 2 is one of the two 16-bit time bases of the compare/capture unit. it can operate as timer, event counter, or gated timer. the block diagram in figure 7-34 a) shows the general configuration of the timer 2. figure 7-34 a) block diagram of timer 2 semiconductor group 98 on-chip peripheral components timer mode in timer function, the count rate is derived from the oscillator frequency. a 2:1 prescaler offers the possibility of selecting a count rate of 1/12 or 1/24 of the oscillator frequency. thus, the 16-bit timer register (consisting of th2 and tl2) is either incremented in every machine cycle or in every second machine cycle. the prescaler is selected by bit t2ps in special function register t2con ( see figure 7-35 ). lf t2ps is cleared, the input frequency is 1/12 of the oscillator frequency; if t2ps is set, the 2:1 prescaler gates 1/24 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. lf t2 is high, the internal clock input is gated to the timer. t2 = 0 stops the counting procedure. this will facilitate pulse width measurements. the external gate signal is sampled once every machine cycle (for the exact port timing, please refer to section 7.1 "parallel i/o"). event counter mode in the counter function, the 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 (24 oscillator periods) to recognize a 1-to-0 transition, the maximum count rate is 1/24 of the oscillator frequency. there are no restrictions on the duty cycle of the external input signal, but to ensure that a given level is sampled at least once before it changes, it must be held for at least one full machine cycle (see also section 7.1 "parallel i/o" for the exact sample time at the port pin p1.7). note: the prescaler must be off for proper counter operation of timer 2, i.e. t2ps must be 0. in either case, no matter whether timer 2 is configured as timer, event counter, or gated timer, a rolling-over of the count from all 1s to all 0s sets the timer overflow flag tf2 (bit 6 in sfr ircon, interrupt request control) which can generate an interrupt. lf tf2 is used to generate a timer overflow interrupt, the request flag must be cleared by the interrupt service routine as it could be necessary to check whether it was the tf2 flag or the external reload request flag exf2 which requested the interrupt (for exf2 see below). both request flags cause the program to branch to the same vector address. the input clock to timer 2 is selected by bits t2i0, t2i1, and t2ps as listed in figure 7-35 . semiconductor group 99 on-chip peripheral components reload of timer 2 the reload mode for timer 2 is selected by bits t2r0 and t2r1 in sfr t2con as listed in figure 7-34 b) . two reload modes are selectable: in mode 0 , when timer 2 rolls over from all 1s to all 0s, it not only sets tf2 but also causes the timer 2 registers to be loaded with the 16-bit value in the crc register, which is preset by software. the reload will happen in the same machine cycle in which tf2 is set, thus overwriting the count value 0000 h . in mode 1 , a 16-bit reload from the crc register is caused by a negative transition at the corresponding input pin t2ex/p1.5. in addition, this transition will set flag exf2, if bit exen2 in sfr ien1 is set. lf 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. the reload of timer 2 registers will then take place in the cycle following the one in which the transition was detected. figure 7-34 b) timer 2 in reload mode semiconductor group 100 on-chip peripheral components figure 7-35 special function register t2con timer 2 control register. bit-addressable register which controls timer 2 function and compare mode of registers crc, cc1 to cc3. bit symbol t2i1 t2i0 00 01 10 11 timer 2 input selection no input selected, timer 2 stops timer function input frequency = f osc /12 (t2ps = 0) or f osc /24 (t2ps = 1) counter function, external input controlled by pin t2/p1.7. gated timer function, input controlled by pin t2/p1.7 t2r1 t2r0 0x 10 11 timer 2 reload mode selection reload disabled mode 0: auto-reload upon timer 2 overflow (tf2) mode 1: reload upon falling edge at pin t2ex/p1.5. t2cm compare mode bit for registers crc, cc1 through cc3. when set, compare mode 1 is selected. t2cm = 0 selects compare mode 0. t2ps prescaler select bit. when set, timer 2 is clocked in the timer or gated timer function with 1/24 of the oscillator frequency. t2ps = 0 gates f osc /12 to timer 2. t2ps must be 0 for the counter operation of timer 2. these bits are not used in controlling the ccu. 0cf h 0ce h 0cd h 0cc h 0cb h 0ca h 0c9 h 0c8 h t2ps i3fr i2fr t2r1 t2r0 t2cm t2i1 t2i0 0c8 h t2con semiconductor group 101 on-chip peripheral components 7.5.2 the compare timer this timer - the fourth timer in the sab 80c517 - is implemented to function as a fast 16-bit time base for the compare registers cm0 to cm7. the compare timer combine with the cmx registers can be employed as high-speed output unit or as a fast 16-bit pulse-width modulator unit. for this case, every cmx register assigned to the compare timer automatically operates in compare mode 0: a compare timer overflow sets the corresponding output line at port 4 to low level, a compare match pulls the pin high again (see also section 7.5.4.1). the minimum resolution attainable at the port 4 outputs is t cycle /6 (appr. 166.6 ns at f osc = 12 mhz). the compare timer is provided with a 16-bit auto-reload and an 8-bit prescaler for a very high flexibility concerning timer period length and input clock frequency. a block diagram of the compare timer is shown in figure 7-36 . input clock selection the compare timer receives its input clock from a programmable prescaler which provides eight different input frequencies: f osc /2, f osc /4, f osc /8, f osc /16, f osc /32, f osc /64, f osc /128, f osc /256. the selection can be done in a three-bit field (binary coded) in special function register ctcon ( see figure 7-37 ). register ctcon can be written to at any time, its default value after reset is 00 h (that is f osc /2 input frequency). figure 7-36 compare timer block diagram semiconductor group 102 on-chip peripheral components programming the compare timer in auto-reload operation the compare timer is, once started, a free-running 16-bit timer, which upon overflow is automatically reloaded by the contents of the special function register ctrell (compare timer reload register, low byte) and ctrelh (compare timer reload register, high byte). an initial writing to the reload register ctrell (the low byte) starts the timer. if the compare timer is already running, a write-to-ctrell again triggers an instant reload of the timer, in other words restarts the timer in the cycle following the write instruction with the count being loaded to the reload registers ctrelh/ ctrell. figure 7-37 compare timer control register ctcon compare timer control register. contains clock selection bits for the compare timer, the compare timer overflow flag and the control bit for the timer 2 prescaler. bit function clk2 clk1 clk0 compare timer input clock selection. see table below. ctf compare timer overflow flag. bit is cleared by hardware. if the compare timer interrupt is enabled, ctf = 1 will cause an interrupt. t2ps1 prescaler select bit for timer 2 t2ps1 must be 0 for the counter operation of timer 2. clk2 clk1 clk0 function 0 0 0 compare timer input clock is f osc /2 0 0 1 compare timer input clock is f osc /4 0 1 0 compare timer input clock is f osc /8 0 1 1 compare timer input clock is f osc /16 1 0 0 compare timer input clock is f osc /32 1 0 1 compare timer input clock is f osc /64 1 1 0 compare timer input clock is f osc /128 1 1 1 compare timer input clock is f osc /256 t2ps1 C C C ctf clk2 clk1 clk0 0e1 h ctcon semiconductor group 103 on-chip peripheral components when the reload register is to be loaded with a 16-bit value, the high byte of ctrel must be written first to ensure a determined start or restart position. writing to the low byte then triggers the actual reload procedure mentioned above. the 16-bit reload value can be overwritten at any time. overflow interrupt of the compare timer the compare timer has - as any other timer in the sab 80c517 - its own interrupt request flag, which is in this case called ctf. this flag is located in register ctcon.ctf and is set when the timer count rolls over from all ones to the reload value. the overflow interrupt eases e.g. software control of pulse width modulated output signals. a periodic interrupt service routine caused by an overflow of the compare timer can be used to load new values in the assigned compare registers and thus change the corresponding pwm output accordingly. please refer to section 8 for details about the overflow interrupt (enabling, vector address, priority, etc.). 7.5.3 compare function in the ccu the compare function of a timer/register combination can be described as follows. the 16-bit value stored in a compare or compare/capture register is compared with the contents of the timer register. lf the count value in the timer register matches the stored value, an appropriate output signal is generated at a corresponding port pin. 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 of this time stamp somehow changes the wave of a rectangular output signal at a port pin. this may - as a variation of the duty cycle of a periodic signal - be used for pulse width modulation as well as for a continually controlled generation of any kind of square wave forms. in the case of the sab 80c517, two compare modes are implemented to cover a wide range of possible applications (see section 7.5.4 below). in the sab 80c517 - thanks to the high number of 13 compare registers and two associated timers - several timer/compare register combinations are selectable. in some of these configurations one of the two compare modes may be freely selected, others, however, automatically establish a compare mode. in the following the two possible modes are generally discussed. this description will be referred to in later sections where the compare registers are described. 7.5.4 compare modes of the ccu as already mentioned, there are only a few compare registers with their corresponding port circuitry which are able to serve both compare modes. in most cases the mode is automatically set depending on the timer which is used as time base or depending on the port which outputs the compare signal. semiconductor group 104 on-chip peripheral components 7.5.4.1 compare mode 0 in mode 0, upon matching the timer and compare register contents, the output signal changes from low to high. lt 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 7-38 shows a functional diagram of a port latch in compare mode 0. the port latch is directly controlled by the two signals timer overflow and compare. 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 initially defined period and duty cycle. this is the mode which needs the least cpu time. once set up, the output goes on oscillating without any cpu intervention. figure 7-39 illustrates the function of compare mode 0. for some information on how to operate a timer/compare register configuration to generate pwm signals (e.g. by using a compare interrupt), please refer to chapter 7.5.5 where more details about the configurations can be found, or to chapter 10 where two application examples are provided. figure 7-38 port latch in compare mode 0 semiconductor group 105 on-chip peripheral components modulation range of a pwm signal and differences between the two timer/compare register configurations in the ccu there are two timer/compare register configurations in the ccu which can operate in compare mode 0 (either timer 2 with a ccx (crc and cc1 to cc4) register or the compare timer with a cmx register). they basically operate in the same way, but show some differences concerning their modulation range when used for pwm. generally it can be said that for every pwm generation 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 then would be 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 which is as long as the timer clock period. in the sab 80c517 there are two different modulation ranges for the above mentioned two timer/ compare register combinations. the difference is the location of the above spike within the timer period: at the end of a timer period or at the beginning plus the end of a timer period. please refer to the description of the relevant timer/register combination in section 7.5.5.1 or 7.5.5.2 for details. figure 7-39 function of compare mode 0 (1 C 1/2 n ) x 100 % semiconductor group 106 on-chip peripheral components 7.5.4.2 compare mode 1 in compare mode 1, the software adaptively determines the transition of the output signal. this mode can only be selected for compare registers assigned to timer 2. lt 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 which are independent of the cpu activity. lf 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 pin- level) or should keep its old value at the time the timer 2 count matches the stored compare value. figure 7-40 shows a functional diagram of a 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 only be transferred to the output latch (and thus to the port pin) 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 in which the cpu could unintentionally change the contents of the port latch. for details see also section 7.5.5.1 "using interrupts in combination with the compare function". a read-modify-write instruction (see section 7.1) will read the user-controlled "shadow latch" and write the modified value back to this "shadow-latch". a standard read instruction will - as usual - read the pin of the corresponding compare output. semiconductor group 107 on-chip peripheral components figure 7-40 compare function of compare mode 1 7.5.5 timer/compare register configurations in the ccu the compare function and the reaction of the corresponding outputs depend on the timer/compare register combination. basically, all compare functions implemented in the sab 80(c)515 can also be used in the sab 80c517. furthermore, the sab 80c517 has nine further compare registers and an additional 16-bit timer, thus providing a high flexibility in assigning compare registers to timers and output lines. table 7-10 shows possible configurations of the ccu and the corresponding compare modes which can be selected. the following sections describe the function of these configurations. semiconductor group 108 on-chip peripheral components table 7-10 ccu configurations 7.5.5.1 compare function of timer 2 with registers crc, cc1 to cc4 compare function of registers crc, cc1 to cc3 the compare function of registers crc, cc1 to cc3 is completely compatible with the corresponding function of the sab 80(c)515. registers crc, cc1 to cc3 are permanently connected to timer 2. all four registers are multifunctional as they additionally provide a capture (see section 7.5.6) or a reload capability (the crc register only, see section 7.5.1). a general selection of the function is done in register ccen ( see figure 7-41 ). for compare function they can be used in compare mode 0 or 1, respectively. the compare mode is selected by setting or clearing bit t2cm in special function register t2con. assigned timer compare register compare output at possible modes timer 2 crch/crcl cch1/ccl1 cch2/ccl2 cch3/ccl3 cch4/ccl4 cch4/ccl4 : cch4/ccl4 cmh0/cml0 : cmh7/cml7 p1.0/int3 /cc0 p1.1/int4/cc1 p1.2/int5/cc2 p1.3/int6/cc3 p1.4/int2 /cc4 p5.0/ccm0 : p5.7/ccm7 p4.0/cm0 : p4.7/cm7 comp. mode 0, 1 + reload comp. mode 0, 1 comp. mode 0, 1 comp. mode 0, 1 comp. mode 0, 1 comp. mode 1 : comp. mode 1 comp. mode 1 : comp. mode 1 compare timer cmh0/cml0 : : cmh7/cml7 p4.0/cm0 : : p4.7/cm7 comp. mode 0 (with shadow latches) : : comp. mode 0 (with shadow latches) semiconductor group 109 on-chip peripheral components figure 7-41 special function register ccen compare/capture enable register selects compare or capture function for register crc, cc1 to cc3. figure 7-42 and 7-43 show the general timer/compare register/port latch configuration for registers crc and cc1 to cc4 in compare mode 0 and compare mode 1. please note that the compare interrupts of registers crc and cc4 can be programmed to be negative or positive transition activated. compare interrupts for the cc1 to cc3 registers are always positive transition activated. bit function cocah0 cocal0 00 01 10 11 compare/capture mode for crc register compare/capture disabled capture on falling/rising edge at pin p1.0/int3 /cc0 compare enabled capture on write operation into register crcl cocah1 cocal1 00 01 10 11 compare/capture mode for cc register 1 compare/capture disabled capture on rising edge at pin p1.1/int4/cc1 compare enabled capture on write operation into register ccl1 cocah2 cocal2 00 01 10 11 compare/capture mode for cc register 2 compare/capture disabled capture on rising edge at pin p1.2/int5/cc2 compare enabled capture on write operation into register ccl2 cocah3 cocal3 00 01 10 11 compare/capture mode for cc register 3 compare/capture disabled capture on rising edge at pin p1.3/int6/cc3 compare enabled capture on write operation into register ccl3 cocah3 cocal3 cocah2 cocal2 cocah1 cocal1 cocah0 cocal0 0c1 h ccen semiconductor group 110 on-chip peripheral components figure 7-42 timer 2 with registers ccx (= crc and cc1 to cc4) in compare mode 0 figure 7-43 timer 2 with registers ccx (= crc and cc1 to cc4) in compare mode 1 semiconductor group 111 on-chip peripheral components modulation range in compare mode 0 as already mentioned in the general description of compare mode 0 (section 7.5.4), a 100% variation of the duty cycle of a pwm signal cannot be reached. a time portion of 1/(2 n ) of an n-bit timer period is always left over. this "spike" may either appear 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 is equal to the reload value of the timer; the other half when the compare register is equal to the maximum value of the timer register (here: 0ffff h ). please refer to figure 7-44 where the maximum and minimum duty cycle of a compare output signal is illustrated. timer 2 is incremented with the machine clock ( f osc /12), thus at 12-mhz operational frequency, these spikes are both approx. 500 ns long. figure 7-44 modulation range of a pmw 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-bit) the modulation range would be so severely limited that it would be negligible. semiconductor group 112 on-chip peripheral components example: timer 2 in auto-reload mode; contents of reload register crc = 0ff00 h 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. compare function of register cc4; "concurrent compare" compare register cc4 is new in the sab 80c517 and permanently assigned to timer 2. lt has its own compare/capture enable register cc4en ( see figure 7-47 ). register cc4 can be set to operate as any of the other cc registers ( see also figures 7-42 and 7-43 ). its output pin is p1.4/ cc4/int2 and it has a dedicated compare mode select bit como located in register cc4en. in addition to the standard operation in compare mode 0 or 1, there is another feature called concurrent compare which is just an application of compare mode 1 to more than one output pin. concurrent compare means that the comparison of cc4 and timer 2 can manipulate up to nine port pins concurrently. a standard compare register in compare mode 1 normally transfers a preprogrammed signal level to a single output line. register cc4, however, is able to put a 9-bit pattern to nine output lines. the nine output lines consist of one line at port p1.4 (which is the standard output for register cc4) and an additional eight lines at port 5 ( see figure 7-45 ). concurrent compare is an ideal and effective option where more than one synchronous output signal is to be generated. applications including this requirement could among others be a complex multiple-phase stepper motor control as well as the control of ignition coils of a car engine. all these applications have in common that predefined bit-patterns must be put to an output port at a precisely predefined moment. this moment refers to a special count of timer 2, which was loaded to compare register cc4. figure 7-46 gives an example of how to generate eight different rectangular wave forms at port 5 using a pattern table and a time schedule for these patterns. the patterns are moved into port 5 before the corresponding timer count is reached. the (future) timer count at which the pattern shall appear at the port must be loaded to register cc4. thus the user can mask each port bit differently depending on whether he wants the output to be changed or not. concurrent compare is enabled by setting bit cocoen in special function register cc4en. a 1 in this bit automatically sets compare mode 1 for register cc4, too. a 3-bit field in special function register cc4en determines the additional number of output pins at port 5. port p1.4/cc4/int2 is used as a standard output pin in any compare mode for register cc4. restriction of module. range = 1 256 x 2 x 100% = 0.195% semiconductor group 113 on-chip peripheral components figure 7-45 "concurrent compare" function of register cc4 figure 7-46 example for a "concurrent compare" at port 5 semiconductor group 114 on-chip peripheral components figure 7-47 compare/capture enable register cc4en selects compare or capture function, number of concurrent compares and compare mode of register cc4. bit function cocah4 cocal4 00 01 10 11 compare/capture mode for cc4 register compare/capture disabled capture on falling/rising edge at pin p1.0/int 2/cc4 compare enabled capture on write operation into register cc4l. como compare mode bit. when set compare mode 1 is selected for cc4. como = 0 selects compare mode 0. cocoen enables the compare mode 1 and the concurrent compare output for cc4. setting of this bit automatically sets bit como. cocon2 cocon1 cocon0 selects additional concurrent compare outputs at port 5. see table below. cocon2 cocon1 cocon0 function 0 0 0 one additional output of cc4 at p5.0 0 0 1 additional outputs of cc4 at p5.0 to p5.1 0 1 0 additional outputs of cc4 at p5.0 to p5.2 0 1 1 additional outputs of cc4 at p5.0 to p5.3 1 0 0 additional outputs of cc4 at p5.0 to p5.4 1 0 1 additional outputs of cc4 at p5.0 to p5.5 1 1 0 additional outputs of cc4 at p5.0 to p5.6 1 1 1 additional outputs of cc4 at p5.0 to p5.7 C cocon2cocon1cocon0cocoencocah4 cocal4 como 0c9 h cc4en semiconductor group 115 on-chip peripheral components using interrupts in combination with the compare function the compare service of registers crc, cc1, cc2, cc3 and cc4 is assigned to alternate output functions at port pins p1.0 to p1.4. another option of these pins is that they can be used as external interrupt inputs. however, when using the port lines as compare outputs then the input line from the port pin to the interrupt system is disconnected (but the pins level can still be read under software control). thus, a change of the pins level will not cause a setting of the corresponding interrupt flag. 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 at a match between timer count and register contents) not only manipulates the compare output but also sets the corresponding interrupt request flag. thus, the current task of the cpu is interrupted - of course provided the priority of the compare interrupt is higher than the present task priority - and the corresponding interrupt service routine is called. this service routine then sets up all the necessary parameters for the next compare event. some advantages in using compare interrupts: firstly, there is no danger of unintentional overwriting a compare register before a match has been reached. this could happen when the cpu writes to the compare register without knowing about the actual timer 2 count. secondly, and this is the most interesting advantage of the compare feature, the output pin is exclusively controlled by hardware therefore completely independent from any service delay which in real time applications could be disastrous. 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 space of time. please note two special cases where a program using compare interrupts could show a "surprising" behavior: the first configuration has already been mentioned in the description of 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 latches" used in compare mode 1 are transparent while the compare signal is active. thus, with a slow input clock for timer 2, the comparator signal is active for a long time (= high number of machine cycles) and therefore a fast interrupt controlled reload of the compare register could not only change the "shadow latch" - as probably intended - but also the output buffer. semiconductor group 116 on-chip peripheral components when using the crc or cc4 register, you can select whether an interrupt should be generated when the compare signal goes active or inactive, depending on the status of bits i3fr or i2fr in t2con, respectively. initializing the interrupt to be negative transition triggered is advisive in the above case. 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 cc registers 1 to 3 an interrupt is always requested when the compare signal goes active. the second configuration which should be noted is when compare functions are combined with negative transition activated interrupts. lf the port latch of port p1.0 or p.1.4 contains a 1, the interrupt request flags iex3 or iex2 will immediately be set after enabling the compare mode for the crc or cc4 register. the reason is that first the external interrupt input is controlled by the pins 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. so 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. 7.5.5.2 compare function of registers cm0 to cm7 the ccu of the sab 80c517 contains another set of eight compare registers, an additional timer (the compare timer) and some control sfr in the ccu which have not been described yet. these compare registers and the compare timer are mainly dedicated to pwm applications. the additional compare registers cm0 to cm7, however, are not permanently assigned to the compare timer, each register may individually be configured to work either with timer 2 or the compare timer as shown in table 7-10 on page 133. the flexible assignment of the cmx registers allows an independent use of two time bases where by different application requirements can be met. any cmx register connected to the compare timer automatically works in compare mode 0 e.g. to provide fast pwm with low cpu intervention. together with timer 2, cmx registers operate in compare mode 1; the latter configuration, which is described in the next section, allows the cpu to control the compare output transitions directly. the assignment of the eight registers cm0 to cm7 to either timer 2 or to the compare timer is done by an 8-channel 2:1 multiplexer (shown in the general block diagram in figure 7-33 ). the multiplexer can be programmed by the corresponding bits in special function register cmsel ( see figure 7-48 ). the compare function itself can individually be enabled in the sfr cmen ( see figure 7-49 ). note however that these register are not bit-addressable, which means that the value of single bits can only be changed by and-ing or or-ing the register with a certain mask. semiconductor group 117 on-chip peripheral components figure 7-48 special function register cmsel contains select bits for registers cm0 to cm7. when set, cmlx/cmhx are assigned to the compare timer and compare mode 0 is enabled. the compare registers are assigned to timer 2 if cmselx = 0. in this case compare mode 1 is selected. figure 7-49 special function register cmen contains enable bits for compare registers cm0 to cm7. when set, compare function is enabled and led to the output lines. bit function cmsel.7 cmsel.6 cmsel.5 cmsel.4 cmsel.3 cmsel.2 cmsel.1 cmsel.0 select bit for cm7 select bit for cm6 select bit for cm5 select bit for cm4 select bit for cm3 select bit for cm2 select bit for cm1 select bit for cm0 bit function cmen.7 cmen.6 cmen.5 cmen.4 cmen.3 cmen.2 cmen.1 cmen.0 compare enable bit for cm7 compare enable bit for cm6 compare enable bit for cm5 compare enable bit for cm4 compare enable bit for cm3 compare enable bit for cm2 compare enable bit for cm1 compare enable bit for cm0 cmsel.7 cmsel.6 cmsel.5 cmsel.4 cmsel.3 cmsel.2 cmsel.1 cmsel.0 0f7 h cmsel cmen.7 cmen.6 cmen.5 cmen.4 cmen.3 cmen.2 cmen.1 cmen.0 0f6 h cmen semiconductor group 118 on-chip peripheral components flrst configuration: cmx registers assigned to the compare timer every cmx register switched to the compare timer as a time base operates in compare mode 0 and uses a port 4 pin as an alternate output function ( see table 7-8 : alternate port functions of the ccu). C modulation range in compare mode 0 in the general description of compare mode 0 (section 7.5.4) and in the description of the timer 2/ ccx register configuration (section 7.5.5.1) it was mentioned that a compare output is restricted in its maximum or minimum duty cycle. there is always a time portion of 1/2 n (at n-bit timer length) which is left over. this "spike" may either appear 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 as realized in this configuration. in a compare timer/cmx register configuration, the compare output is set to a constant high level if the contents of the compare registers are equal to the reload register (ctrel). the compare output shows a high level for one timer clock period when a cmx register is set to 0ffff h . thus, the duty cycle can be varied from 0.xx% to 100% depending on the resolution selected (see calculation example in section 7.5.5.1). please refer to figure 7-50 where the maximum and minimum duty cycle of a compare output signal is illustrated. one clock period of the compare timer is equal to one machine state (= 2 oscillator periods) if the prescaler is off. thus, at 12-mhz operational frequency the spike is approx. 166.6 ns long. C the "timer overflow controlled" loading there is one great difference between a cmx register and the other previously described compare registers: compare outputs controlled by cmx registers have no dedicated interrupt function. they use a "timer overflow controlled loading" (further on called "toc loading") to reach the same performance as an interrupt controlled compare. to show what this "toc loading" is for, it will be explained more detailed in the following: the main advantage of the compare function in general is that the controllers outputs are precisely timed by hardware, no matter which task is running on the cpu. this in turn means that the cpu normally does not know about the timer count. so, if the cpu writes to a compare register only in relation to the program flow, then it could easily be that a compare register is overwritten before the timer had the chance to reach the previously loaded compare value. hence, there must be something to "synchronize" the loading of the compare registers to the running timer circuitry. this could either be an interrupt caused by the timer circuitry (as described before) or a special hardware circuitry. semiconductor group 119 on-chip peripheral components figure 7-50 modulation range of a pwm signal generated with a compare timer/cmx register combination thus "toc-ioading" means that there is dedicated hardware in the ccu which synchronizes the loading of the compare registers cmx in such a way that there is no loss of compare events. lt also relieves the cpu of interrupt load. what does this hardware look like: a cmx compare register in compare mode 0 consists of two latches. when the cpu tries to access a cmx register it only addresses a register latch and not the actual compare latch which is connected to the comparator circuit. the contents of the register latch may be changed by the cpu at any time because this change would never affect the compare event for the current timer period. the compare latch (the "actual" latch) holds the compare value for the present timer period. thus the cpu only changes the compare event for the next timer period since the loading of the latch is performed by the timer overflow signal of the compare timer. this means for an application which uses several pwm outputs that the cpu does not have to serve every single compare line by an individual interrupt. lt only has to watch the timer overflow of the compare timer and may then set up the compare events of all compares for the next timer period. this job may take the whole current timer period since the toc loading prevents unintentional overwriting of the actual (and prepared) value in the compare latch. semiconductor group 120 on-chip peripheral components figure 7-51 compare function of a cmx register assigned to the compare timer figure 7-51 shows a more detailed block diagram of a cmx register connected to the compare timer. lt illustrates that the cpu can only access the special function register cmx; the actual compare latch is, however, loaded at timer overflow. the timer overflow signal also sets an interrupt request flag (ctf in register ctcon) which may be used to inform the cpu by an interrupt that a new timer cycle has started and that the compare values for the next cycle may be programmed from now on. the activation of the toc loading depends on a few conditions described in the following. a toc loading is performed only if the cmlx register has been changed by the cpu. a write instruction to the low byte of the cmx register is used to enable the loading. the 8-bit architecture of the sab 80c517 requires such a defined enable mechanism because 16- bit values are to be transferred in two portions (= two instructions). imagine the following situation: one instruction (e.g. loading the low byte of the compare register) is executed just before timer overflow and the other instruction (loading the high byte) after the overflow. lf there were no "rule", the toc loading would just load the new low byte into the compare latch. the high byte - written after timer overflow - would have to wait till the next timer overflow. semiconductor group 121 on-chip peripheral components the mentioned condition for toc loading prevents such undesired behavior. lf the user writes the high byte first then no toc loading will happen before the low byte has been written - even if there is a timer overflow in between. lf the user just intends to change the low byte of the compare latch then the high byte may be left unaffected. summary of the above description of the toc loading: C the cmx registers are - when switched to the compare timer - protected from direct loading by the cpu. a register latch couple provides a defined load time at timer overflow. C thus, the cpu has a full timer period to load a new compare value: there is no danger of overwriting compare values which are still needed in the current timer period. C when writing a 16-bit compare value, the high byte should be written first since the write-to- low-byte instruction enables a 16-bit wide toc loading at next timer overflow. C lf there was no write access to a cmx low byte then no toc loading will take place. C because of the toc loading, all compare values written to cmx registers are only activated in the next timer period. initializing the compare register/compare latch circuit normally when the compare function is desired the initialization program would just write to the compare register (called register latch). the compare latch itself cannot be accessed directly by a move instruction, it is exclusively loaded by the timer overflow signal. in some very special cases, however, an initial loading of the compare latch could be desirable. lf the following sequence is observed during initialization then latches, the register and the compare latch, can be loaded before the compare mode is enabled. semiconductor group 122 on-chip peripheral components action: comment: select compare mode 1 (cmsel.x = 0). this is also the default value after reset. move the compare value for the first timer in compare mode 1 latch is loaded directly period to the compare register cmx (high after a write-to-cmlx. thus the value slips byte first). directly into the compare latch. switch on compare mode 0 (cmsel.x = 1). now select the rigth compare mode. move the compere value for the second the register latch is loaded. this value is timer period to the compare register. used after the first timer overflow. enable the compare function (cmen.x = 1) set up the prescaler for the compare timer. set specific compare output to low level the compare output is switched to low level. (clr p4.x) start the compare timer with a desired value compare function is initialized. (write-to-ctrel) the output will oscillate. second configuration cmx registers assigned to timer 2 any cmx register switched to timer 2 as a time base operates in compare mode 1. in this case cmx registers behave like any other compare register connected to timer 2 (e.g. the crc or ccx registers). please refer to the above description of compare mode 1 for further details. since there are no dedicated interrupts for the cmx compare outputs, again a buffered compare register structure is used to determine an exact 16-bit wide loading of the compare value: the compare value is transferred to the actual compare latches at a write-to-cmlx instruction (low byte of cmx). thus, the cmx register is to be written in a fixed order, too: high byte first, low byte second. lf the high byte may remain unchanged it is sufficient to load only the low byte. see figure 7-52 , block diagram of a cmx register connected to timer 2. semiconductor group 123 on-chip peripheral components figure 7-52 cmx-register assigned to timer 2 7.5.6 capture function in the ccu each of the four compare/capture registers cc1 to cc4 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 C for cc registers 1 to 3: a positive transition at pins cc1 to cc3 of port 1 C for the crc and cc4 register: a positive or negative transition at the corresponding pins, depending on the status of the bits i3fr and i2fr in sfr t2con. lf the edge flags are cleared, a capture occurs in response to a negative transition; if the edge flags are set a capture occurs in response to a positive transition at pins p1.0/ int3 / cc0 and p1.4/ int2 / cc4. semiconductor group 124 on-chip peripheral components in both cases the appropriate port 1 pin is used as input and the port latch must be programmed to contain a one (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 cc0 to cc4 will also set the corresponding external interrupt request flags iex2 to iex6. lf 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. figures 7-53 and 7-54 show functional diagrams of the capture function of timer 2. figure 7-53 illustrates the operation of the crc or cc4 register, while figure 7-54 shows the operation of the compare/capture registers 1 to 3. the two capture modes can be established individually for each capture register by bits in sfr ccen (compare/capture enable register) and cc4en (compare/capture 4 enable register). that means, in contrast to the compare modes, it is possible to simultaneously select mode 0 for one capture register and mode 1 for another register . the bit positions and functions of ccen are listed in figure 7-41 , the one for cc4en in figure 7-47 . semiconductor group 125 on-chip peripheral components figure 7-53 capture with registers crc, cc4 figure 7-54 capture with registers cc1 to cc3 semiconductor group 126 on-chip peripheral components 7.6 arithmetic unit this on-chip arithmetic unit of the sab 80c517 provides fast 32-bit division, 16-bit multiplication as well as shift and normalize features. all operations are unsigned integer operations. the arithmetic unit (further on also called mdu for "multiplication/division unit") has been integrated to support the 8051 core of the sab 80c517 in real-time control applications. lt can increase the execution speed of math-intensive software routines by factor 5 to 10. the mdu is handled by seven registers, which are memory mapped as special function registers like any other registers for peripheral control. therefore, the arithmetic unit allows operations concurrently to and independent of the cpus activity. the following table describes the four general operations the mdu is able to perform: 1) 1 t cy = 1 microsecond at 12-mhz oscillator frequency 2) the maximal shift speed is 6 shifts per machine cycle 7.6.1 programming the mdu operating registers of the mdu the seven sfr of the mdu consist of registers md0 to md5, which contain the operands and the result (or the remainder, resp.) and one control register called arcon. thus md0 to md5 are used twofold: C for the operands before a calculation has been started and C for storage of the result or remainder after a calculation. this means that any calculation of the mdu overwrites its operands. lf a program needs the original operands for further use, they should be stored in general purpose registers in the internal ram. operation result remainder execution time 32bit/16bit 16bit/16bit 16bit x 16bit 32-bit normalize 32-bit shift l/r 32bit 16bit 32bit C C 16bit 16bit C C C 6 t cy 1) 4 t cy 1) 4 t cy 1) 6 t cy 2) 6 t cy 2) semiconductor group 127 on-chip peripheral components operation of the mdu the mdu can be regarded as a special coprocessor for multiplication, division and shift. its operations can be divided into three phases ( see also figure 7-55 ): 1) loading the mdx registers 2) executing the calculation 3) reading the result from the mdx registers during phase two, the mdu works on its own parallelly to the cpu. execution times of the above table refer to this phase. because of the fast operation and the determined execution time for sab 80c517s instructions, there is no need for a busy flag. the cpu may execute a determined number of instructions before the result is fetched. the result and the remainder of an operation may also be stored in the mdx registers for later use. phase one and phase three require cpu activity. in these phases the cpu has to transfer the operands and fetch the results. figure 7-55 operating phases of the mdu semiconductor group 128 on-chip peripheral components how to select an operation the mdu has no dedicated instruction register (only for shift and normalize operations, register arcon is used in such a way). the type of calculation the mdu has to perform is selected following the order in which the mdx registers are written to ( see table 7-11 ). this mechanism also reduces execution time spent for controlling the mdu. hence, a special write sequence selects an operation. the mdu monitors the whole write and read-out sequence to ensure that the cpu has fetched the result correctly and was not interrupted by another calculation task. (see section 7.6.4 "the error flag"). thus, a complete operation lasts from writing the first byte of the operand in phase 1 until reading the last byte of the result in phase 3. 7.6.2 multiplication/division the general mechanism to start an mdu activity has been described above. the following description of the write and read sequences adds to the information given in the table below where the write and read operations necessary for a multiplication or division are listed. table 7-11 programming the mdu for multiplication and division operation 32bit/16bit 16bit/16bit 16bit x 16bit first write last write md0 dendl md1 dend md2 dend md3 dendh md4 dorl md5 dorh md0 dendl md1 dendh md4 dorl md5 dorh md0 mandl md4 morl md1 mandh md5 morh first read last read md0 quol md1 quo md2 quo md3 quoh md4 reml md5 remh md0 quol md1 quoh md4 reml md5 remh md0 prl md1 md2 md3 prh semiconductor group 129 on-chip peripheral components write sequence the first and the last write operation in phase one are fixed for every calculation of the mdu. all write operations inbetween determine the type of mdu calculation. C a write-to-md0 is the first transfer to be done in any case. this write resets the mdu and triggers the error flag mechanism (see below). C the next two or three write operations select the calculation type (32bit/16bit, 16bit/16bit, 16bit x 16bit) the last write-to-md5 finally starts the selected mul/div operation read sequence C any read-out of the mdx registers should begin with md0 C the last read from md5 (division) or md3 (multiplication) determines the end of a whole calculation and releases the error flag mechanism. there is no restriction on the time within which a calculation must be completed. the cpu is allowed to continue the program simultaneously to phase 2 and to fetch the result bytes at any time. lf the users program takes care that interrupting a calculation is not possible, monitoring of the calculation process is probably not needed. in this case, only the write sequence must be observed. any new write access to md0 starts a new calculation, no matter whether the read-out of the former result has been completed or not. 7.6.3 normalize and shift register arcon controls an up to 32-bit wide normalize and shift operation in registers md0 to md3. lt also contains the overflow flag and the error flag which are described in the next two sections. figure 7-56 illustrates special function register arcon. write sequence C a write-to-md0 is also the first transfer to be done for normalize and shift. this write resets the mdu and triggers the error flag mechanism (see below). C to start a shift or normalize operation the last write must access register arcon. semiconductor group 130 on-chip peripheral components read sequence C the order in which the first three registers md0 to md2 are read is not critical C the last read from md3 determines the end of a whole shift or normalize procedure and releases the error flag mechanism. note: any write access to arcon triggers a shift or normalize operation and therefore changes the contents of registers md0 to md3 ! figure 7-56 register arcon arithmetic control register. contains control flags and the shift counter of the mdu. triggers a shift or a normalize operation in register md0 to md3 when being written to. bit function mdef error flag. indicates an improperly performed operation. mdef is set by hardware when an operation is retriggered by a write access to mdx before the first operation has been completed. mdef is automatically cleared after being read. mdov overflow flag. exclusively controlled by hardware. mdov is set by following events: C division by zero C multiplication with a result greater than 0ffff h . slr shift direction bit. when set, shift right is performed. slr = 0 selects shift left operation. sc.4 sc.3 sc.2 sc.1 sc.0 shift counter. when preset with 00000 b , normalizing is selected. after operation sc.0 to sc.4 contain the number of normalizing shifts performed. when set with a value 1 0, shift operation is started. the number of shifts performed is determined by the count written to sc.0 to sc.4. mdef mdov slr sc.4 sc.3 sc.2 sc.1 sc.0 0ef h arcon semiconductor group 131 on-chip peripheral components normalizing normalizing is done on an integer variable stored in md0 (least significant byte) to md3 (most significant byte). this feature is mainly meant to support applications where floating point arithmetic is used. "to normalize" means, that all reading zeroes of an integer variable in registers md0 to md3 are removed by shift left operations. the whole operation is completed when the msb (most significant bit) contains a 1. to select a normalize operation, the five bit field arcon.0 to arcon.4 must be cleared. that means, a write-to-arcon instruction with the value xxx0 0000 b starts the operation. after normalizing, bits arcon.0 to arcon.4 contain the number of shift left operations which were done. this number may further on be used as an exponent. the maximum number of shifts in a normalize operation is 31 ( = 2 5 C 1). the operation takes six machine cycles at most, that means 6 microseconds at 12 mhz. shifting in the same way - by a write-to-arcon instruction - a shift left/right operation can be started. in this case register bit slr (arcon.5) has to contain the shift direction, and arcon.0 to arcon.4 the shift count (which must not be 0, otherwise a normalize operation would be executed). during shift, zeroes come into the left or right end of the registers md0 or md3, respectively. the first machine cycle of a shift left/right operation executes four shifts, while all following cycles perform 6 shifts. hence, a 31-bit shift takes 6 microseconds at 12 mhz. completion of both operations, normalize and shift, can also be controlled by the error flag mechanism described in 7.6.4. the error flag is set if one of the relevant registers (md0 through md3) is accessed before the previously commenced operation has been completed. for proper operation of the error flag mechanism, it is necessary to take care that the right write or read sequence to or from registers md0 to md3 ( see table 7-12 ) is maintained. semiconductor group 132 on-chip peripheral components table 7-12 programming a shift or normalize operation 7.6.4 the overflow flag an overflow flag is provided for some exceptions during mdu calculations. there are three cases where flag mdov arcon.6 is set by hardware: C division by zero C multiplication with a result greater then 0000 ffff h (= auxiliary carry of the lower 16bit) C start of normalizing if the most significant bit of md3 is set (md3.7 = 1). any operation of the mdu which does not match the above conditions clears the overflow flag. note that the overflow flag is exclusively controlled by hardware. lt cannot be written to. 7.6.5 the error flag an error flag, bit mdef in register arcon ( figure 7-56 ), is provided to indicate whether one of the arithmetic operations of the mdu (multiplication, division, normalize, shift left/right) has been restarted or interrupted by a new operation. this can possibly happen e.g. when an interrupt service routine interrupts the writing or reading sequence of the arithmetic operation in the main program and starts a new operation. then the contents of the corresponding registers are indeterminate (they would normally show the result of the last operation executed). operation normalize, shift left, shift right first write last write md0 least significant byte md1 md2 md3 most significant byte arcon start of conversion first read last read md0 least significant byte md1 md2 md3 most significant byte semiconductor group 133 on-chip peripheral components in this case the error flag can be used to indicate whether the values in the registers md0 to md5 are the expected ones or whether the operation must be repeated. for a multiplication/division, the error flag mechanism is automatically enabled with the first write instruction to md0 (phase 1). according to the above described programming sequences, this is the first action for every type of calculation. the mechanism is disabled with the final read instruction from md3 or md5 (phase 3). every instruction which rewrites md0 (and therefore tries to start a new calculation) in phases 1 through 3 of the same process sets the error flag. the same applies for any shift operation (normalize, shift left/right). the error flag is set if the users program reads one of the relevant registers (md0 to md3) or if it writes to md0 again before the shift operation has been completed. please note that the error flag mechanism is just an option to monitor the mdu operation. lf the users program is designed such that an mdu operation cannot be interrupted by other calculations, then there is no need to pay attention to the error flag. in this case it is also possible to change the order in which the mdx registers are read, or even to skip some register read instructions. concerning the shift or normalize instructions, it is possible to read the result before the complete execution time of six machine cycles has passed (e.g. when a small number of shifts has been programmed). all of the above "illegal" actions would set the error flag, but on the other hand do not affect a correct mdu operation. the user has just to make sure that everything goes right. the error flag (mdef) is located in arcon and can be read only. lt is automatically cleared after being read. semiconductor group 134 on-chip peripheral components 7.7 power saving modes the sab 80c517 provides - due to siemens acmos technology - three modes in which power consumption can be significantly reduced. C idle mode the cpu is gated off from the oscillator. all peripherals are still provided with the clock and are able to work. C power-down mode operation of the sab 80c517 is completely stopped, the oscillator is turned off. this mode is used to save the contents of the internal ram with a very low standby current. C slow-down mode the controller keeps up the full operating functionality, but its normal clock frequency is internally divided by eight. this slows down all parts of the controller, the cpu and all peripherals, to 1/8th of their normal operating frequency. slowing down the frequency greatly reduces power consumption. all of these modes - a detailed description of each is given in the following sections - are entered by software. special function register pcon (power control register, see figure 7-57 ) is used to select one of these modes. these power saving modes, especially the power-down mode, replace the hardware power-down supply for the internal ram via a dedicated pin, as it is common with nmos microcontrollers. during the power saving modes, the power supply for the sab 80c517 is again via all v cc pins. there is no further dedicated pin for power-down supply. for the sab 80c517 several provisions have been made to quality it for both electrically noisy environments and applications requiring high system security. in such applications unintentional entering of the power saving modes must be absolutely avoided. a power saving mode would reduce the controllers performance (in the case of slow-down mode) or even stop any operation (in the case of power-down mode). this situation might be fatal for the system, which is controlled by the microcontroller. such critical applications often use the watchdog timer to prevent the system from program upsets. then, an accidental entering of the power saving modes would even stop the watchdog timer and would circumvent the watchdog timers task of system protection. semiconductor group 135 on-chip peripheral components hardware enable for the use of the power saving modes to provide power saving modes together with effective protection against unintentional entering of these modes, the sab 80c517 has an extra pin disabling the use of the power saving modes. as this pin will most likely be used only in critical applications it is combined with an automatic start of the watchdog timer (see the description in section 7.8 "fail save mechanisms"). this pin is called pe /swd (powers saving enable /start watchdog timer) and its function is as follows: pe /swd = 1 (logic high level) C use of the power saving modes is not possible. the instruction sequences used for entering these modes will not affect the normal operation of the device. C lf and only if pe /swd is held at high level during reset, the watchdog timer is started immediately after reset is released. pe /swd = 0 (logic low level) C all power saving modes can be activated as described in the following sections C the watchdog timer has to be started by software if system protection is desired. when left unconnected, the pin pe /swd is pulled to high level by a weak internal pullup. this is done to provide system protection by default. the logic level applied to pin pe /swd can be changed during program execution in order to allow or block the use of the power saving modes without any effect on the on-chip watchdog circuitry; (the watchdog timer is started only if pe /swd is on high level at the moment when reset is released; a change at pe /swd during program execution has no effect on the watchdog timer; this only enables or disables the use of the power saving modes.). a change of the pins level is detected in state 3, phase 1. a schmitt trigger is used at the input to reduce susceptibility to noise. in addition to the hardware enable/disable of the power saving modes, a double-instruction sequence which is described in the corresponding sections is necessary to enter power-down and idle mode. the combination of all these safety precautions provide a maximum of system protection. semiconductor group 136 on-chip peripheral components application example for switching pin pe /swd for most applications in noisy environments, components external to the chip are used to give warning of a power failure or a turn off of the power supply. these circuits could be used to control the pe /swd pin. the possible steps to go into power-down mode could then be as follows: C a power-fail signal forces the controller to go into a high priority interrupt routine. this interrupt routine saves the actual program status. at the same time pin pe /swd is pulled low by the power-fail signal. C finally the controller enters power-down mode by executing the relevant double-instruction sequence. 7.7.1 idle mode in idle mode the oscillator of the sab 80c517 continues to run, but the cpu is gated off from the clock signal. however, the interrupt system, the serial channels, the a/d converter, the oscillator watchdog, the division/multiplication unit and all timers, except for 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, accumulator, and all other registers maintain their data during idle mode. the reduction of power consumption, which can be achieved by this feature, depends on the number of peripherals running. lf all timers are stopped and the a/d converter and the division/ multiplication unit are not running, maximum power reduction can be achieved. this state is also the test condition for the idle i cc (see the dc characteristics in the data sheet). thus, the user has to take into account that the right peripheral continues to run or is stopped, respectively, during idle. 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. normally the port pins hold the logical state they had at the time idle was activated. lf some pins are programmed to serve their alternate functions they still continue to output during idle if the assigned function is on. this applies for the compare outputs as well as for the system clock output signal and the serial interface in case the latter could not finish reception or transmission during normal operation. the control signals ale and psen are held at logic high levels ( see table 7-13 ). during idle, as in normal operating mode, the ports can be used as inputs. thus, a capture or reload operation as well as an a/d conversion can be triggered, the timers can be used to count external events and external interrupts can be detected. semiconductor group 137 on-chip peripheral components table 7-13 status of external pins during idle and power-down mode the watchdog timer is the only peripheral which is automatically stopped during idle. the idle mode makes it possible to "freeze" the processors status for a certain time or until an external event causes the controller to go back into normal operating mode. since the watchdog timer is stopped during idle mode, this useful feature of the sab 80c517 is provided even if the watchdog function is used simultaneously. lf the idle mode is to be used the pin pe /swd must be held low. entering the idle mode is to be done by two consecutive instructions immediately following each other. the first instruction has to set the flag bit idle (pcon.0) and must not set bit idls (pcon.5), the following instruction has to set 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 will not initiate the idle mode. bits idle and idls will automatically be cleared after having been set. lf one of these register bits is read the value shown is zero (0). figure 7-57 shows special function register pcon. this double-instruction sequence is implemented to minimize the chance of unintentionally entering the idle mode. note that pcon is not a bit-addressable register, so the above mentioned sequence for entering the idle mode is to be done by byte handling instructions. 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 1 data/alternate outputs data/ last output data/alternate outputs data/ last output port 2 data data address data port 3 data/alternate outputs data/ last output data/alternate outputs data/ last output port 4 data/alternate outputs data last output data/alternate outputs data/ last output port 5 data/alternate outputs data/ last output data/alternate outputs data/ last output port 6 data/alternate outputs data/ last output data/alternate outputs data/ last output semiconductor group 138 on-chip peripheral components the following instruction sequence may serve as an exemple: 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. terminating the idle mode C 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 set the bit idls. C the other possibility of terminating the idle mode is a hardware reset. since the oscillator is still running, the hardware reset is held active for only two machine cycles for a complete reset. figure 7-57 special function register pcon (address 87 h ) bit 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 idsl flag bit is the last instruction before entering the idle mode. sd when set, the slow-down mode is enabled. gf1 general purpose flag gf0 general purpose flag pde power-down enable bit. when set, starting the power-down mode is enabled. idle idle mode enable bit. when set, starting the idle mode is enabled. these bits are not used in controlling the power saving modes smod pds idls sd gf1 gf0 pde idle 87 h pcon semiconductor group 139 on-chip peripheral components 7.7.2 power-down mode in the power-down mode, the on-chip oscillator is stopped. therefore, all functions are stopped, only the contents of the on-chip ram and the sfrs are held. the port pins controlled by their port latches output the values that are held by their sfrs. the port pins which 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; when enabled, the clockout signal (p1.6/clkout) will stop at low level. ale and psen are held at logic low level ( see table 7-13 ). lf the power-down mode is to be used, the pin pe /swd must be held low. entering the power-down mode is done by two consecutive instructions immediately following each other. the first instruction has to set the flag bit pde (pcon.1) and must not set bit pds (pcon.6). the following 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, will not initiate the power-down mode. bit pde and pds will automatically be cleared after having been set and the value shown when reading one of these bits is always zero (0). figure 7-57 shows the special function register pcon. this double- instruction sequence is implemented to minimize the chance of unintentional entering the power- down mode, which could possibly "freeze" the chips activity in an undesired status. note that pcon is not a bit-addressable register, so the above mentioned sequence for entering the power-down mode is composed of byte handling instructions. the following instruction sequence may serve as an 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 the instruction that sets bit pds is the last instruction executed before going into power-down mode. lf idle mode and power-down mode are invoked simultaneously, the power-down mode takes precedence. the only exit from power-down mode is a hardware reset. reset will redefine all sfrs, but will not change the contents of the internal ram. in the power-down mode, v cc can be reduced to minimize power consumption. care must be taken, however, to ensure that v cc is not reduced before the power-down mode is invoked, and that v cc is restored to its normal operating level before the power-down mode is terminated. the reset signal that terminates the power-down mode also frees the oscillator. the reset should not be activated before v cc 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). semiconductor group 140 on-chip peripheral components 7.7.3 slow-down mode in some applications, where power consumption and dissipation is 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 interdependence of 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 eight. this also includes the clockout signal at pin p1.6/clkout. lf the slow-down mode is to be used the pin pe /swd must be held low. the slow-down mode is entered by setting bit sd (pcon.4), see figure 7-57 . the controller actually enters the slow-down mode after a short synchronization period (max. two machine cycles). the slow-down mode can be used together with idle and power-down mode. the slow-down mode is disabled by clearing bit sd. semiconductor group 141 on-chip peripheral components 7.8 fail save mechanisms the sab 80c517 offers two on-chip peripherals which monitor the program flow and ensure an automatic "fail-safe" reaction for cases where the controllers hardware fails or the software hangs up: C a programmable watchdog timer (wdt) with variable time-out period from 512 microseconds up to approx. 1.1 seconds at 12 mhz. the sab 80c517s wdt is a superset of the sab 80515 watchdog. C an oscillator watchdog (owd) which monitors the on-chip oscillator and forces the microcontroller into the reset state if the on-chip oscillator fails. 7.8.1 programmable watchdog timer to protect the system against software upset, the users program has to clear this watchdog within a previously programmed time period. lf the software fails to do this periodical refresh of the watchdog timer, 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 sab 80c517 is a 15-bit timer, which is incremented by a count rate of either f cycle /2 or f cycle /32 ( f cycle = f osc /12). that is, the machine clock is divided by a series arrangement of two prescalers, a divide-by-two and a divide-by-16 prescaler ( see figure 7-58 ). the latter is enabled by setting bit wdtrel.7. immediately after start (see next section for the start procedure), the watchdog timer is initialized to the reload value programmed to wdtrel.0 - wdtrel.6. after an external hw or hwpd reset, an oscillator 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. examples (given for a 12-mhz oscillator frequency): wdtrel = time-out period comments 00 h 65.535 ms this is the default value and coincides with the watchdog period of the sab 80515 80 h 1.1 s maximum time period 7f h 512 m s minimum time period semiconductor group 142 on-chip peripheral components starting the watchdog timer there are two ways to start the watchdog timer depending on the level applied to pin pe /swd (pin 4). this pin serves two functions, because it is also used for blocking the power saving modes. for details see chapter 7.7. C the first possibility of starting the watchdog timer the automatic start of the watchdog timer directly after an external hw reset is a hardware start initialized by strapping pin 4 (pe /swd) to v cc . in this case the power-saving modes (power-down mode, idle mode and slow-down mode) are also disabled and cannot be started by software. the self-start of the watchdog timer by a pin option has been implemented to provide high system security in electrically very noisy environments. note: the automatic start of the watchdog timer is only performed if pe /swd (power-save enable /start watchdog timer) is held at high level while reset is active. a positive transition at this pin during normal program execution will not start the watchdog timer. furthermore, when using the hardware start, the watchdog timer starts running with its default time- out period. the value in the reload register wdtrel, however, can be overwritten at any time to set any time-out period desired. C the second possibility of starting the watchdog timer the watchdog timer can also be started by software. this method is compatible to the start procedure in the sab 80(c)515. only setting of bit swdt in special function register ien1 ( figure 7-61 ) starts the watchdog timer. starting the watchdog timer does not automatically reload the wdtrel register into the watchdog timer registers wdtl/wdth. a reload of wdtrel occurs only when using the double instruction refresh sequence setb wdt/setb swdt. using the software start, the time-out period can be programmed before the watchdog timer starts running. note that once the watchdog timer has been started it cannot be stopped by anything but an external hardware reset through pin 10 with a low level applied to pin pe /swd. 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 automatically be cleared 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. semiconductor group 143 on-chip peripheral components the reload register wdtrel can be written to at any time, as already mentioned. therefore, a periodical refresh of wdtrel can be added to the above mentioned starting procedure of the watchdog timer. thus a wrong reload value caused by a possible distortion during the write operation to the wdtrel can be corrected by software. figure 7-58 block diagram of the programmable watchdog timer figure 7-59 special function register wdtrel bit function wdtrel.7 prescaler select bit. when set, the watchdog is clocked through an additional divide-by-16 prescaler ( see figure 7-58 ). wdtrel.6 to wdtrel.0 seven bit reload value for the high-byte of the watchdog timer. this value is loaded to the wdt when a refresh is triggered by a consecutive setting of bits wdt and swdt. watchdog timer reload register wdtrel 086 h semiconductor group 144 on-chip peripheral components watchdog reset and watchdog status flag lf the software fails to clear 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 special function register ip0) is set. figure 7-62 shows a block diagram of all reset requests in the sab 80c517 and the function of the watchdog status flags. the wdts flag is a flip-flop, which is set by a watchdog timer reset and cleared by an external hw reset. bit wdts allows the software to examine from which source the reset was activated. the watchdog timer status flag can also be cleared by software. figure 7-60 special function register ien0 figure 7-61 special function register ien1 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. bit function swdt watchdog timer start flag. set to activate the watchdog timer. when directly set after setting wdt, a watchdog timer refresh is performed. these bits are not used in controlling the fail-safe mechanisms. 0af h 0ae h 0ad h 0ac h 0ab h 0aa h 0a9 h 0a8 h eal wdt et2 es0 et1 ex1 et0 ex0 0a8 h ien0 these bits are not used in controlling the fail-safe mechanisms. 0bf h 0be h 0bd h 0bc h 0bb h 0ba h 0b9 h 0b8 h exen2 swdt ex6 ex5 ex4 ex3 ex2 eadc 0b8 h ien1 semiconductor group 145 on-chip peripheral components figure 7-62 watchdog status flags and reset requests figure 7-63 special function register ip0 bit function owds oscillator watchdog timer status flag. set by hardware when an oscillator watchdog reset occured. can be cleared or set by software wdts watchdog timer status flag. set by hardware when a watchdog timer reset occured. can be cleared or set by software these bits are not used in controlling the fail-safe mechanisms. owds wdts ip0.5 ip0.4 ip0.3 ip0.2 ip0.1 ip0.0 0a9 h ip0 semiconductor group 146 on-chip peripheral components 7.8.2 oscillator watchdog what happens in a microcontroller system it the controllers on-chip oscillator stops working? this failure e.g. caused by a broken crystal, an open connection to the crystal, or a long-term disturbance normally leaves the system in a random, undetermined state. the sab 80c517 provides a "fail- safe" reaction upon an oscillator failure. lf the on-chip oscillator frequency falls below a certain limit due to a hardware defect, the oscillator watchdog initiates an internal reset. this reset state is maintained until the on-chip oscillator is working again. this ensures a maximum of system protection with a minimum of susceptibility to distortion or to operating errors. in the reset state all port pins of the sab 80c517 show a 1. the oscillator watchdog consists of an integrated rc oscillator combined with a frequency comparator. lf the on-chip oscillators frequency falls below the frequency of the rc oscillator, the comparator generates a signal which initiates a reset. the rc oscillator runs with a frequency of typically 300 khz and works without any external components. lt also determines, as long as it is used, the lower limit of the sab 80c517s operating frequency, which is therefore specified at 1 mhz. since the frequency comparator of the oscillator watchdog takes its inputs directly from the on-chip oscillator, the minimum frequency of 1 mhz does not restrict the use of the slow-down mode. in this mode the cpu runs with one eighth of the normal clock rate (see section 7.7). the oscillator watchdog circuitry can be enabled externally. lf the owe pin (oscillator watchdog enable) is pulled low, the oscillator watchdog function is off. lf the pin is left unconnected or has a logic high level, the watchdog oscillator is activated. thus, the watchdog is enabled even if the pin or the path to the pin is broken. like the watchdog timer circuitry, the oscillator watchdog circuitry contains a status flip-flop. this flip-flop is set when an oscillator failure is detected and it is cleared by an external hw reset or by software ( see figure 7-62 ). the block diagram in figure 7-64 illustrates the function of the oscillator watchdog. note that the owd reset request is held for at least three additional cycles after the on-chip oscillator returns to normal operation. this is done to ensure a proper oscillator startup. semiconductor group 147 on-chip peripheral components figure 7-64 functional block diagram of the oscillator watchdog semiconductor group 148 on-chip peripheral components 7.9 oscillator and clock circuit xtal1 and xtal2 are the input and output of a single-stage on-chip inverter which can be configured with off-chip components 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 at half the oscillator frequency. these signals define the internal phases, states and machine cycles, as described in chapter 3. figure 7-65 shows the recommended oscillator circuit. figure 7-65 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 7-66 ). lt 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 30 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. lt a ceramic resonator is used, c 1 and c 2 are normally selected to be of somewhat higher values, typically 47 pf. we recommend consulting the manufacturer of the ceramic resonator for value specifications of these capacitors. semiconductor group 149 on-chip peripheral components to drive the sab 80 c517 with an external clock source, the external clock signal is to be applied to xtal2, as shown in figure 7-67 . xtal1 has to be left unconnected. a pullup resistor is suggested (to increase the noise margin), but is optional if v oh of the driving gate corresponds to the v i h2 specification of xtal2. figure 7-66 on-chip oscillator circuitry figure 7-67 external clock source semiconductor group 150 on-chip peripheral components 7.10 system clock output for peripheral devices requiring a system clock, the sab 80c517 provides a clock output signal derived from the oscillator frequency as an alternate output function on pin p1.6/clkout. lf bit clk is set (bit 6 of special function register adcon0, see figure 7-68 ), a clock signal with 1/12 of the oscillator frequency is gated to pin p1.6/clkout. to use this function the port pin must be programmed to a one (1), which is also the default after reset. figure 7-68 special function register adcon0 (address 0d8 h ) 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 7-69 . note: during slow-down operation (see section 7.7) the frequency of the clockout signal is divided by eight. bit function clk clockout enable bit. when set, pin p1.6/clkout outputs the system clock which is 1/12 of the oscillator frequency. these bits are not used in controlling the clock out functions. 0df h 0de h 0dd h 0dc h 0db h 0da h 0d9 h 0d8 h bd clk adex bsy adm mx2 mx1 mx0 0d8 h adcon0 semiconductor group 151 on-chip peripheral components figure 7-69 timing diagram - system clock output semiconductor group 152 interrupt system 8 interrupt system the sab 80c517 provides 14 interrupt sources with four priority levels. seven interrupts can be generated by the on-chip peripherals (i.e. timer 0, timer 1, timer 2, compare timer, serial interfaces 0 and 1 and a/d converter), and seven interrupts may be triggered externally. short description of the interrupt structure for advanced sab 80(c)515 users the interrupt structure of the sab 80c517 has been mainly adapted from the sab 80(c)515. thus, each interrupt source has its dedicated interrupt vector and can be enabled/disabled individually; there are also four priority levels available. in the sab 80c517 two interrupt sources have been added: C compare timer overflow interrupt C receive and transmit interrupt of serial interface 1 in the sab 80(c)515 the 12 interrupt sources are combined to six pairs; each pair can be programmed to one of the four interrupt priority levels. in the sab 80c517 the new interrupt sources were added to two of these pairs, thus forming triplets; therefore, the 14 interrupt sources are combined to six pairs or triplets; each pair or triplet can be programmed to one of the four interrupt priority levels (see chapter 8.2) figure 8-1 gives a general overview of the interrupt sources and illustrates the request and control flags described in the next sections. the priority structure and the corresponding control bits are listed in section 8.2. 8.1 interrupt structure a common mechanism is used to generate the various interrupts, each source having its own request flag(s) located in a special function register (e.g. tcon, ircon, s0con, s1con). provided the peripheral or external source meets the condition for an interrupt, the dedicated request flag is set, whether an interrupt is enabled or not. for example, each timer 0 overflow sets the corresponding request flag tf0. lf it is already set, it retains a one (1). but the interrupt is not necessarily serviced. now each interrupt requested by the corresponding flag can individually be enabled or disabled by the enable bits in sfrs ien0, ien1, ien2 ( see figure 8-2, 8-3 and 8-4 ). this determines whether the interrupt will actually be performed. in addition, there is a global enable bit for all interrupts which, when cleared, disables all interrupts independent of their individual enable bits. semiconductor group 153 interrupt system figure 8-1 a) interrupt structure of the sab 80c517 semiconductor group 154 interrupt system figure 8-1 b) interrupt structure of the sab 80c517 (contd) semiconductor group 155 interrupt system figure 8-2 special function register ien0 (address 0a8 h ) bit function ex0 enables or disables external interrupt 0. if ex0 = 0, external interrupt 0 is disabled. et0 enables or disables the timer 0 overflow interrupt. if et0 = 0, the timer 0 interrupt is disabled. ex1 enables or disables external interrupt 1. if ex1 = 0, external interrupt 1 is disabled. et1 enables or disables the timer 1 overflow interrupt. if et1 = 0, the timer 1 interrupt is disabled. es0 enables or disables the serial channel 0 interrupt. if es0 = 0, the serial channel 0 interrupt is disabled. et2 enables or disables the timer 2 overflow or external reload interrupt. if et2 = 0, the timer 2 interrupt is disabled. eal enables or disables all interrupts. if eal = 0, no interrupt will be acknowledged. if eal = 1, each interrupt source is individually enabled or disabled by setting or clearing its enable bit. 0af h 0ae h 0ad h 0ac h 0ab h 0aa h 0a9 h 0a8 h eal wdt et2 es0 et1 ex1 et0 ex0 0a8 h ien0 this bit is not used for interrupt control. semiconductor group 156 interrupt system figure 8-3 special function register ien1 (address 0b8 h ) bit function eadc enables or disables the a/d converter interrupt. if eadc = 0, the a/d converter interrupt is disabled. ex2 enables or disables external interrupt 2/capture/compare interrupt 4. if ex2 = 0, external interrupt 2 is disabled. ex3 enables or disables external interrupt 3/capture/compare interrupt 0. if ex3 = 0, external interrupt 3 is disabled. ex4 enables or disables external interrupt 4/capture/compare interrupt 1. if ex4 = 0, external interrupt 4 is disabled. ex5 enables or disables external interrupt 5/capture/compare interrupt 2. if ex5 = 0, external interrupt 5 is disabled. ex6 enables or disables external interrupt 6/capture/compare interrupt 3. if ex6 = 0, external interrupt 6 is disabled. exen2 exables or disables the timer 2 external reload interrupt. exen2 = 0 disables the timer 2 external reload interrupt. the external reload function is not affected by exen2. 0bf h 0be h 0bd h 0bc h 0bb h 0ba h 0b9 h 0b8 h exen2 swdt ex6 ex5 ex4 ex3 ex2 eadc 0b8 h ien1 this bit is not used for interrupt control. semiconductor group 157 interrupt system figure 8-4 special function register ien2 (address 09a h ) in the following the interrupt sources are discussed individually. 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 ( see figure 8-5 ). 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. lf 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 (exception see section 7.3.4 for timer 0 in mode 3). when a timer interrupt is generated, the flag that generated it is cleared by the on-chip hardware when the service routine is vectored too. the two interrupts of the serial interfaces are generated by the request flags ri0 and ti0 (in register s0con) or rl1 and tl1 (in register s1con), respectively. figures 7-7 and 7-12 show sfrs s0con and s1con. that is, the two request flags of each serial interface are logically or- ed together. neither of these flags is cleared by hardware when the service routine is vectored too. in fact, the service routine of each interface will normally have to determine whether it was the receive interrupt flag or the transmission interrupt flag that generated the interrupt, and the bit will have to be cleared by software. the timer 2 interrupt is generated by the logical or of bit tf2 in register t2con and bit exf2 in register ircon. figures 8-6 and 8-7 show sfrs t2con and ircon. neither of these flags is cleared by hardware when the service routine is vectored too. 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. bit function es1 enable serial interrupt of interface 1. enables or disables the interrupt of serial interface 1. if es1 = 0, the interrupt is disabled. ect enable compare timer interrupt. enables or disables the interrupt at compare timer overflow. if ect = 0, the interrupt is disabled. C C C C ect C C es1 09a h ien2 semiconductor group 158 interrupt system figure 8-5 special function register tcon (address 88 h ) the a/d converter interrupt is generated by iadc in register ircon ( see figure 8-7 ). lt is set some cycles before the result is available. that is, if an interrupt is generated, in any case the converted result in addat is valid on the first instruction of the interrupt service routine (with respect to the minimal interrupt response time). lf continuous conversions are established, iadc is set once during each conversion. lf an a/d converter interrupt is generated, flag iadc will have to be cleared by software. the external interrupt 2 (int2 /cc4) can be either positive or negative transition-activated depending on bit i2fr in register t2con ( see figure 8-6 ). the flag that actually generates this interrupt is bit iex2 in register ircon. in addition, this flag will be set if a compare event occurs at the corresponding output pin p1.4/int2 /cc4, regardless of the compare mode established and the transition at the respective pin. lf an interrupt 2 is generated, flag iex2 is cleared by hardware when the service routine is vectored too. bit function it0 interrupt 0 type control bit. set/cleared by software to specify falling edge/low- level triggered external interrupts. ie0 interrupt 0 edge flag. set by hardware when external interrupt edge is detected. cleared when interrupt is initiated. it1 interrupt 1 type control bit. set/cleared by software to specify falling edge/low- level triggered external interrupts. ie1 interrupt 1 edge flag. set by hardware when external interrupt edge is detected. cleared when interrupt is initiated. tf0 timer 0 overflow flag. set by hardware on timer/counter overflow. cleared by hardware when interrupt is initiated. tf1 timer 1 overflow flag. set by hardware on timer/counter overflow. cleared by hardware when interrupt is initiated. 8f h 8e h 8d h 8c h 8b h 8a h 89 h 88 h tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 88 h tcon these bits are not used for interrupt control. semiconductor group 159 interrupt system figure 8-6 special function register t2con (address 0c8 h ) like the external interrupt 2, the external interrupt 3 can be either positive or negative transition- activated, 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/int3 /cc0, regardless of the compare mode established and the transition at the respective pin. the flag iex3 is cleared by hardware when the service routine is vectored too. the external interrupts 4 (int4), 5 (int5), 6 (int6) are positive transition-activated. the flags that actually generate these interrupts are bits iex4, iex5, and iex6 in register ircon ( see figure 8-7 ). in addition, these flags will be set if a compare event occurs at the corresponding output pin p1.1/int4/cc1, p1.2/int5/cc2, and p1.3/int6/cc3, 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 the service routine is vectored too. the compare timer interrupt is generated by bit ctf in register ctcon ( see figure 8-8 ), which is set by a rollover in the compare timer. lf a compare timer interrupt is generated, flag ctf will have to be cleared by software. bit function i2fr external interrupt 2 falling/rising edge flag. when set, the interrupt 2 request flag iex2 will be set on a positive transition at pin p1.4/int2 . i2fr = 0 specifies external interrupt 2 to be negative-transition activated. i3fr external interrupt 3 falling/rising edge flag. when set, the interrupt 3 request flag iex3 will be set on a positive transition at pin p1.0/int3 . i3fr = 0 specifies external interrupt 3 to be negative-transition active. 0cf h 0ce h 0cd h 0cc h 0cb h 0ca h 0c9 h 0c8 h t2ps i3fr i2fr t2r1 t2r0 t2cm t2i1 t2i0 0c8 h t2con these bits are not used for interrupt control. semiconductor group 160 interrupt system figure 8-7 special function register ircon (address 0c0 h ) bit function iadc a/d converter interrupt request flag. set by hardware at the end of a conversion. must be cleared by software. iex2 external interrupt 2 edge flag. set by hardware when external interrupt edge was detected or when a compare event occurred at pin 1.4/int2 /cc4. cleared when interrupt is initiated. iex3 external interrupt 3 edge flag. set by hardware when external interrupt edge was detected or when a compare event occurred at pin 1.0/int3 /cc0. cleared when interrupt is initiated. iex4 external interrupt 4 edge flag. set by hardware when external interrupt edge was detected or when a compare event occurred at pin 1.1/int4/cc1. cleared when interrupt is initiated. iex5 external interrupt 5 edge flag. set by hardware when external interrupt edge was detected or when a compare event occurred at pin 1.2/int5/cc2. cleared when interrupt is initiated. iex6 external interrupt 6 edge flag. set by hardware when external interrupt edge was detected or when a compare event occurred at pin 1.3/int6/cc3. cleared when interrupt is initiated. tf2 timer 2 overflow flag. set by timer 2 overflow. must be cleared by software. if the timer 2 interrupt is enabled, tf2 = 1 will cause an interrupt. exf2 timer 2 external reload flag. set when a reload is caused by a negative transition on pin t2ex while exen2 = 1. when the timer 2 interrupt is enabled, exf2 = 1 will cause the cpu to vector the timer 2 interrupt routine. can be used as an additional external interrupt when the reload function is not used. exf2 must be cleared by software. 0c7 h 0c6 h 0c5 h 0c4 h 0c3 h 0c2 h 0c1 h 0c0 h exf2 tf2 iex6 iex5 iex4 iex3 iex2 iadc 0c0 h ircon semiconductor group 161 interrupt system figure 8-8 special function register ctcon (address 0e1 h ) all of these 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. lf 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. each of these interrupt sources can be individually enabled or disabled by setting or clearing a bit in the special function registers ien0, ien1 and ien2 ( figures 8-2, 8-3 and 8-4 ). note that ien0 contains also a global disable bit, eal, which disables all interrupts at once. also note that in the sab 8051 the interrupt priority register ip is located at address 0b8 h ; in the sab 80c517 this location is occupied by register ien1. 1) only available in sab 80c517 identification mark bb or later. bit function ctf compare timer overflow. set by hardware at a rollover of the compare timer. bit is cleared by hardware (since ca-step; cleared by software in bc-step and earlier versions). if the compare timer interrupt is enabled. ctf = 1 will cause an interrupt. these bits are not used for interrupt control. t2ps1 1) C C C ctf clk2 clk1 clk0 0e1 h ctcon semiconductor group 162 interrupt system 8.2 priority level structure as already mentioned above, all interrupt sources are combined as pairs or triplets; table 8-1 lists the structure of the interrupt sources. table 8-1 pairs and triplets of interrupt sources each pair or triplet of interrupt sources can be programmed individually to one of four priority levels by setting or clearing one bit in the special function register ip0 and one in ip1 ( figure 8-9 ). a low- priority interrupt can itself 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. lf two or more requests of different priority levels are received simultaneously, the request of the highest priority is serviced first. lf 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 polling sequence, as follows ( see figure 8-10 ): C within one pair or triplet the leftmost interrupt is serviced first, then the second and third, when available. C the pairs or triplets are serviced from top to bottom of the table. external interrupt 0 serial channel 1 interrupt a/d converter interrupt timer 0 interrupt C external interrupt 2 external interrupt 1 C external interrupt 3 timer 1 interrupt compare timer interrupt external interrupt 4 serial channel 0 interrupt C external interrupt 5 timer 2 interrupt C external interrupt 6 semiconductor group 163 interrupt system figure 8-9 special function registers ip0 and ip1 (address 0a9 h and 0b9 h ) corresponding bit locations in both registers are used to set the interrupt priority level of an interrupt pair or triplet. bit function ip1.x ip0.x C 0 0 set priority level 0 (lowest) 0 1 set priority level 1 1 0 set priority level 2 1 1 set priority level 3 (highest) bit function ip1.0/ip0.0 ie0/ri1 + ti1/iadc ip1.1/ip0.1 tf0/iex2 ip1.2/ip0.2 ie1/iex3 ip1.3/ip0.3 tf1/ctf/iex4 ip1.4/ip0.4 ri0 + ti0/iex5 ip1.5/ip0.5 tf2 + exf2/iex6 these bits are not used for interrupt control. owds wdts ip0.5 ip0.4 ip0.3 ip0.2 ip0.1 ip0.0 0a9 h ip0 C C ip1.5 ip1.4 ip1.3 ip1.2 ip1.1 ip1.0 0b9 h ip1 semiconductor group 164 interrupt system figure 8-10 priority-within-level structure. note: this "priority-within-level" structure is only used to resolve simultaneous requests of the same priority level. 8.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. lf 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, ien2 or ip0 and 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, ien2 or ip0 and ip1, then at least one more instruction will be executed before any interrupt is vectored too; this delay guarantees that changes of the interrupt status can be observed by the cpu. high ? low priority interrupt source ie0 ri1+ti1 iadc tf0 iex2 ie1 iex3 tf1 ctf iex4 ri0 + ti0 Ciex5 tf2 + exf2 C iex6 high low semiconductor group 165 interrupt system 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 8-11 . figure 8-11 interrupt response timing diagram note that if an interrupt of a higher priority level goes active prior to s5p2 in the machine cycle labeled c3 in figure 8-11 , 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; then this has to be done by the users software. the hardware clears the external interrupt flags ie0 and le1 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 psw) and reloads the program counter with an address that depends on the source of the interrupt being vectored too, as shown in the following ( table 8-2 ). mct01859 s5p2 interrupt is latched interrupts are polled vector address long call to interrupt routine interrupt c2 c1 c3 c4 c5 semiconductor group 166 interrupt system table 8-2 interrupt source and vectors 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 left the current interrupt priority level. a simple ret instruction would also have returned execution to the interrupted program, but it would have left the interrupt control system thinking an interrupt was still in progress. in this case no interrupt of the same or lower priority level would be acknowledged. interrupt request flags interrupt vector address interrupt source ie0 0003 h external interrupt 0 tf0 000b h timer 0 overflow ie1 0013 h external interrupt 1 tf1 001b h timer 1 overflow ri0/ti0 0023 h serial channel 0 tf2/exf2 002b h timer 2 overflow/ext. reload iadc 0043 h a/d converter iex2 004b h external interrupt 2 iex3 0053 h external interrupt 3 iex4 005b h external interrupt 4 iex5 0063 h external interrupt 5 iex6 006b h external interrupt 6 ri1/ti1 0083 h serial channel 1 ctf 009b h compare timer overflow semiconductor group 167 interrupt system 8.4 external interrupts the external interrupts 0 and 1 can be programmed to be level-activated or negative-transition activated by setting or clearing bit it0 or it1, respectively, in register tcon ( see figure 8-5 ). lf itx = 0 (x = 0 or 1), external interrupt x is triggered by a detected low level at the intx pin. lf 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 lex in tcon is set. flag bit lex then requests the interrupt. lf 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 2 and 3 can be programmed to be negative or positive transition-activated by setting or clearing bit i2fr or i3fr in register t2con ( see figure 8-6 ). lf ixfr = 0 (x = 2 or 3), external interrupt x is negative transition-activated. lf ixfr = 1, external interrupt is triggered by a positive transition. the external interrupts 4, 5, and 6 are activated by a positive transition. the external timer 2 reload trigger interrupt request flag exf2 will be activated by a negative transition at pin p1.5/t2ex but only if bit exen2 is set. since the external interrupt pins (int2 to int6) are sampled once in each machine cycle, an input high or low should be held for at least 12 oscillator periods to ensure sampling. lf the external inter- rupt is transition-activated, the external source has to hold the request pin low (high for int2 and int3 , if it is programmed to be negative transition-active) for at least one cycle, and then hold it high (low) for at least one cycle to ensure that the transition is recognized so that the corresponding in- terrupt request flag will be set ( see figure 8-12 ). the external interrupt request flags will automati- cally be cleared by the cpu when the service routine is called. semiconductor group 168 interrupt system figure 8-12 external interrupt detection 8.5 response time lf 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. lf 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. lf an interrupt of equal or higher priority is already in progress, the additional wait time obviously depends on the nature of the other interrupts service routine. lf the instruction in progress is not in its final cycle, the additional wait time cannot be more than 3 cycles since the longest instructions (mul and div) are only 4 cycles long; and, if the instruction in progress is reti or a write access to registers ien0, ien1, ien2 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. semiconductor group 169 instruction set 9 instruction set the sab 80c517 instruction set includes 111 instructions, 49 of which are single-byte, 45 two-byte and 17 three-byte instructions. the instruction opcode format consists of a function mnemonic followed by a destination, source operand field. this field specifies the data type and addressing method(s) to be used. like all other members of the 8051-family, the sab 80c517 can be programmed with the same instruction set common to the basic member, the sab 8051. thus, the sab 80c517 is 100% software compatible to the sab 8051 and may be programmed with 8051 assembler or high-level languages. 9.1 addressing modes the sab 80c517 uses five addressing modes: C register Cdirect C immediate C register indirect C base register plus index-register indirect table 9-1 summarizes the memory spaces which may be accessed by each of the addressing modes. register addressing register addressing accesses the eight working registers (r0 - r7) of the selected register bank. the least significant bit of the instruction opcode indicates which register is to be used. acc, b, dptr and cy, the boolean processor accumulator, can also be addressed as registers. direct addressing direct addressing is the only method of accessing the special function registers. the lower 128 bytes of internal ram are also directly addressable. immediate addressing immediate addressing allows constants to be part of the instruction in program memory. semiconductor group 170 instruction set table 9-1 addressing modes and associated memory spaces register indirect addressing register indirect addressing uses the contents of either r0 or r1 (in the selected register bank) as a pointer to locations in a 256-byte block: the 256 bytes of internal ram or the lower 256 bytes of external data memory. note that the special function registers are not accessible by this method. the upper half of the internal ram can be accessed by indirect addressing only. access to the full 64 kbytes of external data memory address space is accomplished by using the 16-bit data pointer. execution of push and pop instructions also uses register indirect addressing. the stack may reside anywhere in the internal ram. base register plus index register addressing base register plus index register addressing allows a byte to be accessed from program memory via an indirect move from the location whose address is the sum of a base register (dptr or pc) and index register, acc. this mode facilitates look-up table accesses. boolean processor the boolean processor is a bit processor integrated into the sab 80c517. it has its own instruction set, accumulator (the carry flag), bit-addressable ram and l/o. addressing modes associated memory spaces register addressing r0 through r7 of selected register bank, acc, b, cy (bit), dptr direct addressing lower 128 bytes of internal ram, special function registers immediate addressing program memory register indirect addressing internal ram (@r1, @r0, sp), external data memory (@r1, @r0, @dptr) base register plus index register addressing program memory (@dptr + a, @pc + a) semiconductor group 171 instruction set the bit manipulation instructions allow: C set bit C clear bit C complement bit C jump if bit is set C jump if bit is not set C jump if bit is set and clear bit C move bit from / to carry addressable bits, or their complements, may be logically and-ed or or-ed with the contents of the carry flag. the result is returned to the carry register. 9.2 introduction to the instruction set the instruction set is divided into four functional groups: C data transfer C arithmetic C logic C control transfer 9.2.1 data transfer data operations are divided into three classes: C general-purpose C accumulator-specific C address-object none of these operations affects the psw flag settings except a pop or mov directly to the psw. semiconductor group 172 instruction set general-purpose transfers C mov performs a bit or byte transfer from the source operand to the destination operand. C push increments the sp register and then transfers a byte from the source operand to the stack location currently addressed by sp. C pop transfers a byte operand from the stack location addressed by the sp to the destination operand and then decrements sp. accumulator-specific transfers C xch exchanges the byte source operand with register a (accumulator). C xchd exchanges the low-order nibble of the source operand byte with the low-order nibble of a. C movx performs a byte move between the external data memory and the accumulator. the external address can be specified by the dptr register (16 bit) or the r1 or r0 register (8 bit). C movc moves a byte from program memory to the accumulator. the operand in a is used as an index into a 256-byte table pointed to by the base register (dptr or pc). the byte operand accessed is transferred to the accumulator. address-object transfer C mov dptr, #data loads 16 bits of immediate data into a pair of destination registers, dph and dpl. 9.2.2 arithmetic the sab 80c517 has four basic mathematical operations. only 8-bit operations using unsigned arithmetic are supported directly. the overflow flag, however, permits the addition and subtraction operation to serve for both unsigned and signed binary integers. arithmetic can also be performed directly on packed bcd representations. addition C inc (increment) adds one to the source operand and puts the result in the operand. C add adds a to the source operand and returns the result to a. C addc (add with carry) adds a and the source operand, then adds one (1) if cy is set, and puts the result in a. C da (decimal-add-adjust for bcd addition) corrects the sum which results from the binary addition of two-digit decimal operands. the packed decimal sum formed by da is returned to a. cy is set if the bcd result is greater than 99; otherwise, it is cleared. semiconductor group 173 instruction set subtraction C subb (subtract with borrow) subtracts the second source operand from the the first operand (the accumulator), subtracts one (1) if cy is set and returns the result to a. C dec (decrement) subtracts one (1) from the source operand and returns the result to the operand. multiplication C mul performs an unsigned multiplication of the a register, returning a double byte result. a receives the low-order byte, b receives the high-order byte. ov is cleared if the top half of the result is zero and is set if it is not zero. cy is cleared. ac is unaffected. division C div performs an unsigned division of the a register by the b register; it returns the integer quotient to the a register and returns the fractional remainder to the b register. division by zero leaves indeterminate data in registers a and b and sets ov; otherwise, ov is cleared. cy is cleared. ac remains unaffected. flags unless otherwise stated in the previous descriptions, the flags of psw are affected as follows: C cy is set if the operation causes a carry to or a borrow from the resulting high-order bit; otherwise cy is cleared. C ac is set if the operation results in a carry from the low-order four bits of the result (during addition), or a borrow from the high-order bits to the low-order bits (during subtraction); otherwise ac is cleared. C ov is set if the operation results in a carry to the high-order bit of the result but not a carry from the bit, or vice versa; otherwise ov is cleared. ov is used in twos-complement arithmetic, because it is set when the signal result cannot be represented in 8 bits. C p is set if the modulo-2 sum of the eight bits in the accumulator is 1 (odd parity); otherwise p is cleared (even parity). when a value is written to the psw register, the p bit remains unchanged, as it always reflects the parity of a. semiconductor group 174 instruction set 9.2.3 logic the sab 80c517 performs basic logic operations on both bit and byte operands. single-operand operations C clr sets a or any directly addressable bit to zero (0). C setb sets any directly bit-addressable bit to one (1). C cpl is used to complement the contents of the a register without affecting any flag, or any directly addressable bit location. C rl, rlc, rr, rrc, swap are the five operations that can be performed on a. rl, rotate left, rr, rotate right, rlc, rotate left through carry, rrc, rotate right through carry, and swap, rotate left four. for rlc and rrc the cy flag becomes equal to the last bit rotated out. swap rotates a left four places to exchange bits 3 through 0 with bits 7 through 4. two-operand operations C anl performs bitwise logical and of two operands (for both bit and byte operands) and returns the result to the location of the first operand. C orl performs bitwise logical or of two source operands (for both bit and byte operands) and returns the result to the location of the first operand. C xrl performs logical exclusive or of two source operands (byte operands) and returns the result to the location of the first operand. 9.2.4 control transfer there are three classes of control transfer operations: unconditional calls, returns, jumps, conditional jumps, and interrupts. all control transfer operations, some upon a specific condition, cause the program execution to continue a non-sequential location in program memory. semiconductor group 175 instruction set unconditional calls, returns and jumps unconditional calls, returns and jumps transfer control from the current value of the program counter to the target address. both direct and indirect transfers are supported. C acall and lcall push the address of the next instruction onto the stack and then transfer control to the target address. acall is a 2-byte instruction used when the target address is in the current 2k page. lcall is a 3-byte instruction that addresses the full 64k program space. in acall, immediate data (i.e. an 11-bit address field) is concatenated to the five most significant bits of the pc (which is pointing to the next instruction). if acall is in the last 2 bytes of a 2k page then the call will be made to the next page since the pc will have been incremented to the next instruction prior to execution. C ret transfers control to the return address saved on the stack by a previous call operation and decrements the sp register by two (2) to adjust the sp for the popped address. C ajmp, ljmp and sjmp transfer control to the target operand. the operation of ajmp and ljmp are analogous to acall and lcall. the sjmp (short jump) instruction provides for transfers within a 256-byte range centered about the starting address of the next instruction (C 128 to + 127). C jmp @a + dptr performs a jump relative to the dptr register. the operand in a is used as the offset (0 - 255) to the address in the dptr register. thus, the effective destination for a jump can be anywhere in the program memory space. conditional jumps conditional jumps perform a jump contingent upon a specific condition. the destination will be within a 256-byte range centered about the starting address of the next instruction (C 128 to + 127). C jz performs a jump if the accumulator is zero. C jnz performs a jump if the accumulator is not zero. C jc performs a jump if the carry flag is set. C jnc performs a jump if the carry flag is not set. C jb performs a jump if the directly addressed bit is set. C jnb performs a jump if the directly addressed bit is not set. C jbc performs a jump if the directly addressed bit is set and then clears the directly addressed bit. C cjne compares the first operand to the second operand and performs a jump if they are not equal. cy is set if the first operand is less than the second operand; otherwise it is cleared. comparisons can be made between a and directly addressable bytes in internal data memory or an immediate value and either a, a register in the selected register bank, or a register indirectly addressable byte of the internal ram. C djnz decrements the source operand and returns the result to the operand. a jump is performed if the result is not zero. the source operand of the djnz instruction may be any directly addressable byte in the internal data memory. either direct or register addressing may be used to address the source operand. interrupt returns C reti transfers control as ret does, but additionally enables interrupts of the current priority level. semiconductor group 176 instruction set 9.3 instruction definitions all 111 instructions of the sab 80c517 can essentially be condensed to 54 basic operations, in the following alphabetically ordered according to the operation mnemonic section. a brief example of how the instruction might be used is given as well as its effect on the psw flags. the number of bytes and machine cycles required, the binary machine language encoding, and a symbolic description or restatement of the function is also provided. note: only the carry, auxiliary carry, and overflow flags are discussed. the parity bit is computed after every instruction cycle that alters the accumulator. similarily, instructions which alter directly addressed registers could affect the other status flags if the instruction is applied to the psw. status flags can also be modified by bit manipulation. instruction flag instruction flag cy ov ac cy ov ac add x x x setb c 1 addc xxxclr c 0 subb xxxcpl c x mul 0 x anl c,bit x div 0 x anl c,/bit x da x orl c,bit x rrc x orl c,/bit x rlc x mov c,bit x cjne x semiconductor group 177 instruction set notes on data addressing modes rn - working register r0-r7 direct - 128 internal ram locations, any l/o port, control or status register @ri - indirect internal or external ram location addressed by register r0 or r1 #data - 8-bit constant included in instruction #data 16 - 16-bit constant included as bytes 2 and 3 of instruction bit - 128 software flags, any bit-addressable l/o pin, control or status bit a - accumulator notes on program addressing modes addr16 - destination address for lcall and ljmp may be anywhere within the 64-kbyte program memory address space. addr11 - destination address for acall and ajmp will be within the same 2-kbyte page of program memory as the first byte of the following instruction. rel - sjmp and all conditional jumps include an 8-bit offset byte. range is + 127/C 128 bytes relative to the first byte of the following instruction. all mnemonics copyrighted: ? intel corporation 1980 semiconductor group 178 instruction set acall addr11 function: absolute call description: acall unconditionally calls a subroutine located at the indicated address. the instruction increments the pc twice to obtain the address of the following instruction, then pushes the 16-bit result onto the stack (low-order byte first) and increments the stack pointer twice. the destination address is obtained by successively concatenating the five high-order bits of the incremented pc, op code bits 7-5, and the second byte of the instruction. the subroutine called must therefore start within the same 2k block of program memory as the first byte of the instruction following acall. no flags are affected. example: initially sp equals 07 h . the label subrtn is at program memory location 0345 h . after executing the instruction acall subrtn at location 0123 h , sp will contain 09 h , internal ram location 08 h and 09 h will contain 25 h and 01 h , respectively, and the pc will contain 0345 h . operation: acall (pc) ? (pc) + 2 (sp) ? (sp) + 1 ((sp)) ? (pc7-0) (sp) ? (sp) + 1 ((sp)) ? (pc15-8) (pc10-0) ? page address bytes: 2 cycles: 2 encoding: a10 a9 a8 1 0 0 0 1 a7 a6 a5 a4 a3 a2 a1 a0 semiconductor group 179 instruction set add a, semiconductor group 180 instruction set add a, @ri operation: add (a) ? (a) + ((ri)) bytes: 1 cycles: 1 add a, #data operation: add (a) ? (a) + #data bytes: 2 cycles: 1 encoding: 0 0 1 0 0 1 1 i encoding: 0 0 1 0 0 1 0 0 immediate data semiconductor group 181 instruction set addc a, < src-byte> function: add with carry description: addc simultaneously adds the byte variable indicated, the carry flag and the accumulator contents, leaving the result in the accumulator. the carry and auxiliary carry flags are set, respectively, if there is a carry out of bit 7 or bit 3, and cleared otherwise. when adding unsigned integers, the carry flag indicates an overflow occurred. ov is set if there is a carry out of bit 6 but not out of bit 7, or a carry out of bit 7 but not out of bit 6; otherwise ov is cleared. when adding signed integers, ov indicates a negative number produced as the sum of two positive operands or a positive sum from two negative operands. four source operand addressing modes are allowed: register, direct, register- indirect, or immediate. example: the accumulator holds 0c3 h (11000011 b ) and register 0 holds 0aa h (10101010 b ) with the carry flag set. the instruction addc a,r0 will leave 6e h (01101110 b ) in the accumulator with ac cleared and both the carry flag and ov set to 1. addc a,rn operation: addc (a) ? (a) + (c) + (rn) bytes: 1 cycles: 1 addc a,direct operation: addc (a) ? (a) + (c) + (direct) bytes: 2 cycles: 1 encoding: 0 0 1 1 1 r r r encoding: 0 0 1 1 0 1 0 1 direct address semiconductor group 182 instruction set addc a, @ri operation: addc (a) ? (a) + (c) + ((ri)) bytes: 1 cycles: 1 addc a, #data operation: addc (a) ? (a) + (c) + #data bytes: 2 cycles: 1 encoding: 0 0 1 1 0 1 1 i encoding: 0 0 1 1 0 1 0 0 immediate data semiconductor group 183 instruction set ajmp addr11 function: absolute jump description: ajmp transfers program execution to the indicated address, which is formed at run- time by concatenating the high-order five bits of the pc ( after incrementing the pc twice), op code bits 7-5, and the second byte of the instruction. the destination must therefore be within the same 2k block of program memory as the first byte of the instruction following ajmp. example: the label jmpadr is at program memory location 0123 h . the instruction ajmp jmpadr is at location 0345 h and will load the pc with 0123 h . operation: ajm p (pc) ? (pc) + 2 (pc10-0) ? page address bytes: 2 cycles: 2 encoding: a10 a9 a8 0 0 0 0 1 a7 a6 a5 a4 a3 a2 a1 a0 semiconductor group 184 instruction set anl semiconductor group 185 instruction set anl a, @ri operation: anl (a) ? (a) ((ri)) bytes: 1 cycles: 1 anl a, #data operation: anl (a) ? (a) #data bytes: 2 cycles: 1 anl direct,a operation: anl (direct) ? (direct) (a) bytes: 2 cycles: 1 encoding: 0 1 0 1 0 1 1 i encoding: 0 1 0 1 0 1 0 0 immediate data encoding: 0 1 0 1 0 1 0 1 direct address semiconductor group 186 instruction set anl direct, #data operation: anl (direct) ? (direct) #data bytes: 3 cycles: 2 encoding: 0 1 0 1 0 0 1 1 direct address immediate data semiconductor group 187 instruction set anl c, semiconductor group 188 instruction set cjne semiconductor group 189 instruction set cjne a,direct,rel operation: (pc) ? (pc) + 3 if (a) < > (direct) then (pc) ? (pc) + relative offset if (a) < (direct) then (c) ? 1 else (c) ? 0 bytes: 3 cycles: 2 cjne a, #data,rel operation: (pc) ? (pc) + 3 if (a) < > data then (pc) ? (pc) + relative offset if (a) ? data then (c) ? 1 else (c) ? 0 bytes: 3 cycles: 2 cjne rn, #data, rel operation: (pc) ? (pc) + 3 if (rn) < > data then (pc) ? (pc) + relative offset if (rn) < data then (c) ? 1 else (c) ? 0 bytes: 3 cycles: 2 encoding: 1 0 1 1 0 1 0 1 direct address rel. address encoding: 1 0 1 1 0 1 0 0 immediate data rel. address encoding: 1 0 1 1 1 r r r immediate data rel. address semiconductor group 190 instruction set cjne @ri, #data,rel operation: (pc) ? (pc) + 3 if ((ri)) < > data then (pc) ? (pc) + relative offset if ((ri)) < data then (c) ? 1 else (c) ? 0 bytes: 3 cycles: 2 encoding: 1 0 1 1 0 1 1 i immediate data rel. address semiconductor group 191 instruction set clr a function: clear accumulator description: the accumulator is cleared (all bits set to zero). no flags are affected. example: the accumulator contains 5c h (01011100 b ). the instruction clr a will leave the accumulator set to 00 h (00000000 b ). operation: clr (a) ? 0 bytes: 1 cycles: 1 encoding: 1 1 1 0 0 1 0 0 semiconductor group 192 instruction set clr bit function: clear bit description: the indicated bit is cleared (reset to zero). no other flags are affected. clr can operate on the carry flag or any directly addressable bit. example: port 1 has previously been written with 5d h (01011101 b ). the instruction clr p1.2 will leave the port set to 59 h (01011001 b ). clr c operation: clr (c) ? 0 bytes: 1 cycles: 1 clr bit operation: clr (bit) ? 0 bytes: 2 cycles: 1 encoding: 1 1 0 0 0 0 1 1 encoding: 1 1 0 0 0 0 1 0 bit address semiconductor group 193 instruction set cpl a function: complement accumulator description: each bit of the accumulator is logically complemented (ones complement). bits which previously contained a one are changed to zero and vice versa. no flags are affected. example: the accumulator contains 5c h (01011100 b ). the instruction cpl a will leave the accumulator set to 0a3 h (10100011 b ). operation: cpl (a) ? / (a) bytes: 1 cycles: 1 encoding: 1 1 1 1 0 1 0 0 semiconductor group 194 instruction set cpl bit function: complement bit description: the bit variable specified is complemented. a bit which had been a one is changed to zero and vice versa. no other flags are affected. cpl can operate on the carry or any directly addressable bit. note: when this instruction is used to modify an output pin, the value used as the original data will be read from the output data latch, not the input pin. example: port 1 has previously been written with 5d h (01011101 b ). the instruction sequence cpl p1.1 cpl p1.2 will leave the port set to 5b h (01011011 b ). cpl c operation: cpl (bit) ?/ (c) bytes: 1 cycles: 1 cpl bit operation: cpl (c) ?/ (bit) bytes: 2 cycles: 1 encoding: 1 0 1 1 0 0 1 1 encoding: 1 0 1 1 0 0 1 0 bit address semiconductor group 195 instruction set da a function: decimal adjust accumulator for addition description: da a adjusts the eight-bit value in the accumulator resulting from the earlier addition of two variables (each in packed bcd format), producing two four-bit digits. any add or addc instruction may have been used to perform the addition. if accumulator bits 3-0 are greater than nine (xxxx1010-xxxx1111), or if the ac flag is one, six is added to the accumulator producing the proper bcd digit in the low- order nibble. this internal addition would set the carry flag if a carry-out of the low- order four-bit field propagated through all high-order bits, but it would not clear the carry flag otherwise. if the carry flag is now set, or if the four high-order bits now exceed nine (1010xxxx- 1111xxxx), these high-order bits are incremented by six, producing the proper bcd digit in the high-order nibble. again, this would set the carry flag if there was a carry- out of the high-order bits, but wouldnt clear the carry. the carry flag thus indicates if the sum of the original two bcd variables is greater than 100, allowing multiple precision decimal addition. ov is not affected. all of this occurs during the one instruction cycle. essentially; this instruction performs the decimal conversion by adding 00 h , 06 h , 60 h , or 66 h to the accumulator, depending on initial accumulator and psw conditions. note: da a cannot simply convert a hexadecimal number in the accumulator to bcd notation, nor does da a apply to decimal subtraction. example: the accumulator holds the value 56 h (01010110 b ) representing the packed bcd digits of the decimal number 56. register 3 contains the value 67 h (01100111 b ) representing the packed bcd digits of the decimal number 67. the carry flag is set. the instruction sequence addc a,r3 da a will first perform a standard twos-complement binary addition, resulting in the value 0be h (10111110 b ) in the accumulator. the carry and auxiliary carry flags will be cleared. the decimal adjust instruction will then alter the accumulator to the value 24 h (00100100 b ), indicating the packed bcd digits of the decimal number 24, the low- order two digits of the decimal sum of 56, 67, and the carry-in. the carry flag will be set by the decimal adjust instruction, indicating that a decimal overflow occurred. the true sum 56, 67, and 1 is 124. semiconductor group 196 instruction set bcd variables can be incremented or decremented by adding 01 h or 99 h . if the accumulator initially holds 30 h (representing the digits of 30 decimal), then the instruction sequence add a, #99h da a will leave the carry set and 29 h in the accumulator, since 30 + 99 = 129. the low- order byte of the sum can be interpreted to mean 30 C 1 = 29. operation: da contents of accumulator are bcd if [[(a3-0) > 9] [(ac) = 1]] then (a3-0) ? (a3-0) + 6 and if [[(a7-4) > 9] [(c) = 1]] then (a7-4) ? (a7-4) + 6 bytes: 1 cycles: 1 encoding: 1 1 0 1 0 1 0 0 semiconductor group 197 instruction set dec byte function: decrement description: the variable indicated is decremented by 1. an original value of 00 h will underflow to 0ff h . no flags are affected. four operand addressing modes are allowed: accumulator, register, direct, or register-indirect. note: when this instruction is used to modify an output port, the value used as the original port data will be read from the output data latch, not the input pins. example: register 0 contains 7f h (01111111 b ). internal ram locations 7e h and 7f h contain 00 h and 40 h , respectively. the instruction sequence dec @r0 dec r0 dec @r0 will leave register 0 set to 7e h and internal ram locations 7e h and 7f h set to 0ff h and 3f h . dec a operation: dec (a) ? (a) C 1 bytes: 1 cycles: 1 dec rn operation: dec (rn) ? (rn) C 1 bytes: 1 cycles: 1 encoding: 0 0 0 1 0 1 0 0 encoding: 0 0 0 1 1 r r r semiconductor group 198 instruction set dec direct operation: dec (direct) ? (direct) C 1 bytes: 2 cycles: 1 dec @ri operation: dec ((ri)) ? ((ri)) C 1 bytes: 1 cycles: 1 encoding: 0 0 0 1 0 1 0 1 direct address encoding: 0 0 0 1 0 1 1 i semiconductor group 199 instruction set div ab function: divide description: div ab divides the unsigned eight-bit integer in the accumulator by the unsigned eight-bit integer in register b. the accumulator receives the integer part of the quotient; register b receives the integer remainder. the carry and ov flags will be cleared. exception: if b had originally contained 00 h , the values returned in the accumulator and b register will be undefined and the overflow flag will be set. the carry flag is cleared in any case. example: the accumulator contains 251 (0fb h or 11111011 b ) and b contains 18 (12 h or 00010010 b ). the instruction div ab will leave 13 in the accumulator (0d h or 00001101 b ) and the value 17 (11 h or 00010001 b ) in b, since 251 = (13x18) + 17. carry and ov will both be cleared. operation: div (a15-8) (b7-0) bytes: 1 cycles: 4 encoding: 1 0 0 0 0 1 0 0 ? (a) / (b) semiconductor group 200 instruction set djnz semiconductor group 201 instruction set djnz rn,rel operation: djnz (pc) ? (pc) + 2 (rn) ? (rn) C 1 if (rn) > 0 or (rn) < 0 then (pc) ? (pc) + rel bytes: 2 cycles: 2 djnz direct,rel operation: djnz (pc) ? (pc) + 2 (direct) ? (direct) C 1 if (direct) > 0 or (direct) < 0 then (pc) ? (pc) + rel bytes: 3 cycles: 2 encoding: 1 1 0 1 1 r r r rel. address encoding: 1 1 0 1 0 1 0 1 direct address rel. address semiconductor group 202 instruction set inc semiconductor group 203 instruction set inc direct operation: inc (direct) ? (direct) + 1 bytes: 2 cycles: 1 inc @ri operation: inc ((ri)) ? ((ri)) + 1 bytes: 1 cycles: 1 encoding: 0 0 0 0 0 1 0 1 direct address encoding: 0 0 0 0 0 1 1 i semiconductor group 204 instruction set inc dptr function: increment data pointer description: increment the 16-bit data pointer by 1. a 16-bit increment (modulo 2 16 ) is performed; an overflow of the low-order byte of the data pointer (dpl) from 0ff h to 00 h will increment the high-order byte (dph). no flags are affected. this is the only 16-bit register which can be incremented. example: registers dph and dpl contain 12 h and 0fe h , respectively. the instruction sequence inc dptr inc dptr inc dptr will change dph and dpl to 13 h and 01 h . operation: inc (dptr) ? (dptr) + 1 bytes: 1 cycles: 2 encoding: 1 0 1 0 0 0 1 1 semiconductor group 205 instruction set jb bit,rel function: jump if bit is set description: if the indicated bit is a one, jump to the address indicated; otherwise proceed with the next instruction. the branch destination is computed by adding the signed relative-displacement in the third instruction byte to the pc, after incrementing the pc to the first byte of the next instruction. the bit tested is not modified. no flags are affected. example: the data present at input port 1 is 11001010 b . the accumulator holds 56 (01010110 b ). the instruction sequence jb p1.2,label1 jb acc.2,label2 will cause program execution to branch to the instruction at label label2. operation: jb (pc) ? (pc) + 3 if (bit) = 1 then (pc) ? (pc) + rel bytes: 3 cycles: 2 encoding: 0 0 1 0 0 0 0 0 bit address rel. address semiconductor group 206 instruction set jbc bit,rel function: jump if bit is set and clear bit description: if the indicated bit is one, branch to the address indicated; otherwise proceed with the next instruction. in either case, clear the designated bit. the branch destination is computed by adding the signed relative displacement in the third instruction byte to the pc, after incrementing the pc to the first byte of the next instruction. no flags are affected. note: when this instruction is used to test an output pin, the value used as the original data will be read from the output data latch, not the input pin. example: the accumulator holds 56 h (01010110 b ). the instruction sequence jbc acc.3,label1 jbc acc.2,label2 will cause program execution to continue at the instruction identified by the label label2, with the accumulator modified to 52 h (01010010 b ). operation: jbc (pc) ? (pc) + 3 if (bit) = 1 then (bit) ? 0 (pc) ? (pc) + rel bytes: 3 cycles: 2 encoding: 0 0 0 1 0 0 0 0 bit address rel. address semiconductor group 207 instruction set jc rel function: jump if carry is set description: if the carry flag is set, branch to the address indicated; otherwise proceed with the next instruction. the branch destination is computed by adding the signed relative- displacement in the second instruction byte to the pc, after incrementing the pc twice. no flags are affected. example: the carry flag is cleared. the instruction sequence jc label1 cpl c jc label2 will set the carry and cause program execution to continue at the instruction identified by the label label2. operation: jc (pc) ? (pc) + 2 if (c) = 1 then (pc) ? (pc) + rel bytes: 2 cycles: 2 encoding: 0 1 0 0 0 0 0 0 rel. address semiconductor group 208 instruction set jmp @a + dptr function: jump indirect description: add the eight-bit unsigned contents of the accumulator with the sixteen-bit data pointer, and load the resulting sum to the program counter. this will be the address for subsequent instruction fetches. sixteen-bit addition is performed (modulo 2 16 ): a carry-out from the low-order eight bits propagates through the higher-order bits. neither the accumulator nor the data pointer is altered. no flags are affected. example: an even number from 0 to 6 is in the accumulator. the following sequence of instructions will branch to one of four ajmp instructions in a jump table starting at jmp_tbl: mov dptr, #jmp_tbl jmp @a + dptr jmp_tbl: ajmp label0 ajmp label1 ajmp label2 ajmp label3 if the accumulator equals 04 h when starting this sequence, execution will jump to label label2. remember that ajmp is a two-byte instruction, so the jump instructions start at every other address. operation: jmp (pc) ? (a) + (dptr) bytes: 1 cycles: 2 encoding: 0 1 1 1 0 0 1 1 semiconductor group 209 instruction set jnb bit,rel function: jump if bit is not set description: if the indicated bit is a zero, branch to the indicated address; otherwise proceed with the next instruction. the branch destination is computed by adding the signed relative-displacement in the third instruction byte to the pc, after incrementing the pc to the first byte of the next instruction. the bit tested is not modified. no flags are affected. example: the data present at input port 1 is 11001010 b . the accumulator holds 56 h (01010110 b ). the instruction sequence jnb p1.3,label1 jnb acc.3,label2 will cause program execution to continue at the instruction at label label2. operation: jnb (pc) ? (pc) + 3 if (bit) = 0 then (pc) ? (pc) + rel. bytes: 3 cycles: 2 encoding: 0 0 1 1 0 0 0 0 bit address rel. address semiconductor group 210 instruction set jnc rel function: jump if carry is not set description: if the carry flag is a zero, branch to the address indicated; otherwise proceed with the next instruction. the branch destination is computed by adding the signed relative-displacement in the second instruction byte to the pc, after incrementing the pc twice to point to the next instruction. the carry flag is not modified. example: the carry flag is set. the instruction sequence jnc label1 cpl c jnc label2 will clear the carry and cause program execution to continue at the instruction identified by the label label2. operation: jnc (pc) ? (pc) + 2 if (c) = 0 then (pc) ? (pc) + rel bytes: 2 cycles: 2 encoding: 0 1 0 1 0 0 0 0 rel. address semiconductor group 211 instruction set jnz rel function: jump if accumulator is not zero description: if any bit of the accumulator is a one, branch to the indicated address; otherwise proceed with the next instruction. the branch destination is computed by adding the signed relative-displacement in the second instruction byte to the pc, after incrementing the pc twice. the accumulator is not modified. no flags are affected. example: the accumulator originally holds 00 h . the instruction sequence jnz label1 inc a jnz label2 will set the accumulator to 01 h and continue at label label2. operation: jnz (pc) ? (pc) + 2 if (a) 1 0 then (pc) ? (pc) + rel. bytes: 2 cycles: 2 encoding: 0 1 1 1 0 0 0 0 rel. address semiconductor group 212 instruction set jz rel function: jump if accumulator is zero description: if all bits of the accumulator are zero, branch to the address indicated; otherwise proceed with the next instruction. the branch destination is computed by adding the signed relative-displacement in the second instruction byte to the pc, after incrementing the pc twice. the accumulator is not modified. no flags are affected. example: the accumulator originally contains 01 h . the instruction sequence jz label1 dec a jz label2 will change the accumulator to 00 h and cause program execution to continue at the instruction identified by the label label2. operation: jz (pc) ? (pc) + 2 if (a) = 0 then (pc) ? (pc) + rel bytes: 2 cycles: 2 encoding: 0 1 1 0 0 0 0 0 rel. address semiconductor group 213 instruction set lcall addr16 function: long call description: lcall calls a subroutine located at the indicated address. the instruction adds three to the program counter to generate the address of the next instruction and then pushes the 16-bit result onto the stack (low byte first), incrementing the stack pointer by two. the high-order and low-order bytes of the pc are then loaded, respectively, with the second and third bytes of the lcall instruction. program execution continues with the instruction at this address. the subroutine may therefore begin anywhere in the full 64 kbyte program memory address space. no flags are affected. example: initially the stack pointer equals 07 h . the label subrtn is assigned to program memory location 1234 h . after executing the instruction lcall subrtn at location 0123 h , the stack pointer will contain 09 h , internal ram locations 08 h and 09 h will contain 26 h and 01 h , and the pc will contain 1234 h . operation: lcall (pc) ? (pc) + 3 (sp) ? (sp) + 1 ((sp)) ? (pc7-0) (sp) ? (sp) + 1 ((sp)) ? (pc15-8) (pc) ? addr15-0 bytes: 3 cycles: 2 encoding: 0 0 0 1 0 0 1 0 addr15 . . addr8 addr7 . . addr0 semiconductor group 214 instruction set ljmp addr16 function: long jump description: ljmp causes an unconditional branch to the indicated address, by loading the high- order and low-order bytes of the pc (respectively) with the second and third instruction bytes. the destination may therefore be anywhere in the full 64k program memory address space. no flags are affected. example: the label jmpadr is assigned to the instruction at program memory location 1234 h . the instruction ljmp jmpadr at location 0123 h will load the program counter with 1234 h . operation: ljmp (pc) ? addr15-0 bytes: 3 cycles: 2 encoding: 0 0 0 0 0 0 1 0 addr15 . . . addr8 addr7 . . . addr0 semiconductor group 215 instruction set mov semiconductor group 216 instruction set mov a,@ri operation: mov (a) ? ((ri)) bytes: 1 cycles: 1 mov a, #data operation: mov (a) ? #data bytes: 2 cycles: 1 mov rn,a operation: mov (rn) ? (a) bytes: 1 cycles: 1 mov rn,direct operation: mov (rn) ? (direct) bytes: 2 cycles: 2 encoding: 1 1 1 0 0 1 1 i encoding: 0 1 1 1 0 1 0 0 immediate data encoding: 1 1 1 1 1 r r r encoding: 1 0 1 0 1 r r r direct address semiconductor group 217 instruction set mov rn, #data operation: mov (rn) ? #data bytes: 2 cycles: 1 mov direct,a operation: mov (direct) ? (a) bytes: 2 cycles: 1 mov direct,rn operation: mov (direct) ? (rn) bytes: 2 cycles: 2 mov direct,direct operation: mov (direct) ? (direct) bytes: 3 cycles: 2 encoding: 0 1 1 1 1 r r r immediate data encoding: 1 1 1 1 0 1 0 1 direct address encoding: 1 0 0 0 1 r r r direct address encoding: 1 0 0 0 0 1 0 1 dir.addr. (src) dir.addr. (dest) semiconductor group 218 instruction set mov direct, @ ri operation: mov (direct) ? ((ri)) bytes: 2 cycles: 2 mov direct, #data operation: mov (direct) ? #data bytes: 3 cycles: 2 mov @ ri,a operation: mov ((ri)) ? (a) bytes: 1 cycles: 1 mov @ ri,direct ooeration: mov ((ri)) ? (direct) bytes: 2 cycles: 2 encoding: 1 0 0 0 0 1 1 i direct address encoding: 0 1 1 1 0 1 0 1 direct address immediate data encoding: 1 1 1 1 0 1 1 i encoding: 1 0 1 0 0 1 1 i direct address semiconductor group 219 instruction set mov @ ri,#data operation: mov ((ri)) ? #data bytes: 2 cycles: 1 encoding: 0 1 1 1 0 1 1 i immediate data semiconductor group 220 instruction set mov semiconductor group 221 instruction set mov dptr, #data16 function: load data pointer with a 16-bit constant description: the data pointer is loaded with the 16-bit constant indicated. the 16 bit constant is loaded into the second and third bytes of the instruction. the second byte (dph) is the high-order byte, while the third byte (dpl) holds the low-order byte. no flags are affected. this is the only instruction which moves 16 bits of data at once. example: the instruction mov dptr, #1234h will load the value 1234 h into the data pointer: dph will hold 12 h and dpl will hold 34 h . operation: mov (dptr) ? #data15-0 dph dpl ? #data15-8 #data7-0 bytes: 3 cycles: 2 encoding: 1 0 0 1 0 0 0 0 immed. data 15 . . . 8 immed. data 7 . . . 0 semiconductor group 222 instruction set movc a, @a + semiconductor group 223 instruction set movc a, @a + pc operation: movc (pc) ? (pc) + 1 (a) ? ((a) + (pc)) bytes: 1 cycles: 2 encoding: 1 0 0 0 0 0 1 1 semiconductor group 224 instruction set movx semiconductor group 225 instruction set movx a,@ri operation: movx (a) ? ((ri)) bytes: 1 cycles: 2 movx a,@dptr operation: movx (a) ? ((dptr)) bytes: 1 cycles: 2 movx @ri,a operation: movx ((ri)) ? (a) bytes: 1 cycles: 2 movx @dptr,a operation: movx ((dptr)) (a) bytes: 1 cycles: 2 encoding: 1 1 1 0 0 0 1 i encoding: 1 1 1 0 0 0 0 0 encoding: 1 1 1 1 0 0 1 i encoding: 1 1 1 1 0 0 0 0 semiconductor group 226 instruction set mul ab function: multiply description: mul ab multiplies the unsigned eight-bit integers in the accumulator and register b. the low-order byte of the sixteen-bit product is left in the accumulator, and the high-order byte in b. if the product is greater than 255 (0ff h ) the overflow flag is set; otherwise it is cleared. the carry flag is always cleared. example: originally the accumulator holds the value 80 (50 h ). register b holds the value 160 (0a0 h ). the instruction mul ab will give the product 12,800 (3200 h ), so b is changed to 32 h (00110010 b ) and the accumulator is cleared. the overflow flag is set, carry is cleared. operation: mul (a7-0) (b15-8) bytes: 1 cycles: 4 encoding: 1 0 1 0 0 1 0 0 ? (a) x (b) semiconductor group 227 instruction set nop function: no operation description: execution continues at the following instruction. other than the pc, no registers or flags are affected. example: it is desired to produce a low-going output pulse on bit 7 of port 2 lasting exactly 5 cycles. a simple setb/clr sequence would generate a one-cycle pulse, so four additional cycles must be inserted. this may be done (assuming no interrupts are enabled) with the instruction sequence clr p2.7 nop nop nop nop setb p2.7 operation: nop bytes: 1 cycles: 1 encoding: 0 0 0 0 0 0 0 0 semiconductor group 228 instruction set orl semiconductor group 229 instruction set orl a,direct operation: orl (a) ? (a) (direct) bytes: 2 cycles: 1 orl a,@ri operation: orl (a) ? (a) ((ri)) bytes: 1 cycles: 1 orl a,#data operation: orl (a) ? (a) #data bytes: 2 cycles: 1 orl direct,a operation: orl (direct) ? (direct) (a) bytes: 2 cycles: 1 encoding: 0 1 0 0 0 1 0 1 direct address encoding: 0 1 0 0 0 1 1 i encoding: 0 1 0 0 0 1 0 0 immediate data encoding: 0 1 0 0 0 0 1 0 direct address semiconductor group 230 instruction set orl direct, #data operation: orl (direct) ? (direct) #data bytes: 3 cycles: 2 encoding: 0 1 0 0 0 0 1 1 direct address immediate data semiconductor group 231 instruction set orl c, semiconductor group 232 instruction set pop direct function: pop from stack description: the contents of the internal ram location addressed by the stack pointer is read, and the stack pointer is decremented by one. the value read is the transfer to the directly addressed byte indicated. no flags are affected. example: the stack pointer originally contains the value 32 h , and internal ram locations 30 h through 32 h contain the values 20 h , 23 h , and 01 h , respectively. the instruction sequence pop dph pop dpl will leave the stack pointer equal to the value 30 h and the data pointer set to 0123 h . at this point the instruction pop sp will leave the stack pointer set to 20 h . note that in this special case the stack pointer was decremented to 2f h before being loaded with the value popped (20 h ). operation: pop (direct) ? ((sp)) (sp) ? (sp) C 1 bytes: 2 cycles: 2 encoding: 1 1 0 1 0 0 0 0 direct address semiconductor group 233 instruction set push direct function: push onto stack description: the stack pointer is incremented by one. the contents of the indicated variable is then copied into the internal ram location addressed by the stack pointer. otherwise no flags are affected. example: on entering an interrupt routine the stack pointer contains 09 h . the data pointer holds the value 0123 h . the instruction sequence push dpl push dph will leave the stack pointer set to 0b h and store 23 h and 01 h in internal ram locations 0a h and 0b h , respectively. operation: push (sp) ? (sp) + 1 ((sp)) ? (direct) bytes: 2 cycles: 2 encoding: 1 1 0 0 0 0 0 0 direct address semiconductor group 234 instruction set ret function: return from subroutine description: ret pops the high and low-order bytes of the pc successively from the stack, decrementing the stack pointer by two. program execution continues at the resulting address, generally the instruction immediately following an acall or lcall. no flags are affected. example: the stack pointer originally contains the value 0b h . internal ram locations 0a h and 0b h contain the values 23 h and 01 h , respectively. the instruction ret will leave the stack pointer equal to the value 09 h . program execution will continue at location 0123 h . operation: ret (pc15-8) ? ((sp)) (sp) ? (sp) C 1 (pc7-0) ? ((sp)) (sp) ? (sp) C 1 bytes: 1 cycles: 2 encoding: 0 0 1 0 0 0 1 0 semiconductor group 235 instruction set reti function: return from interrupt description: reti pops the high and low-order bytes of the pc successively from the stack, and restores the interrupt logic to accept additional interrupts at the same priority level as the one just processed. the stack pointer is left decremented by two. no other registers are affected; the psw is not automatically restored to its pre-interrupt status. program execution continues at the resulting address, which is generally the instruction immediately after the point at which the interrupt request was detected. if a lower or same-level interrupt is pending when the reti instruction is executed, that one instruction will be executed before the pending interrupt is processed. example: the stack pointer originally contains the value 0b h . an interrupt was detected during the instruction ending at location 0122 h . internal ram locations 0a h and 0b h contain the values 23 h and 01 h , respectively. the instruction reti will leave the stack pointer equal to 09 h and return program execution to location 0123 h . operation: reti (pc15-8) ? ((sp)) (sp) ? (sp) C 1 (pc7-0) ? ((sp)) (sp) ? (sp) C 1 bytes: 1 cycles: 2 encoding: 0 0 1 1 0 0 1 0 semiconductor group 236 instruction set rl a function: rotate accumulator left description: the eight bits in the accumulator are rotated one bit to the left. bit 7 is rotated into the bit 0 position. no flags are affected. example: the accumulator holds the value 0c5 h (11000101 b ). the instruction rl a leaves the accumulator holding the value 8b h (10001011 b ) with the carry unaffected. operation: rl (an + 1) ? (an) n = 0-6 (a0) ? (a7) bytes: 1 cycles: 1 encoding: 0 0 1 0 0 0 1 1 semiconductor group 237 instruction set rlc a function: rotate accumulator left through carry flag description: the eight bits in the accumulator and the carry flag are together rotated one bit to the left. bit 7 moves into the carry flag; the original state of the carry flag moves into the bit 0 position. no other flags are affected. example: the accumulator holds the value 0c5 h (11000101 b ), and the carry is zero. the instruction rlc a leaves the accumulator holding the value 8a h (10001010b) with the carry set. operation: rlc (an + 1) ? (an) n = 0-6 (a0) ? (c) (c) ? (a7) bytes: 1 cycles: 1 encoding: 0 0 1 1 0 0 1 1 semiconductor group 238 instruction set rr a function: rotate accumulator right description: the eight bits in the accumulator are rotated one bit to the right. bit 0 is rotated into the bit 7 position. no flags are affected. example: the accumulator holds the value 0c5 h (11000101 b ). the instruction rr a leaves the accumulator holding the value 0e2 h (11100010 b ) with the carry unaffected. operation: rr (an) ? (an + 1) n = 0-6 (a7) ? (a0) bytes: 1 cycles: 1 encoding: 0 0 0 0 0 0 1 1 semiconductor group 239 instruction set rrc a function: rotate accumulator right through carry flag description: the eight bits in the accumulator and the carry flag are together rotated one bit to the right. bit 0 moves into the carry flag; the original value of the carry flag moves into the bit 7 position. no other flags are affected. example: the accumulator holds the value 0c5 h (11000101 b ), the carry is zero. the instruction rrc a leaves the accumulator holding the value 62 h (01100010 b ) with the carry set. operation: rrc (an) ? (an + 1) n=0-6 (a7) ? (c) (c) ? (a0) bytes: 1 cycles: 1 encoding: 0 0 0 1 0 0 1 1 semiconductor group 240 instruction set setb semiconductor group 241 instruction set sjmp rel function: short jump description: program control branches unconditionally to the address indicated. the branch destination is computed by adding the signed displacement in the second instruction byte to the pc, after incrementing the pc twice. therefore, the range of destinations allowed is from 128 bytes preceding this instruction to 127 bytes following it. example: the label reladr is assigned to an instruction at program memory location 0123 h . the instruction sjmp reladr will assemble into location 0100 h . after the instruction is executed, the pc will contain the value 0123 h . note: under the above conditions the instruction following sjmp will be at 102 h . therefore, the displacement byte of the instruction will be the relative offset (0123 h - 0102 h ) = 21 h . in other words, an sjmp with a displacement of 0fe h would be a one-instruction infinite loop. operation: sjmp (pc) ? (pc) + 2 (pc) ? (pc) + rel bytes: 2 cycles: 2 encoding: 1 0 0 0 0 0 0 0 rel. address semiconductor group 242 instruction set subb a, semiconductor group 243 instruction set subb a,direct operation: subb (a) ? (a) C (c) C (direct) bytes: 2 cycles: 1 subb a, @ ri operation: subb (a) ? (a) C (c) C ((ri)) bytes: 1 cycles: 1 subb a, #data operation: subb (a) ? (a) C (c) C #data bytes: 2 cycles: 1 encoding: 1 0 0 1 0 1 0 1 direct address encoding: 1 0 0 1 0 1 1 i encoding: 1 0 0 1 0 1 0 0 immediate data semiconductor group 244 instruction set swap a function: swap nibbles within the accumulator description: swap a interchanges the low and high-order nibbles (four-bit fields) of the accumulator (bits 3-0 and bits 7-4). the operation can also be thought of as a four- bit rotate instruction. no flags are affected. example: the accumulator holds the value 0c5 h (11000101 b ). the instruction swap a leaves the accumulator holding the value 5c h (01011100 b ). operation: swap (a3-0) (a7-4), (a7-4) ? (a3-0) bytes: 1 cycles: 1 encoding: 1 1 0 0 0 1 0 0 ? ? semiconductor group 245 instruction set xch a, semiconductor group 246 instruction set xch a, @ ri operation: xch (a) ((ri)) bytes: 1 cycles: 1 encoding: 1 1 0 0 0 1 1 i ? ? semiconductor group 247 instruction set xchd a,@ri function: exchange digit description: xchd exchanges the low-order nibble of the accumulator (bits 3-0, generally representing a hexadecimal or bcd digit), with that of the internal ram location indirectly addressed by the specified register. the high-order nibbles (bits 7-4) of each register are not affected. no flags are affected. example: r0 contains the address 20 h . the accumulator holds the value 36 h (00110110 b ). internal ram location 20 h holds the value 75 h (01110101 b ). the instruction xchd a, @ r0 will leave ram location 20 h holding the value 76 h (01110110 b ) and 35 h (00110101 b ) in the accumulator. operation: xchd (a3-0) ((ri)3-0) bytes: 1 cycles: 1 encoding: 1 1 0 1 0 1 1 i ? ? semiconductor group 248 instruction set xrl semiconductor group 249 instruction set xrl a,direct operation: xrl (a) ? (a) (direct) bytes: 2 cycles: 1 xrl a, @ ri operation: xrl (a) ? (a) ((ri)) bytes: 1 cycles: 1 xrl a, #data operation: xrl (a) ? (a) #data bytes: 2 cycles: 1 xrl direct,a operation: xrl (direct) ? (direct) (a) bytes: 2 cycles: 1 encoding: 0 1 1 0 0 1 0 1 direct address encoding: 0 1 1 0 0 1 1 i encoding: 0 1 1 0 0 1 0 0 immediate data encoding: 0 1 1 0 0 0 1 0 direct address v v v v semiconductor group 250 instruction set xrl direct, #data operation: xrl (direct) ? (direct) #data bytes: 3 cycles: 2 encoding: 0 1 1 0 0 0 1 1 direct address immediate data v semiconductor group 251 instruction set instruction set summary arithmetic operations mnemonic description byte cycle add a,rn add register to accumulator 1 1 add a,direct add direct byte to accumulator 2 1 add a, @ri add indirect ram to accumulator 1 1 add a,#data add immediate data to accumulator 2 1 addc a,rn add register to accumulator with carry flag 1 1 addc a,direct add direct byte to a with carry flag 2 1 addc a, @ri add indirect ram to a with carry flag 1 1 addc a, #data add immediate data to a with carry flag 2 1 subb a,rn subtract register from a with borrow 1 1 subb a,direct subtract direct byte from a with borrow 2 1 subb a,@ri subtract indirect ram from a with borrow 1 1 subb a,#data subtract immediate data from a with borrow 2 1 inc a increment accumulator 1 1 inc rn increment register 1 1 inc direct increment direct byte 2 1 inc @ri increment indirect ram 1 1 dec a decrement accumulator 1 1 dec rn decrement register 1 1 dec direct decrement direct byte 2 1 dec @ri decrement indirect ram 1 1 inc dptr increment data pointer 1 2 mul ab multiply a and b 1 4 div ab divide a by b 1 4 da a decimal adjust accumulator 1 1 semiconductor group 252 instruction set instruction set summary (contd) logic operations mnemonic description byte cycle anl a,rn and register to accumulator 1 1 anl a,direct and direct byte to accumulator 2 1 anl a,@ri and indirect ram to accumulator 1 1 anl a,#data and immediate data to accumulator 2 1 anl direct,a and accumulator to direct byte 2 1 anl direct,#data and immediate data to direct byte 3 2 orl a,rn or register to accumulator 1 1 orl a,direct or direct byte to accumulator 2 1 orl a,@ri or indirect ram to accumulator 1 1 orl a,#data or immediate data to accumulator 2 1 orl direct,a or accumulator to direct byte 2 1 orl direct,#data or immediate data to direct byte 3 2 xrl a,rn exclusive or register to accumulator 1 1 xrl a direct exclusive or direct byte to accumulator 2 1 xrl a,@ri exclusive or indirect ram to accumulator 1 1 xrl a,#data exclusive or immediate data to accumulator 2 1 xrl direct,a exclusive or accumulator to direct byte 2 1 xrl direct,#data exclusive or immediate data to direct byte 3 2 clr a clear accumulator 1 1 cpl a complement accumulator 1 1 rl a rotate accumulator left 1 1 rlc a rotate accumulator left through carry 1 1 rr a rotate accumulator right 1 1 rrc a rotate accumulator right through carry 1 1 swap a swap nibbles within the accumulator 1 1 semiconductor group 253 instruction set instruction set summary (contd) data transfer 1) mov a,acc is not a valid instruction mnemonic description byte cycle mov a,rn move register to accumulator 1 1 mov a,direct 1) move direct byte to accumulator 2 1 mov a,@ri move indirect ram to accumulator 1 1 mov a,#data move immediate data to accumulator 2 1 mov rn,a move accumulator to register 1 1 mov rn,direct move direct byte to register 2 2 mov rn,#data move immediate data to register 2 1 mov direct,a move accumulator to direct byte 2 1 mov direct,rn move register to direct byte 2 2 mov direct,direct move direct byte to direct byte 3 2 mov direct,@ri move indirect ram to direct byte 2 2 mov direct,#data move immediate data to direct byte 3 2 mov @ri,a move accumulator to indirect ram 1 1 mov @ri,direct move direct byte to indirect ram 2 2 mov @ri, #data move immediate data to indirect ram 2 1 mov dptr, #data16 load data pointer with a 16-bit constant 3 2 movc a,@a + dptr move code byte relative to dptr to accumulator 1 2 movc a,@a + pc move code byte relative to pc to accumulator 1 2 movx a,@ri move external ram (8-bit addr.) to a 1 2 movx a,@dptr move external ram (16-bit addr.) to a 1 2 movx @ri,a move a to external ram (8-bit addr.) 1 2 movx @dptr,a move a to external ram (16-bit addr.) 1 2 push direct push direct byte onto stack 2 2 pop direct pop direct byte from stack 2 2 xch a,rn exchange register with accumulator 1 1 xch a,direct exchange direct byte with accumulator 2 1 xch a,@ri exchange indirect ram with accumulator 1 1 xchd a,@ri exchange low-order nibble indir. ram with a 1 1 semiconductor group 254 instruction set instruction set summary (contd) boolean variable manipulation program and machine control mnemonic description byte cycle clr c clear carry flag 1 1 clr bit clear direct bit 2 1 setb c set carry flag 1 1 setb bit set direct bit 2 1 cpl c complement carry flag 1 1 cpl bit complement direct bit 2 1 anl c,bit and direct bit to carry flag 2 2 anl c,/bit and complement of direct bit to carry 2 2 orl c,bit or direct bit to carry flag 2 2 orl c,/bit or complement of direct bit to carry 2 2 mov c,bit move direct bit to carry flag 2 1 mov bit,c move carry flag to direct bit 2 2 acall addr11 absolute subroutine call 2 2 lcall addr16 long subroutine call 3 2 ret return from subroutine 1 2 reti return from interrupt 1 2 ajmp addr11 absolute jump 2 2 ljmp addr16 long iump 3 2 sjmp rel short jump (relative addr.) 2 2 jmp @a + dptr jump indirect relative to the dptr 1 2 jz rel jump if accumulator is zero 2 2 jnz rel jump if accumulator is not zero 2 2 jc rel jump if carry flag is set 2 2 jnc rel jump if carry flag is not set 2 2 jb bit,rel jump if direct bit is set 3 2 jnb bit,rel jump if direct bit is not set 3 2 jbc bit,rel jump if direct bit is set and clear bit 3 2 cjne a,direct,rel compare direct byte to a and jump if not equal 3 2 semiconductor group 255 instruction set instruction set summary (contd) program and machine control (contd) mnemonic description byte cycle cjne a,#data,rel compare immediate to a and jump if not equal 3 2 cjne rn,#data rel compare immed. to reg. and jump if not equal 3 2 cjne @ri,#data,rel compare immed. to ind. and jump if not equal 3 2 djnz rn,rel decrement register and jump if not zero 2 2 djnz direct,rel decrement direct byte and jump if not zero 3 2 nop no operation 1 1 semiconductor group 256 10 application examples 10.1 application examples for the compare functions 10.1.1 generation of two different pwm signals with "additive compare" using the "ccx registers" the following example gives an idea of how to use compare mode 1 and compare interrupts for an "additive pulse width modulation". assume that an application requires two pwm signals at two port pins providing different switching frequencies, e.g. a switching frequency of 2 khz at port 1.1 (further on called pwm channel 1) and 5 khz at port 1.2 (further on called pwm channel 2). in this case compare mode 0 cannot be used since it uses the timer overflow signal to switch all compare outputs to low level and thereby provides the same switching frequency. in our case, however, the period of each pwm signal is different, being 0.5 ms for signal 1 ( 500 timer 2 counts at f osc = 12 mhz) and 0.2 ms for signal 2 ( 200 counts). thus compare mode 1 must be used, because in this mode both transitions can be preset by software. timer 2 may run with its full period from 0000, overflowing at a count rate of 65.535 ( 0ffff h ). external interrupts int4 and int5 are enabled as compare interrupts and the compare registers cc1 and cc2 are initialized to 50 % duty cycle thus containing a value of 250 and 100, respectively. the contents of the port latches must be preprogrammed to a complementary level which will appear after the corresponding compare event. now timer 2 is started. the first compare interrupt occurs after 100 timer increments caused by the contents of register cc2. figure 10-1 illustrates the task schedule of the program. every compare event causes an interrupt request, which is served after a certain response time (depending on the current task being in progress). there are a few jobs to be done, which are described in the following. ^ C ^ C ^ C application examples semiconductor group 257 figure 10-1 task schedule for "additive compare" program the interrupt routine has to calculate the next compare value for the current channel (e.g. cc2): t ccnext = t ccact + (t cctot C t ccduty ) where t ccnext is the next compare value in cc2 t cctot is the (constant) total number of counts for one pwm cycle ( = 200 for pwm channel 2) t ccact is the actual compare register contents which just caused the interrupt t ccduty is the (variable) count determining the duty cycle of the pwm signal. the interrupt routine may be left when Ct ccnext is loaded to register cc2 C the port latch is complemented and prepared for the next transition and C a user-defined flag is set to mark that this pwm cycle is now completed. application examples semiconductor group 258 the same calculation must be performed when register cc1 has had its match and has caused an interrupt for pwm channel 1. but this is done independently from channel 2 since both channels have their own interrupt request flags. when either of the two count values of t ccnext has been reached by timer 2 (in our example, channel 1 is first) then the corresponding interrupt routine polls the user flag and is informed that a new pwm cycle is to be generated. it therefore calculates the next compare value to: t ccnext = t ccact + t ccduty where t ccduty may be a new value for the duty cycle calculated in another task of the program. 10.1.2 sine-wave generation with a cmx registers/compare timer configuration the following example of a pwm generation demonstrates the use of some important features of the sab 80c517s ccu: C flexibly programmable compare timer with 16-bit reload and 8 selectable input clocks ( f osc /2 to f osc /256) C "toc-loading" mechanism to reduce interrupt load of the cpu the above features allow: C pwm generation for digital-to-analog conversion with extremely low external hardware costs (simple passive rc filter or any other integrating device) C output frequencies from less than 1 hz (16-bit reload, timer input clock of f osc /256) to 3 mhz (2-bit reload, timer input clock of f osc /2) the following paragraphs do not contain a basic description of pwm generation with microcontrollers but rather should give an idea of how to use the ccu of the sab 80c517 in this kind of applications. please refer to other literature for a general description of the pulse width modulation. the example in the following uses typical parameters: a pwm frequency above the audible range (23.4 khz), with 8-bit resolution. the pwm may, for instance, be used to generate a sine-wave via a low-cost rc filter. to simplify matters, just one pwm channel is used in this example. the sab 80c517, however, can drive up to eight channels with the fast compare timer. application examples semiconductor group 259 explanation of a few terms C pulse width modulation in our case the pwm is used to synthesize a sine-wave. this means that a digital output signal is periodically varied in the length of its high or low time (= duty cycle). one high and one low time together make up a sample point of the sine-wave to be synthesized. the generation of the sine- wave out of the modulated digital signal is done by a low-pass filter. C pwm frequency in this example the switching frequency of the pwm signal is fixed. the frequency is determined by the reload value ( ? resolution) and the input clock of the timer. C 8-bit resolution this means that only eight bits of the 16-bit wide timer and compare circuitry are used to generate the pwm signal ( ? faster pwm frequency). thus the duty cycle of the signal is programmable in 256 steps. each step represents a quantum of one machine state or 166.6 ns at f osc = 12 mhz (256 x 166.6 ns = 42.649 m s; 1/42.649 m s = 23.4 khz) configuration of the ccu to generate a sine-wave, the duty cycle of a pwm signal must be varied periodically, as mentioned above. one pwm period (or one sample point) is represented by a full compare timer period. the high-to-low transition of the pwm signal takes place upon every compare timer overflow, the low- to-high transition is programmable and takes place when the timer count matches the contents of the compare register ( ? compare mode 0). in the worst case (maximum sine-wave frequency), the contents of the compare register must be reloaded in every compare timer period. C compare timer setup input clock the input clock is set to f osc /2. this can be done in special function register ctcon. in this case the timer is incremented every machine cycle (166.6 ns at 12 mhz). reload the reload register ctrel h (high byte) is set to 0ff h , ctrell (low byte) must contain 00 h . thus the timer counts from 0ff00 h to 0ffff h (= 8-bit reload ? 256 steps). application examples semiconductor group 260 figure 10-2 pwm generation for sine-wave synthesis application examples semiconductor group 261 C compare setup compare mode compare register cm0 (consisting of cmh0 and cml0) is used in compare mode 0. this means bit cmsel.0 must be set (in register cmsel) to assign cm0 to the compare timer and switch on compare mode 0. enable port output the compare is enabled with sfr bit cmen.0 in register cmen. the corresponding compare output pin is port 4.0. C interrupts since the compare value may be varied in every compare timer period, it is most effective to use the compare timer overflow interrupt for reloading the compare register cm0 with a new value. enable interrupt the compare timer overflow interrupt is enabled by sfr bit ect in register ien2. the general enable flag eal in register ien0 must be set, too. the program variation of the duty cycle of the pwm signal is done by a variation of the contents of the compare register cm0. cm0 is loaded with new compare values in an (high prioritized) interrupt routine. this makes the loading independent from other tasks running on the cpu. the new compare values are loaded by a cyclic look-up table routine. the table is located in the rom and contains the compare values for every sample point. (in our case the sine-wave is synthesized by six sample points.) the program flow is best described by a program flow chart (see figure 10-3 ). the following paragraphs give some additional details. C main program ccu and interrupt initialization is done according to the previous description of the ccu configuration. there is no other task in this application to be done in the main program. the controller is free for any other job (e.g. i/o, control algorithms, adapting the sine wave table, etc.). C interrupt service routine the interrupt program contains the table look-up routine only. this routine is illustrated in figure 10-3 and performs the following two little jobs: C managing the table pointer C loading the cm0-register. application examples semiconductor group 262 application examples figure 10-3 program flow charts the interrupt routine takes full advantage of the toc loading. the interrupt routine is always vectored to some time after a compare timer overflow. this means that the new compare value is moved to cm0 at an undefined moment in the current timer period. the moment depends on the interrupt response time (uncertainty of 3 to 9 machine cycles) and on the length of the interrupt routine itself (perhaps there are more channels to serve), etc. without any further provisions (like the toc loading) there would be no chance for loading an early compare value (e.g. cm0 = 0000 h ) because the timer would have passed these early counts before the loading was completed. the toc loading now solves the above problem. the interrupt service routine is always "thinking" one cycle in advance. it actually loads the compare value (or sample point) for the next timer period. thus, the cpu has one full timer period to serve all compares. the compare value loaded to the cm0 register by the interrupt routine will be immediately transferred to the actual compare latch at the next compare timer overflow. this overflow then again requests a new interrupt service routine. semiconductor group 263 application examples conclusion this application example is meant to show that the ccu of the sab 80c517 is able to generate very fast pwm signals with low cpu effort. small single-chip systems which have to manage pwm periods below 50 microseconds require a very efficient on-chip timer hardware to leave enough cpu time to perform other control tasks in real time. the sab 80c517 takes advantage of the fast compare timer and the toc loading mechanism to meet the above requirements. 10.2 using an sab 80c537 with external program memory and additional external data memory figure 10-4 shows an example of how to connect an external program and data memory to the sab 80c517/80c537. for the program memory a standard eprom 2764a is used. an 8-kbyte static ram 5565 serves as external data memory. the 74hct573 works as address latch. the address space ranges from 0 to 1fff h (8 kbyte). pin ea is tied low, so all program memory accesses are done from external memory. port 0 is the multiplexed address/data bus, while port 2 always emits the high order byte of the address. therefore, in this configuration port 0 and port 2 must not be used as general-purpose l/o ports. semiconductor group 264 application examples figure 10-4 connecting the sab 80c517 with external program and data memory semiconductor group 265 04.95 high-performance sab 80c517/80c537 8-bit cmos single-chip microcontroller advanced information sab 80c517 microcontroller with factory mask-programmable rom sab 80c537 microcontroller for external rom l versions for 12 mhz and 16 mhz l fast 32-bit division, 16-bit 2 multiplication, operating frequency 32-bit normalize and shift by peripheral l 8 k 8 rom (sab 80c517 only) mul/div unit (mdu) l 256 8 on-chip ram l eight data pointers for external memory l superset of sab 80c51 architecture: addressing 1 m s instruction cycle time at 12 mhz l fourteen interrupt vectors, four priority 750 ns instruction cycle time at 16 mhz levels selectable 256 directly addressable bits l 8-bit a/d converter with 12 multiplexed boolean processor inputs and programmable ref. voltages 64 kbyte external data and program l two full duplex serial interfaces memory addressing l fully upward compatible with sab 80c515 l four 16-bit timer/counters l extended power saving modes l powerful 16-bit compare/capture unit l nine ports: 56 i/o lines, 12 input lines (ccu) with up to 21 high-speed or pwm l two temperature ranges available: output channels and 5 capture inputs 0 to 70 o c l versatile "fail-safe" provisions C 40 to 85 o c l plastic packages: p-lcc-84, p-mqfp-100-2 sab 80c517/80c537 sab 80c517/80c537 semiconductor group 266 the sab 80c517/80c537 is a high-end member of the siemens sab 8051 family of microcontrollers. it is designed in siemens acmos technology and based on the sab 8051 architecture. acmos is a technology which combines high-speed and density characteristics with low-power consumption or dissipation. while maintaining all the sab 80c515 features and operating characteristics the sab 80c517 is expanded in its arithmetic capabilities, "fail-safe" characteristics, analog signal processing and timer capabilities. the sab 80c537 is identical with the sab 80c517 except that it lacks the on-chip program memory. the sab 80c517/sab 80c537 is supplied in a 84 pin plastic leaded chip carrier package (p-lcc-84) and in a 100-pin plastic quad metric flat package (p-mqfp-100-2). ordering information type ordering code package description 8-bit cmos microcontroller sab 80c517-n q67120-c397 p-lcc-84 with factory mask-programma- ble rom, 12 mhz sab 80c517-m tbd p-mqfp-100-2 sab 80c537-n q67120-c452 p-lcc-84 for external memory, 12 mhz sab 80c537-m tbd p-mqfp-100-2 sab 80c517-n-t40/85 q67120-c483 p-lcc-84 with factory mask-programma- ble rom, 12 mhz, ext. temperature C 40 to 85 c sab 80c517-m-t40/85 tbd p-mqfp-100-2 sab 80c537-n-t40/85 q67120-c484 p-lcc-84 for external rom, 12 mhz, ext. temperature C 40 to 85 c sab 80c537-m-t40/85 tbd p-mqfp-100-2 sab 80c517-n16 q67120-c723 p-lcc-84 with mask-programmable rom,16 mhz ext. temperature C 40 to 110 c sab 80c517-m16 tbd p-mqfp-100-2 sab 80c537-n16 q67120-c722 p-lcc-84 for external memory, 16 mhz sab 80c537-m16 tbd p-mqfp-100-2 sab 80c517-n16-t40/85 q67120-c724 p-lcc-84 with mask-programmable rom, 16 mhz ext. temperature C 40 to 85 c sab 80c517-16-n-t40/85 q67120-c725 p-lcc-84 with factory mask-programma- ble rom, 12 mhz sab 80c517/80c537 semiconductor group 267 logic symbol sab 80c517/80c537 semiconductor group 268 pin configuration (p-lcc-84) sab 80c517/80c537 semiconductor group 269 pin configuration (p-mqfp-100-2) sab 80c517/80c537 semiconductor group 270 pin definitions and functions symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 p4.0 C p4.7 1C 3, 5 C 9 64 - 66, 68 - 72 i/o port 4 is a bidirectional i/o port with internal pull-up resistors. port 4 pins that have 1 s written to them are pulled high by the internal pull-up resistors, 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 pull-up resistors. this port also serves alternate compare functions. the secondary functions are assigned to the pins of port 4 as follows: C cm0 (p4.0): compare channel 0 C cm1 (p4.1): compare channel 1 C cm2 (p4.2): compare channel 2 C cm3 (p4.3): compare channel 3 C cm4 (p4.4): compare channel 4 C cm5 (p4.5): compare channel 5 C cm6 (p4.6): compare channel 6 C cm7 (p4.7): compare channel 7 pe /swd 4 67 i power saving modes enable / start watchdog timer a low level on this pin allows the software to enter the power down, idle and slow down mode. in case the low level is also seen during reset, the watchdog timer function is off on default. use of the software controlled power saving modes is blocked, when this pin is held on high level. a high level during reset performs an automatic start of the watchdog timer immediately after reset. when left unconnected this pin is pulled high by a weak internal pull-up resistor. * i = input o = output sab 80c517/80c537 semiconductor group 271 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 reset 10 73 i reset a low level on this pin for the duration of one machine cycle while the oscillator is running resets the sab 80c517. a small internal pull-up resistor permits power-on reset using only a capacitor connected to v ss . v aref 11 78 reference voltage for the a/d con- verter. v agnd 12 79 reference ground for the a/d converter. p7.7 -p7.0 13 - 20 80 - 87 i port 7 is an 8-bit unidirectional input port. port pins can be used for digital input, if voltage levels meet the specified input high/low voltages, and for the lower 8-bit of the multiplexed analog inputs of the a/d converter, simultaneously. * i = input o = output sab 80c517/80c537 semiconductor group 272 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 p3.0 - p3.7 21 - 28 90 - 97 i/o port 3 is a bidirectional i/o port with internal pull-up resistors. port 3 pins that have 1 s written to them are pulled high by the internal pull-up resistors, 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 pull-up resistors. port 3 also contains the interrupt, timer, serial port 0 and external memory strobe pins that are used by various options. the output latch corresponding to a secondary function must be programmed to a one (1) for that function to operate. the secondary functions are assigned to the pins of port 3, as follows: C r d0 (p3.0): receiver data input (asynchronous) or data input/output (synchronous) of serial interface C t d0 (p3.1): transmitter data output (asynchronous) or clock output (synchronous) of serial interface 0 C int0 (p3.2): interrupt 0 input /timer 0 gate control C int1 (p3.3): interrupt 1 input /timer 1 gate control C t0 (p3.4): counter 0 input C t1 (p3.5): counter 1 input Cwr (p3.6): the write control signal latches the data byte from port 0 into the external data memory C rd (p3.7): the read control signal enables the external data memory to port 0 * i = input o = output sab 80c517/80c537 semiconductor group 273 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 p1.7 - p1.0 29 - 36 98 - 100, 1, 6 - 9 i/o port 1 is a bidirectional i/o port with internal pull-up resistors. port 1 pins that have 1 s written to them are pulled high by the internal pull-up resistors, and in that state can be used as inputs. as inputs, port 1 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pull-up resistors. it is used for the low order address byte during program verifi-cation. it also contains the interrupt, timer, clock, capture and compare pins that are used by various options. the output latch must be programmed to a one (1) for that function to operate (except when used for the compare functions). the secondary functions are assigned to the port 1 pins as follows: C int3 /cc0 (p1.0): interrupt 3 input / compare 0 output / capture 0 input C int4/cc1 (p1.1): interrupt 4 input / compare 1 output /capture 1 input C int5/cc2 (p1.2): interrupt 5 input / compare 2 output /capture 2 input C int6/cc3 (p1.3): interrupt 6 input / compare 3 output /capture 3 input C int2 /cc4 (p1.4): interrupt 2 input / compare 4 output /capture 4 input C t2ex (p1.5): timer 2 external reload trigger input C clkout (p1.6): system clock output C t2 (p1.7): counter 2 input * i = input o = output sab 80c517/80c537 semiconductor group 274 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 xtal2 39 12 C xtal2 input to the inverting oscillator amplifier and input to the internal clock generator circuits. xtal1 40 13 C xtal1 output of the inverting oscillator amplifier. to drive the device from an external clock source, xtal2 should be driven, while xtal1 is left unconnected. there are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is devided down by a divide-by-two flip-flop. minimum and maximum high and low times as well as rise/fall times specified in the ac characteristics must be observed. p2.0 - p2.7 41 - 48 14 - 21 i/o port 2 is a bidirectional i/o port with internal pull-up resistors. port 2 pins that have 1 s written to them are pulled high by the internal pull-up resistors, and in that state can be used as in-puts. as inputs, port 2 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pull-up 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 pull-up resistors 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. * i = input o = output sab 80c517/80c537 semiconductor group 275 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 psen 49 22 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 six oscillator periodes except during external data memory accesses. remains high during internal pro-gram execution. ale 50 23 o the address latch enable output is used for latching the address into external memory during normal operation. it is activated every six oscillator periodes except during an external data memory access ea 51 24 i external access enable when held at high level, instructions are fetched from the internal rom when the pc is less than 8192. when held at low level, the sab 80c517 fetches all instructions from external program memory. for the sab 80c537 this pin must be tied low p0.0 - p0.7 52 - 59 26 - 27, 30 - 35 i/o port 0 is an 8-bit open-drain bidirectional i/o port. port 0 pins that have 1 s written to them float, and in that state can be used as high-impedance 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 pull-up resistors when issuing 1 s. port 0 also outputs the code bytes during program verification in the sab 83c517. external pull-up resistors are required during program verification. * i = input o = output sab 80c517/80c537 semiconductor group 276 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 p5.7 - p5.0 61 - 68 37 - 44 i/o port 5 is a bidirectional i/o port with internal pull-up resistors. port 5 pins that have 1 s written to them are pulled high by the internal pull-up resistors, 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 pull-up resistors. this port also serves the alternate function "concurrent compare". the secondary functions are assigned to the port 5 pins as follows: C ccm0 (p5.0): concurrent compare 0 C ccm1 (p5.1): concurrent compare 1 C ccm2 (p5.2): concurrent compare 2 C ccm3 (p5.3): concurrent compare 3 C ccm4(p5.4): concurrent compare 4 C ccm5 (p5.5): concurrent compare 5 C ccm6 (p5.6): concurrent compare 6 C ccm7(p5.7): concurrent compare 7 owe 69 45 i oscillator watchdog enable a high level on this pin enables the oscillator watchdog. when left unconnected this pin is pulled high by a weak internal pull-up resistor. when held at low level the oscillator watchdog function is off. * i = input o = output sab 80c517/80c537 semiconductor group 277 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 p6.0 - p6.7 70 - 77 46 - 50, 54 - 56 i/o port 6 is a bidirectional i/o port with internal pull-up resistors. port 6 pins that have 1 s written to them are pulled high by the internal pull-up resistors, and in that state can be used as inputs. as inputs, port 6 pins being externally pulled low will source current ( i il , in the dc characteristics) because of the internal pull-up resistors. port 6 also contains the external a/d converter control pin and the transmit and receive pins for serial channel 1. the output latch corresponding to a secondary function must be programmed to a one (1) for that function to operate. the secondary functions are assigned to the pins of port 6, as follows: C adst (p6.0): external a/d converter start pin C r d1 (p6.1): receiver data input of serial interface 1 C t d1 (p6.2): transmitter data output of serial interface 1 p8.0 - p8.3 78 - 81 57 - 60 i port 8 is a 4-bit unidirectional input port. port pins can be used for digital input, if voltage levels meet the specified input high/low voltages, and for the higher 4-bit of the multiplexed analog inputs of the a/d converter, simultaneously * i = input o = output sab 80c517/80c537 semiconductor group 278 pin definitions and functions (contd) symbol pin number i/o *) function p-lcc-84 p-mqfp-100-2 ro 82 61 o reset output this pin outputs the internally synchronized reset request signal. this signal may be generated by an external hardware reset, a watchdog timer reset or an oscillator watch-dog reset. the reset output is active low. v ss 37,60, 83 10, 62 C circuit ground potential v cc 38,84 11, 63 C supply terminal for all operating modes n.c. C 2 - 5, 25, 28 - 29, 36, 51 - 53, 74 - 77; 88 - 89 C not connected * i = input o = output sab 80c517/80c537 semiconductor group 279 figure 1 block diagram sab 80c517/80c537 semiconductor group 280 functional description the sab 80c517 is based on 8051 architecture. it is a fully compatible member of the siemens sab 8051/80c51 microcontroller family being a significantly enhanced sab 80c515. the sab 80c517 is therefore 100 % compatible with code written for the sab 80c515. cpu having an 8-bit cpu with extensive facilities for bit-handling and binary bcd arithmetics the sab 80c517 is optimized for control applications. with a 12 mhz crystal, 58% of the instructions execute in 1 m s. being designed to close the performance gap to the 16-bit microcontroller world, the sab 80c517s cpu is supported by a powerful 32-/16-bit arithmetic unit and a more flexible addressing of external memory by eight 16-bit datapointers. memory organisation according to the sab 8051 architecture, the sab 80c517 has separate address spaces for program and data memory. figure 2 illustrates the mapping of address spaces. figure 2 memory mapping sab 80c517/80c537 semiconductor group 281 program memory the sab 80c517 has 8 kbyte of on-chip rom, while the sab 80c537 has no internal rom. the program memory can externally be expanded up to 64 kbyte. pin ea controls whether program fetches below address 2000 h are done from internal or external memory. data memory the data memory space consists of an internal and an external memory space. external data memory up to 64 kbyte external data memory can be addressed by instructions that use 8-bit or 16-bit indirect addressing. for 8-bit addressing movx instructions utilizing registers r0 and r1 can be used. a 16-bit external memory addressing is supported by eight 16-bit datapointers. multiple datapointers as a functional enhancement to standard 8051 controllers, the sab 80c517 contains eight 16-bit datapointers. the instruction set uses just one of these datapointers at a time. the selection of the actual datapointers is done in special function register dpsel (data pointer select, addr. 92 h ). figure 3 illustrates the addressing mechanism. internal data memory the internal data memory is divided into three physically distinct blocks: C the lower 128 bytes of ram including four banks of eight registers each C the upper 128 byte of ram C the 128 byte special function register area. a mapping of the internal data memory is also shown in figure 2 . the overlapping address spaces are accessed by different addressing modes. the stack can be located anywhere in the internal data memory. sab 80c517/80c537 semiconductor group 282 figure 3 addressing of external data memory sab 80c517/80c537 semiconductor group 283 special function registers all registers, except the program counter and the four general purpose register banks, reside in the special function register area. the 81 special function registers include arithmetic registers, pointers, and registers that provide an interface between the cpu and the on-chip peripherals. there are also 128 directly addressable bits within the sfr area. the special function registers are listed in table 1 . in this table they are organized in groups which refer to the functional blocks of the sab 80c517. block names and symbols are listed in alphabetical order. table 1 special function register address register name register contents after reset cpu acc b dph dpl dpsel psw sp accumulator b-register data pointer, high byte data pointer, low byte data pointer select register program status word register stack pointer 0e0 h 1) 0f0 h 1) 83 h 82 h 92 h 0d0 h 1) 81 h 00 h 00 h 00 h 00 h xxxx.x000 b 3) 00 h 07 h a/d- converter adcon0 adcon1 addat dapr a/d converter control register 0 a/d converter control register 1 a/d converter data register d/aconverter program register 0d8 h 1) 0dc h 0d9 h 0da h 00 h xxxx.0000 b 3) 00 h 00 h interrupt system ien0 ctcon 2) ien1 ien2 ip0 ip1 ircon tcon 2) t2con 2) interrupt enable register 0 com. timer control register interrupt enable register 1 interrupt enable register 2 interrupt priority register 0 interrupt priority register 1 interrupt request control register timer control register timer 2 control register 0a8 h 1) 0e1 h 0b8 h 1) 9a h 0a9 h 0b9 h 0c0 h 1) 88 h 1) 0c8 h 00 h 0xxx.0000 b 00 h xxxx.00x0 b 3) 00 h xx00 0000 b 00 h 00 h 00 h 1) bit-addressable special function registers 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate and the location is reserved sab 80c517/80c537 semiconductor group 284 table 1 special function register (contd) address register name register contents after reset mul/div unit arcon md0 md1 md2 md3 md4 md5 arithmetic control register multiplication/division register 0 multiplication/division register 1 multiplication/division register 2 multiplication/division register 3 multiplication/division register 4 multiplication/division register 5 0ef h 0e9 h 0ea h 0eb h 0ec h 0ed h 0ee h 0xxx.xxxx b 3) xx h 3) xx h 3) xx h 3) xx h 3) xx h 3) xx h 3) 1) bit-addressable special function registers 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate and the location is reserved sab 80c517/80c537 semiconductor group 285 table 1 special function register (contd) address register name register contents after reset compare/ capture- unit (ccu) ccen cc4en cch1 cch2 cch3 cch4 ccl1 ccl2 ccl3 ccl4 cmen cmh0 cmh1 cmh2 cmh3 cmh4 cmh5 cmh6 cmh7 cml0 cml1 cml2 cml3 cml4 cml5 cml6 cml7 cmsel crch crcl ctcon ctrelh ctrell th2 tl2 t2con comp./capture enable reg. comp./capture enable 4 reg. comp./capture reg. 1, high byte comp./capture reg. 2, high byte comp./capture reg. 3, high byte comp./capture reg. 4, high byte comp./capture reg. 1, low byte comp./capture reg. 2, low byte comp./capture reg. 3, low byte comp./capture reg. 4, low byte compare enable register compare register 0, high byte compare register 1, high byte compare register 2, high byte compare register 3, high byte compare register 4, high byte compare register 5, high byte compare register 6, high byte compare register 7, high byte compare register 0, low byte compare register 1, low byte compare register 2, low byte compare register 3, low byte compare register 4, low byte compare register 5, low byte compare register 6, low byte compare register 7, low byte compare input select com./rel./capt. reg. high byte com./rel./capt. reg. low byte com. timer control reg. com. timer rel. reg., high byte com. timer rel. reg., low byte timer 2, high byte timer 2, low byte timer 2 control register 0c1 h 0c9 h 0c3 h 0c5 h 0c7 h 0cf h 0c2 h 0c4 h 0c6 h 0ce h 0f6 h 0d3 h 0d5 h 0d7 h 0e3 h 0e5 h 0e7 h 0f3 h 0f5 h 0d2 h 0d4 h 0d6 h 0e2 h 0e4 h 0e6 h 0f2 h 0f4 h 0f7 h 0cb h 0ca h 0e1 h 0df h 0de h 0cd h 0cc h 0c8 h 1 ) 00 h x000.0000 b 3) 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 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 00 h 0xxx.0000 b 3 ) 00 h 00 h 00 h 00 h 00 h 1) bit-addressable special function registers 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate and the location is reserved sab 80c517/80c537 semiconductor group 286 table 1 special function register (contd) address register name register contents after reset ports p0 p1 p2 p3 p4 p5 p6 p7 p8 port 0 port 1 port 2 port 3 port 4 port 5 port 6, port 7, analog/digital input port 8, analog/digital input, 4-bit 80 h 1) 90 h 1) 0a0 h 1) 0b0 h 1) 0e8 h 1) 0f8 h 1) 0fa h 0db h 0dd h ff h ff h ff h ff h ff h ff h ff h xx h 3) xx h 3) pow.sav. modes pcon power control register 87 h 00 h serial channels adcon0 2) pcon 2) s0buf s0con s0rell 4) s0relh 4) s1buf s1con s1rel s1relh 4) a/d converter control reg. power control register serial channel 0 buffer reg. serial channel 0 control reg . serial channel 0, reload reg., low byte serial channel 0, reload reg., high byte serial channel 1 buffer reg., serial channel 1 control reg. serial channel 1 reload reg., low byte serial channel 1, reload reg., high byte 0d8 h 1) 87 h 99 h 98 h 1) 0aah 0bah 9c h 9b h 9d h 0bb h 00 h 00 h xx h 3) 00 h 0d9 h xxxx.xx11 b 3) 0xx h 3) 0x00.000 b 3) 00 h xxxx.xx11 b 3) timer 0/ timer 1 tcon th0 th1 tl0 tl1 tmod timer 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 watchdog ien0 2) ien1 2) ip0 2) ip1 2) wdtrel interrupt enable register 0 interrupt enable register 1 interrupt priority register 0 interrupt priority register 1 watchdog timer reload reg. 0a8 h 1) 0b8 h 1) 0a9 h 0b9 h 86 h 00 h 00 h 00 h xx00.0000 b 3) 00 h 1) bit-addressable special function registers. 2) this special function register is listed repeatedly since some bits of it also belong to other functional blocks. 3) x means that the value is indeterminate and the location is reserved. 4) these registers are available in the ca step and later steps. sab 80c517/80c537 semiconductor group 287 a/d converter the sab 80c517 contains an 8-bit a/d converter with 12 multiplexed input channels which uses the successive approximation method. it takes 7 machine cycles to sample an analog signal (during this sample time the input signal should be held constant); the total conversion time (including sample time) is 13 machine cycles (13 m s at 12 mhz oscillator frequency). conversion can be programmed to be single or continuous; at the end of a conversion an interrupt can be generated. a unique feature is the capability of internal reference voltage programming. the internal reference voltages v intaref and v intagnd for the a/d converter are both programmable to one of 16 steps with respect to the external reference voltages. this feature permits a conversion with a smaller internal reference voltage range to gain a higher resolution. in addition, the internal reference voltages can easily be adapted by software to the desired analog input voltage range (see table 2 ). table 2 adjustable internal reference voltages step dapr (.3-.0) dapr (.7-.4) v intagnd v intaref 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0.0 0.3125 0.625 0.9375 1.25 1.5625 1.875 2.1875 2.5 2.8125 3.125 3.4375 3.75 C C C 5.0 C C C 1.25 1.5625 1.875 2.1875 2.5 2.8125 3.125 3.4375 3.75 4.0625 4.375 4.68754 sab 80c517/80c537 semiconductor group 288 figure 4 block diagram a/d converter sab 80c517/80c537 semiconductor group 289 compare/capture unit (ccu) the compare capture unit is a complex timer/register array for applications that require high speed i/o, pulse width modulation and more timer/counter capabilities. the ccu contains C one 16-bit timer/counter (timer 2) with 2-bit prescaler, reload capability and a max. clock frequency of f osc /12 (1 mhz with a 12 mhz crystal). C one 16-bit timer (compare timer) with 8-bit prescaler, reload capability and a max. clock frequency of f osc /2 (6 mhz with a 12 mhz crystal). C thirteen 16-bit compare registers. C five of which can be used as 16-bit capture registers. C up to 21 output lines controlled by the ccu. C seven interrupts which can be generated by ccu-events. figure 5 shows a block diagram of the ccu. eight compare registers (cm0 to cm7) can individually be assigned to either timer 2 or the compare timer. diagrams of the two timers are shown in figures 6 and 7 . the four compare/capture registers and the compare/reload/capture register are always connected to timer 2. dependent on the register type and the assigned timer two compare modes can be selected. table 3 illustrates possible combinations and the corresponding output lines. table 3 ccu configuration assigned timer compare register compare output at possible modes timer 2 crch/crcl cc1h/cc1l cc2h/cc2l cc3h/cc3l cc4h/cc4l cc4h/cc4l : cc4h/cc4l cm0h/cm0l : cm7h/cm7l p1.0/int3 /cc0 p1.0/int4/cc1 p1.0/int5/cc2 p1.0/int6/cc3 p1.0/int2 /cc4 p5.0/ccm0 : p5.7/ccm7 p4.0/cm0 : p4.7/cm7 comp. mode 0, 1 + reload comp. mode 0, 1 comp. mode 0, 1 comp. mode 0, 1 comp. mode 0, 1 comp. mode 1 : comp. mode 1 comp. mode 1 : comp. mode 1 compare timer cm0h/cm0l : : cm7h/cm7l p4.0/cm0 : : p4.7/cm7 comp. mode 0 (with add. latches) : : comp. mode 0 (with shadow latches) sab 80c517/80c537 semiconductor group 290 figure 5 block diagram of the compare/capture unit sab 80c517/80c537 semiconductor group 291 compare in the compare mode, the 16-bit values stored in the dedicated compare registers are compared to the contents of the timer 2 register or the compare timer register. if the count value in the timer registers matches one of the stored values, an appropriate output signal is generated and an interrupt is requested. two compare modes are provided: mode 0: upon a match the output signal changes from low to high. it goes back to low level when the timer overflows. mode 1: the transition of the output signal can be determined by software. a timer overflow signal doesnt affect the compare-output. compare registers cm0 to cm7 use additional compare latches when operated in mode 0. figure 8 shows the function of these latches. the latches are implemented to prevent from loss of compare matches which may occur when loading of the compare values is not correlated with the timer count. the compare latches are automatically loaded from the compare registers at every timer overflow. capture this feature permits saving of the actual timer/counter contents into a selected register upon an external event or a software write operation. two modes are provided to latch the current 16-bit value of timer 2 registers into a dedicated capture register. mode 0: capture is performed in response to a transition at the corresponding port pins cc0 to cc3. mode 1: write operation into the low-order byte of the dedicated capture register causes the timer 2 contents to be latched into this register. reload of timer 2 a 16-bit reload can be performed with the 16-bit crc register, which is a concatenation of the 8-bit registers crcl and crch. there are two modes from which to select: mode 0: reload is caused by a timer overflow (auto-reload). mode 1: reload is caused in response to a negative transition at pin t2ex (p1.5), which also can request an interrupt. timer/counters 0 and 1 these timer/counters are fully compatible with timer/counter 0 or 1 of the sab 8051 and can operate in four modes: mode 0: 8-bit timer/counter with 32:1 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; timer/counter 1 in this mode holds its count. external inputs int0 and int1 can be programmed to function as a gate for timer/counters 0 and 1 to facilitate pulse width measurements. sab 80c517/80c537 semiconductor group 292 figure 6 block diagram of timer 2 sab 80c517/80c537 semiconductor group 293 figure 7 block diagram of the compare timer sab 80c517/80c537 semiconductor group 294 figure 8 compare-mode 0 with registers cm0 to cm7 sab 80c517/80c537 semiconductor group 295 interrupt structure the sab 80c517 has 14 interrupt vectors with the following vector addresses and request flags. each interrupt vector can be individually enabled/disabled. the response time to an interrupt request is more than 3 machine cycles and less than 9 machine cycles. external interrupts 0 and 1 can be activated by a low-level or a negative transition (selectable) at their corresponding input pin, external interrupts 2 and 3 can be programmed for triggering on a negative or a positive transition. the external interrupts 2 to 6 are combined with the corresponding alternate functions compare (output) and capture (input) on port 1. for programming of the priority levels the interrupt vectors are combined to pairs or triples. each pair or triple can be programmed individually to one of four priority levels by setting or clearing one bit in special function register ip0 and one in ip1. figure 9 shows the interrupt request sources, the enabling and the priority level structure. table 4 interrupt sources and vectors source (request flags) vector address vector ie0 tf0 ie1 tf1 ri0/ti0 tf2 + exf2 iadc iex2 iex3 iex4 iex5 iex6 ri1/ti1 ctf 0003 h 000b h 0013 h 001b h 0023 h 002b h 0043 h 004b h 0053 h 005b h 0063 h 006b h 0083 h 009b h external interrupt 0 timer 0 overflow external interrupt 1 timer 1 overflow serial channel 0 timer 2 overflow/ext. reload a/d converter external interrupt 2 external interrupt 3 external interrupt 4 external interrupt 5 external interrupt 6 serial channel 1 compare timer overflow sab 80c517/80c537 semiconductor group 296 figure 9 interrupt structure sab 80c517/80c537 semiconductor group 297 figure 9 (contd) interrupt structure sab 80c517/80c537 semiconductor group 298 multiplication/division unit this on-chip arithmetic unit provides fast 32-bit division, 16-bit multiplication as well as shift and normalize features. all operations are integer operations. the mdu consists of six registers used for operands and results and one control register. operation of the mdu can be divided in three phases: figure 10 operation of the mdu to start an operation, register md0 to md5 (or arcon) must be written to in a certain sequence according to table 5 or 6. the order the registers are accessed determines the type of the operation. a shift operation is started by a final write operation to register arcon ( see also the register description ). operation result remainder execution time 32-bit/16-bit 16-bit/16-bit 32-bit 16-bit 16-bit 16-bit 6 t cy 1 ) 4 t cy 16-bit * 16-bit 32-bit C4 t cy 32-bit normalize C C 6 t cy 2 ) 32-bit shift left/right C C 6 t cy 2 ) 1) 1 t cy = 1 m s @ 12 mhz oscillator frequency. 2) the maximal shift speed is 6 shifts/cycle. sab 80c517/80c537 semiconductor group 299 table 5 programming the mdu for multiplication and division table 6 shift operation with the ccu abbreviations d'end : dividend, 1st operand of division d'or : divisor, 2nd operand of division m'and : multiplicand, 1st operand of multiplication m'or : multiplicator, 2nd operand of multiplication pr : product, result of multiplication rem : remainder quo : quotient, result of division ...l : means, that this byte is the least significant of the 16-bit or 32-bit operand ...h : means, that this byte is the most significant of the 16-bit or 32-bit operand operation 32-bit/16-bit 16-bit/16-bit 16-bit * 16-bit first write last write first read last read md0 d'endl md1 d'end md2 d'end md3 d'endh md4 d'orl md5 d'orh md0 quol md1 quo md2 quo md3 quoh md4 reml md5 remh md0 d'endl md1 d'end d'end md4 d'endh d'orl md5 d'orh md0 quol md1 quoh md4 reml md5 remh md0 m'andl md4 m'orl md1 m'andh md5 m'orh md0 prl md1 md2 md3 prh operation normalize, shift left, shift right first write last write first read last read md0 least significant byte md1 md2 md3 most significant byte arcon start of conversion md0 least significant byte md1 md2 md3 most significant byte sab 80c517/80c537 semiconductor group 300 i/o ports the sab 80c517 has seven 8-bit i/o ports and two input ports (8-bit and 4-bit wide). port 0 is an open-drain bidirectional i/o port, while ports 1 to 6 are quasi-bidirectional i/o ports with internal pull-up resistors. that means, when configured as inputs, ports 1 to 6 will be pulled high and will source current when externally pulled low. port 0 will float when configured as input. port 0 and port 2 can be used to expand the program and data memory externally. during an access to external memory, port 0 emits the low-order address byte and reads/writes the data byte, while port 2 emits the high-order address byte. in this function, port 0 is not an open-drain port, but uses a strong internal pullup fet. port 1, 3, 4, 5 and port 6 provide several alternate functions. please see the "pin description" for details. port pins show the information written to the port latches, when used as general purpose port. when an alternate function is used, the port pin is controlled by the respective peripheral unit. therefore the port latch must contain a "one" for that function to operate. the same applies when the port pins are used as inputs. ports 1, 3, 4 and 5 are bit- addressable. the sab 80c517 has two dual-purpose input ports. the twelve port lines at port 7 and port 8 can be used as analog inputs for the a/d converter. if input voltages at p7 and p8 meet the specified digital input levels ( v il and v ih ) the port can also be used as digital input port. sab 80c517/80c537 semiconductor group 301 power saving modes the sab 80c517 provides C due to siemens acmos technology C three modes in which power consumption can be significantly reduced. Cthe slow down mode the controller keeps up the full operating functionality, but is driven with the eighth part of its normal operating frequency. slowing down the frequency greatly reduces power consumption. Cthe idle mode the cpu is gated off from the oscillator, but all peripherals are still supplied by the clock and able to work. Cthe power down mode operation of the sab 80c517 is stopped, the oscillator is turned off. this mode is used to save the contents of the internal ram with a very low standby current. all of these modes are entered by software. special function register pcon (power control register, address is 87 h ) is used to select one of these modes. hardware enable for power saving modes a dedicated pin (pe /swd) of the sab 80c517 allows to block the power saving modes. since this pin is mostly used in noise-critical application it is combined with an automatic start of the watchdog timer (see there for further description). pe /swd = v ih (logic high level): using of the power saving modes is not possible. the instruction sequences used for entering of these modes will not affect the normal operation of the device. pe /swd = v il (logic low level): all power saving modes can be activated by software. when left unconnected, pin pe /swd is pulled to high level by a weak internal pullup. this is done to provide system protection on default. the logic-level applied to pin pe /swd can be changed during program execution to allow or to block the use of the power saving modes without any effect on the on-chip watchdog circuitry. power down mode the power down mode is entered by two consecutive instructions directly following each other. the first instruction has to set the flag pde (power down enable) and must not set pds (power down set). the following instruction has to set the start bit pds. bits pde and pds will automatically be cleared after having been set. the instruction that sets bit pds is the last instruction executed before going into power down mode. the only exit from power down mode is a hardware reset. the status of all output lines of the controller can be looked up in table 7 . sab 80c517/80c537 semiconductor group 302 table 7 status of external pins during idle and power down idle mode during idle mode all peripherals of the sab 80c517 are still supplied by the oscillator clock. thus the user has to take care which peripheral should continue to run and which has to be stopped during idle. the procedure to enter the idle mode is similar to entering the power down mode. the two bits idle and idls must be set by to consecutive instructions to minimize the chance of unintentional activating of the idle mode. there are two ways to terminate the idle mode: C the idle mode can be terminated by activating any enabled interrupt. this interrupt will be serviced and normally the instruction to be executed following the reti instruction will be the one following the instruction that sets the bit idls. C 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 only for two machine cycles for a complete reset. normally the port pins hold the logical state they had at the time idle mode was activated. if some pins are programmed to serve their alternate functions they still continue to output during idle mode if the assigned function is on. the control signals ale and psen hold at logic high levels (see table 7 ). 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 0datadatafloat float port 1 data/alternate outputs data/last output data/alternate outputs data/last output port 2datadataaddressdata port 3 data/alternate outputs data/last output data/alternate outputs data/last output port 4 data/alternate outputs data/last output data/alternate outputs data/last output port 5 data/alternate outputs data/last output data/alternate outputs data/last output port 6 data/alternate outputs data/last output data/alternate outputs data/last output sab 80c517/80c537 semiconductor group 303 table 8 baud rate generation function serial interface 0 serial interface 1 mode mode 0 C 8-bit synchronous channel baud rate *) 1 mhz @ f osc = 12 mhz C baud rate derived from f os c C mode mode 1 mode b 8-bit uart baud rate *) 1 C 62.5 k 4800, 9600 1.5 C 375 k baud rate derived from timer 1 bd 8-bit baud rate generator mode mode 2 mode 3 mode a 9-bit uart baud rate *) 187.5 k/ 375 k 1 C 62.5 k 1.5 C 375 k baud rate derived from f osc /2 timer 1 8-bit baud rate generator *) baud rate values are given for 12 mhz oscillator frequency. sab 80c517/80c537 semiconductor group 304 serial interface 0 serial interface 0 can operate in 4 modes: mode 0: shift register mode: serial data enters and exits through rxd0. txd0 outputs the shift clock 8 data bits are transmitted/received (lsb first). the baud rate is fixed at 1/12 of the oscillator frequency. mode 1: 8-bit uart, variable baud rate: 10-bit are transmitted (through rxd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on reception, the stop bit goes into rb80 in special function register s0con. the baud rate is variable. mode 2: 9-bit uart, fixed baud rate: 11-bit are transmitted (through txd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), a programmable 9th, and a stop bit (1). on transmission, the 9th data bit (tb80 in s0con) can be assigned to the value of 0 or 1. for example, the parity bit (p in the psw) could be moved into tb80 or a second stop bit by setting tb80 to 1. on reception the 9th data bit goes into rb80 in special function register s0con, while the stop bit is ignored. the baud rate is programmable to either 1/32 or 1/64 of the oscillator frequency. mode 3: 9-bit uart, variable baud rate: 11-bit are transmitted (through txd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), a programmable 9th, and a stop bit (1). in fact, mode 3 is the same as mode 2 in all respects except the baud rate. the baud rate in mode 3 is variable. variable baud rates for serial interface 0 variable baud rates for modes 1 and 3 of serial interface 0 can be derived from either timer 1 or from the oscillator via a special prescaler ("bd"). timer 1 may be operated in mode 1 (to generate slow baud rates) or mode 2. the dedicated baud rate generator "bd" provides the two standard baud rates 4800 or 9600 baud with 0.16% deviation. table 8 shows possible configurations and the according baud rates. sab 80c517 devices with stepping code "ca" or later provide a dedicated baud rate generator for the serial interface 0. this baud rate genertaor is a free running 10-bit timer with programmable reload registers. mode 1.3 baud rate = the default value after reset in the reload registers s0rell and s0relh prvide a baud rate of 4.8 kbaud (smod = 0) or 9.6 kbaud (smod = 1) at 12 mhz oscillator frequency. this guarantees full compatibility to the sab 80c517 older steppings. 2 smod f osc 64 2 10 s0rel C () ------------------------------------------------------ sab 80c517/80c537 semiconductor group 305 serial interface 1 serial interface 1 can operate in two asynchronous modes: mode a: 9-bit uart, variable baud rate. 11 bits are transmitted (through txd0) or received (through rxd0): a start bit (0), 8 data bits (lsb first), a programmable 9th, and a stop bit (1). on transmission, the 9 th data bit (tb81 in s1con) can be assigned to the value of 0 or 1. for example, the parity bit (p in the psw) could be moved into tb81 or a second stop bit by setting tb81 to 1. on reception the 9 th data bit goes into rb81 in special function register s1con, while the stop bit is ignored. mode b: 8-bit uart, variable baud rate. 10 bits are transmitted (through txd1) or received (through rxd1): a start bit (0), 8 data bits (lsb first), and a stop bit (1). on reception, the stop bit goes into rb81 in special function register s1con. variable baud rates for serial interface 1 variable baud rates for modes a and b of serial interface 1 can be derived from a dedicated baud rate generator. the baud rate clock (baud rate = ) is generated by a 8-bit free running timer with programmable reload register. sab 80c517 devices with stepping code "ca" or later provide a 10-bit free running timer for baud rate generation. mode a, b baud rate = watchdog units the sab 80c517 offers two enhanced fail safe mechanisms, which allow an automatic recov- ery from hardware failure or software upset: C programmable watchdog timer (wdt), variable from 512 ms up to about 1.1 s time out period @12 mhz. upward compatible to sab 80515 watchdog. C oscillator watchdog (owd), monitors the on-chip oscillator and forces the microcontroller to go into reset state, in case the on-chip oscillator fails. programmable watchdog timer the wdt can be activated by hardware or software. hardware initialization is done when pin pe/ swd (pin 4) is held high during reset. the sab 80c517 then starts program execution with the wdt running. pin pe /swd doesnt allow dynamic switching of the wdt. software initialization is done by setting bit swdt. a refresh of the watchdog timer is done by setting bits wdt and swdt consecutively. a block diagram of the watchdog timer is shown in figure 11 . when a watchdog timer reset occurs, the watchdog timer keeps on running, but a status flag wdts is set. this flag can also be manipulated by software. baud rate clock 16 ---------------------------------------- f osc 32 2 10 reload value C () --------------------------------------------------------------------- - sab 80c517/80c537 semiconductor group 306 figure 11 block diagram of the programmable watchdog timer oscillator watchdog the oscillator watchdog monitors the on-chip quartz oscillator. a detected oscillator failure ( f osc < appr. 300 khz) causes a hardware reset. the reset state is held until the on-chip oscillator is working again. the oscillator watchdog feature is enabled by a high level at pin owe (pin 69). an oscillator watchdog reset sets status flag owds which can be examined and modified by software. figure 12 shows a block diagram of the oscillator watchdog. figure 12 functional block diagram of the oscillator watchdog sab 80c517/80c537 semiconductor group 307 instruction set summary the sab 80c517/80c537 has the same instruction set as the industry standard 8051 micro- controller. a pocket guide is available which contains the complete instruction set in functional and hexa- decimal order. furtheron it provides helpful information about special function registers, in- terrupt vectors and assembler directives. literature information title ordering no. microcontroller family sab 8051 pocket guide b158-h6497-x-x-7600 sab 80c517/80c537 semiconductor group 308 absolute maximum ratings ambient temperature under bias sab 80c517/83c537.................................................................................. 0 to 70 o c sab 80c517/83c537-t40/85 .................................................................................... C 40 to 85 o c storage temperature t st ............................................................................ C 65 to 150 o c voltage on v cc pins with respect to ground ( v ss ) ...................................... C 0.5 v to 6.5 v voltage on any pin with respect to ground ( v ss )......................................... C 0.5 to v cc +0.5 v input current on any pin during overload condition ..................................... C 10ma to +10ma absolute sum of all input currents during overload condition ..................... | 100ma | power dissipation ........................................................................................ 2 w note stresses above those listed under "absolute maximum ratings" may cause permanent damage of the device. this is a stress rating only and functional operation of the device at these or any other conditions above those indicated in the operational sections of this specification is not implied. exposure to absolute maximum rating conditions for longer periods may affect device reliability. during overload conditions ( v in > v cc or v in < v ss ) thevoltage on v cc pins with respect to ground ( v ss ) must not exeed the values definded by the absolute maximum ratings. dc characteristics v cc = 5 v 10 %; v ss = 0 v; t a = 0 to 70 o c for the sab 80c517/83c537 t a = C 40 to 85 o c for the sab 80c517-/83c537-t40/85 parameter symbol limit values unit test condition min. max. input low voltage (except ea ) v il C 0.5 0.2 v cc C C 0.1 vC input low voltage (ea ) v il1 C 0.5 0.2 v cc C C 0.3 vC input high voltage v ih 0.2 v cc + 0.9 v cc + 0.5 v C input high voltage to xtal2 v ih1 0.7 v cc v cc + 0.5 v C input high voltage to reset v ih2 0.6 v cc v cc + 0.5 v C output low voltage (ports 1, 2, 3, 4, 5, 6) v ol C 0.45 v i ol = 1.6 ma 1) notes see page 311. sab 80c517/80c537 semiconductor group 309 dc characteristics (contd) parameter symbol limit values unit test condition min. max. output low voltage (ports ale, psen , ro ) v ol1 C0.45v i ol = 3.2ma 1) output high voltage (ports 1, 2, 3, 4, 5, 6) v oh 2.4 0.9 v cc C C v v i oh = C 80 m a i oh = C 10 m a output high voltage (port 0 in external bus mode, ale, psen , ro ) v oh1 2.4 0.9 v cc C C v v i oh = C 800 m a 2) i oh = C 80 m a 2) logic 0 input current (ports 1, 2, 3, 4, 5, 6) i il C 10 C 70 m a v in = 0.45 v input low current to reset for reset i il2 C 10 C100 m a v in = 0.45 v input low current (xtal2) i il3 CC 15 m a v in = 0.45 v input low current (owe, pe /swd) i il4 CC 20 m a v in = 0.45 v logical 1-to-0 transition current (ports 1, 2, 3, 4, 5, 6) i tl C 65 C 650 m a v in = 2 v input leakage current (port 0, ea , ports 7, 8) i li C 1 m a 0.45 < v in < v cc 10) pin capacitance c io C10pf f c = 1 mhz t a = 25 o c power supply current: active mode, 12 mhz 6) idle mode, 12 mhz 6) slow down mode, 12 mhz 6) active mode, 16 mhz 6) idle mode, 16 mhz 6) slow down mode, 16mhz 6) power down mode i cc i cc i pd C C C C C C C 40 15 15 52.3 19 19 50 ma ma ma ma ma ma m a v cc = 5 v, 4) v cc = 5 v, 5) v cc = 5 v, 5) v cc = 5 v, 4) v cc = 5 v, 5) v cc = 5 v, 5) v cc = 2...5.5 v 3) notes see page 311. sab 80c517/80c537 semiconductor group 310 a/d converter characteristics v cc = 5 v 10 %; v ss = 0 v v aref = v cc 5%; v agnd = v ss 0.2 v; v intaref - v intagnd 3 1v t a = 0 to 70 o c for the sab 80c517/83c537 t a = C 40 to 85 o c for the sab 80c517/83c537-t40/875 parameter symbol limit values unit test condition min. typ. max. analog input voltage v ainput v agnd C 0.2 C v ar e f + 0.2 v 9) analog input capacitance c i C 25 60 pf 7) load time t l C C 2 t cy m s 7) sample time (incl. load time) t s C C 7 t cy m s 7) conversion time (incl. sample time) t c C C 13 t cy m s 7) total unadjusted error tue C 2lsb v aref = v cc v ag n d = v ss 11) internal reference error v intreferr C 30 mv 8) v aref supply current i re f C C 5 ma 8) notes see page 311. sab 80c517/80c537 semiconductor group 311 notes for pages 308, 309 and 310: 1) capacitive loading on ports 0 and 2 may cause spurious noise pulses to be superimposed on the v ol of ale and ports 1, 3, 4, 5 and 6. the noise is due to external bus capacitance discharging into the port 0 and port 2 pins when these pins make 1-to-0 transitions during bus operation. in the worst case (capacitive loading > 100 pf), the noise pulse on ale line may exceed 0.8 v. in such cases it may be desirable to qualify ale with a schmitt-trigger, or use an address latch with a schmitt- trigger strobe input. 2) capacitive loading on ports 0 and 2 may cause the v oh on ale and psen to momentarily fall below the 0.9 v cc specification when the address lines are stabilizing. 3) power down i pd is measured with all output pins disconnected; ea = reset = v cc ; port 0 = port 7 = port 8 = v cc ; xtal1 = n.c.; xtal2 = v ss ; v agnd = n.c.; v aref = v cc ; pe /swd = owe = v ss . 4) i cc (active mode) is measured with all output pins disconnected; xtal2 driven with clock signal according to the figure below; xtal1 = n.c.; ea = owe = pe /swd = v cc ; port 0 = port 7 = port 8 = v cc ; reset = v ss . i cc would be slightly higher if a crystal oscillator is used. 5) i cc (idle mode,) is measured with all output pins disconnected and with all peripherals disabled; xtal2 driven with clock signal according to the figure below; xtal1 = n.c.; reset = owe = v cc ; port 0 = port 7 = port 8 = v cc ; ea = pe /swd = v ss . i cc (slow down mode) is measured with all output pins disconnected and with all peripherals disabled; xtal2 driven with clock signal according to the figure below; xtal = n.c.; port 7 = port 8 = v cc ; ea = pe /swd = v ss . 6) i cc (max.) at other frequencies is given by: active mode: i cc max = 3.1 * f osc + 3.0 idle mode: i cc max = 1.0 * f osc + 3.0 where f osc is the oscillator frequency in mhz. i cc values are given in ma and measured at v cc = 5 v ( see also notes 4 and 5 ). 7) the output impedance of the analog source must be low enough to assure full loading of the sample capacitance ( c i ) during load time ( t l ). after charging of the internal capacitance ( c i ) in the load time ( t l ) the analog input must be held constant for the rest of the sample time ( t s ). 8) the differential impedance r d of the analog reference voltage source must be less than 1k w at reference supply voltage. 9) exceeding the limit values at one or more input channels will cause additional current which is sinked sourced at these channels. this may also affect the accuracy of other channels which are operated within the specification. 10) only valid for not selected analog inputs. 11) no missing code. sab 80c517/80c537 semiconductor group 312 clock of waveform for i cc tests in active, idle mode and slow down mode sab 80c517/80c537 semiconductor group 313 ac characteristics v cc = 5 v 10 %; v ss = 0 v t a = 0 to 70 o c for the sab 80c517/83c537 t a = C 40 to 85 o c for the sab 80c517/83c537-t40/85 ( c l for port 0, ale and psen outputs = 100 pf; c l for all other outputs = 80 pf)) parameter symbol limit values unit 12 mhz clock variable clock 1/ t clcl = 3.5 mhz to 12 mhz min max. min. max. program memory characteristics ale pulse width t lhll 127 C2 t clcl C 40 C ns address setup to ale t avll 53 C t clcl C 30 C ns address hold after ale t llax 48 C t clcl C 35 C ns ale to valid instruction in t lliv C 233 C 4 t clcl C 100 ns ale to psen t llpl 58 C t clcl C 25 C ns psen pulse width t plph 215 C 3 t clcl C 35 C ns psen to valid instruction in t pliv C 150 C 3 t clcl C 100 ns input instruction hold after psen t pxix 0C0 ns input instruction float after psen *) t pxix *) C63C t clcl C 20 ns address valid after psen *) t pxav *) 75 C t clcl C 8 C ns address to valid instruction in t aviv C 302 0 5 t clcl C 115 ns address float to psen t azpl CCC ns *) interfacing the sab 80c517 to devices with float times up to 75 ns is permissible. this limited bus contention will not cause any damage to port 0 drivers. sab 80c517/80c537 semiconductor group 314 ac characteristics (contd) parameter symbol limit values unit 12 mhz clock variable clock 1/ t clcl = 3.5 mhz to 12 mhz min max. min. max. external data memory characteristics rd pulse width t rlrh 400 C 6 t clcl C 100 C ns wr pulse width t wlwh 400 C 6 t clcl C 100 C ns address hold after ale t llax2 132 C 2 t clcl C 30 C ns rd to valid instr in t rldv C252C 5 t clcl C 165 ns data hold after rd t rhdx 0C0Cns data float after rd t rhdz C97C 2 t clcl C 70 ns ale to valid data in t lldv C517C 8 t clcl C 150 ns address to valid data in t avdv C585C 9 t clcl C 165 ns ale to wr or rd t llwl 200 300 3 t clcl C 50 3 t clcl + 50 ns wr or rd high to ale high t whlh 43 123 t clcl C 40 t clcl +40 ns address valid to wr t avwl 203 C 4 t clcl C 130 C ns data valid to wr transition t qvwx 33 C t clcl C 50 C ns data setup before wr t qvwx 433 C 7 t clcl C 150 C ns data hold after wr t whqx 33 C t clcl C 50 C ns address float after rd t rlaz C0C0ns sab 80c517/80c537 semiconductor group 315 ac characteristics v cc = 5 v 10 %; v ss = 0 v t a = 0 to 70 o c for the sab 80c517-16/83c537-16 t a = C 40 to 85 o c for the sab 80c517-16/83c537-16-t40/85 (c l for port 0, ale and psen outputs = 100pf; c l for all outputs = 80 pf) parameter symbol limit values unit 16 mhz clock variable clock 1/ t clcl = 3.5 mhz to 16 mhz min max. min. max. program memory characteristics ale pulse width t lhll 85 C2 t clcl C 40 C ns address setup to ale t avll 33 C t clcl C 30 C ns address hold after ale t llax 28 C t clcl C 35 C ns ale to valid instr. in t lliv C 150 C 4 t clcl C 100 ns ale to psen t llpl 38 C t clcl C 25 C ns psen pulse width t plph 153 C 3 t clcl C 35 C ns psen to valid instr. in t pliv C88C 3 t clcl C 100 ns input instruction hold after psen t pxix 0C0 C ns input instruction float * ) after psen t pxiz C43C t clcl C 20 ns address valid after psen *) t pxav 55 C t clcl C 8 C ns address to valid instr. in t aviv C 198 0C 5 t clcl C 115 ns address float to psen t azpl 0C0 C ns *) interfacing the sab 80c517 to devices with float times up to 55 ns is permissible. this limited bus contention will not cause any damage to port 0 drivers. sab 80c517/80c537 semiconductor group 316 ac characteristics (contd) parameter symbol limit values unit 16 mhz clock variable clock 1/ t clcl = 3.5 mhz to 16 mhz min max. min. max. external data memory characteristics rd pulse width t rlrh 275 C 6 t clcl C 100 C ns wr pulse width t wlwh 275 C 6 t clcl C 100 C ns address hold after ale t llax2 90 C 2 t clcl C 35 C ns rd to valid data in t rldv C148C 5 t clcl C 165 ns data hold after rd t rhdx 0C0Cns data float after rd t rhdz C55C 2 t clcl C 70 ns ale to valid data in t lldv C350C 8 t clcl C 150 ns address to valid data in t avdv C398C 9 t clcl C 165 ns ale to wr or rd t llwl 138 238 3 t clcl C 50 3 t clcl + 50 ns wr or rd high to ale high t whlh 23 103 t clcl C 40 t clcl + 40 ns address valid to wr t avwl 120 C 4 t clcl C 130 C ns data valid to wr transition t qvwx 13 C t clcl C 50 C ns data setup before wr t qvwh 288 C 7 t clcl C 150 C ns data hold after wr t whqx 13 C t clcl C 50 C ns address float after rd t rlaz C0C0ns sab 80c517/80c537 semiconductor group 317 program memory read cycle data memory read cycle sab 80c517/80c537 semiconductor group 318 data memory write cycle mct00098 ale psen port 2 whlh t port 0 wr t wlwh t llwl t qvwx t avll t llax2 t qvwh t avwl t whqx a0 - a7 from ri or dpl from pcl a0 - a7 instr.in data out a8 - a15 from pch p2.0 - p2.7 or a8 - a15 from dph sab 80c517/80c537 semiconductor group 319 ac characteristics (cont'd) ac characteristics (cont'd) parameter symbol limit values unit variable clock frequ. = 3.5 mhz to 12 mhz min max. external clock drive oscillator period t clcl 83.3 285 ns oscillator frequency 1/ t clcl 3.5 12 mhz high time t chcx 20 C ns low time t clcx 20 C ns rise time t clch C20ns fall time t chcl C20ns parameter symbol limit values unit variable clock frequ. = 1 mhz to 16 mhz min max. external clock drive oscillator period t clcl 62.5 285 ns oscillator frequency 1/ t clcl 3.5 16 mhz high time t chcx 25 C ns low time t clcx 25 C ns rise time t clch C20ns fall time t chcl C20ns sab 80c517/80c537 semiconductor group 320 external clock cycle sab 80c517/80c537 semiconductor group 321 ac characteristics (contd) ac characteristics (contd) parameter symbol limit values unit 12 mhz clock variable clock 1/ t clcl =3.5 mhz to 12 mhz min. max. min. max. system clock timing ale to clkout t llsh 543 C 7 t clcl C 40 C ns clkout high time t shsl 127 C 2 t clcl C 40 C ns clkout low time t slsh 793 C 10 t clcl C 40 C ns clkout low to ale high t sllh 43 123 t clcl C 40 t clcl + 40 ns parameter symbol limit values unit 16 mhz clock variable clock 1/ t clcl = 3.5 mhz to 16 mhz min. max. min. max. system clock timing ale to clkout t llsh 398 C 7 t clcl C 40 C ns clkout high time t shsl 85 C 2 t clcl C 40 C ns clkout low time t slsh 585 C 10 t clcl C 40 C ns clkout low to ale high t sllh 23 103 t clcl C 40 t clcl + 40 ns sab 80c517/80c537 semiconductor group 322 system clock timing sab 80c517/80c537 semiconductor group 323 rom verification characteristics t a = 25c 5c; v cc = 5 v 10%; v ss = 0 v rom verification for timing purposes a port pin is no longer floating when a 100 mv change from load voltage occurs and begins to float when a 100 mv change from the loaded v oh / v ol level occurs. i ol / i oh 3 20 ma. parameter symbol limit values unit min max. rom verification address to valid data t avqv C 48 t clcl ns enable to valid data t elqv C 48 t clcl ns data float after enable t ehqz 048 t clcl ns oscillator frequency 1/ t clcl 46mhz sab 80c517/80c537 semiconductor group 324 recommended oscillator circuits ac testing input, output waveforms float waveforms ac inputs during testing are driven at v cc C 0.5 v for a logic 1 and 0.45 v for a logic 0. timing measure- ments are made at v ihmin for a logic 1 and v ilmax for a logic 0. |
Price & Availability of Q67121C452
![]() |
|
|
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] |