89c420 Userguide
89c420 Userguide
89c420 Userguide
33
16kB 1kB
FLASH MEMORY SRAM
DUAL DATA 25
MIPS
POINTERS FOUR
HIGH-SPEED 8-BIT
WITH AUTO- ONE CLOCK-CYCLE PARALLEL
SELECT 8051 MICROPROCESSOR PORTS
INCREMENT/ 5
DECREMENT
1
DUAL SERIAL
PORTS 0
ORIGINAL
8051 DS89C420
DS89C420
SECTION 1: INTRODUCTION
Dallas Semiconductor’s DS89C420 is an 8051-compatible micro- priority, and a crystal multiplier. The device provides 256 bytes of
controller that provides improved performance and power con- RAM for variables and stack; 128 bytes can be reached using
sumption when compared to the original 8051 version. It retains direct or indirect addressing, or using indirect addressing only.
instruction set and object code compatibility with the 8051, yet In addition to improved efficiency, the DS89C420 can operate at
performs the same operations in fewer clock cycles. a maximum clock rate of 33MHz. Combined with the 12 times per-
Consequently, greater throughput is possible for the same crys- formance, this allows for a maximum performance of 33 million
tal speed. As an alternative, the DS89C420 can be run at a instructions per second (MIPs). This level of computing power is
reduced frequency to save power. The more efficient design comparable to many 16-bit processors, but without the added
allows a much slower crystal speed to get the same results as an expense and complexity if implementing a 16-bit interface.
original 8051, using much less power.
The DS89C420 incorporates a power-management mode that
The fundamental innovation of the DS89C420 is the use of only allows the device to dynamically vary the internal clock speed
one clock per instruction cycle compared with 12 for the original from 1 clock per cycle (default) to 1024 clocks per cycle. Because
8051. This results in up to 12 times improvement in performance power consumption is directly proportional to clock speed, the
over the original 8051 architecture and up to four times improve- device can reduce its operating frequency during periods of little
ment over other Dallas Semiconductor high-speed microcon- switchback. This greatly reduces power consumption. The switch-
trollers. The DS89C420 provides several peripherals and features back feature allows the device to quickly return to highest speed
in addition to all of the standard features of an 80C32. These operation upon receipt of an interrupt or serial port activity, allow-
include 16kB of on-chip flash memory, 1kB of on-chip RAM, four 8- ing the device to respond to external events while in power-man-
bit I/O ports, three 16-bit timer/counters, two on-chip UARTs, dual agement mode.
data pointers, an on-chip watchdog timer, five levels of interrupt
SECTION 3: ARCHITECTURE
The DS89C420 architecture is based on the industry-standard 87C52 and executes the standard 8051 instruction set. The core is an
accumulator-based architecture using internal registers for data storage and peripheral control. This section provides a brief descrip-
tion of each architecture feature. Details concerning the programming model, instruction set, and register description are provided in
Section 4.
ALU
The ALU is responsible for math functions, comparisons, and general decision making in the DS89C420. The ALU is not used explic-
itly by software. Instruction decoding prepares the ALU automatically and passes it the appropriate data. The ALU primarily uses two
special-function registers (SFRs) as the source and destination for all operations. These are the accumulator and B register. The ALU
also provides status information in the program status register. The SFRs are described in the following pages.
Special-Function Registers
All peripherals and operations that are not explicitly controlled by instructions in the DS89C420 are controlled through SFRs. All SFRs are
described in Section 4. The most commonly used registers that are basic to the architecture are also described in the following pages.
Accumulator
The accumulator is the primary register used in the DS89C420. It is a source and destination for many operations involving math, data
movement, and decisions. Although it can be bypassed, most high-speed instructions require the use of the accumulator (A or ACC)
as one argument.
B Register
The B register is used as the second 8-bit argument in multiply and divide operations. When not used for these purposes, the B reg-
ister can be used as a general-purpose register.
Program Status Word
The program status word holds a selection of bit flags that include the carry flag, auxiliary carry flag, general-purpose flag, register
bank select, overflow flag, and parity flag.
Data Pointer(s)
The data pointers (DPTR and DPTR1) are used to assign a memory address for the MOVX instructions. This address can point to a
data memory location, either on- or off-chip, or a memory-mapped peripheral. When moving data from one memory area to another or
from memory to a memory-mapped peripheral, a pointer is needed for both the source and destination. The user can select the active
pointer through a dedicated SFR bit (Sel = DPS.0), or can activate an automatic toggling feature for altering the pointer selection (TSL
= DPS.5). An additional feature, if selected, provides automatic incrementing or decrementing of the current DPTR.
Stack Pointer
The stack pointer denotes the register location at the top of the stack, which is the last used value. The user can place the stack any-
where in the scratchpad RAM by setting the stack pointer to the desired location, although the lower bytes are normally used for work-
ing registers.
______________________________________________________________________________________________ 2
Ultra-High-Speed Flash
Microcontroller User’s Guide
I/O Ports
The DS89C420 offers four 8-bit I/O ports. Each I/O port is represented by an SFR location, and can be written or read. The I/O port has
a latch that contains the value written by software. In general, software reads the state of external pins during a read operation.
Timer/Counters
Three 16-bit timer/counters are available in the DS89C420. Each timer is contained in two SFR locations that can be written or read by
software. The timers are controlled by other SFRs described in Section 4.
UARTs
The DS89C420 provides two UARTs, which are controlled and accessed by SFRs. Each UART has an address that is used to read and
write the UART. The same address is used for both read and write operations, which are distinguished by the instruction. Each UART
is controlled by its own SFR control register.
Scratchpad Registers (RAM)
The high-speed core provides 256 bytes of scratchpad RAM for general-purpose data and variable storage. The first 128 bytes are
directly available to software. The second 128 are available through indirect addressing. Selected portions of this RAM have other
optional functions.
Stack
The stack is a RAM area that the DS89C420 uses to store return address information during calls and interrupts. The user can also
place variables on the stack when necessary. The stack pointer designates the RAM location that is the top of the stack. Thus, depend-
ing on the value of the stack pointer, the stack can be located anywhere in the 256 bytes of RAM. A common location would be in the
upper 128 bytes of RAM, as these locations are accessible through indirect addressing only.
Working Registers
The first 32 bytes of the scratchpad RAM can be used as four banks of eight working registers for high-speed data movement. Using
four banks, software can quickly change context by changing to a different bank. In addition to the accumulator, the working registers
are commonly used as data source or destination. Some of the working registers can also be used as pointers to other RAM locations
(indirect addressing).
Program Counter
The program counter (PC) is a 16-bit value that designates the next program address to be fetched. On-chip hardware automatically
increments the PC value to move to the next ROM location.
Address/Data Bus
The DS89C420 addresses a 64kB program and 64kB data memory area that resides in a combination of internal and external memory.
When external memory is accessed, ports 0 and 2 are used as a multiplexed address and data bus. The DS89C420 supports three
external memory bus structures. The nonpage mode (traditional 8051) bus structure provides the address MSB on port 2 and multiplexes
port 0 between address LSB and data. The page mode 1 bus structure uses port 0 exclusively for data and multiplexes port 2 between
address MSB and address LSB. The page mode 2 bus structure uses port 0 exclusively for address LSB and multiplexes port 2 between
address MSB and data. These addressing modes are detailed later.
Watchdog Timer
The watchdog timer provides a supervisory function for applications that cannot afford to run out of control. The watchdog timer is a
programmable, free-running timer. If allowed to reach the termination of its count, if enabled, the watchdog resets the CPU software
must prevent this by clearing or resetting the watchdog prior to its timeout.
Power Monitor
The DS89C420 incorporates a bandgap reference and analog circuitry to monitor the power-supply conditions. When VCC begins to
drop out of tolerance, the power monitor issues an optional early warning power-fail interrupt. If power continues to fall, the power mon-
itor invokes a reset condition. This remains until power returns to normal operating voltage. The power monitor also functions on power-
up, holding the microcontroller in a reset state until power is stable.
Interrupts
The DS89C420 is capable of evaluating 13 interrupt sources simultaneously. Each interrupt has an associated interrupt vector, flag,
priority, and enable. These interrupts can be globally enabled or disabled.
3 ______________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Timing Control
The DS89C420 provides an on-chip oscillator for use with an external crystal. This can be bypassed by injecting a clock source into
the XTAL1 pin. The clock source is used to create machine cycle timing (four clocks), ALE, PSEN, watchdog, timer, and serial baud-
rate timing. In addition, an on-chip ring oscillator can be used to provide an approximately 10MHz clock source. A frequency multipli-
er feature is included, which can be selected by SFR control to multiply the input clock source by either two or four. This allows lower
frequency (and cost) crystals to be used while still allowing internal operation up to the full 33MHz limit.
Flash Memory
On-chip program memory is implemented in 16kB of flash memory. This can be programmed in-system with the standard 5V VCC sup-
ply under the control of the user software (in-application), or through a serial port (in-system) using a built-in program memory loader
(ROM loader), or by a standard flash or EPROM programmer. Full programming details are given in Section 15.
The DS89C420 incorporates a memory management unit (MMU) and other hardware to support any of the three programming meth-
ods. The MMU controls program and data memory access, and provides sequencing and timing controls for programming of the on-
chip program memory. There is also a separate security flash block that is used to support a standard three-level lock, a 64-byte
encryption array, and other flash options.
The full on-chip program memory range can be fetched by the processor automatically. Reset routines and all interrupt vectors are
located in the lower 128 bytes of the on-chip program memory area.
______________________________________________________________________________________________ 4
Ultra-High-Speed Flash
Microcontroller User’s Guide
FFh
INDIRECT RAM
7Fh
DIRECT RAM
2Fh 7F 7E 7D 7C 7B 7A 79 78
2Eh 77 76 75 74 73 72 71 70
2Dh 6F 6E 6D 6C 6B 6A 69 68
2Ch 67 66 65 64 63 62 61 60
2Bh 5F 5E 5D 5C 5B 5A 59 58
2Ah 57 56 55 54 53 52 51 50
29h 4F 4E 4D 4C 4B 4A 49 48
28h 47 46 45 44 43 42 41 40
27h 3F 3E 3D 3C 3B 3A 39 38
26h 37 36 35 34 333 32 31 30
25h 2F 2E 2D 2C 2B 2A 29 28
24h 27 26 25 24 23 22 21 20
23h 1F 1E 1D 1C 1B 1A 19 18
22h 17 16 15 14 13 12 11 10
21h 0F 0E 0D 0C 0B 0A 09 08
20h 07 06 05 04 03 02 01 00
1Fh
BANK 3
18h
17h
BANK 2
10h
0Fh
BANK 1
08h
07h
00h BANK 0
MSB LSB
5 ______________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
location. A direct reference to one of the lower 128 addresses (0h-7Fh) accesses the scratchpad RAM. A direct reference to one of the upper
128 addresses (80h-FFh) must be an SFR access. In contrast, indirect references can access the entire scratchpad RAM range (0h-FFh).
Scratchpad RAM is available for general-purpose data storage. It is commonly used in place of off-chip RAM when the total data con-
tents are small. When off-chip RAM is needed, the scratchpad area still provides the fastest general-purpose access. Within the 256
bytes of RAM, there are several special purpose areas. These are described as follows:
Bit Addressable Locations
In addition to direct register access, some individual bits are also accessible. These are individually addressable bits in both the RAM
and SFR area. In the scratchpad RAM area, registers 20h to 2Fh are bit addressable. This provides 128 (16 x 8) individual bits avail-
able to software. A bit access is distinguished from a full register access by the type of instruction. Addressing modes are discussed
later in this section. In the SFR area, any register location ending in a 0 or 8 is bit addressable. Figure 4-3 shows details of the on-chip
RAM addressing, including the locations of individual RAM bits.
Working Registers
As part of the lower 128 bytes of RAM, there are four banks of working registers (8 bytes each). The working registers are general-purpose
RAM locations that can be addressed in a special way. They are designated R0 through R7. Since there are four banks, the currently
selected bank is used by any instruction using R0–R7. This allows software to change context by simply switching banks. This is con-
trolled through the program status word register in the next SFR area. The working registers also allow their contents to be used for
indirect addressing of the upper 128 bytes of RAM. Thus, an instruction can designate the value stored in R0 (for example) to address
the upper RAM. This value might be the result of another calculation.
Stack
Another use of the scratchpad area is for the programmer’s stack. This area is selected using the stack pointer (SP;81h) SFR. Whenever
a call or interrupt is invoked, the return address is placed on the stack. It also is available to the programmer for variables, etc. Since
the stack can be moved, there is no fixed location within the RAM designated as stack. The stack pointer defaults to 07h upon reset.
The user can then move it as needed. A convenient location would be the upper RAM area (>7Fh), since this is only available indi-
rectly. The SP points to the last used value. Therefore, the next value placed on the stack is put at SP + 1. Each PUSH or CALL incre-
ments the SP by the appropriate value. Each POP or RET decrements as well.
Address Modes
The DS89C420 uses the standard 8051 instruction set that is supported by a wide range of third-party assemblers and compilers. Like
the 8051, the DS89C420 uses three memory areas. These are program memory, data memory, and registers. The program and data
areas are 64kB each. They extend from 0000h to FFFFh. The register areas are located between 00h and FFh, but do not overlap with
the program and data segments. This is because the DS89C420 uses different modes of addressing to reach each memory segment.
These modes are described below.
Program memory is the area from which all instructions are fetched. It is inherently read only. This is because the 8051 instruction set
provides no instructions that write to this area. Read/write access is for data memory and registers only. No special action is required
to fetch from program memory. Each instruction fetch is performed automatically by the on-chip CPU. In versions that contain on-chip
memory, the hardware decides whether the fetch is on-chip or off-chip based on the address. Explicit addressing modes are needed
for the data memory and register areas. These modes determine which register area is accessed or if off-chip data memory is used.
______________________________________________________________________________________________ 6
Ultra-High-Speed Flash
Microcontroller User’s Guide
7 ______________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
This mode is also used for stack manipulation. This is because all stack references are directed by the value in the stack pointer reg-
ister. The push and pop instructions use this method of addressing. An example is as follows:
PUSH A ;Saves the contents of the
;accumulator on the stack.
Register indirect addressing is used for all off-chip data memory accesses. These involve the MOVX instruction. The pointer registers
can be R0, R1, DPTR0 and DPTR1. Both R0 and R1 reside in the working register area of the scratchpad RAM. They can be used to
reference a 256-byte area of off-chip data memory. When using this type of addressing, the upper address byte is supplied by the
value in the port 2 latch. This value must be selected by software prior to the MOVX instruction. An example is as follows:
MOVX @R0, A ;Write the value in the accumulator
;to the address pointed to by R0 in
;the page pointed to by P2.
The 16-bit data pointers (DPTRs) can be used as an absolute off-chip reference. This gives access to the entire 64kB data memory
map. An example is as follows:
MOVX @DPTR, A ;Write the value in the accumulator
;to the address referenced by the
;selected data pointer.
Immediate Addressing
Immediate addressing is used when one of the operands is predetermined and coded into the software. This mode is commonly used
to initialize SFRs and to mask particular bits without affecting others. An example is as follows:
ORL A, #40h ;Logical OR the Accumulator with 40h.
Register Indirect with Displacement
Register indirect addressing with displacement is used to access data in lookup tables in program memory space. The location is cre-
ated using a base address with an index. The base address can be either the PC or the DPTR. The index is the accumulator. The result
is stored in the accumulator. An example is as follows:
MOVC A, @A +DPTR ;Load the accumulator with the contents
of program memory
;pointed to by the contents of the DPTR
plus the value in
;the accumulator.
Relative Addressing
Relative addressing is used to determine a destination address for the conditional branch. Each of these instructions includes an 8-bit
value that contains a two’s complement address offset (-127 to +128), which is added to the PC to determine the destination address.
This destination is branched to when the tested condition is true. The PC points to the program memory location immediately follow-
ing the branch instruction when the offset is added. If the tested condition is not true, the next instruction is performed. An example is
as follows:
JZ $–20 ;Branch to the location (PC+2)–20
;if the contents of the accumulator = 0.
Page Addressing
Page addressing is used by the branching instructions to specify a destination address within the same 2kB block as the next con-
tiguous instruction. The full 16-bit address is calculated by taking the five highest-order bits for the next instruction (PC + 2) and
concatenating them with the lowest order 11-bit field contained in the current instruction. An example is as follows:
0870h ACALL 100h ;Call to the subroutine at address 100h
plus the
;current page address.
In this example, the current page address is 800h, so the destination address is 900h.
Extended Addressing
Extended addressing is used by the branching instructions to specify a 16-bit destination address within the 64kB address space. The
destination address is fixed in the software as an absolute value. An example is as follows:
LJMP 0F732h ;Jump to address 0F732h.
______________________________________________________________________________________________ 8
Ultra-High-Speed Flash
Microcontroller User’s Guide
PSW.6 AC
Auxiliary Carry Set when the previous operation resulted in a carry (during addition) or a borrow (during
subtraction) from the high-order nibble. Otherwise cleared.
PSW.2 OV
Overflow For addition, OV is set when a carry is generated into a high order bit (bit 6 or bit 7), but not a carry
out of the same high-order bit. For subtraction, OV is set if a borrow is needed into a high order bit
(bit 6 or bit 7), but not into the other high-order bit. For multiplication, OV is set when the product
exceeds FFh. For division, OV is always cleared.
PSW.0 P
Parity Set to logic 1 to indicate an odd number of ones in the accumulator (odd parity). Cleared for an
even number of ones. This produces even parity.
*All of these bits are cleared to a logic 0 for all resets.
Special Function-Registers
The DS89C420, like the 8051, uses SFRs to control peripherals and modes. In many cases, an SFR controls individual functions or
report status on individual functions. The SFRs reside in register locations 80h–FFh and are reached using direct addressing. SFRs that
end in 0 or 8 are bit addressable.
All standard SFR locations from the original 8051 are duplicated in the DS89C420, with several additions. Tables are provided to illus-
trate the locations of the SFRs for the DS89C420 device and the default reset conditions of all SFR bits. Detailed descriptions of each
SFR follow.
9 ______________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 10
Ultra-High-Speed Flash
Microcontroller User’s Guide
11 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Special-Function Registers
Most of the unique features of the ultra-high-speed microcontroller family are controlled by bits in SFRs located in unused locations in
the 8051 SFR map. This allows for increased functionality while maintaining complete instruction set compatibility.
The description for each bit indicates its read and write access, as well as its state after a power-on reset.
Port 0 (P0)
7 6 5 4 3 2 1 0
SFR 80h P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
P0.7–0 Port 0. This port functions according to the table below where PAGEE = ACON.7 and PAGES =
ACON.6-5.
Port 0 Function
PAGEE PAGES PORT 0 FUNCTION
0 XX General-Purpose I/O (code execution < ROMSIZE.2-0)
0 XX Multiplexed Address LSB / Data (code execution > ROMSIZE.2-0)
1 00, 01, 10 Data
1 11 Address LSB
When serving as general-purpose I/O (GPIO), the port is open-drain and requires pullups. Writing
a 1 to one of the bits of this register configures the associated port 0 pin as an input. All read oper-
ations, with the exception of read-modify-write instructions, leave the port latch unchanged. During
external memory addressing and data memory write cycles, the port has high-and-low drive capa-
bility. During external memory data read cycles, the port is held in a high-impedance state.
Stack Pointer (SP)
7 6 5 4 3 2 1 0
SFR 81h SP.7 SP.6 SP.5 SP.4 SP.3 SP.2 SP.1 SP.0
RW-0 RW-0 RW-0 RW-0 RW-0 RW-1 RW-1 RW-1
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
SP.7–0 Stack Pointer. This stack pointer is written by software to identify the location where the stack
Bits 7–0 begins. The stack pointer is incremented before every PUSH operation and is decremented fol-
lowing every POP operation. This register defaults to 07h after reset.
DPL.7–0 Data Pointer LOW 0. This register is the low byte of the standard 80C32 16-bit data pointer. DPL
Bits 7–0 and DPH are used to point to nonscratchpad data RAM.
_____________________________________________________________________________________________ 12
Ultra-High-Speed Flash
Microcontroller User’s Guide
13 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SEL Data Pointer Select. This bit selects the active data pointer.
Bit 0 0 = Instructions that use the DPTR use DPL and DPH.
1 = Instructions that use the DPTR use DPL1 and DPH1.
SMOD_0 Serial Port 0 Baud Rate Doubler Enable. This bit enables/disables the serial baud rate doubling
Bit 7 function for Serial Port 0.
0 = Serial Port 0 baud rate is that defined by baud rate generation equation.
1 = Serial Port 0 baud rate is double that defined by baud rate generation equation.
SMOD0 Framing Error Detection Enable. When clear (= 0), SCON1.7 and SCON0.7 serve as mode select
Bit 6 bit SM0 for the respective serial ports. When set (= 1), SCON1.7 and SCON0.7 report whether a
Framing Error has been detected.
OFDF Oscillator Fail Detect Flag. When OFDE = 1, this flag will be set if a reset condition is generated
Bit 5 due to oscillator failure. This bit is cleared on a power-on reset and is unchanged by other reset
sources. This bit must be cleared by software.
OFDE Oscillator Fail Detect Enable. When set (= 1), the oscillator fail detect circuitry and flag generation
Bit 4 are enabled. An oscillator fail detection occurs if the crystal oscillator falls below ~20kHz. An oscillator
fail detection does not occur if the oscillator is halted through software setting of the STOP bit
(PCON.1) or when running from the internal ring oscillator source. When clear (= 0), the oscillator
fail detect circuitry is disabled.
GF1 General-Purpose User Flag 1. This is a general-purpose flag for software control.
Bit 3
GF0 General-Purpose User Flag 0. This is a general-purpose flag for software control.
Bit 2
STOP Stop Mode Select. Setting this bit stops program execution, halts the CPU oscillator and internal
Bit 1 timers, and places the CPU in a low-power mode. This bit always be reads as a 0. Setting both the
STOP bit and the IDLE bit causes the device to enter stop mode; however, doing this is not advised.
IDLE Idle Mode Select. Setting this bit stops program execution but leaves the CPU oscillator, timers,
Bit 0 serial ports, and interrupts active. This bit is always read as a 0. Setting both the STOP bit and
the IDLE bit causes the device to enter stop mode; however, doing this is not advised.
_____________________________________________________________________________________________ 14
Ultra-High-Speed Flash
Microcontroller User’s Guide
TF1 Timer 1 Overflow Flag. This bit indicates when Timer 1 overflows its maximum count as defined
Bit 7 by the current mode. This bit can be cleared by software and is automatically cleared when the
CPU vectors to the Timer 1 interrupt service routine.
0 = No Timer 1 overflow has been detected.
1 = Timer 1 has overflowed its maximum count.
TR1 Timer 1 Run Control. This bit enables/disables the operation of Timer 1.
Bit 6 0 = Timer 1 is halted.
1 = Timer 1 is enabled.
TF0 Timer 0 Overflow Flag. This bit indicates when Timer 0 overflows its maximum count as defined
Bit 5 by the current mode. This bit can be cleared by software and is automatically cleared when the
CPU vectors to the Timer 0 interrupt service routine or by software.
0 = No Timer 0 overflow has been detected.
1 = Timer 0 has overflowed its maximum count.
TR0 Timer 0 Run Control. This bit enables/disables the operation of Timer 0.
Bit 4 0 = Timer 0 is halted.
1 = Timer 0 is enabled.
IE1 Interrupt 1 Edge Detect. This bit is set when an edge/level of the type defined by IT1 is detected.
Bit 3 If IT1 = 1, this bit remains set until cleared in software or until the start of the External Interrupt 1
service routine. If IT1 = 0, this bit inversely reflects the state of the INT1 pin.
IT1 Interrupt 1 Type Select. This bit selects whether the INT1 pin detects edge- or level-triggered
Bit 2 interrupts.
0 = INT1 is level triggered.
1 = INT1 is edge triggered.
IE0 Interrupt 0 Edge Detect. This bit is set when an edge/level of the type defined by IT0 is detected.
Bit 1 If IT0 = 1, this bit remains set until cleared in software or until the start of the External Interrupt 0
service routine. If IT0 = 0, this bit inversely reflects the state of the INT0 pin.
IT0 Interrupt 0 Type Select. This bit selects whether the INT0 pin detects edge- or level-triggered
Bit 0 interrupts.
0 = INT0 is level triggered.
1 = INT0 is edge triggered.
15 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
GATE Timer 1 Gate Control. This bit enables/disables the ability of Timer 1 to increment.
Bit 7 0 = Timer 1 clocks when TR1 = 1, regardless of the state of INT.
1 = Timer 1 clocks only when TR1 = 1 and INT1 = 1.
C/T Timer 1 Counter/Timer Select.
Bit 6 0 = Timer 1 is incremented by internal clocks.
1 = Timer 1 is incremented by pulses on T1 when TR1 (TCON.6) is 1.
M1, M0 Timer 1 Mode Select. These bits select the operating mode of Timer 1.
Bits 5, 4 Timer 1 Mode Selection
M1 M0 MODE
0 0 Mode 0: 8 bits with 5-bit prescale
0 1 Mode 1: 16 bits
1 0 Mode 2: 8 bits with autoreload
1 1 Mode 3: Timer 1 is halted, but holds its count
GATE Timer 0 Gate Control. This bit enables/disables the ability of Timer 0 to increment.
Bit 3 0 = Timer 0 clocks when TR0 = 1, regardless of the state of INT0.
1 = Timer 0 clocks only when TR0 = 1 and INT0 = 1.
C/T Timer 0 Counter/Timer Select.
Bit 2 0 = Timer incremented by internal clocks.
1 = Timer 1 is incremented by pulses on T0 when TR0 (TCON.4) is 1.
M1, M0 Timer 0 Mode Select. These bits select the operating mode of Timer 0. When Timer 0 is in mode
Bits 1, 0 3, TL0 is started/stopped by TR0 and TH0 is started/stopped by TR1. Run control from Timer 1 is
then provided by the Timer 1 mode selection.
Timer 0 Mode Selection
M1 M0 MODE
0 0 Mode 0: 8 bits with 5-bit prescale
0 1 Mode 1: 16 bits
1 0 Mode 2: 8 bits with autoreload
1 1 Mode 3: Timer 0 is two 8-bit counters
_____________________________________________________________________________________________ 16
Ultra-High-Speed Flash
Microcontroller User’s Guide
TL1.7–0 Timer 1 LSB. This register contains the least significant byte of Timer 1.
Bits 7–0
TH0.7–0 Timer 0 MSB. This register contains the most significant byte of Timer 0.
Bits 7–0
Timer 1 MSB (TH1)
7 6 5 4 3 2 1 0
SFR 8Dh TH1.7 TH1.6 TH1.5 TH1.4 TH1.3 TH1.2 TH1.1 TH1.0
RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
TH1.7–0 Timer 1 MSB. This register contains the most significant byte of Timer 1.
Bits 7–0
WD1, WD0 Watchdog Timer Mode Select 1-0. These bits determine the watchdog timer timeout period for
Bits 7, 6 the watchdog timer. The timer divides the crystal (or external oscillator) frequency by a program-
mable value as shown on the next page. The divider value is expressed in crystal (oscillator)
cycles. The settings of the system clock control bits 4X/2X (PMR.3) and CD1:0 (PMR.7-6) affect the
clock input to the watchdog timer and therefore its timeout period as shown below. All watchdog
timer reset timeouts follow the setting of the interrupt flag by 512 system clocks.
17 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
MD2, MD1, MD0 Stretch MOVX Select 2-0. These bits select the time by which external MOVX cycles are to be
Bits 2, 1, 0 stretched. This allows slower memory or peripherals to be accessed without using ports or manual
software intervention. The RD or WR strobe is stretched by the specified interval, which is transparent
to the software except for the increased time to execute to MOVX instruction. All internal MOVX
instructions are executed at the two machine cycle rate (0 stretch) independent of these bit settings.
MOVX Instruction
MD2, MD1, MD0 STRETCH VALUE MOVX DURATION
000 0 2 machine cycles
3 machine cycles
001 1
(default)
010 2 4 machine cycles
011 3 5 machine cycles
100 4 9 machine cycles
101 5 10 machine cycles
110 6 11 machine cycles
111 7 12 machine cycles
_____________________________________________________________________________________________ 18
Ultra-High-Speed Flash
Microcontroller User’s Guide
Port 1 (P1)
7 6 5 4 3 2 1 0
P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
SFR 90h
INT5 INT4 INT3 INT2 TXD1 RXD1 T2EX T2
RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
P1.7–0 General-Purpose I/O Port 1. This register functions as a general-purpose I/O port. In addition, all
Bits 7–0 the pins have an alternative function listed below. Each of the functions is controlled by several
other SFRs. The associated Port 1 latch bit must contain a logic 1 before the pin can be used in its
alternate function capacity.
INT5 External Interrupt 5. A falling edge on this pin causes an external interrupt 5 if enabled.
Bit 7
INT4 External Interrupt 4. A rising edge on this pin causes an external interrupt 4 if enabled.
Bit 6
INT3 External Interrupt 3. A falling edge on this pin causes an external interrupt 3 if enabled.
Bit 5
INT2 External Interrupt 2. A rising edge on this pin causes an external interrupt 2 if enabled.
Bit 4
TXD1 Serial Port 1 Transmit. This pin transmits the serial port 1 data in serial port modes 1, 2, 3 and
Bit 3 emits the synchronizing clock in serial port mode 0.
RXD1 Serial Port 1 Receive. This pin receives the serial port 1 data in serial port modes 1, 2, 3 and is a
Bit 2 bidirectional data transfer pin in serial port mode 0.
T2EX Timer 2 Capture/Reload Trigger. A 1-to-0 transition on this pin causes the value in the T2
Bit 1 registers to be transferred into the capture registers if enabled by EXEN2 (T2CON.3). When in auto-
reload mode, a 1-to-0 transition on this pin reloads the Timer 2 registers with the value in RCAP2L
and RCAP2H if enabled by EXEN2 (T2CON.3).
T2 Timer 2 External Input. A 1-to-0 transition on this pin causes Timer 2 increment or decrement bit
Bit 0 depending on the timer configuration.
External Interrupt Flag (EXIF)
7 6 5 4 3 2 1 0
SFR 91h IE5 IE4 IE3 IE2 CKRY RGMD RGSL BGS
RW-0 RW-0 RW-0 RW-0 R-* R-* RW-* RT-0
R = Unrestricted read, W = Unrestricted write, T = Timed-access write only, -n = Value after reset,* = See description.
IE5 External Interrupt 5 Flag. This bit is set when a falling edge is detected on INT5. This bit must
Bit 7 be cleared manually by software. Setting this bit in software causes an interrupt if enabled.
IE4 External Interrupt 4 Flag. This bit is set when a rising edge is detected on INT4. This bit must
Bit 6 be cleared manually by software. Setting this bit in software causes an interrupt if enabled.
IE3 External Interrupt 3 Flag. This bit is set when a falling edge is detected on INT3. This bit must
Bit 5 be cleared manually by software. Setting this bit in software causes an interrupt if enabled.
IE2 External Interrupt 2 Flag. This bit is set when a rising edge is detected on INT2. This bit must
Bit 4 be cleared manually by software. Setting this bit in software causes an interrupt if enabled.
CKRY Clock Ready. This bit indicates the status of the startup period for the crystal oscillator or crystal
Bit 3 multiplier warm-up period. This bit is cleared after a reset or when exiting STOP mode. It is also
cleared when the clock multiplier is enabled (setting of PMR.4 = 1). Once CKRY is cleared, a
65,536 clock count must take place before CKRY is set and the lockout preventing modification of
CD1:CD0 is removed. Once CKRY is set (= 1), the clock multiplier can then be selected as the
clock source or switchover from the ring oscillator to the crystal oscillator can occur.
RGMD Ring Mode Status. This status bit indicates the current clock source for the device. This bit is
19 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Bit 2 cleared to 0 after a power-on reset, and unchanged by all other forms of reset.
0 = Device is operating from the external crystal or oscillator.
1 = Device is operating from the ring oscillator.
RGSL Ring Oscillator Select. When set (= 1), this bit enables operation using the on-chip ring oscillator
Bit 1 as the clock source until the oscillator warm-up period has completed (CKRY = 1). Using the ring
oscillator to resume from stop mode allows almost instantaneous startup. This bit is cleared to 0
after a power-on reset, and unchanged by all other forms of reset.
0 = Device operation is held until completion of the crystal oscillator warm-up delay period.
1 = The device begins operating from the ring oscillator and switch over to the crystal oscillator
upon completion of the warm-up delay period.
BGS Bandgap Select. This bit enables/disables the bandgap reference during stop mode. Disabling
Bit 0 the bandgap reference provides significant power savings in stop mode, but sacrifices the ability
to perform a power-fail interrupt or power-fail reset while stopped. This bit can only be modified
with a timed access procedure.
0 = The bandgap reference is disabled in stop mode but functions during normal operation.
1 = The bandgap reference operates in stop mode.
Timer and Serial Port Clock Mode Register (CKMOD)
7 6 5 4 3 2 1 0
SFR 96h — — T2MH T1MH T0MH — — —
RW-1 RW-1 RW-0 RW-0 RW-0 RW-1 RW-1 RW-1
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
T2MH Timer 2 Clock Mode High-Speed Select. When set (= 1), the system clock is used as the input
Bit 5 clock for Timer 2 and the T2M bit (CKCON.5) setting is ignored. When clear (= 0), the input
clock for Timer 2 is selected using the T2M bit.
T1MH Timer 1 Clock Mode High-Speed Select. When set (= 1), the system clock is used as the input
Bit 4 clock for Timer 2 and the T1M bit (CKCON.4) setting is ignored. When clear (= 0), the input
clock for Timer 2 is selected using the T1M bit.
T0MH Timer 0 Clock Mode High-Speed Select. When set (= 1), the system clock is used as the input
Bit 3 clock for Timer 2 and the T0M bit (CKCON.3) setting is ignored. When clear (= 0), the input
clock for Timer 2 is selected using the T0M bit.
Serial Port 0 Control (SCON0)
7 6 5 4 3 2 1 0
SFR 98h SM0/FE_0 SM1_0 SM2_0 REN_0 TB8_0 RB8_0 TI_0 RI_0
RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
SM0–2 Serial Port Mode. These bits control the mode of serial port 0. In addition the SM0 and SM2_0 bits
Bits 7, 6, 5 have secondary functions as shown below.
_____________________________________________________________________________________________ 20
Ultra-High-Speed Flash
Microcontroller User’s Guide
SM0/FE_0 Framing Error Flag. When SMOD0 (PCON.6) = 0, this bit is used as a mode select bit (SM0) for
Bit 7 serial port 0. When SMOD0 (PCON.6) = 1, this bit becomes a framing error (FE) bit, which reports
detection of an invalid stop bit. When used as FE, this bit must be cleared in software. Once the
SMOD0 bit is set, modifications to this bit do not affect the serial port mode settings. Although
accessed from the same register, the data for bits SM0 and FE are stored internally in different
physical locations.
SM1_0 No alternate function.
Bit 6
SM2_0 Multiple CPU Communications. The function of this bit is dependent on the serial port 0 mode.
Bit 5 Mode 0: Selects period for synchronous serial port 0 data transfers.
Mode 1: When set, reception is ignored (RI_0 is not set) if invalid stop bit received.
Modes 2/3: When this bit is set, multiprocessor communications are enabled in modes 2 and 3.
This prevents the RI_0 bit from being set, and an interrupt being asserted, if the 9th bit received is not 1.
REN_0 Receiver Enable. This bit enable/disables the serial port 0 receiver shift register.
Bit 4 0 = Serial port 0 reception disabled.
1 = Serial port 0 receiver enabled (modes 1, 2, 3). Initiate synchronous reception (mode 0).
TB8_0 9th Transmission Bit State. This bit defines the state of the 9th transmission bit in serial port 0
Bit 3 modes 2 and 3.
RB8_0 9th Received Bit State. This bit identifies that state of the 9th reception bit of received data in
Bit 2 serial port 0 modes 2 and 3. In serial port mode 1, when SM2_0 = 0, RB8_0 is the state of the stop
bit. RB8_0 is not used in mode 0.
TI_0 Transmitter Interrupt Flag. This bit indicates that data in the serial port 0 buffer has been
Bit 1 completely shifted out. In serial port mode 0, TI_0 is set at the end of the 8th data bit. In all other
modes, this bit is set at the end of the last data bit. This bit must be manually cleared by software.
RI_0 Receiver Interrupt Flag. This bit indicates that a byte of data has been received in the serial port
Bit 0 0 buffer. In serial port mode 0, RI_0 is set at the end of the 8th bit. In serial port mode 1, RI_0 is set
after the last sample of the incoming stop bit subject to the state of SM2_0. In modes 2 and 3, RI_0
is set after the last sample of RB8_0. This bit must be manually cleared by software.
SBUF0.7–0 Serial Data Buffer 0. Data for serial port 0 is read from or written to this location. The serial
Bits 7–0 transmit and receive buffers are separate registers, but both are addressed at this location.
21 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
P2.7–0 Port 2. This port functions according to the table below where PAGEE = ACON.7 and PAGES =
Bits 7–0 ACON.6-5.
Port 2 Functions
PAGEE PAGES PORT2 FUNCTION
0 XX General-Purpose I/0 (code execution < ROMSIZE.2-0)
0 XX Address MSB (code execution > ROMSIZE.2-0)
1 00, 01, 10 Multiplexed Address MSB/LSB
1 11 Multiplexed Address MSB/Data
Writing a 1 to an SFR bit configures the associated port pin as an input. All read operations, with
the exception of read-modify-write instructions, leave the port latch unchanged. During external
memory addressing and data memory write cycles, the port has high and low drive capability.
During external memory data read cycles, the port is held in a high-impedance state.
_____________________________________________________________________________________________ 22
Ultra-High-Speed Flash
Microcontroller User’s Guide
SADDR0.7–0 Slave Address Register 0. This register is programmed with the given or broadcast address
Bits 7–0 assigned to serial port 0.
23 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SADDR1.7–0 Slave Address Register 1. This register is programmed with the given or broadcast address
Bits 7–0 assigned to serial port 1.
Port 3 (P3)
7 6 5 4 3 2 1 0
P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0
SFR B0h
RD WR T1 T0 INT1 INT0 TXD0 RXD0
RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1 RW-1
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
P3.7–0 Purpose I/O Port 3. This register functions as a general-purpose I/O port. In addition, all the pins
Bits 7–0 have an alternative function listed below. Each of the functions is controlled by several other SFRs.
The associated port 3 latch bit must contain a logic 1 before the pin can be used in its alternate
function capacity.
RD External Data Memory Read Strobe. This pin provides an active-low read strobe to an external
Bit 7 memory device.
WR External Data Memory Write Strobe. This pin provides an active-low write strobe to an external
Bit 6 memory device.
T1 Timer/Counter External Input. A 1-to-0 transition on this pin increments Timer 1.
Bit 5
T0 Counter External Input. A 1-to-0 transition on this pin increments Timer 0.
Bit 4
INT1 External Interrupt 1. A falling edge/low level on this pin causes an external interrupt 1 if enabled.
Bit 3
INT0 External Interrupt 0. A falling edge/low level on this pin causes an external interrupt 0 if enabled.
Bit 2
TXD0 Serial Port 0 Transmit. This pin transmits the serial port 0 data in serial port modes 1, 2, 3 and
Bit 1 emits the synchronizing clock in serial port mode 0.
RXD0 Serial Port 0 Receive. This pin receives the serial port 0 data in serial port modes 1, 2, 3 and is a
Bit 0 bidirectional data transfer pin in serial port mode 0.
Interrupt Priority 1 (IP1)
7 6 5 4 3 2 1 0
SFR B1h — MPS1 MPT2 MPS0 MPT1 MPX1 MPT0 MPX0
R-1 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
IP17.0
Bit 7 Reserved. Read data is 1.
MPS1 Most Significant Priority Select Bit for Serial Port 1 Interrupt. This is the most significant bit of
Bit 6 the bit pair MPS1, LPS1 (IP0.6) that designates priority level for the serial port 1 interrupt.
MPT2 Most Significant Priority Select Bit for Timer 2 Interrupt. This is the most significant bit of the
Bit 5 bit pair MPT2, LPT2 (IP0.5) that designates priority level for the timer 2 interrupt.
_____________________________________________________________________________________________ 24
Ultra-High-Speed Flash
Microcontroller User’s Guide
MPS0 Most Significant Priority Select Bit for Serial Port 0 Interrupt. This is the most significant bit of
Bit 4 the bit pair MPS0, LPS0 (IP0.4) that designates priority level for the serial port 0 interrupt
MPT1 Most Significant Priority Select Bit for Timer 1 Interrupt. This is the most significant bit of the
Bit 3 bit pair MPT1, LPT1 (IP0.3) that designates priority level for the timer 1 interrupt.
MPX1 Most Significant Priority Select Bit for External Interrupt 1. This is the most significant bit
Bit 2 of the bit pair MPX1, LPX1 (IP0.2) that designates priority level for external interrupt 1
MPT0 Most Significant Priority Select Bit for Timer 0 Interrupt. This is the most significant bit of the
Bit 1 bit pair MPT0, LPT0 (IP0.1) that designates priority level for the timer 0 interrupt
MPX0 Most Significant Priority Select Bit for External Interrupt 0. This is the most significant bit of the
Bit 0 bit pair MPX0, LPX0 (IP0.0) that designates priority level for external interrupt 0.
Interrupt priority level for the above sources is assigned using one bit from register IP1 (B1h) and
one bit from IP0 (B8h). The bit from IP1 serves as the most significant bit and the bit from IP0 serves
as the least significant bit in forming a 2-bit binary number. This number represents the priority level.
Higher priority interrupts, when enabled, take precedence over lower priority sources. The power-
fail warning interrupt source is assigned priority level 4.
Most Significant Priority Select Bit Levels
MP (IP1.X) LP (IP0.X) PRIORITY LEVEL
0 0 0 (natural priority)
0 1 1
1 0 2
1 1 3 (high priority)
IP07.0
Bit 7 Reserved. Read data is 1.
LPS1 Least Significant Priority Select Bit for Serial Port 1 Interrupt. LPS1 is the least significant bit
Bit 6 of the bit pair MPS1 (IP1.6), LPS1 that designates priority level for the serial port 1 interrupt.
LPT2 Least Significant Priority Select Bit for Timer 2 Interrupt. LPT2 is the least significant bit of the
Bit 5 bit pair MPT2 (IP1.5), LPT2 that designates priority level for the Timer 2 interrupt.
LPS0 Least Significant Priority Select Bit for Serial Port 0 Interrupt. MPS0 is the least significant bit
Bit 4 of the bit pair MPS0 (IP1.4), LPS0 that designates priority level for the serial port 0 interrupt.
LPT1 Least Significant Priority Select Bit for Timer 1 Interrupt. MPT1 is the least significant bit of the
Bit 3 bit pair MPT1 (IP1.3), LPT1 that designates priority level for the Timer 1 interrupt.
LPX1 Least Significant Priority Select Bit for External Interrupt 1. MPX1 is the least significant bit of
Bit 2 the bit pair MPX1 (IP1.2), LPX1 that designates priority level for external interrupt 1.
LPT0 Least Significant Priority Select Bit for Timer 0 Interrupt. MPT0 is the least significant bit of the
Bit 1 bit pair MPT0 (IP1.1), LPT0 that designates priority level for the Timer 0 interrupt.
25 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Least Significant Priority Select Bit Levels
MP (IP1.X) LP (IP0.X) PRIORITY LEVEL
0 0 0 (natural priority)
0 1 1
1 0 2
1 1 3 (high priority)
SADEN0.7–0 Slave Address Mask Enable Register 0. This register functions as a mask when comparing
Bits 7–0 serial port 0 addresses for automatic address recognition. When a bit in this register is set, the cor-
responding bit location in the SADDR0 register is exactly compared with the incoming serial port 0
data to determine if a receiver interrupt should be generated. When a bit in this register is cleared,
the corresponding bit in the SADDR0 register becomes a “don’t care” and is not compared against
the incoming data. All incoming data generates a receiver interrupt when this register is cleared.
SADEN1.7–0 Slave Address Mask Enable Register 1. This register functions as a mask when comparing
Bits 7–0 serial port 1 addresses for automatic address recognition. When a bit in this register is set, the
corresponding bit location in the SADDR1 register is exactly compared with the incoming serial
port 1 data to determine if a receiver interrupt should be generated. When a bit in this register is
cleared, the corresponding bit in the SADDR1 register becomes a “don’t care” and is not compared
against the incoming data. All incoming data generates a receiver interrupt when this register is
cleared.
Serial Port 1 Control (SCON1)
7 6 5 4 3 2 1 0
SFR C0h SM0/FE_1 SM1_1 SM2_1 REN_1 TB8_1 RB8_1 TI_1 RI_1
RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
SM0–2 Serial Port 1 Mode. These bits control the mode of serial port 1 as shown in the following table.
Bits 7, 6, 5 In addition, the SM0 and SM2 bits have secondary functions as shown.
_____________________________________________________________________________________________ 26
Ultra-High-Speed Flash
Microcontroller User’s Guide
SM0/FE_1 Framing Error Flag. When SMOD0 (PCON.6) = 0, this bit is used as a mode select bit (SM0) for
Bit 7 serial port 1. When SMOD0 (PCON.6) = 1, this bit becomes a framing error (FE) bit, which reports
detection of an invalid stop bit. When used as FE, this bit must be cleared in software. Once the
SMOD0 bit is set, modifications to this bit does not affect the serial port mode settings. Although
accessed from the same register, the data for bits SM0 and FE are stored internally in different
physical locations.
SM1_1 No alternate function.
Bit 6
SM2_1 Multiple CPU Communications. The function of this bit is dependent on the serial port 1 mode.
Bit 5 Mode 0: Selects period for synchronous port 1 data transfers.
Mode 1: When this bit is set, reception is ignored (RI_1 is not set) if invalid stop bit received.
Modes 2/3: When this bit is set, multiprocessor communications are enabled in mode 2 and 3. This
prevents RI_1 from being set, and an interrupt being asserted, if the 9th bit received is not 1.
REN_1 Receive Enable. This bit enables/disables the serial port 1 receiver shift register.
Bit 4 0 = Serial port 1 reception disabled.
1 = Serial port 1 receiver enabled (modes 1, 2, 3). Initiate synchronous reception (mode 0).
TB8_1 9th Transmission Bit State. This bit defines the state of the 9th transmission bit in serial port 1
Bit 3 modes 2 and 3.
RB8_1 9th Received Bit State. This bit identifies the state for the 9th reception bit received data in serial
Bit 2 port 1 modes 2 and 3. In serial port mode 1, when SM2_1 = 0, RB8_1 is the state of the stop bit.
RB8_1 is not used in mode 0.
TI_1 Transmitter Interrupt Flag. This bit indicates that data in the serial port 1 buffer has been com-
Bit 1 pletely shifted out. In serial port mode 0, TI_1 is set at the end of the 8th data bit. In all other modes,
this bit is set at the end of the last data bit. This bit must be manually cleared by software.
RI_1 Transmitter Interrupt Flag. This bit indicates that a byte of data has been received in the serial
Bit 0 port 1 buffer. In serial port mode 1, RI_1 is set at the end of the 8th bit. In serial port mode 1, RI_1
is set after the last sample of the incoming stop bit subject to the state of SM2_1. In modes 2 and
3, RI_1 is set after the last sample of RB8_1. This bit must be manually cleared by software.
SBUF1.7–0 Serial Data Buffer 1. Data for serial port 1 is read from or written to this location. The serial
Bits 7–0 transmit and receive buffers are separate registers, but both are addressed at this location.
27 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
ROM Size Select (ROMSIZE)
7 6 5 4 3 2 1 0
SFR C2h — — — — PRAME RMS2 RMS1 RMS0
R-1 R-1 R-1 R-1 RT-0 RT-1 RT-0 RT-1
R = Unrestricted read, W = Unrestricted write, T = Timed-access write only, -n = Value after reset
LPX0 Least Significant Priority Select Bit for External Interrupt 0. MPX0 is the least significant bit of
Bit 0 the bit pair MPX0 (IP1.0), LPX0 that designates priority level for external interrupt 0.
Bits 7–3 These bits are reserved. Read data is 1.
PRAME Program RAM Enable. When set (= 1), the internal 1k RAM is mapped as internal program
Bit 3 space between addresses 0400h–07FFh. All program fetches and MOVC accesses are directed
to this 1k RAM. When serving as program memory, the RAM continues to be accessible as MOVX
data space (if DME0 = 1). The 1k RAM is not accessible as program space when EA = 0. When
clear (= 0), the internal 1k RAM is not accessible as program space.
RMS2–0 ROM Memory Size Select 2-0. This register is used to select the maximum on-chip decoded
Bits 2–0 address. Care must be taken that the memory location of the current program counter is valid
both before and after modification. These bits can only be modified using a timed-access procedure.
The EA pin overrides the function of these bits when asserted, forcing the device to access external
program memory only. Configuring this register to a setting that exceeds the maximum amount of
internal memory can corrupt device operation. These bits default on reset to the maximum amount
of internal program memory (i.e., 16k for DS89C420).
On-Chip ROM Address
.
RS2 RS1 RS0 MAXIMUM ON-CHIP ROM ADDRESS
0 0 0 0kB/Disable on-chip ROM
0 0 1 1kB/03FFh
0 1 0 2kB/07FFh
0 1 1 4kB/0FFFh
1 0 0 8kB/1FFFh
1 0 1 16kB/3FFFh (default)
1 1 0 32kB/7FFFh
1 1 1 64kB/FFFFh
CD1, CD0 Clock Divide Control 1-0. These bits select the number of crystal oscillator clocks required to
Bits 7, 6 generate one machine cycle. Switching between modes requires a transition through the default
divide-by-1 mode (CD1, CD0 = 10b). Attempts to perform an invalid transition are ignored. For
example, going from the crystal multiplier 2X mode to the divide-by-1024 mode would require first
switching from the 2X crystal multiplier mode to the divide-by-1 mode, followed by the switch from
the divide-by-1 to the divide-by-1024 mode. These bits cannot be modified when running from the
internal ring oscillator (RGMD = 1). The divide-by-1024 setting (CD1,CD0 = 11b) cannot be selected
when switchback is enabled (SWB = 1) and a switchback source (serial port or external interrupt)
is active.
CD1,
CLOCK FUNCTION
CD0
00 Crystal multiplier (4X or 2X mode as determined by PMR.3)
01 Reserved (forced into divide-by-1 mode if set)
10 Divide-by-1 (default state)
11 Divide-by-1024
The setting of these bits affects timer and serial port operation. Tables located in the SFR decription
for CKCON (8Eh) detail the respective operational dependencies on these bits.
_____________________________________________________________________________________________ 28
Ultra-High-Speed Flash
Microcontroller User’s Guide
Serial Port Operation (in Oscillator Clocks)
4X/2X CD1:0 CLOCK (MODE 0) CLOCK (MODE 2)
SM2 = 0 SM2 = 1 SMOD = 0 SMOD = 1
1 00 3 1 64 32
0 00 6 2 64 32
X 01 12 4 64 32
X 10 12 4 64 32
X 11 3072 1024 16384 8192
SWB Switchback Enable. This bit allows an enabled external interrupt or serial port activity to force the
Bit 5 clock divide control bits to the divide-by-1 state (01b). Upon acknowledgement of an external
interrupt source, the device switches modes in order to service the interrupt. Note that this means
that an external interrupt must actually be recognized (i.e., be enabled and not masked by higher
priority interrupts) for the switchback to occur. For serial port reception, the switch occurs at the
start of the instructions following the falling edge of the start bit.
CTM Crystal Multiplier Enable. This bit enables (= 1) or disables (= 0) the crystal multiplier function.
Bit 4 When set (= 1), the CKRY bit (EXIF.3) is cleared and the multiplier circuitry begins a stabilization
warm-up period to provide the clock multiplication factor specified by the 4X/2X bit (PMR.3). Upon
completion of the warm-up delay, the CKRY bit is set and the user can then modify CD1,CD0
(PMR.1, PMR.0) to select the crystal multiplier clock output. When clear (= 0), the crystal multipler
circuitry is disabled to conserve power. The CTM bit cannot be changed unless CD1,CD0 = 10b
and RGMD (EXIF.2) is cleared to 0. This bit is automatically cleared to 0 when the processor enters
stop mode.
4X/2X Clock Multiplier Selection. This bit selects the clock multiplication factor as shown. 4X/2X = 0
Bit 3 The frequency multiplier is set to two times the incoming clock by 4X/2X = 0. 4X/2X = 1 sets the
frequency multiplier to 4 times the incoming clock. This bit can only be altered when the crystal
multiplier enable bit (CTM) is cleared. Therefore, it must be set for the desired multiplication factor
prior to setting the CTM bit.
ALEON ALE Enable. When set (= 1), this bit enables the ALE signal output during on-chip program and
Bit 2 data memory accesses. When clear (= 0), the ALE signal output is disabled during on-chip program
and data memory accesses. External memory access automatically enables ALE independent of
the state of ALEON.
DME1, DME0 Data Memory Enable 1-0. These bits determine the functional relationship of the first 1024 bytes
Bits 1, 0 of data memory. Two memory configurations are supported to allow either external data memory
access through the expanded bus of port 0 and port 2, or internal SRAM data memory access.
Note these bits are cleared after a reset, so access to the internal SRAM is prohibited until these
bits are modified.
Data Memory Access
DATA MEMORY
DME1 DME0 ADDRESS MEMORY ACCESS
RANGE
0 0 0000h–FFFFh External Data Memory (default)
0000h–03FFh Internal SRAM Data Memory
X 1
0400h–FFFFh External Data Memory
1 0 Reserved Reserved
TA.7–0 Timed Access. Correctly accessing this register permits modification of timed access protected
Bits 7–0 bits. Write AAh to this register first, followed within 3 cycles by writing 55h. Timed access protected
bits can then be modified for a period of 3 cycles measured from the writing of the 55h
TF2 Timer 2 Overflow Flag. This flag is set when Timer 2 overflows from FFFFh or the count equal
Bit 7 to the capture register in down count mode. It must be cleared by software. TF2 is only set if RCLK
and TCLK are both cleared to 0.
EXF2 Timer 2 External Flag. A negative transition on the T2EX pin (P1.1) or timer 2 underflow/overflow
Bit 6 causes this flag to set based on the CP/RL2 (T2CON.0), EXEN2 (T2CON.3), and DCEN
(T2MOD.0) bits (see the following table). If set by a negative transition, this flag must be cleared to
0 by software. Setting this bit in software or detection of a negative transition on the T2EX pin forces
a timer interrupt if enabled.
_____________________________________________________________________________________________ 30
Ultra-High-Speed Flash
Microcontroller User’s Guide
RCLK Receive Clock Flag. This bit determines the serial port 0 time base when receiving data in serial
Bit 5 modes 1 or 3. Setting this bit forces Timer 2 into baud-rate generation mode. The timer operates
from a divide-by-2 of the external clock.
0 = Timer 1 overflow is used to determine receiver baud rate for serial port 0.
1 = Timer 2 overflow is used to determine receiver baud rate for serial port 0.
TCLK Transmit Clock Flag. This bit determines the serial port 0 time base when transmitting data in
Bit 4 serial modes 1 or 3. Setting this bit forces Timer 2 into baud rate generation mode. The timer operates
from a divide-by-2 of the external clock.
0 = Timer 1 overflow is used to determine transmitter baud rate for serial port 0.
1 = Timer 2 overflow is used to determine transmitter baud rate for serial port 0.
EXEN2 Timer 2 External Enable. This bit enables the capture/reload function on the T2EX pin if Timer 2
Bit 3 is not generating baud rates for the serial port.
0 = Timer 2 ignores all external events at T2EX.
1 = Timer 2 captures or reload a value if a negative transition is detected on the T2EX pin.
TR2 Timer 2 Run Control. This bit enables/disables the operation of Timer 2. Halting this timer preserves
Bit 2 the current count in TH2, TL2.
0 = Timer 2 is halted.
1 = Timer 2 is enabled.
C/T2 Counter/Timer Select. This bit determines whether Timer 2 functions as a timer or counter.
Bit 1 Independent of this bit, Timer 2 runs at 2 clocks per tick when used in either baud-rate generator
or clock-output mode.
0 = Timer 2 function as a timer.
1 = Timer 2 counts negative transitions on the T2 pin (P1.0).
CP/RL2 Capture/Reload Select. This bit determines whether the capture or reload function is used for
Bit 0 Timer 2. When set (= 1), Timer 2 captures occur when a falling edge is detected on T2EX(P1.1)
if EXEN2 = 1. When clear (= 0), Timer 2 functions in an autoreload mode. An autoreload occurs
following each overflow if RCLK or TCLK is set or if a falling edge is detected on T2EX if EXEN2 = 1.
0 = Autoreloads occur when Timer 2 overflows or a falling edge is detected on T2EX if EXEN2 = 1.
1 = Timer 2 captures occur when a falling edge is detected on T2EX if EXEN2 = 1.
31 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
T2MOD 7–2
Bits 7–2 Reserved. Read data is 1.
T2OE Timer 2 Output Enable. This bit enables/disables the clock output function of the T2 pin (P1.0).
Bit 1 When set (= 1), Timer 2 drives the T2 pin with a clock output if C/(T2CON.1) = 0. For this setting,
Timer 2 rollovers do not cause interrupts. When clear (= 0), the T2 pin functions as either a standard
port pin or as a counter input for Timer 2.
DCEN Down Count Enable. This bit, in conjunction with the T2EX (P1.1) pin, controls the direction that
Bit 0 Timer 2 counts in 16-bit autoreload mode.
RCAP2L.7–0 Timer 2 Capture LSB. This register is used to capture the TL2 value when Timer 2 is configured
Bits 7–0 in capture mode. RCAP2L is also used as the LSB of a 16-bit reload value when Timer 2 is configured
in autoreload mode.
Timer 2 Capture LSB (RCAP2H)
7 6 5 4 3 2 1 0
SFR CBh RCAP2H.7 RCAP2H.6 RCAP2H.5 RCAP2H.4 RCAP2H.3 RCAP2H.2 RCAP2H.1 RCAP2H.0
RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
RCAP2H.7–0 Timer 2 Capture MSB. This register is used to capture the TH2 value when Timer 2 is configured
Bits 7–0 in capture mode. RCAP2H is also used as the MSB of a 16-bit reload value when Timer 2 is con-
figured in autoreload mode.
TL2.7–0 Timer 2 LSB. This register contains the least significant byte of Timer 2.
Bits 7–0
TH2.7–0 Timer 2 MSB. This register contains the most significant byte of Timer 2.
Bits 7–0
_____________________________________________________________________________________________ 32
Ultra-High-Speed Flash
Microcontroller User’s Guide
OV Overflow Flag. This bit is set to 1 if the last arithmetic operation resulted in a carry (addition),
Bit 2 borrow (subtraction), or overflow (multiplication or division). Otherwise it is cleared to 0 by all arith-
metic operations.
F1 User Flag 1. This is a bit-addressable, general-purpose flag for software control.
Bit 1
PARITY Parity Flag. This bit is set to 1 if the module-2 sum of the 8 bits of the accumulator is 1 (odd parity),
Bit 0 and cleared to 0 on even parity.
FBUSY Flash Busy. This status bit held low (= 0) to indicate that an erase/program operation is in
Bit 7 progress by the MMU. Upon completion of the operation or in the event that an error occurs, this
bit returned to a logic high (= 1).
FERR Flash Error. This status bit will be set (= 1) if an error occurs during any flash program/erase
Bit 6 operation or if an invalid flash command is written to FC3-0. The bit can be cleared only by writing
the flash command bits (FC3-0) to 0000b.
Bits 5-4 Reserved. Read data is 1.
FC3-0 Flash Command Bits 3-0. These command bits provide an interface for executing flash
Bits 3-0 operations. See the Flash Command Bit Operations Table for the list of flash commands rec-
ognized during in-application programming. Note that these bits must always be in the 0000b
(read mode) state to allow program execution from the upper memory bank (2000h – 3FFFh).
33 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 34
Ultra-High-Speed Flash
Microcontroller User’s Guide
FDATA.7–0 Flash Memory Data. This register is used by the ROM loader or user software to support the flash
Bits 7–0 memory program/erase operations. Writes to this register are only permitted when a valid flash
command has been loaded into the flash command bits FC3-0 (FCNTL.3-0).
Watchdog Control (WDCON)
7 6 5 4 3 2 1 0
SFR D8h SMOD_1 POR EPFI PFI WDIF WTRF EWT RWT
RW-0 RT-* RW-0 RW-* RT-0 RW-* RT-* RT-0
R = Unrestricted read, W = Unrestricted write, T = Timed-access write only, -n = Value after reset, * = see description
SMOD_1 Serial Modification. This bit controls the doubling of the serial port 1 baud rate in modes 1, 2, and 3.
Bit 7 0 = Serial port 1 baud rate operates at normal speed.
1 = Serial port 1 baud rate is doubled.
POR Power-on Reset Flag. This bit indicates whether the last reset was a power-on reset. This bit is
Bit 6 typically interrogated following a reset to determine if the reset was caused by a power-on reset. It
must be cleared by a timed access write before the next reset of any kind or user software may
erroneously determine that another power-on reset has occurred. This bit is set following a power-
on reset and unaffected by all other resets. This bit automatically cleared when the ROM loader is
invoked.
0 = Last reset was from a source other than a power-on reset.
1 = Last reset was a power-on reset.
EPFI Enable Power-Fail Interrupt. This bit enables/disables the ability of the internal bandgap
Bit 5 reference to generate a power-fail interrupt when VCC falls below approximately 4.5V. While in stop
mode, both this bit and the bandgap Select bit, BGS (EXIF.0), must be set to enable the power-fail
interrupt.
0 = Power-fail interrupt disabled.
1 = Power-fail interrupt enabled during normal operation. Power-fail interrupt enabled in stop mode
if BGS is set.
PFI Power-Fail Interrupt Flag. When set, this bit indicates that a power-fail interrupt has occurred. This
Bit 4 bit must be cleared in software before exiting the interrupt service routine, or another interrupt is
generated. Setting this bit in software generate a power-fail interrupt, if enabled. This bit is auto-
matically cleared when the ROM loader is invoked..
WDIF Watchdog Interrupt Flag. This bit indicates if a watchdog timer event has occurred. The timeout
Bit 3 period of the watchdog timer is controlled by the Watchdog Timer Mode Select bits (CKCON.7-6).
The Watchdog Timer Interrupt Enable bit, EWDI (EIE.4), and Enable Watchdog Timer Reset bit,
EWT (WDCON.1), determine what action is taken. This bit must be cleared in software before
exiting the interrupt service routine, or another interrupt is generated. Setting this bit in software
generates a watchdog interrupt if enabled. This bit can only be modified using a Timed Access
Procedure.
WTRF Watchdog Timer Reset Flag. When set, this bit indicates that a watchdog timer reset has
Bit 2 occurred. It is typically interrogated to determine if a reset was caused by watchdog timer reset. It
is cleared by a power-on reset but otherwise must be cleared by software before the next reset
of any kind or software can erroneously determine that a watchdog timer reset has occurred.
Setting this bit in software does not generate a watchdog timer reset. If the EWT bit is cleared, the
watchdog timer has no effect on this bit. This bit is automatically cleared when the ROM loader is
invoked.
35 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
EWT Enable Watchdog Timer Reset. This bit enables/disables the generation of a watchdog timer
Bit 1 reset 512 system clocks after the occurrence of a watchdog timeout. This bit can only be modi-
fied using a Timed Access Procedure and is unaffected by all other resets. The default power-on
reset state of EWT is determined by Option Control Register bit 3 (OCR.3) located in flash memo
ry. This bit will automatically be cleared when the ROM loader is invoked.
0 = A watchdog reset is not generated after a watchdog timeout
1 = A watchdog reset is generated 512 system clocks after a watchdog timeout unless RWT is
strobed or EWT is cleared.
RWT Reset Watchdog Timer. Setting this bit resets the watchdog timer count. This bit must be set
Bit 0 using a Timed Access procedure before the watchdog timer expires, or a watchdog timer reset
and/or interrupt is generated if enabled. The timeout period is defined by the Watchdog Timer
Mode Select bits (CKCON.7-6). This bit is always be 0 when read.
Accumulator (A or ACC)
7 6 5 4 3 2 1 0
SFR E0h ACC.7 ACC.6 ACC.5 ACC.4 ACC.3 ACC.2 ACC.1 ACC.0
RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
ACC.7–0 Accumulator. This register serves as the accumulator for arithmetic operations.
Bits 7–0
_____________________________________________________________________________________________ 36
Ultra-High-Speed Flash
Microcontroller User’s Guide
B Register (B)
7 6 5 4 3 2 1 0
SFR F0h B.7 B.6 B.5 B.4 B.3 B.2 B.1 B.0
RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
B.7–0 B Register. This register serves as a second accumulator for certain arithmetic operations.
Bits 7–0
Extended Interrupt Priority 1 (EIP1)
7 6 5 4 3 2 1 0
SFR F1h — — — MPWDI MPX5 MPX4 MPX3 MPX2
R-1 R-1 R-1 RW-0 RW-0 RW-0 RW-0 RW-0
R = Unrestricted read, W = Unrestricted write, -n = Value after reset
37 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
LPWDI Least significant priority select bit for watchdog interrupt. This is the least significant bit of the
Bit 4 bit pair MPWDI (EIP1.4), LPWDI that designates priority level for the watchdog interrupt.
LPX5 Least significant priority select bit for external interrupt 5. This is the least significant bit of the
Bit 3 bit pair MPX5 (EIP1.3), LPX5 that designates priority level for external interrupt 5.
LPX4 Least significant priority select bit for external interrupt 4. This is the least significant bit of the
Bit 2 bit pair MPX4 (EIP1.2), LPX4 that designates priority level for external interrupt 4.
LPX3 Least significant priority select bit for external interrupt 3. This is the least significant bit of the
Bit 1 bit pair MPX3 (EIP1.1), LPX3 that designates priority level for external interrupt 3.
LPX2 Least significant priority select bit for external interrupt 2. This is the least significant bit of the
Bit 0 bit pair MPX2 (EIP1.0), LPX2 that designates priority level for external interrupt 2.
_____________________________________________________________________________________________ 38
Ultra-High-Speed Flash
Microcontroller User’s Guide
ULTRA-HIGH-SPEED ULTRA-HIGH-SPEED
MICROCONTROLLER MICROCONTROLLER
XTAL1 TO INTERNAL CLOCK XTAL1 TO INTERNAL
CIRCUITS OSCILLATOR CIRCUITS
00
01, 10
SYSTEM
DIVIDE 1024 11 CLOCK
RING
OSCILLATOR
RING
ENABLE
CD0 SELECTOR
CD1
Figure 5-3. System Clock Sources
39 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
INSTRUCTION TIMING
The ultra-high-speed microcontroller executes the industry standard 8051 instruction set. Each instruction requires a minimum of one
memory cycle of execution time, and may require as many as ten memory cycles (DIV AB only). The number of memory cycles required
to execute any given 8051 instruction is documented at the end of this section and can be found in Section 14 (Instruction Set Details).
A memory cycle is the basic timing unit for the ultra-high-speed microcontroller. If internal program code is being executed, a memo-
ry cycle always consists of one system clock. If external program code is being executed, a memory cycle is then composed of 1, 2,
or 4 system clocks, as defined by the external bus configuration (non page mode, page mode 1, or page mode 2).
Calculating the number of external crystal or oscillator clock periods (tCLCL) per memory cycle additionally depends upon how the
user has configured the system clock as a function of the external clock. The system clock control function was covered earlier in the
section. As an example, if the crystal multiplier is used to generate a system clock frequency four times the frequency of the external
clock source, a nonpaged mode external memory cycle would consist of one external clock.
All instructions are coded within an 8-bit field called an op code. This single byte must be fetched from program memory. The CPU
decodes the op code to determine what action the microcontroller must take or whether additional information is needed from memo-
ry. If no other memory is needed, then only 1 byte was required. Thus, the instruction is called a 1-byte instruction. In some cases,
more data is needed. These are 2- or 3-byte instructions.
SINGLE-BYTE INSTRUCTIONS
A single-byte instruction can require anywhere between one and ten memory cycles to execute. When the execution cycle count
exceeds the byte count, the program counter must stall until instruction execution is completed. All MOVX data memory access instruc-
tions have a single-byte op code, but require more memory cycles so that data may be accessed. The MOVX instruction timing is cov-
ered in Section 6 (Memory Access). Following are examples of single byte instructions, each requiring a different number of execution
cycles:
OPCODE NO. OF CYCLES
RRC A 13h 1
DA A D4h 2
RET 22h 3
MUL AB A4h 9
DIV AB 84h 10
2-BYTE INSTRUCTIONS
All 2-byte instructions require a minimum of two cycles, since fetching each byte requires a separate memory access. The first byte is
the instruction op code that is decoded by the CPU. The second byte is normally an operand, or it can specify the location of the
operand. For example, “ADD A, direct” is a 2-byte, two cycle instruction where the second byte specifies the direct address location
of the operand. Due to internal access restrictions, certain direct addressing instructions require one extra memory cycle when oper-
ating on the PSW, SP, DPS, IE, EIE, IP0, IP1, EIP0, or EIP1 register. Following are examples of these and other 2-byte instructions:
OPCODE OPERAND/LOCATION NO. OF CYCLES
ADD A, direct 25h <addr7-0> 2
ADD A, #data 24h <data7-0> 2
SJMP rel 80h <addr7-0> 3
_____________________________________________________________________________________________ 40
Ultra-High-Speed Flash
Microcontroller User’s Guide
ANL direct, A 52h <addr7-0> 2 or 3
ORL direct, A 42h <addr7-0> 2 or 3
DJNZ Rn, direct D8h-DFh <addr7-0> 4
3-BYTE INSTRUCTIONS
Three-byte instructions require a minimum of three cycles since each byte fetch requires one memory cycle. The first byte, the opcode,
instructs the CPU on how to handle the next two bytes. Most 3-byte instructions involve comparison or branching, but not all. Just like
the 2-byte instructions, certain 3-byte instructions may require 1 extra memory cycle when operating on the PSW, SP, DPS, IE, EIE, IP0,
IP1, EIP0, or EIP1 register. Following are examples of 3-byte instructions.
OPCODE OPERAND(s)/LOCATION(s) NO. Of CYCLES
LJMP addr16 02h <addr15-8><addr7-0> 3
MOV dptr, #data16 90h <data15-8><data7-0> 3
MOV direct, direct 85h <addr7-0><addr7-0> 3 or 4
JBC bit, rel 10h <addr7-0><addr7-0> 4 or 5
DJNZ direct, rel D5h <addr7-0><addr7-0> 5
SYSCLK
ALE
PSEN
DA A RRC A
SYSCLK
ALE
PSEN
41 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
ACALL NOP
SYSCLK
ALE
PSEN
RET NOP
_____________________________________________________________________________________________ 42
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
MISS STALL HIT HIT
PORT 0 D4 13 13
DA A RRC A
SYSCLK
ALE
PSEN STALL
HIT MISS HIT HIT
PORT 2 LSB ADDRESS MSB ADDRESS LSB ADDRESS LSB ADDRESS LSB ADDRESS
PORT 0 D4 13 13
DA A RRC A
43 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
FOUR-CYCLE PAGE MODE 1: INC DIRECT (TWO CYCLES) – INC DIRECT (THREE CYCLES)
SYSCLK
ALE
PSEN
HIT HIT HIT STALL HIT
PORT 0 05 82 05 86 E0 E0
SYSCLK
ALE
PSEN
HIT HIT MISS HIT
PORT 2 LSB ADDRESS LSB ADDRESS MSB ADDRESS LSB ADDRESS LSB ADDRESS
PORT 0 71 33
ACALL
_____________________________________________________________________________________________ 44
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
HIT STALL STALL HIT HIT
PORT 0 22
RET
SYSCLK
ALE
PSEN
HIT STALL STALL MISS
PORT 2 LSB ADDRESS LSB ADDRESS MSB ADDRESS LSB ADDRESS
PORT 0 22
ACALL
45 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
MISS HIT HIT STALL STALL HIT HIT
PORT 0 C3 13 C6
SYSCLK
ALE
PSEN
MISS HIT HIT MISS HIT HIT
PORT 0 02 50 00
LJMP ADDR16
_____________________________________________________________________________________________ 46
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
MISS HIT HIT STALLS HIT STALL HIT HIT
PORT 0 C3 13 A4 D4 00
ONE-CYCLE PAGE MODE 1: (PAGE MISS) – ORL DIRECT, A (TWO CYCLES) – ORL DIRECT, A (THREE CYCLES) – NOP
SYSCLK
ALE
PSEN
MISS HIT HIT HIT HIT STALL HIT HIT HIT HIT HIT HIT HIT HIT HIT
PORT 2 LSB
PORT 0 45 90 45 A8 00
47 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
1-CYCLE PAGE MODE 1: (PAGE MISS) – JBC bit, rel (4 CYCLES) – RET – (PAGE MISS) – MOV direct, data
SYSCLK
ALE
PSEN
MISS HIT HIT stall HIT stall stall MISS HIT HIT HIT HIT HIT HIT
10 D1 1D 22 75 90 55
PORT0
1-CYCLE PAGE MODE 1: (PAGE MISS) – JBC bit, rel (5 CYCLES) – (PAGE MISS) -- RET – MOV direct, data
SYSCLK
ALE
PSEN
MISS HIT HIT stall stall MISS stall stall HIT HIT HIT HIT HIT HIT
PORT2 LSB
10 D1 1D 22 75 90 55
PORT0
_____________________________________________________________________________________________ 48
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
MISS HIT HIT stall stall HIT HIT
PORT2 MSB C3 13 C6
SYSCLK
ALE
PSEN
MISS HIT HIT MISS HIT HIT
LJMP addr16
49 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Table 5-1 shows each instruction, the number of clocks used in the ultra-high-speed microcontroller, and the number used in the 8051 for
comparison. The factor by which the ultra-high-speed microcontroller improves on the 8051 is shown as the speed advantage. A speed
advantage of 12 means that the ultra-high-speed microcontroller performs the same instruction 12 times faster than the original 8051.
Table 5-2 provides a summary by instruction type. Note that many of the instructions provide multiple op codes. As an example, the
ADD A, Rn instruction can act on one of eight working registers. There are eight op codes for this instruction because it can be used
on eight independent locations. Table 5-2 shows totals for both number of instructions and number of op codes. Averages are provid-
ed in the tables. However, the real speed improvement seen in any system depends on the instruction mix.
_____________________________________________________________________________________________ 50
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 52
Ultra-High-Speed Flash
Microcontroller User’s Guide
53 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Program and data memory areas can be implemented on-chip, off-chip, or as a combination. When opting not to use the internal mem-
ory provided, or when exceeding the maximum address of on-chip program or data memory, the device performs an external mem-
ory access using the expanded memory bus on ports 0 and 2. While serving as a memory bus, port 0 and port 2 cannot function as
I/O ports. The PSEN signal is driven active low to function as a chip enable or output enable when performing external code memory
fetches. The RD and WR signals serve as enables when accessing external SRAM data memory.
Program execution always begins at the reset vector, address 0000h. If on-chip program memory is enabled, program execution
begins at internal location 0000h; otherwise, external program memory is used. Any reset causes the next program fetch to begin at
this location. Subsequent branches and interrupts determine how program memory fetches deviate from sequential addressing.
INTERNAL FLASH MEMORY
The DS89C420 ultra-high-speed microcontroller contains five physically distinct blocks of embedded flash memory. The two largest
blocks, each 8kB, provide a total of 16kB for use as internal program memory. A 64-byte flash security block has been incorporated
to allow encryption during program memory verify operations. To further protect internal code against undesirable access, a three-level
lock system has been implemented in a separate flash memory block. This single-byte block contains three lock bits (LB1, LB2, LB3),
each of which can individually enable higher lock levels and greater code protection. The fifth flash memory block resident to the
DS89C420 is the option control register. This byte contains a bit to enable or disable the watchdog timer reset function (EWT =
WDCON.1) on a power-on reset.
The two 8kB program memory blocks form a contiguous 16kB address range extending from 0000h through 3FFFh. The on-chip
decoded address range is controlled in hardware by the EA pin, and in software through the ROMSIZE feature. The EA pin enables or
disables the ability to access internal program memory and overrides any software configured bit settings. The logic state of the EA
pin should be changed only when the microcontroller is being held in reset. The EA pin is sampled on each exit from the reset state to
determine whether program fetching should begin internally or externally. When the EA pin is low, all code fetches are done external-
ly through the expanded bus. When the EA pin is high, code fetches begin from internal program memory. Code fetches exceeding
the maximum address of on-chip program memory cause the device to access off-chip program memory. The maximum on-chip
decoded address is selectable by software using the ROMSIZE feature.
ROMSIZE FEATURE
Using the ROMSIZE feature, software can allow the DS89C420 to behave like a device with less on-chip memory. The maximum mem-
ory size is dynamically variable. Thus, a portion of memory can be removed from the memory map to access off-chip memory, then
restored to access on-chip memory. In fact, all of the on-chip memory can be removed from the memory map, allowing the full 64kB
of external memory space to be addressed.
The ROMSIZE feature has two primary uses. In the first instance, it allows the device to act as a bootstrap loader for a flash memory
or nonvolatile SRAM (NVSRAM). The internal program memory can contain a bootstrap loader, which can program the external mem-
ory device. Secondly, this method can be used to increase the amount of available program memory from 64kB to 80kB without bank
switching.
The maximum amount of on-chip memory is selected by configuring the ROM size select register bits RMS2, RMS1, RMS0 (ROM-
SIZE.2-0). The reset default condition gives access to the maximum on-chip program memory of 16kB. In this configuration, only code
addresses greater than 16kB result in external program memory accesses. The possible settings for the ROM size select register are
shown in the following table.
Table 6-1. ROMSIZE REGISTER SETTINGS
RMS2 RMS1 RMS0 MAX ON-CHIP PROGRAM MEMORY
0 0 0 0kB
0 0 1 1kB (0-03FFh)
0 1 0 2kB (0-07FFh)
0 1 1 4kB (0-0FFFh)
1 0 0 8kB (0-1FFFh)
1 0 1 16kB (0-3FFFh) DEFAULT
1 1 0 INVALID – RESERVED
1 1 1 INVALID – RESERVED
Modification of the ROMSIZE (C2h) special function register requires using the timed access procedure and must be followed by a two
machine cycle delay, such as executing two NOP instructions, before jumping to the new address range. Interrupts must be disabled
during this operation, because a call to an interrupt vector during the changing of the memory map can cause erratic results. To select
_____________________________________________________________________________________________ 54
Ultra-High-Speed Flash
Microcontroller User’s Guide
a different internal program memory size, software must alter bits RMS2–RMS0. The procedure to reconfigure the size of on-chip mem-
ory should be done as follows:
1) Jump to a location in program memory that is unaffected by the change.
2) Disable interrupts by clearing the EA bit (IE.7).
3) Write AAh to the timed access register (TA;C7h).
4) Write 55h to the timed access register (TA;C7h).
5) Modify the ROM size select bits (RMS2-RMS0).
6) Delay 2 machine cycles (2 NOP instructions).
7) Enable interrupts by setting the EA bit (IE.7).
As noted in the first step above, ensure that changes the ROMSIZE register do not corrupt program execution. For example, assume
that a DS89C420 is executing instructions from internal program memory near the 12kB boundary (~3000h) and the ROMSIZE regis-
ter is still configured to the default 16kB internal program space. If software reconfigures the ROMSIZE register for a maximum of 4kB
(0000h–0FFFh) internal program space (RMS2–0 = 011b), the device immediately accesses external program memory since current
program execution no longer resides within the new on-chip decoded range. This could result in code misalignment and execution of
an invalid instruction. The recommended method is to modify the ROMSIZE register from a location in memory that is internal (or exter-
nal) both before and after the operation. In the above example, the instruction which modifies the ROMSIZE register should be locat-
ed below the 4kB (1000h) boundary or above the 16kB boundary, so that it is unaffected by the memory modification. The same rule
applies when executing from external program memory and increasing the on-chip decoded address range.
If the 0kB of internal program memory setting is selected, take extra precautions. In this case, it is necessary to duplicate the interrupt
vector table in external program memory. This is because the interrupt vector table is located in the lower 1kB of memory, and the
device automatically redirects any fetches from the interrupt vector table to external memory. Be careful when assembling or compil-
ing the program so that all the modules are located at the correct starting address, including the interrupt vector table.
The read/write accessibility of the flash memory during in-application programming is not affected by the state of the lock bits. However,
the lock bits do affect the read/write accessibility in program memory loader and parallel programming modes.
55 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
the watchdog reset function automatically. Other bits of this register are undefined and are at logic 1 when read. The value of this reg-
ister can be read at address FCh in parallel programming mode or by executing the verify option control register instruction in ROM
Loader or in-application programming mode.
FFFF FFFF
INTERNAL
MEMORY
03FF
1kB x 8
SRAM External External
Program Data
INTERNAL SCRATCH Data OR Memory Memory
REGISTERS PAD prog mem
addr from
128 Bytes SFR 0000
400–7FF
4000
FF 3FFF
8kB x 8
128 Bytes Flash
Indirect Memory
Addressing (Program)
2000
80
7F
1FFF
2F
20 Bit Addressable 8kB x 8
1F Flash
Bank 3
Memory 03FF
Bank 2 Non-usable if
(Program)
Bank 1 Internal SRAM
Bank 0 is activated
00 0000 0000 0000
_____________________________________________________________________________________________ 56
Ultra-High-Speed Flash
Microcontroller User’s Guide
PSEN OE
ALE CK
LSB ADDRESS (8)
74F373
PORT 0 LATCH 32kB X 8
MEMORY
When configured as program memory, code fetches and MOVC read operations can be directed to this 1kB internal SRAM. To enable
the 1kB SRAM as internal program memory, software must set the PRAME bit (ROMSIZE.3). After setting this bit, code accesses to the
address range 0400h–07FFh are made to the internal 1kB SRAM in place of the program memory previously mapped to that address
range. For applications using only external program memory (EA = 0), the internal 1kB SRAM cannot be enabled as program space.
The internal 1kB SRAM can serve as merged program/data memory if both the DME0 and PRAME bits have been set. This feature can
be effective for changing small pieces of frequently executed code, but be cautious when employing self-modifying code techniques.
57 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
ALE
PSEN
LSB Add Data LSB Add Data
Port 0
Figure 6-3. External Program Memory Access (Nonpage Mode and CD1:0 = 10b)
As illustrated in that same figure, ALE is deasserted when executing an internal memory fetch. The DS89C420 provides a program-
mable user option (ALEON bit = PMR.2) to turn on the ALE signal during internal program memory operation. The ALE signal is
automatically enabled for external code fetches, independent of the setting of this bit. PSEN is asserted only for external code fetch-
es, and is inactive during internal execution.
_____________________________________________________________________________________________ 58
Ultra-High-Speed Flash
Microcontroller User’s Guide
PSEN OE
ALE CK
MSB ADDRESS (7)
74F373
LATCH
PORT 2 32kB X 8
MEMORY
LSB ADDRESS (8)
DS80C320
CE
During external code fetches, P0 is held in a high-impedance state by the processor. Opcodes are driven by the external memory onto
P0 and latched on the rising edge of PSEN at the end of the external fetch cycle.
• A page miss occurs when the most significant byte of the subsequent address is different from the last address. The exter
nal memory machine cycle can be 2, 4, or 8 system clocks in length for a page miss.
• A page hit occurs when the most significant byte of the subsequent address does not change from the last address. The exter-
nal memory machine cycle can be 1, 2, or 4 system clocks in length for a page hit.
During a page hit, P2 drives Addr [7:0] of the 16-bit address while the most significant address byte is held in the external address latch-
es. PSEN, RD, and RD strobe accordingly for the appropriate operation on the P0 data bus. There is no ALE assertion for page hits.
59 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
During a page miss, P2 drives the Addr [15:8] of the 16-bit address and holds it for the duration of the first half of the memory cycle
to allow the external address latches to latch the new most significant address byte. ALE is asserted to strobe the external address
latches. During this operation, PSEN, RD, and WR are all held in inactive states and P0 is in a high-impedance state. The following half-
memory cycle is executed as a page-hit cycle and the appropriate operation takes place.
A page-miss can occur at set intervals or during external operations that require a memory access into a page of memory that has not
been accessed during the last external cycle. Generally, the first external memory access causes a page miss. The new page address
is stored internally and is used to detect a page miss for the current external memory cycle.
Note that there are a few exceptions for this mode of operation when PAGES1 and PAGES2 are set to 00b:
• PSEN is asserted for both page hit and page miss for a full clock cycle.
• The execution of external MOVX instruction causes a page miss.
• A page miss occurs when fetching the next external instruction following the execution of an external MOVX instruction.
The figure below shows external memory cycles for the page mode 1 bus structure. The first case illustrates a back-to-back MOVX
execution sequence for one-cycle page mode (PAGES 1:0 = 00b). PSEN remains active during page-hit cycles, and page misses are
forced during and after MOVX executions, independent of the most significant byte of the subsequent addresses. The second case
illustrates a MOVX execution sequence for two-cycle page mode (PAGES 1:0 = 01b). PSEN is active for a full clock cycle in code fetch-
es. Note that the page misses in this sequence are caused by changing of the most significant byte of the data address. The third case
illustrates a MOVX execution sequence for four-cycle page mode (PAGES 1:0 = 10b). There is no page-miss in this execution cycle,
as the most significant byte of the data address is assumed to match the last program address.
XTAL1
ALE
PSEN
RD / WR
PAGES=00
Port 0 Inst Inst MOVX MOVX Data Inst Data
Port 2 MSB LSB LSB LSB LSB MSB LSB MSB LSB MSB LSB MSB
Page Miss Page Hit Data Access Page Miss Data Access
ALE
PSEN
RD / WR PAGES=01
Port 2 MSBAdd LSB Add LSB Add MSBAdd LSB Add MSBAdd
ALE
PSEN
RD / WR
PAGES=10
_____________________________________________________________________________________________ 60
Ultra-High-Speed Flash
Microcontroller User’s Guide
PSEN OE
ALE CK
MSB ADDRESS (7)
74F373
PORT 2 LATCH
32kB X 8
MEMORY
DS80C320 DATA BUS (8)
CE
ALE
PSEN
Figure 6-7. Page Mode 2 External Code Fetch Cycle (CD1:0 = 10B)
61 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
using the MOVX instruction. Any use of this instruction automatically accesses the data area. Although the original 8051 convention
placed all data memory off-chip, the DS89C420 incorporates 1kB of on-chip data memory. The means for enabling and accessing this
1kB SRAM was covered earlier in this section.
From a software standpoint, the physical location of the data area is not relevant because the same instructions are used. Like the pro-
gram segment, if software accesses a data address that is above the on-chip data area, this access is automatically routed to the
expanded bus. Thus, data or peripherals that are off-chip can be used in conjunction with on-chip memory by selecting addresses
that do not overlap. For example, since the DS89C420 microcontroller has 1kB of on-chip data memory, an MOVX instruction at loca-
tion 0400h is directed off-chip through the expanded bus.
The DS89C420 external data memory interface follows the same bus structure as defined for program memory. The page mode enable
(PAGEE) and page mode select (PAGES 1:0) bits control whether the external bus structure follows the nonpage mode, page mode 1,
or page mode 2 scheme. During external data read/write operations, P0 or P2 (depending upon external memory mode) serves as the
bidirectional data bus. This port is held in a high-impedance state for external reads from data memory, and driven with data during
external writes to data memory. The read and write strobes used to access external data memory are provided on P3.7 and P3.6,
respectively.
_____________________________________________________________________________________________ 62
Ultra-High-Speed Flash
Microcontroller User’s Guide
ALE CK
LSB ADDRESS (8)
74F373
PORT 0 LATCH
64kB X 8
SRAM
DS80C320 DATA BUS (8)
CE
Table 6-6. Page Mode 1—Data Memory Stretch Values 1 Cycle (PAGES 1:0 = 00b)
RD/WR PULSE WIDTH (IN NUMBER OF OSCILLATOR CLOCKS)
MD2:MD0 STRETCH
(STRETCH VALUE) CYCLES 4X/2X, CD1, CD0 = 100 4X/2X, CD1, CD0 = 000 4X/2X, CD1, CD0 = X10 4X/2X, CD1, CD0 = X11
63 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Table 6-7. Page Mode 1—Data Memory Stretch Values Two Cycles (PAGES 1:0 = 01b)
RD/WR PULSE WIDTH (IN NUMBER OF OSCILLATOR CLOCKS)
MD2:MD0 STRETCH
(STRETCH VALUE) CYCLES 4X/2X, CD1, CD0 = 100 4X/2X, CD1, CD0 = 000 4X/2X, CD1, CD0 = X10 4X/2X, CD1, CD0 = X11
Table 6-8. Page Mode 1—Data Memory Stretch Values Four Cycles (PAGES 1:0 = 10b)
RD/WR PULSE WIDTH (IN NUMBER OF OSCILLATOR CLOCKS)
MD2:MD0 STRETCH
(STRETCH VALUE) CYCLES 4X/2X, CD1, CD0 = 100 4X/2X, CD1, CD0 = 000 4X/2X, CD1, CD0 = X10 4X/2X, CD1, CD0 = X11
Table 6-9. Page Mode 2—Data Memory Stretch Values (PAGES 1:0 = 11b)
RD/WR PULSE WIDTH (IN NUMBER OF OSCILLATOR CLOCKS)
MD2:MD0 STRETCH
(STRETCH VALUE) CYCLES 4X/2X, CD1, CD0 = 100 4X/2X, CD1, CD0 = 000 4X/2X, CD1, CD0 = X10 4X/2X, CD1, CD0 = X11
_____________________________________________________________________________________________ 64
Ultra-High-Speed Flash
Microcontroller User’s Guide
Figures 6-9 and 6-10 below show data memory interconnect examples for page mode 1 and page mode 2.
ALE CK
MSB ADDRESS (8)
74F373
PORT 2 LATCH
64kB X 8
SRAM
DS80C320 LSB ADDRESS (8)
CE
RD (P3.7) OE
WR (P3.6) WE
ALE CK
MSB ADDRESS (8)
74F373
PORT 2 LATCH 64kB X 8
SRAM
RD (P3.7) OE
WR (P3.6) WE
The following pages provide timing diagrams to illustrate the external data memory timing for the nonpage and page mode external
bus structures.
65 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
WR / RD
LSB DATA
PORT0
MOVX
MOVX INST INSTRUCTIONS
Data Access
SYSCLK
ALE
PSEN
WR / RD
_____________________________________________________________________________________________ 66
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
WR / RD
PORT0 DATA
SYSCLK
ALE
PSEN
WR / RD
= STRETCH CYCLE
67 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
WR / RD
MOVX MOVX
PORT0 DATA DATA
MOVX #1
MOVX MOVX INST MOVX #2 INSTRUCTIONS
Data Access
#1 #2 Data Access
(Page Miss)
(Page Miss)
SYSCLK
ALE
PSEN
WR / RD
MOVX DATA
PORT0
= STRETCH CYCLE
_____________________________________________________________________________________________ 68
Ultra-High-Speed Flash
Microcontroller User’s Guide
PAGE MODE 1 DATA MEMORY TIMING–PAGES 1:0 = 01b (TWO CYCLES) (CONTINUED)
The first diagram below shows execution of a MOVX instruction with default stretch value = 1 (MD2:0 = 001b) from external program
memory. The most probable case, where a page-miss is needed for the MOVX instruction, is given here. However, if the MOVX address
happened to coincide with the current code execution page, a page hit would occur.
The second diagram illustrates the MOVX timing that would occur if the address MSB for the MOVX data were to coincide with the
code execution pages before and after the data access. Since a different MSB would not need to be latched, neither of the page-miss
cycles seen in the third diagram would occur.
TWO-CYCLE PAGE MODE 1: MOVX (THREE CYCLE) EXTERNAL CODE EXECUTION WITH PAGE MISSES
SYSCLK
ALE
PSEN
WR / RD
MOVX MOVX
PORT2 LSB LSB MSB MSB LSB
LSB
MOVX
PORT0 DATA
TWO-CYCLE PAGE MODE 1: MOVX (THREE CYCLE) EXTERNAL CODE EXECUTION - NO PAGE MISSES
SYSCLK
ALE
PSEN
WR / RD
MOVX
PORT0 DATA
= STRETCH CYCLE
69 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SYSCLK
ALE
PSEN
WR / RD
MOVX MOVX
PORT2 MSB MOVX#1 LSB Address MSB MOVX#2 LSB Address
MOVX MOVX MOVX #1 Data Access INST MOVX #2 Data Access INST
#1 #2 (Page Miss + 1 Stretch Cycle) (Page Miss + 1 Stretch Cycle)
SYSCLK
ALE
PSEN
WR / RD
MOVX MOVX
PORT0 DATA DATA
= STRETCH CYCLE
_____________________________________________________________________________________________ 70
Ultra-High-Speed Flash
Microcontroller User’s Guide
PAGE MODE 1 DATA MEMORY TIMING–PAGES 1:0 = 00b (ONE CYCLE) (CONTINUED)
The next diagram, still using a MOVX stretch value = 0, shows the back-to-back MOVX instructions being executed from external pro-
gram memory.
The last diagram shows external code memory execution of an external MOVX instruction with stretch value = 4 (MD2:0 = 100b). It has
been assumed, for this example, that a page-miss is required for the MOVX data access. A stretch value = 4 results in the addition of
4 stretch cycles beyond the stretch value = 3. The four stretch cycles are distributed as folllows: two stretch cycles added for address
setup, one stretch cycle added to RD or WR pulse duration, and 1 stretch cycle added for address/data hold. For subsequent stretch
values of 5, 6, or 7, the added stretch cycle increases the RD or WR pulse duration.
ONE-CYCLE PAGE MODE 1: MOVX (TWO CYCLES) — MOVX (TWO CYCLES) EXTERNAL CODE EXECUTION
SYSCLK
ALE
PSEN
WR / RD
MOVX MOVX MOVX MOVX MSB LSB LSB LSB LSB LSB LSB LSB
PORT2 LSB LSB MSB LSB
MSB LSB MSB LSB
MOVX MOVX
PORT0 DATA DATA
SYSCLK
ALE
WR / RD
MOVX DATA
PORT0
71 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 72
Ultra-High-Speed Flash
Microcontroller User’s Guide
‘+D’ to indicate a data access page-miss and ‘+C’ to indicate a code-fetch page-miss. Thus, in the case of back-to-back MOVX oper-
ations, the second MOVX operation has two clock cycles added (‘+CD’), one associated with the code fetch and one associated with
the data access.
The sample code listings for these programs appear on the following pages.
Program 1 listed below is original code written for an 8051 and utilizes a single data pointer.
Program 2 uses the dual data pointer feature.
Program 3 uses the dual data pointer with autoincrement enhancement.
Program 4 uses the dual data pointer with autotoggle enhancement.
Program 5 uses the dual data pointer with autoincrement and autotoggle enhancements.
# HSM/UHSM CYCLES
MOVX @DPTR, A ; WRITE DATA TO DESTINATION 2/3 +D
INC DPTR ; NEXT DESTINATION ADDRESS 3/2 +C
MOV R3, DPL ; SAVE NEW DESTINATION POINTER 2/2
MOV R4, DPH ; 2/2
MOV DPL, R1 ; GET NEW SOURCE POINTER 2/2
MOV DPH, R2 ; 2/2
INC DPTR ; NEXT SOURCE ADDRESS 3/1
DJNZ R5, MOVE ; FINISHED WITH TABLE? 3/4
_____________________________________________________________________________________________ 74
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 76
Ultra-High-Speed Flash
Microcontroller User’s Guide
VCC
VPFW
VRST
VSS
INTERRUPT
SERVICE ROUTINE
tCSU
XTAL1
tPOR
INTERNAL RESET
If the use of the power-fail features is desired in stop mode, the BGS bit (EXIF, 91h) can be used. When set to a logic 1 by software,
the bandgap reference and associated power monitor circuits remain active in stop mode. The price of this feature is higher power-
supply current requirements. In stop mode with the bandgap reference disabled (default), the processor draws approximately 10µA.
With the bandgap enabled, it draws approximately 75µA.
BGS allows the user to decide whether the control circuitry and its associated power consumption are needed. If the application is
such that power does not fail while in stop, or if it does not matter that power fails, the BGS should be set to 0 (default). If power can
fail at any time and cause problems, the BGS should be set to 1.
WATCHDOG WAKE-UP
The watchdog wake-up is more of an application than a feature. It allows a system to enter the idle mode for power savings, then to
wake up periodically to sample the external world. Idle mode is a low-power state described below. Any of the programmable timers
can perform this function, but the watchdog allows a much longer period to be selected. At 33MHz, the maximum watchdog timeout
is over 2s. This contrasts with 23.8ms using the 16-bit timers. Software that uses the watchdog as a wake-up alarm should enable only
the watchdog interrupt and not the reset. Note that the watchdog cannot be used to wake the system while in stop mode since no
clocks are running. Stop mode is described in the Power Management Summary section below.
POWER MANAGEMENT SUMMARY
The following is a summary of the power management bits and those that are useful or related. They are contained in the register loca-
tions WDCON;D8h, EIE;E8h, EXIF;91h, and PCON; 87h.
WDCON.6 POR: Power-on reset. Hardware sets this bit on a power-up condition. Software can read it, but must clear it man-
ually. This bit assists software in determining the cause of a reset.
WDCON.5 EPFI: enable power-fail interrupt. Setting this bit to 1 enables the power-fail interrupt. This occurs when VCC drops
to approximately 4.375V, and the processor vectors to location 33h. Setting this bit to a 0 turns off the power-fail interrupt.
WDCON.4 PFI: Power fail interrupt flag. Hardware sets this bit to a 1 when a power-fail condition occurs. Software must clear the
bit manually. Writing a 1 to this bit forces an interrupt, if enabled.
77 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
WDCON.3 WDIF: Watchdog interrupt flag. If the watchdog interrupt is enabled (EIE.4), hardware sets this bit to indicate that
the watchdog interrupt has occurred. If the interrupt is not enabled, this bit indicates that the timeout has passed. If
the watchdog reset is enabled (WDCON.1), the user has 512 system clocks to strobe the watchdog prior to a reset.
Software or any reset can clear this flag.
WDCON.2 WTRF: Watchdog timer reset flag. Hardware sets this bit when the watchdog timer causes a reset. Software can read
it, but must clear it manually. A power-fail reset also clears the bit. This bit assists software in determining the cause of
a reset. If EWT = 0, the watchdog timer has no affect on this bit.
WDCON.1 EWT: Enable watchdog timer reset. Setting this bit turns on the watchdog timer reset function. The interrupt does not
occur unless the EWDI bit in the EIE register is set. A reset occurs according to the WD1 and WD0 bits in the CKCON
register. Setting this bit to a 0 disables the resets but leaves the timer running.
WDCON.0 RWT: Reset watchdog timer. This bit serves as the strobe for the watchdog function. During the timeout period, soft-
ware must set the RWT bit if the watchdog is enabled. Failing to set the RWT causes a reset when the timeout has
elapsed. There is no need to set the RWT bit to a 0 because it is self-clearing.
EIE.4 EWDI: Enable watchdog interrupt. Setting this bit in software enables the watchdog interrupt.
EXIF.0 BGS: Bandgap select. Setting this bit to a 1 allows the use of the bandgap voltage reference while in stop mode. Since
this function uses as much as 75µA, the bandgap is optional in stop mode. Setting this bit to a 0 turns off the bandgap
while in stop mode. When BGS = 0, no power-fail interrupt or power-fail reset is available in stop mode.
PCON.1 STOP. When this bit is set, the program stops execution, clocks are stopped, and the CPU enters power-down mode.
PCON.0 IDLE. Program execution halts, leaving timers, serial ports, and clocks running.
EXIF.2 RGMD: Ring oscillator mode. Hardware sets this status bit to a 1 when the clock source is the ring oscillator.
Hardware sets this status bit to a 0 when the crystal is the clock source. Refer to RGSL for operation of the ring oscil-
lator.
EXIF.1 RGSL: Ring oscillator select. When set to a 1 by software, the DS89C420 uses a ring oscillator to come out of stop
mode without waiting for crystal startup. This allows an instantaneous startup when coming out of stop mode. It is use-
ful if software needs to perform a short task, and then return to stop. It is also useful if software must respond quickly
to an external event. After the crystal has performed 65,536 cycles, hardware switches to the crystal as its clock
source. The RGMD status bit reports on this changeover. When RGSL is set to a 0, the DS89C420 delays software exe-
cution until after the 65,536 clock crystal startup time. RGSL is only cleared by a power-on reset and is not altered by
other forms of reset.
POWER SAVING
The DS89C420 is implemented using full CMOS circuitry for low-power operation. It is fully static, so the clock speed can be run down
to DC. Like other CMOS, the power consumption is also a function of operating frequency. Although the DS89C420 is designed for
maximum performance, it also provides improved power versus work relationships compared with standard 8051 devices. These top-
ics are discussed in detail in the following pages.
CLOCK DIVIDE CONTROL
The programmable clock divide control bits CD1 and CD0 (PMR, C4h) provide the processor with the ability to adapt to different crys-
tals and also to slow the system clocks, providing lower power operation when required. An on-chip crystal multiplier allows the
DS89C420 to operate at two or four times the crystal frequency by setting the 4X/2X bit and is enabled by setting the CTM bit to a logic
1. An additional circuit provides a clock source at divide-by-1024. When used with a 10MHz crystal, for example, the processor exe-
cutes machine cycle in times ranging from 25ns (divide-by-0.25) to 102.4µs (divide-by-1024) and maintains a highly accurate, serial
port baud rate while allowing the use of more cost-effective, lower-frequency crystals. Although the clock divide control bits can be
written at any time, certain hardware features have been provided to enhance the use of these clock controls to guarantee proper ser-
ial port operation, and also to allow for a high-speed response to an external interrupt. The 01b setting of CD1 and CD0 is reserved
and has the same effect as the setting of 10b, which forces the system clock into a divide-by-1 mode. The DS89C420 defaults to divide-
by-1 clock mode on all forms of reset.
When programmed to the divide-by-1024 mode, and the switchback bit (PMR.5: SWB) is also set, the system forces the clock divide
control bits to reset automatically to the divide-by-1 mode whenever the system has detected externally enabled interrupts.
_____________________________________________________________________________________________ 78
Ultra-High-Speed Flash
Microcontroller User’s Guide
4X/2X
CTM
Clock
Multiplier
Crystal
Oscillator
System
MUX
Clock
Divide-by-1024
Ring
Oscillator
Ring
Enable Selector
CD0
CD1
The oscillator divide ratios of 0.25, 0.5 and 1 are also used to provide standard baud rate generation for the serial ports through a
forced divide-by-12 input clocks (TxMH,TxM = 00b, x = 1, 2, or 3) to the timers. When in divide-by-1024 mode, in order to allow a quick
response to incoming data on a serial port, the system utilizes the switchback mode to automatically revert to divide-by-1 mode when-
ever a start bit is detected. This automatic switchback is only enabled during divide-by-1024 mode and all other clock modes are unaf-
fected by interrupts and serial port activity. See power management mode for more details.
Use of the divide-by-0.25 or 0.5 option through the clock divide control bits requires that the crystal multiplier be enabled and the spe-
cific system clock multiply value be established by the 4X/2X bit in the PMR register. The multiplier is enabled by the CTM (PMR.4) bit
but cannot be automatically selected until a startup delay has been established through the CKRY bit in the status register. The 4X/2X
bit can only be altered when the CTM bit is cleared to a logic 0. This prevents the system from changing the multiplier until the system
has moved back to the divide-by-1 mode and the multiplier has been disabled through the CTM bit. The CTM bit can only be altered
when the CD1 and CD0 bits are set to divide-by-1 mode and the RGMD bit is cleared to 0. Setting the CTM to a logic 1 from a previ-
ous logic 0 automatically clears the CKRY bit in the status register and starts the multiplier startup timeout in the multiplier startup
counter. During the multiplier startup period, the CKRY bit remains cleared and the CD1 and CD0 clock controls cannot be set to 00b.
The CTM bit is cleared to a logic 0 on all resets. Figure 7-2 (System Clock Sources) gives a simplified description of the generation of
the system clocks. Specifics of hardware restrictions associated with the use of the 4X/2X CTM, CKRY, CD1, and CD0 bits are outlined
in the SFR description.
The DS89C420 provides two modes (other than operating) that allow power conservation. They are similar, but have different merits
and drawbacks. These modes are idle and stop. In the original 8051, the stop mode is called power-down. These modes are invoked
in the same manner as the original 8051 series.
IDLE MODE
Idle mode suspends all CPU processing by holding the program counter in a static state. No program values are fetched and no pro-
cessing occurs. This saves considerable power versus full operation. The virtue of idle mode is that it uses half the power of the oper-
ating state, yet reacts instantly to any interrupt conditions. All clocks remain active so the timers, watchdog, serial port, and power mon-
itor functions are all working. Since all clocks are running, the CPU can exit the idle state using any of the interrupt sources.
Software can invoke the idle mode by setting the IDLE bit in the PCON register at location 87h. The bit is located at PCON.0. The
79 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
instruction that executes this step is the last instruction prior to freezing the program counter. Once in idle, all resources are preserved.
There are two ways to exit the idle mode. First, any interrupt (that is enabled) will cause an exit. This results in a jump to the appropri-
ate interrupt vector. The IDLE bit in the PCON register is cleared automatically. Upon returning from this vector using the RETI instruc-
tion, the next address is the one immediately after the instruction that invoked the idle state.
The idle mode can also be removed using a reset. Any of the three reset sources can do this. On receiving the reset stimulus, the CPU
is placed in a reset state and the idle condition cleared. When the reset stimulus is removed, software begins execution as for any
reset. Since all clocks are active, there is no delay after the reset stimulus is removed. Note that if enabled, the watchdog timer con-
tinues to run during idle and must be supported.
STOP MODE
Stop mode is the lowest power state that the DS89C420 can enter. This is achieved by stopping all on-chip clocks, resulting in a fully
static condition. No processing is possible, timers are stopped, and no serial communication is possible. Software can invoke stop
mode by setting the STOP bit in the PCON register at location 87h. The bit is located at PCON.1. Processor operation halts on the
instruction that sets the STOP bit. The internal amplifier that excites the external crystal is disabled, halting crystal oscillation in stop
mode. Stop mode takes precedence if application code attempts to set both the STOP and IDLE bits. However, doing this is not sug-
gested. Table 7-1 shows the state of the processor pins in idle and stop modes.
Stop mode can be exited in two ways. First, like the 8052 microcontrollers, a nonclocked interrupt such as the external interrupts or
the power-fail interrupt can be used. Clocked interrupts, such as the watchdog timer, internal timers, and serial ports do not operate
in stop mode. Note that the bandgap reference must be enabled in order to use the power-fail interrupt to exit stop mode, which
increases stop mode current. Processor operation resumes with the fetching of the interrupt vector associated with the interrupt that
caused the exit from stop mode. When the interrupt service routine is complete, an RETI returns the program to the instruction imme-
diately following the one that invoked the stop mode.
A second method of exiting stop mode is with a reset. The watchdog timer reset is not available as a reset source because no timers
are running in stop mode. An external reset by the RST pin unconditionally exits the device from stop mode. If the BGS bit is set, the
device provides a reset while in stop mode if VCC should drop below the VRST level. If the BGS bit is 0, then a dip in power below
VRST does not cause a reset. For example, if VCC drops to a level of VRST -0.5V, then returns to the full level, no reset is generated.
For this reason, use of the bandgap reference is recommended if a brownout condition is possible in stop mode. If power fails com-
pletely (VCC = 0V), then a power-on reset is still performed when VCC is reapplied, regardless of the state of the BGS bit. Processor
operation resumes execution from address 0000h like any other reset.
_____________________________________________________________________________________________ 80
Ultra-High-Speed Flash
Microcontroller User’s Guide
If the ring select (RGSL) is enabled, the DS89C420 can exit stop mode running from an internal ring oscillator. Upon receipt of an inter-
rupt, this oscillator can start instantaneously, allowing software execution to begin immediately while the oscillator is stabilizing. Ring
oscillator execution cannot be used to support accurate baud-rate generation or precise timer/counter operations. Once 65,536 clock
cycles have been detected, the CPU automatically switches to the normal oscillator as its clock source. However, if the required inter-
rupt response is very short, the software can reenter stop mode before the crystal is even stable. In this case, stop mode can be
invoked and both oscillators are stopped.
SPEED REDUCTION
The DS89C420 is a fully CMOS 8051-compatible microcontroller. It can use significantly less power than other 8051 versions, because
it is more efficient. As an average, software runs 10 times faster on the DS89C420 than on other 8051 derivatives. Thus, the same job
can be accomplished by slowing down the crystal by a factor of 10. For example, an existing 8051 design that runs at 12MHz can run
at approximately 1.2MHz on the DS89C420. At this reduced speed, the ultra-high-speed microcontroller has lower power consump-
tion than an 8051, yet performs the same job.
Using the 10X factor, Table 7-2 shows the approximate speed at which the DS89C420 can accomplish the same work as an 8051. The
exact improvement varies depending on the actual instruction mix. Available crystal speeds must also be considered. Refer to Section
14 for information on instruction timing.
81 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 82
Ultra-High-Speed Flash
Microcontroller User’s Guide
INTERNAL
SYSTEM
CLOCK
(PMM)
EXTERNAL
CLOCK
1024 CLOCKS
SWITCHBACK
The switchback feature solves one of the most vexing problems faced by power-conscious systems. Many applications are unable to
use the stop and idle modes because they require constant computation. Traditionally, system designers could not reduce the oper-
ating speed below that required to process the fastest event. This meant that system architects would be forced to operate their sys-
tems at the highest rate of speed, even when it was not required. The switchback feature allows a system to operate at a relatively slow
speed and burst to a faster mode when required by an external event. When this feature is enabled by setting the switchback enable
bit (SWB), (PMR.5), a qualified interrupt, serial port reception, or transmission causes the device to return to the default divide-by-1
mode. A qualified interrupt is defined as an interrupt that has occurred and been acknowledged. This means that an interrupt must be
enabled and also not blocked by a higher priority interrupt. After the event is complete, software can manually return the device to
PMM. The following sources can trigger a switchback:
• External interrupt 0/1/2/3/4/5
• Serial start bit detected, serial port 0/1
• Transmit buffer loaded, serial port 0/1
83 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 84
Ultra-High-Speed Flash
Microcontroller User’s Guide
85 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
_____________________________________________________________________________________________ 86
Ultra-High-Speed Flash
Microcontroller User’s Guide
SECTION 9: INTERRUPTS
The ultra-high-speed microcontroller family improves upon the traditional 8051 architecture by utilizing a five-priority interrupt system.
The five priority levels, from highest priority to lowest, are 4, 3, 2, 1, and 0. The power-fail interrupt, when enabled, always receives the
highest priority (level 4), while other interrupt sources can be configured to level 3, 2, 1, or 0. Each source has independent priority
bits, flag(s), interrupt vector, and enable. In addition, interrupts can be globally enabled (or disabled). The interrupt system is com-
patible with the original 8051 family, having all of the original interrupts available. A summary of all interrupt sources is provided in the
table below.
INTERRUPT OVERVIEW
An interrupt allows the software to react to unscheduled or asynchronous events. When an interrupt occurs, the CPU is expected to
“service” the interrupt. This service takes the form of an interrupt service routine (ISR). The ISR resides at a predetermined address,
as shown in Table 9-1. When the interrupt occurs, the CPU vectors to this address and runs code created to service the interrupt. The
CPU stays in an interrupt service state until the return from interrupt instruction (RETI) is executed at completion of the ISR. When an
RETI is performed, the processorl returns to the instruction that would have been next when the interrupt occurred. Once an ISR has
begun, it can be interrupted only by a higher priority interrupt.
87 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
When an interrupt condition occurs, the processor indicates this by setting a flag bit. This flag bit cannot alone cause an interrupt, and
is set regardless of whether the interrupt is enabled. Most flags must be cleared manually by software. However, IE0 and IE1 are
cleared automatically by hardware upon vectoring to the service routine if the interrupt was edge-triggered. In level-triggered mode,
the IE0 or IE1 flags will follow the state of the pin. Flags TF0 and TF1 are always cleared automatically when the service routine is vec-
tored to. Refer to the individual bit descriptions for more details.
Each source must be individually enabled in order to generate CPU interrupts. Each interrupt source has an independent enable, as
shown in Table 9-1. In order for the processor to acknowledge the interrupt and vector to the ISR, the enable all bit (IE.7: EA) must be
set to globally enable interrupt sources. Clearing the EA bit to a logic 0 disables all interrupts, regardless of the individual interrupt
enables. The power-fail warning interrupt source is the only exception, requiring only its individual enable bit be set (WDCON.5: EPFI)
to be recognized by the CPU. The EA bit has no effect on the power-fail interrupt.
INTERRUPT SOURCES
The interrupt sources present on the ultra-high-speed microcontroller can broken into several categories: external, timer-based, serial
communication, and power-fail. Each type is described in the following pages. Interrupt sources are evaluated during the final memo-
ry cycle of each instruction to determine whether and which interrupt is serviced. If the interrupt source goes active after this evalua-
tion, it is not considered until the final memory cycle of the next instruction.
External Interrupts
The ultra-high-speed microcontroller has six external interrupt sources. These include the standard two interrupts of the 8051 archi-
tecture and four new sources. The original interrupts are INT0 and INT1. These are active-low and can be programmed to be edge- or
level-sensitive. The detection mode for each source is controlled through TCON register bits IT0 and IT1, respectively. When ITx = 0,
the interrupt is triggered by a logic 0 on the appropriate interrupt pin. The interrupt condition remains in effect as long as the pin is low.
When ITx = 1, the interrupt is pseudo-edge-triggered. This means that the interrupt is activated, if on successive samples the pin is
found to be in a low state, indicating that a falling edge occurred. Since the external interrupts are sampled, the pin driver of an edge-
triggered interrupt should hold both the high and then the low condition for at least two system clock cycles (each) to ensure detec-
tion. This means maximum sampling frequency on any interrupt pin is one-fourth of the system clock frequency.
It is important to note that level-sensitive interrupts are not latched. This is most important if using other interrupts of equal or higher
priority, because the level-sensitive interrupt request may not receive immediate service by the processor. A level-sensitive interrupt
request is missed unless the condition is held until it can be serviced.
The remaining four external interrupts are similar in nature, with two differences. First, the four new interrupts are edge-detect only. They
do not have level-detect modes. Second, INT2 and INT4 are positive-edge sensitive instead of negative-edge sensitive. All associat-
ed bits and flags operate the same and have the same polarity as the original two. A logic 1 indicates the presence of a condition, not
the logic state of the pin.
If the power management mode is utilized, the designer must remember that detection of edge-triggered interrupts is defined in rela-
tion to the system clock (= 1024 oscillator clock cycles). This means that it requires 2048 external clock cycles before detecting that
an edge has just occurred. As a result, the latency for these interrupts is much longer in power management mode.
Timer Interrupts
The DS89C420 incorporates three 16-bit programmable timers, each of which can generate an interrupt, and a programmable watch-
dog timer. The three 16-bit programmable timers operate in the same manner as the 80C52. Each timer has an independent interrupt
enable, flag, vector, and priority. The watchdog timer also has its own interrupt enable, flag, and priority.
Timers 0 and 1 set their respective interrupt flags when the timer overflows from a full condition, depending on its mode. This flag is
set regardless of the interrupt enable state. If the interrupt is enabled, this event generates a call to the corresponding interrupt vec-
tor. For timers 0 and 1, the flags are cleared when the processor jumps to the interrupt vector. Thus, these flags are not available for
use by the interrupt service routine (ISR), but are available outside of the ISR and in applications that do not acknowledge the inter-
rupt (i.e., jump to the vector). If the interrupt is not acknowledged, then software must manually clear the flag bit. In addition to having
an interrupt flag for an overflow condition (as is the case for timers 0 and 1), timer 2 has a second interrupt flag (EXF2) that is associ-
ated with detection of a falling edge on the T2EX (P1.1) pin. When timer 2 has been configured in capture mode (CP/RL2 = 1, EXEN2
= 1) or autoreload mode (CP/RL2 = 0, EXEN2 = 1, DCEN = 0), a negative transition on T2EX causes the EXF2 interrupt flag to be set.
For timer 2 interrupts, jumping to the interrupt vector does not clear either of the flags. Instead, software must ascertain which flag
caused the interrupt and clear it manually. Timer 0 and 1 flag bits reside in the TCON register. Timer 2 flag bits reside in the T2CON
register. The interrupt enables and priorities for timers 0, 1, and 2 reside in the IE and IP0, IP1 registers.
_____________________________________________________________________________________________ 88
Ultra-High-Speed Flash
Microcontroller User’s Guide
The watchdog interrupt usually has a different connotation than the timer interrupts. Unless the watchdog is being used as a very long
timer, the interrupt means that the software has failed to reset the timer and may be lost. The watchdog ISR can attempt to determine
the system state or allow the CPU to be reset if the watchdog reset function has been enabled (EWT = 1). Like other sources, the watch-
dog timer has a flag bit, enable bit, priority bits, and its own vector.
Serial Communication Interrupts
Each UART is capable of generating an interrupt. Each UART has its own interrupt enable, vector, and priority. Each UART interrupt
has two flags (RI, TI) that are used by the ISR to determine whether the interrupt comes from a received word or a transmitted one.
Unlike the timers, the UART flags are not altered when the interrupt is serviced. Software must change them manually.
When a UART finishes the transmission of a word, the TI bit is set and an interrupt is generated (if enabled). Likewise, the UART sets
the RI bit and generates an interrupt when a word is completely received. The CPU is not notified until the word is completely received
or transmitted.
Power-Fail Interrupt
The ultra-high-speed microcontroller has the ability to generate an interrupt when VCC drops below a predetermined level. By com-
paring a fixed ratio of VCC versus an internal reference, the DS89C420 can assess when VCC drops below the VPFW level and cause
an interrupt (if enabled). The level of VPFW is provided in the data sheet on DC electrical specifications. The power-fail interrupt is a
level-sensitive condition, and remains in effect as long as VCC remains below VPFW. The power-fail interrupt has the highest priority
level, which cannot be altered by the user. The EPFI bit solely controls the enabling or disabling of the power-fail interrupt source, and
is not subject to the global interrupt enable (EA). The EPFI bit should always be cleared to a logic 0 state if the power-fail interrupt is
not needed.
Simulated Interrupts
Software can simulate any interrupt source by setting the corresponding flag bit. This forces an interrupt condition that is acknowledged
(if enabled) and is otherwise indistinguishable from the real thing. Thus, an interrupt flag bit should never be set to a logic 1 by soft-
ware inadvertently. Once an interrupt has been acknowledged, software cannot prevent or end the interrupt by clearing its flag. If, how-
ever, software clears an interrupt flag before the interrupt is acknowledged, the interrupt does occur.
INTERRUPT PRIORITIES
The ultra-high-speed microcontroller has five interrupt priority levels. The five priority levels, from highest priority to lowest, are 4, 3, 2,
1, and 0.
The power-fail interrupt, when enabled, always receives the highest priority (level 4), while the remaining interrupt sources can indi-
vidually be programmed to level 3, 2, 1, or 0. The lowest priority (level 0) is the default condition for the other sources. An interrupt
being serviced can only be interrupted by a higher priority interrupt. The power-fail interrupt source, assigned priority level 4, there-
fore, has the ability to interrupt the service routine of any other source. No interrupt source with equal or lesser priority to one current-
ly being serviced can interrupt the service routine.
If two interrupt sources of equal priority levels are requested simultaneously, natural priority is used to arbitrate. The natural priority is
given in Table 9-1. Note that natural priority is only used to resolve simultaneous requests. Once an interrupt of a given priority is
invoked, only a source that is programmed with a higher priority can intercede.
Interrupt Register Conflicts
During normal operation, there is a small but finite probability that application software might try to read or modify a register associat-
ed with interrupt functions at the same time that the interrupt hardware is modifying the register. In general, these hardware/software
interrupt conflicts are resolved according to the “hardware wins” philosophy: In the event of a conflict, the hardware modification of a
register takes precedence over the software action to ensure that the interrupt event is not missed.
To assist in prevention of hardware/software conflicts, the interrupt selection process that normally occurs in the final memory cycle of
each instruction is aborted for any instructions that write to the IP0, IP1, EIP0, EIP1, IE, or EIE registers. When the evaluation takes place
in the subsequent instruction, the interrupt source incorporates the new priority and enable values from the previous instruction. If this
situation occurs, it lengthens the interrupt latency by the length of the instruction that modified the register.
89 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
INTERRUPT
INTERRUPT INTERRUPT SELECTION
FLAG ENABLE BITS PRIORITY BITS HARDWARE
BITS
HIGHEST
PRIORITY
PFI
INT0
TF0
INT1 IT1
TF1
RI 0
TI_0
INTERRUPT
TF2 VECTOR
EXF2
RI_1
TI 1
INT2
INT3
INT4
INT5
WATCHDOG
INDIVIDUAL GLOBAL
ENABLES ENABLE
_____________________________________________________________________________________________ 90
Ultra-High-Speed Flash
Microcontroller User’s Guide
INTERRUPT LATENCY
Interrupt response time is normally between 4 and 18 memory cycles, depending on the state of the microcontroller when the interrupt
occurs. If the microcontroller is performing an ISR with equal or greater priority, interrupt latency increases because the new interrupt
is not invoked. In other cases, the response time depends on the current instruction. The fastest possible response to an interrupt is
four memory cycles. The four memory cycle response time includes one cycle for detecting the interrupt and three cycles to perform
the LCALL that is inherent in the interrupt request.
The maximum response time occurs if the microcontroller is performing a JBC instruction that clears a bit in IE, IP0, EIE, or EIP0, and
then executes a DIV as the next instruction. From the time an interrupt source is activated (not detected), the longest reaction time is
18 memory cycles. This includes one cycle to detect the interrupt, four cycles to finish the JBC, ten cycles to perform the DIV, then
three cycles for the LCALL to the ISR. This maximum response time of eighteen memory cycles assumes that there are no other pend-
ing interrupts of higher priority to be serviced and that the JBC instruction is not preceded and does not jump to any instruction that
aborts the priority decoding process (RETI or writes to IP0, IP1, EIP0, EIP1, IE, or EIE).
EXTERNAL
ADDRESS\ ADDRESS
DATA CONTROL VCC
PORT
0.n
INTERNAL
DATA BUS
D Q
WRITE
ENABLE
READ
READ LATCH/PIN
ENABLE
91 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Parallel I/O
Each I/O port can be used as a general-purpose, bidirectional parallel I/O port. Data written to the port latch serves to set both the
level and the direction of the data on the pin. The output of the port pin is established by writing to the associated port pin latch. When
logic 0 is written to the port for output, the port is pulled to ground. When logic 1 is written to ports 1, 2, or 3, a strong driver momen-
tarily drives the pin from 0 to 1, and then a weak pullup maintains the 1. A logic 1 written to port 0 causes those pins to go tri-state,
functioning as open-drain outputs. A logic 1 in the port latch also configures the port pin to the input state. Since the pin is either weak-
ly pulled up or in three-state, the pin is the same as the driven logic state. The logic state of the pin itself does not alter the logic value
of the port latch.
Port 0
This is an open drain, 8-bit, bidirectional, general-purpose I/O port. A reset condition or logic 1, written to the latches of this port, three-
state, the port pins. This condition also serves as an input mode. When used as an I/O port, external pullups are required. As an alter-
nate function, this port can be used as part of the multiplexed address/data bus to access external memory. The DS89C420 supports
both nonpage and page mode. During the original 8051 expanded bus configuration (nonpage mode), when ALE is high, the LSB of
the address is presented to P0. When ALE is low, the port transitions to a bidirectional data bus. When used in page mode 1, P0 is
used as the primary data bus only. When used in page mode 2, P0 is used for the LSB of the address only.
The use of port 0 as general-purpose I/O is not recommended if the device is used to access external memory. In this case, the state
of the pins are disturbed during the memory access. In addition, the pullups required to maintain a high state during the use as gen-
eral-purpose I/O interfere with the complementary drivers employed when the device operates as an expanded memory bus.
When port 0 is used as an address bus, the AD0-7 pins provide true drive capability for logic levels 1 and 0. No external pullups are
required. In fact, external pullups degrade the memory interface timing. The DS89C420 employs a two-state system on AD0-7. This
allows the pin to be driven hard for a period of time, allowing the greatest possible setup or access time. The pin states are then held
in a weak latch until forced to the next state or overwritten by an external device. This assures a smooth transition between logic states
and also allows a longer hold time.
ADDRESS ADDRESS
A8-A15 CONTROL
VCC
DELAY
= 2Tclk VCC
PORT
INTERNAL 2.n
DATA BUS
D Q
Q VCC
WRITE
ENABLE
READ
READ LATCH/PIN
ENABLE
_____________________________________________________________________________________________ 92
Ultra-High-Speed Flash
Microcontroller User’s Guide
ALE
PSEN
LSB Add Data LSB Add Data
Port 0
Port 2
Port 2 is an 8-bit bidirectional I/O port. The reset condition sets the port pins to logic 1. In this state, a weak pullup holds the port pin
high. This condition also serves as an input mode, since any external circuit that writes to the port overcomes the weak pullup. Writing
a logic 0 to the port pin activates a strong pulldown that remains on until a 1 is written or a reset occurs. Writing a logic 1 after the port
has been at 0 causes a strong transition driver to turn on, followed by a weaker sustaining pullup. Once the momentary strong driver
turns off, the pin assumes both the output high and input state. As an alternate function, port 2 can function as the MSB of the address
bus for external memory access during nonpage mode. When used in page mode 1, P2 is used for both LSB and MSB of external
address. When used in page mode 2, P2 is used for the MSB of external address and data.
Port 1
Port 1 functions as both an 8-bit bidirectional I/O port and an alternate functional interface for timer 2 I/O, external interrupts 2, 3, 4, 5,
and serial port 1. Reset conditions set these port pins to logic 1 and are held high with weak pullups. This condition also serves as an
input mode, since any external circuit that writes to the port overcomes the weak pullup. When a logic 0 is written to any port pin, the
port activates a strong pulldown that remains on until a 1 is written or a reset occurs. Writing a logic 1 after the port has been a 0 caus-
es a strong transition driver to turn on, followed by a weaker sustaining pullup. Once the momentary strong driver turns off, the pin
assumes both the output high and input state.
Port 3
Port 3 functions as both an 8-bit bidirectional I/O port and an alternate functional interface for external interrupts 0 and 1, serial port 0,
timers 0 and 1 inputs, and external data memory strobes. The reset condition sets all bits to logic 1. In this state, a weak pullup holds
the port high. This condition also serves as an input mode, since any external circuit that writes to the port overcomes the weak pullup.
Writing a logic 0 to any port pin activates a strong pulldown that remains on until a 1 is written or a reset occurs. Writing a logic 1 after
the port has been a 0 causes a strong transition driver to turn on, followed by a weaker sustaining pullup. Once the momentary strong
driver turns off, the pin assumes both the output high and input state.
Alternate Functions of Ports 1 and 3
When any of the pins of ports 1 and 3 is enabled as a special function, the port latch should be programmed to logic 1 to avoid poten-
tial bus contention and ensure proper operation. The drive characteristics of these pins do not change when the pins are used for gen-
eral I/O or as a special function associated with the pin. port 0 and 2 pins, as well as PSEN, ALE, P3.6 and P3.7, incorporate special
circuitry to limit the current consumed by the device.
93 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
XTAL1
ALE
PSEN
RD / WR
Inst Inst Inst Inst Inst Inst
Port 0 Data
MOVX
Instruction Memory Access (Stretch = 4)
Fetch
PSEN
RD / WR
Inst Inst Inst Inst Inst Inst Inst
Port 0 Data
MOVX
Instruction Memory Access (Stretch = 4)
Fetch
ALE
PSEN
_____________________________________________________________________________________________ 94
Ultra-High-Speed Flash
Microcontroller User’s Guide
The special functions and the associated port pins are listed below:
P1.0 T2 Timer 2 output
P1.1 T2EX Timer 2 capture/reload input
P1.2 RXD1 Serial receive UART1
P1.3 TXD1 Serial transmit UART1
P1.4 INT2 External interrupt 2, rising-edge active
P1.5 INT3 External interrupt 3, falling-edge active
P1.6 INT4 External interrupt 4, rising-edge active
P1.7 INT5 External interrupt 5, falling-edge active
P3.0 RXD0 Serial receive UART0
P3.1 TXD0 Serial transmit UART0
P3.2 INT0 External interrupt 0, falling-edge active
P3.3 INT1 External interrupt 1, falling-edge active
P3.4 T0 Timer 0 input
P3.5 T1 Timer 1 input
P3.6 WR External data memory-write strobe
P3.7 RD External data memory-read strobe
Read-Modify-Write
The normal read instructions associated with the I/O ports read the pin state without regard to the port latches. However, the read-mod-
ify-write instructions read the state of the port latches instead of the port pins. This type of instruction reads the contents of an SFR,
then modifies it in the ALU, and returns it to the original source. The instructions of this type are listed below:
ANL Logical AND
ORL Logical OR
XRL Logical exclusive OR
JBC Branch if bit set and clear bit
CPL Complement bit
INC Increment
DEC Decrement
DJNZ Decrement and branch if not zero
MOV Px.n, C Move carry bit to bit n of port x
CLR Px.n Clear bit n in port x
SETB Px.n Set bit n in port x
Output Functions
The DS89C420 I/O ports appear to be true I/O, but their output characteristics are dependent on the individual port and pin conditions.
When software writes logic 0 to the port for output, the port is pulled to ground. When software writes logic 1 to the port for output,
ports 1, 2, or 3 drive weak pullups (after the strong transition from 0 to 1). Thus, as long as the port is not heavily loaded, true logic val-
ues are output. Port 0, having open-drain outputs, three-states when written to logic 1 and hence requires external pullups be present
when used as an output. DC drive capability is provided in the electrical specifications. Note that the DC current available from an I/O
port pin is a function of the permissible voltage drop.
Transition current is available to help move the port pin from logic 0 to logic 1. Since the logic 0 driver is strong, no additional drive
current is needed in the 1 to 0 direction. The transition current is applied when the port latch is changed from logic 0 to logic 1. Writing
logic 1 where a 1 was already in place does not change the strength of the pullup. This transition current is applied for two oscillator
cycles. The absolute current is not guaranteed, but is approximately 2 mA at 5V.
95 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
When serving as an I/O port, the drive varies as follows: for logic 0, the port invokes a strong pulldown; for logic 1, the port invokes a
strong pullup for two oscillator cycles to assist with the logic transition. Then the port reverts to a weak pullup. This weak pullup is main-
tained until the port transitions from logic 1 to logic 0. External circuits can overdrive the weak pullup. This allows the logic 1 output
state to serve as the input state as well.
Substantial DC current is available in both the high and low levels. However, the power dissipation limitations make it inadvisable to heav-
ily load multiple pins. In general, sink and source currents should not exceed 10mA total per port (8 bits) and 25mA total per package.
Input Functions
The input state of the I/O ports is the same as that of the output logic 1. That is, the pin is pulled weakly to logic 1. This logic 1 state is
easily overcome by external components. Thus, after software writes a 1 to the port pin, the port is configured for input. When the port
is read by software, the state of the pin is read. The only exception is the read-modify-write instructions, discussed earlier. If the exter-
nal circuit is driving logic 1, then the pin is logic 1. If the external circuit is driving logic 0, then it overcomes the internal pullup. Thus,
the pin is the same as the driven logic state. Note that the port latch is not altered by a read operation. Therefore, if logic 0 is driven
onto a port pin from an external source, then removed, the pin reverts to the weak pullup, as determined by the internal latch.
_____________________________________________________________________________________________ 96
Ultra-High-Speed Flash
Microcontroller User’s Guide
GATE Gate control enable for INT1 pin TMOD – 89h TMOD.7
C/T Counter/timer select TMOD – 89h TMOD.6
M1, M0 Timer mode select bits TMOD – 89h TMOD.5,4
TIMER 1
97 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Note that when used as a timer, the input clock selection can be affected by the clock divide bits (PMR.7-6), the TxM bit (in the CKCON
register), and the TxMH bit (in the CKMOD register). The time base selection is described in more detail later in this section.
Mode 0 operates identically when timer 1 is used. The same information applies to TL1 and TH1, which form the 13-bit register. TR1
(TCON.6), INT1 (P3.3), T1 (P3.5) and the relevant C/T (TMOD.6), and GATE (TMOD.7) bits have the same functions.
MODE 1
Mode 1 configures the timer for 16-bit operation as either a timer or counter. Figure 11-1 shows that setting the TMOD select bits M1,
M0 = 01b invoke this operating mode. For timer n, all of the TLn and THn registers are used. For example, if timer 1 is configured in
mode 1, then TL1 holds the LSB and TH1 holds the MSB. Rollover occurs when the timer reaches FFFFh. An interrupt also occurs if
enabled and the relevant TFn flag is set. Time-base selection, counter/timer selection, and the gate function operate as described in
mode 0.
MODE 2
This mode configures the timer as an 8-bit timer/counter with automatic reload of the start value. This configuration is shown in Figure
11-2, and is selected when bits M1and M0 of the TCON register are set to 1 and 0, respectively. When configured in mode 2, the timer
uses TLn to count and THn to store the reload value. Software must initialize both TLn and THn with the same starting value for the first
count to be correct. Once the TLn reaches FFh, it is automatically loaded with the value in THn. The THn value remains unchanged
unless modified by software. Mode 2 is commonly used to generate baud rates since it runs without continued software intervention.
As in modes 0 and 1, mode 2 allows counting of either clock cycles or pulses on pin Tn (C/T = 1) when counting is enabled by TRn
and the proper setting of GATE and INTn pins.
T0M = CKCON.3
(T1M = CKCON.4)
C / T = TMOD.2
DIVIDE- 1 0
INPUT TO TIMER BY-4 (C / T = TMOD.6)
CLK MODE SYSCLK TL0
DIVIDE-BY-1 OSC / 1 (TL1)
2X OSC / 0.5 1 0
CLK 0 4 7
4X OSC / 0.25
1 00 MODE 0
T0 = P3.4 M1, M0 = TMOD.1,
(T1 = P3.5) TMOD.0
(M1, M0 = TMOD.5,
01 TMOD.4)
TR0 = TCON.4
MODE 1
(TR1 = TCON.6) TH0
(TH1)
GATE = TMOD.3 0 7
(GATE = TMOD.7)
INT0 = P3.2
( INT1 = P3.3)
TF0 = TCON.5 INTERRUPT
(TF1 = TCON.7)
TIMER 1 FUNCTIONS
SHOWN IN PARENTHESES ()
NOTE: FOR POWER-MANAGEMENT MODE (DIVIDE-BY-1024) OPERATION, THE TIMER INPUT CLOCK TO THE TIMER IS
OSC / 1024 IF EITHER TXM = 1 OR TXMH = 1. OTHERWISE, THE TIMER INPUT IS OSC / 3072.
_____________________________________________________________________________________________ 98
Ultra-High-Speed Flash
Microcontroller User’s Guide
T0M = CKCON.3
(T1M = CKCON.4)
C / T = TMOD.2
DIVIDE- 1 0
INPUT TO TIMER (C / T = TMOD.6)
BY-4
CLK MODE SYSCLK TL0
DIVIDE-BY-1 OSC / 1 (TL1)
2X OSC / 0.5 1 0
CLK 0 RELOAD
4X OSC / 0.25 7
1
T0 = P3.4
(T1 = P3.5)
TR0 = TCON.4
(TR1 = TCON.6)
0 TH0 7
GATE = TMOD.3
(GATE = TMOD.7) (TH1)
INT0 = P3.2
( INT1 = P3.3) TF0 = TCON.5
INTERRUPT
(TF1 = TCON.7)
TIMER 1 FUNCTIONS
SHOWN IN PARENTHESES ()
NOTE: FOR POWER-MANAGEMENT MODE (DIVIDE-BY-1024) OPERATION, THE TIMER INPUT CLOCK TO THE TIMER IS
OSC / 1024 IF EITHER TXM = 1 OR TXMH = 1. OTHERWISE, THE TIMER INPUT IS OSC / 3072.
MODE 3
This mode provides an 8-bit timer/counter and a second 8-bit timer as indicated in Figure 11-3. In mode 3, TL0 is an 8-bit timer/counter
controlled by the normal timer 0 bits (TR0 = TCON.4 and TF0 = TCON.5). TL0 can be used to count clock cycles or 1 to 0 transitions
on pin T0, as determined by C/T(TMOD.2). As in the other modes, the GATE function can use INT0 to give external run control of the
timer to an outside signal.
TH0 becomes an independent 8-bit timer in mode 3; however, it can only count clock cycles as shown in Figure 11-2. In this mode,
some of timer 1’s control signals are used to manipulate TH0. That is, TR1 (TCON.6) and TF1 (TCON.7) become the relevant control
and flag bits associated with TH0.
In mode 3, timer 1 stops counting and holds its value. Thus, timer 1 has no practical application while in mode 3.
As mentioned, when timer 0 is in mode 3, it uses some of timer 1’s resources (i.e., TR1 and TF1). Timer 1 can still be used in modes
0, 1, and 2 in this situation, but its flexibility becomes somewhat limited. While it maintains its basic functionality, its inputs and outputs
are no longer available. Therefore, when timer 0 is in mode 3, timer 1 can only count clock cycles, and it does not have an interrupt or
flag. With these limitations, baud-rate generation is its most practical application, but other time-base functions may be achieved by
reading the registers.
TIMER 2 MODES
Like timers 0 and 1, timer 2 is a full-function timer/counter; however, it has several additional capabilities that make it more useful. Timer
2 has independent control registers in T2CON and T2MOD, and is based on count registers TL2 and TH2. It does not offer the 13-bit
or dual 8-bit mode, but instead runs in the 16-bit mode at all times. Also note that while timers 0 and 1 have an 8-bit autoreload mode,
timer 2 provides a 16-bit autoreload mode. This mode uses the timer capture registers to hold the reload values. The modes available
on timer 2 are described in the following pages.
99 _____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
T0M = CKCON.3
DIVIDE- 1 C / T = TMOD.2
INPUT TO TIMER 0
BY-4
CLK MODE SYSCLK 0
DIVIDE-BY-1 OSC / 1
2X OSC / 0.5 1 CLK 0 TL0 7
4X OSC / 0.25
1
T0 = P3.4
TF0 = TCON.5 INTERRUPT
TR0 = TCON.4
INT0 = P3.2
TR1 = TCON.6
0 TH0 7
NOTE: FOR POWER-MANAGEMENT MODE (DIVIDE-BY-1024) OPERATION, THE TIMER INPUT CLOCK TO THE TIMER IS
OSC / 1024 IF EITHER TXM = 1 OR TXMH = 1. OTHERWISE, THE TIMER INPUT IS OSC / 3072.
____________________________________________________________________________________________ 100
Ultra-High-Speed Flash
Microcontroller User’s Guide
T2M = CKCON.5
DIVIDE- 1 C / T2 = T2CON.1
INPUT TO TIMER 0
BY-4
CLK MODE SYSCLK 0
DIVIDE-BY-1 OSC / 1 CLK
2X 0 78 15
OSC / 0.5 1 TF2 =
TL2 TH2 T2CON.7
4X OSC / 0.25
1
T2 = P1.0
TR2 = T2CON.2
RCAP2L RCAP2H
T2EX = P1.1 0 78 15
NOTE: FOR POWER-MANAGEMENT MODE (DIVIDE-BY-1024) OPERATION, THE TIMER INPUT CLOCK TO THE TIMER IS
OSC / 1024 IF EITHER TXM = 1 OR TXMH = 1. OTHERWISE, THE TIMER INPUT IS OSC / 3072.
T2M = CKCON.5
DIVIDE- 1 C / T2 = T2CON.1
INPUT TO TIMER 0
BY-4
CLK MODE SYSCLK 0
DIVIDE-BY-1 OSC / 1 CLK
2X OSC / 0.5 1 0 78 15 TF2 =
4X OSC / 0.25 TL2 TH2 T2CON.7
1
T2 = P1.0
TR2 = T2CON.2 RCAP2L RCAP2H
T2EX = P1.1 0 78 15
TIMER 2
INTERRUPT
EXF2 =
EXEN2 = T2CON.3 T2CON.6
NOTE: FOR POWER-MANAGEMENT MODE (DIVIDE-BY-1024) OPERATION, THE TIMER INPUT CLOCK TO THE TIMER IS
OSC / 1024 IF EITHER TXM = 1 OR TXMH = 1. OTHERWISE, THE TIMER INPUT IS OSC / 3072.
101 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
T2M = CKCON.5
TF2 = TIMER 2
T2CON.7 INTERRUPT
EXF2 =
T2CON.6
NOTE: FOR POWER-MANAGEMENT MODE (DIVIDE-BY-1024) OPERATION, THE TIMER INPUT CLOCK TO THE TIMER IS
OSC / 1024 IF EITHER TXM = 1 OR TXMH = 1. OTHERWISE, THE TIMER INPUT IS OSC / 3072.
____________________________________________________________________________________________ 102
Ultra-High-Speed Flash
Microcontroller User’s Guide
TIMER 1
OVERFLOW
OSC INPUT TO TIMER
CLK MODE TIMER INPUT C / T2 = T2CON.1
DIVIDE- SMOD_0 =
DIVIDE BY 1 OSC / 2 BY-2 PCON.7
2X OSC / 2 0
4X OSC / 2
PMM ( / 1024) OSC / 2048 0 1
CLK
1 RCLK =
T2 = P1.0 0 78 15 T2CON.5
TR2 = T2CON.2 TL2 TH2
1 0
DIVIDE-
TCLK = BY-16
T2CON.4 Rx
T2EX = P1.1 RCAP2L RCAP2H 1 0 CLOCK
0 78 15
DIVIDE-
BY-1 6
EXF2 = Tx
TIMER 2 CLOCK
EXEN2 = T2CON.3 T2CON.6 INTERRUPT
Another feature of the baud-rate generator mode is that the crystal-derived time base for the timer is the crystal frequency divided by
2. No other crystal-divider selection is possible unless operating in power-management mode. If a different time base is desired, bit
C/T2 (T2CON.1) may be set to a 1, sourcing the time base from an external clock source supplied by the user on pin T2 (P1.0). The
RCAP registers may be read, but not modified, while TR2 = 1. Stop the timer (TR2 = 0) to modify these registers.
Timer Output Clock Generator
Timer 2 can also be configured to drive a clock output on port pin P1.0 (T2), as shown in Figure 11-8. To configure timer 2 for this mode,
it must first be set to 16-bit autoreload timer mode (CP/RL2 = 0, C/T2 = 0). Next, the T2OE (T2MOD.1) bit must be set to a logic 1. TR2
(T2CON.2) must also be set to a logic 1 to enable the timer.
This mode produces a 50% duty cycle square-wave output. The frequency of the square wave is given by the formula in Figure 11-7.
Each timer overflow causes an edge transition on the pin, i.e., the state of the pin toggles.
Note that this mode has two somewhat unique features in common with the baud-rate generation mode. First, the time base is the crys-
tal frequency divided by 2, and other than power-management mode operation, no other divider selection is possible. Second, the
timer itself does not generate an interrupt, but, if needed, an additional external interrupt may be caused using T2EX as described
above. Because of the two modes’ similarities, the timer can be used to generate both an external clock and a baud-rate clock simul-
taneously. Once the clock-out mode is established, either TCLK or RCLK is set to 1, and the RCAP2 registers are loaded, the timer
provides a clock to both functions.
Time-Base Selection
The ultra-high-speed microcontroller allows the user to select the time base for each timer independently. In the standard 8051, the
timers count the oscillator divided by 12, which is the standard 8051 machine cycle timing. Following a reset, the timers default to an
oscillator divided-by-12 input clock to remain drop-in compatible with the original 8051. The ultra-high-speed microcontroller timers
can additionally be configured to use the system clock or the system clock divided by 4 for the input clock. These selections, while not
affecting the CPU timing, allow for higher precision timing and faster baud rates. As an example, a user might select both the baud-
rate generator timer and another timer to run at 12 oscillator clocks per timer tick with the third timer running at four system clocks per
tick. This allows one timer to measure higher speed events or to gain better resolution.
103 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
DIVIDE-
BY-2
T2OE = T2MOD.1
EXEN2 = T2CON.3
The input clock selection is independent for each timer and the default is 12 oscillator clocks per timer tick. The control bits for the
time-base selection (TxM, TxMH) are located in the clock control register (CKCON;8Eh) and the clock-mode register (CKMOD;96h).
The TxM and TxMH bits for each of the timers enable input clock selections of the system clock divided by 4 and the system clock
divided by 1, respectively. When TxMH is set to a logic 1, the associated TxM bit for that timer is ignored. Note that, when operating
in the default system clock mode, the system clock is the same frequency as the oscillator clock. System clock mode selection is con-
trolled by the CD1, CD0 bits of the PMR register. See the PMR register description and the CPU timing section for more information on
how to modify the system clock. As described earlier, timer 2 does, however, automatically switch to two oscillator clocks per tick when
configured for baud-rate generation or clock-output mode. When the time base is derived from an external source (i.e., the T0, T1, or
T2 pins), the timer operates at the frequency of the external source and is not affected by the setting of the TxM or TxMH bits. The only
limitation is that the external source frequency can be no faster than one-fourth of the main system clock frequency. Use of power man-
agement-mode changes the input clock to the timers in a way that does not exactly follow any of the guidelines set forth to this point.
Tables 11-2 and 11-3 show the resulting timer input clock for the various system clock modes and timer control bit setting. Table 11-2
pertains only to timer 2 in the baud-rate generation or clock-output mode.
____________________________________________________________________________________________ 104
Ultra-High-Speed Flash
Microcontroller User’s Guide
WATCHDOG TIMER
The watchdog timer reset provides CPU monitoring by requiring software to clear the timer before the user-selected interval expires. If
the timer is not reset, the CPU can be reset by the watchdog. The watchdog function is optional and is described below.
The watchdog timer is a user-programmable clock counter that can serve as a time-base generator, an event timer, or a system super-
visor. As can be seen in Figure 11-9, the timer is driven by the main system clock that is supplied to a series of dividers. The divider
output is selectable, and determines the interval between timeouts. When the timeout is reached, an interrupt flag is set, and if enabled,
a reset occurs. The interrupt flag causes an interrupt to occur if its individual enable bit is set and the global interrupt enable is set.
The reset and interrupt are completely discrete functions that may be acknowledged or ignored, together or separately for various
applications.
The watchdog timer reset function works as follows. After initializing the correct timeout interval (discussed later), software first restarts
the watchdog using RWT (WDCON.0) and then enables, if desired, the reset function by setting the enable watchdog timer reset (EWT
= WDCON.1) bit. Any time prior to reaching its user-selected terminal value, software can set the reset watchdog timer (RWT =
WDCON.0) bit. If the watchdog timer is reset (RWT bit written to a logic 1) before the timeout period expires, the timer starts over.
Hardware automatically clears the RWT after software sets it.
XTAL1
RWT (WDCON.0)
(RESET WATCHDOG)
XTAL2
SYSTEM CLOCK DIVIDE-BY- DIVIDE-BY- DIVIDE-BY- DIVIDE-BY-
MODE CONTROL 17 3 3 3
2 2 2 2
17 20 23 26
2 2 2 2
WD1 (CKCON.7) TIMEOUT TIMEOUT
WD0 (CKCON.6) SELECTOR
SYSCLK OUTPUT
CLK MODE SYSCLK WDIF
WATCHDOG
DIVIDE-BY-1 OSC / 1 (WDCON.3) INTERRUPT
2X OSC / 0.5 EWDI (EIE.4)
4X OSC / 0.25 (ENABLE WATCHDOG TIMER)
PMM OSC / 1024
512 SYSCLK
DELAY RESET
105 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
If the timeout is reached without RWT being set, hardware generates a watchdog interrupt if the interrupt source has been enabled. If
no further action is taken to prevent a watchdog reset in the 512 system clock cycles following the timeout, hardware has the ability to
reset the CPU if EWT = 1. When the reset occurs, the watchdog timer reset flag (WTRF = WDCON.2) is automatically set to indicate
the cause of the reset; however, software must clear this bit manually.
The watchdog timer is a free-running timer. When used as a simple timer with both the reset and interrupt functions disabled (EWT =
0 and EWDI = 0), the timer continues to set the watchdog interrupt flag each time the timer completes the selected timer interval as
programmed by WD1 (CKCON.7) and WD0 (CKCON.6). Restarting the timer using the RWT (WDCON.0) bit allows software to use the
timer in a polled timeout mode. The WDIF bit is cleared by software or any reset.
The watchdog interrupt is also available for applications that do not need a true watchdog reset, but a very long timer. The interrupt is
enabled using the enable watchdog timer interrupt (EWDI = EIE.4) bit. When the timeout occurs, the watchdog timer sets the WDIF bit
(WDCON.3), and an interrupt occurs if the global interrupt enable (EA = IE.7) is set. Note that WDIF is set 512 clocks before a poten-
tial watchdog reset. The watchdog interrupt flag indicates the source of the interrupt, and must be cleared by software.
Using the watchdog interrupt during software development can allow the user to select ideal watchdog reset locations. Code is first
developed without enabling the watchdog interrupt or reset functions. Once the program is complete, the watchdog interrupt function
is enabled to identify the required locations in code to set the RWT (WDCON.0) bit. Incrementally adding instructions to reset the watch-
dog timer prior to each address location (identified by the watchdog interrupt) allows the code to eventually run without receiving a
watchdog interrupt. At this point, the watchdog timer reset can be enabled without the potential of generating unwanted resets. At the
same time, the watchdog interrupt may also be disabled. Proper use of the watchdog interrupt with the watchdog reset allows inter-
rupt software to survey the system for errant conditions.
When using the watchdog timer as a system monitor, the watchdog reset function should be used. If the interrupt function were used,
the purpose of the watchdog would be defeated. For example, assume the system is executing errant code prior to the watchdog inter-
rupt. The interrupt would temporarily force the system back into control by vectoring the CPU to the interrupt service routine. Restarting
the watchdog and exiting by an RETI or RET would return the processor to the lost position prior to the interrupt. By using the watch-
dog reset function, the processor is restarted from the beginning of the program and, therefore, placed into a known state.
The watchdog timeout selection is made using bits WD1 (CKCON.7) and WD0 (CKCON.6). The watchdog has four timeout selections
based on the system clock frequency, as shown in the figure. Since the timeout is a function of the system clock, the actual timeout
interval is dependent on both the crystal frequency and the system clock mode. Shown in Table 11-4 is a summary of the selectable
watchdog timeout intervals for the various system clock modes and WD1:0 control bit settings. The watchdog reset, if enabled, is
always scheduled to occur 512 system clocks following the timeout. Watchdog-generated resets last for 13 oscillator cycles.
As discussed above, the watchdog timer has several SFR bits that contribute to its operation. It can be enabled to function as either
a reset source, interrupt source, software polled timer, or any combination of the three. Both the reset and the interrupt have status
flags. The watchdog also has a bit that restarts the timer. Table 11-5 shows the watchdog timer-related bits. Detailed bit descriptions
can be found in Section 4.
____________________________________________________________________________________________ 106
Ultra-High-Speed Flash
Microcontroller User’s Guide
107 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
MODE 1
This mode provides standard full-duplex asynchronous communication. A total of 10 bits are transmitted including 1 start bit, 8 data
bits, and 1 stop bit. The received stop bit is stored in bit location RB8 of the relevant SCON register.
In mode 1, the baud rate is a function of timer overflow. This makes the baud rate programmable by the user. One difference that exists
between the two UARTs, with respect to mode 1 configuration, is that serial port 1 can use only timer 1, whereas serial port 0 can use
either timer 1 or 2 to generate baud rates. If both serial ports use the same timer, they run at the same baud rate, or one can run twice
as fast as the other (when baud-rate doubler bits, PCON.7 and WDCON.7, are configured differently). If the two UARTs use different
timers, the baud-rate configurations, in relation to one another, are not as restrictive. Baud rates are discussed in more detail later. Mode
1 operation is identical to the standard 80C32 when timers 1 or 2 use the default oscillator divide-by-12 as an input clock.
MODE 2
This mode is an asynchronous mode that transmits a total of 11 bits. These include 1 start bit, 9 data bits (the ninth data bit being pro-
grammable), and 1 stop bit. The ninth bit is determined by the value in TB8 (SCON0.3 or SCON1.3) for transmission. When the ninth
bit is received, it is stored in RB8 (SCON0.2 or SCON1.2). The ninth bit can be a parity value by moving the P bit (PSW.0) to TB8.
When not using the power-management mode, the baud rate for mode 2 is a function only of the oscillator frequency. It is either the
oscillator input divided by 32 or 64 as programmed by the SMOD doubler bit for the associated UART. The SMOD_0 baud-rate dou-
bler bit for serial port 0 is located at PCON.7, and the SMOD_1 baud-rate doubler bit for serial port 1 is located at WDCON.7. Mode 2
operation is identical to the standard 80C32.
MODE 3
This mode has the same functionality as mode 2, but generates baud rates like mode 1. That is, this mode transmits 11 bits, but gen-
erates baud rates through the timers. Like mode 1, either timer 1 or 2 can be used for serial port 0 and timer 1 can be used for serial
port 1. Mode 3 operation is identical to the standard 80C32 when timers 1 or 2 use the default oscillator divide-by-12 as an input clock.
SERIAL PORT INITIALIZATION
In order to use the UART function(s), the serial port must be initialized. This involves selecting the mode and time base, then initializ-
ing the baud-rate generator, if necessary. Serial communication is then available. Once the baud-rate generator is running, the UART
can receive data.
In mode 0, the high-speed microcontroller provides the clock. Serial reception is initiated by setting the RI bit to a logic 0 and REN to
a logic 1. This generates a clock on the TXD pin and a shift in the 8 bits on the RXD pin. In the other modes, setting the REN bit to a
logic 1 allows serial reception, but the external device must actually initiate it by sending a start bit. In any mode, serial transmission
is initiated by writing to either the SBUF0 or SBUF1 location.
Most of the serial port controls are provided by the SCON0 and SCON1 registers. For convenience, the Table 12-2 is provided, which
summarizes the SFRs controlling serial port operation. Detailed bit descriptions can be found in Section 4.
____________________________________________________________________________________________ 108
Ultra-High-Speed Flash
Microcontroller User’s Guide
BAUD RATES
Each mode has a baud-rate generator associated with it. This generator is generally the same for each UART. Several of the baud-rate
generation techniques have options that are independent for the two UARTs. The following baud-rate descriptions are separated by
mode.
Mode 0
Mode 0 is synchronous, so the shift clock output frequency is the baud rate. Table 12-3 summarizes baud-rate generation as a func-
tion of the external oscillator frequency.
The default case is divide-by-12. The user can select the shift clock frequency using the SM2 bit in the associated SCON register. For
serial port 0, the SM2_0 bit is SCON0.5. For serial port 1, the SM2_0 bit is SCON1.5.
When SM2 is set to a logic 0, the baud rate is fixed at a divide-by-12 of the system clock frequency, unless power-management mode
is invoked. When operating in power-management mode, with the SM2 bit clear ( = 0), the serial port clock frequency is the oscillator
frequency divided by 3072.
When SM2 is set to a logic 1, the baud rate is generated using the system clock frequency divided by 4, unless power-management
mode is invoked. When power-management mode is used with the SM2 bit set ( = 1), the serial port clock frequency tracks the sys-
tem clock frequency. Note that this use of SM2 differs from a standard 80C32. In that device, SM2 had no valid use when the UART
was in mode 0. Since it was generally set to a zero, for the divide-by-12, there is no compatibility problem.
109 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Mode 2
In this asynchronous mode, baud rates are derived directly from the oscillator input. The following table summarizes baud-rate gener-
ation as a function of the external oscillator frequency. This mode works identically to the original 8051 family.
The default case is divide-by-64. The user can effectively double the serial port clock frequency by setting the SMOD bit to a logic 1
for the associated UART. For serial port 0, the SMOD_0 bit is PCON.7. This is the original location in the 8051 family. For serial port 1,
the SMOD_1 bit is WDCON.7. When operating in the power management mode (CD1:0 = 11b), the serial port clock frequency is the
oscillator frequency divided by 16384 when the SMOD bit is a logic 0 and twice that frequency (OSC/8192) when the SMOD doubler
bit is a logic 1. SMOD bits default to a logic 0 on all resets.
Mode 1 or 3
These asynchronous modes are commonly used for communication with PCs, modems, and other similar interfaces. The baud rates
and bit timing are generated using either timer 1 or timer 2. The respective timer is placed in autoreload mode. When the timer reach-
es its rollover condition (FFFFh - timer 2 or FFh - timer 1), a clock is sent to the baud-rate circuit. The baud-rate circuit generates the
exact baud rate by further dividing the clock by 16 or 32 (depending upon the UART baud-rate doubler bit).
For serial port 0, either timer 1 or 2 can be used to generate baud rates. For serial port 1, only timer 1 can be used as the baud-rate
generator. If operated in mode 1 or 3, the two UARTs may both use timer 1 for baud-rate generation, if desired.
Using Timer 1 for Baud-Rate Generation
To use timer 1 as the baud-rate generator, it is commonly put into the 8-bit autoreload mode. In this way, the CPU is not involved in
baud-rate generation. Note that the timer interrupt should not be enabled. In the 8-bit autoreload mode (timer 1, mode 2), the reload
value is stored in TH1. Thus, the combination of timer 1 input clock frequency and TH1 determine the baud rate.
The timer 1 input clock, relative to the external crystal clock, can be altered in two ways: 1) changing the system clock, or 2) chang-
ing the timer input clock divide ratio. Modifying the system clock is accomplished using the clock divide bits (CD1:0) found in the PMR
special function register. This procedure is discussed in Section 5. The timer 1 input clock divide ratio is configurable using the T1M
(CKCON.4) and T1MH (CKMOD.4) register bits. Setting the T1MH bit to a logic 1 results in the system clock being used to clock timer
1. When T1MH is clear ( = 0), setting the T1M bit to a logic 1 provides the system clock divided by 4 input to timer 1. When both T1M
and T1MH are logic 0, the Timer 1 input clock is fixed at the oscillator frequency divided by 12. When using power-management mode,
setting either T1MH or T1M to a logic 1 results in the system clock (OSC/1024) being used as the input clock to timer 1. While, if both
bits are clear ( = 0) in power-management mode, the system clock divided by 3 (OSC/3072) are provided to timer 1. The following
table summarizes the relationship between the external crystal frequency and the timer 1 input clock for the various configurations.
____________________________________________________________________________________________ 110
Ultra-High-Speed Flash
Microcontroller User’s Guide
Using timer 1 in the 8-bit autoreload mode, serial port baud rates for mode 1 or 3 can be calculated using the formula below.
Timer 1 input clock frequency can be found in the previous table, SMOD_x is the logic state of the baud-rate doubler bit for the asso-
ciated UART, and TH1 is the user assigned timer 1 reload value.
Often, users already know what baud rate is desired and only need to calculate the timer reload value. An equation to calculate the
timer reload value, TH1, is as follows:
111 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
When using timer 2 to generate baud rates, the formula is as follows. Note that the reload value is a 16-bit number, as compared with
timer 1, which uses only 8 bits. A second equation is provided so that the timer 2 reload value can be calculated for a given baud rate.
1 ✕
Timer 2 input clock frequency
Modes 1, 3 baud rate = 16 (65536–RCAP2H,RCAP2L)
____________________________________________________________________________________________ 112
Ultra-High-Speed Flash
Microcontroller User’s Guide
SBUF
OUTPUT SHIFT REGISTER
SYSTEM CLOCK P3.0
CLOCK
RXD
S0
LOAD
LATCH PIN
D7
D6
D5
D4
D3
D2
D1
D0
DIVIDE- DIVIDE-
BY-12 BY-4
0 1
LOAD SHIFT
SERIAL READ
SERIAL I/O
CONTROL
DATA LOAD
CLOCK
CLOCK
D7
D6
D5
D4
D3
D2
D1
D0
T1 R1
FLAG = FLAG =
SCONx.1 SCONx.0 SI
RECEIVE SHIFT REGISTER
SERIAL
INTERRUPT
TXD
PIN
TRANSMIT TIMING
LDSBUF WRITE TO SBUF
SHIFT
RXD
D0 D1 D2 D3 D4 D5 D6 D7
(DATA OUT)
TXD
(DATA CLOCK)
TI
RECEIVE TIMING
RDSBUF WRITE TO SCON (CLEAR RI)
SHIFT
RXD
(DATA IN) D0 D1 D2 D3 D4 D5 D6 D7
TXD
(DATA CLOCK)
RI
113 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Mode 1
Mode 1 is asynchronous and full duplex, using a total of 10 bits. The 10 bits consist of a start bit (logic 0), 8 data bits, and 1 stop bit
(logic 1) as illustrated in Figure 12-2. The data is transferred LSb first. As described above, the baud rates for mode 1 are generated
by either a divide-by-16 of timer 1 rollover, a divide-by-16 of the timer 2 rollover, or a divide-by-32 of timer 1 rollover. The UART begins
transmission after the first rollover of the divide-by-16 counter following a software write to SBUF. Transmission takes place on the TXD
pin. It begins by the start bit being placed on the pin. Data is then shifted out onto the pin, LSb first. The stop bit follows. The TI bit is
set by hardware after the stop bit is placed on the pin. All bits are shifted out at the rate determined by the baud-rate generator.
Once the baud-rate generator is active, reception can begin at any time. The REN bit (SCON0.4 or SCON1.4) must be set to a logic 1
to allow reception. The falling edge of a start bit on the RXD pin begins the reception process. Data is shifted in at the selected baud
rate. At the middle of the stop bit time, certain conditions must be met to load SBUF with the received data:
• RI must = 0, and either
• If SM2 = 0, the state of the stop bit does not matter, or
• If SM2 = 1, the state of the stop bit must = 1.
If these conditions are true, then SBUF (hex address 99h or C1h) is loaded with the received byte, the RB8 bit (SCON0.2 or SCON1.2)
is loaded with the stop bit, and the RI bit (SCON0.0 or SCON1.0) is set. If these conditions are false, then the received data is lost
(SBUF and RB8 not loaded) and RI is not set. Regardless of the receive word status, after the middle of the stop bit time, the receiver
goes back to looking for a 1 to 0 transition on the RXD pin.
Each data bit received is sampled on the 7th, 8th, and 9th clock used by the divide-by-16 counter. Using majority voting, two equal
samples out of the three determine the logic level for each received bit. If the start bit was determined to be invalid ( = 1), then the
receiver goes back to looking for a 1 to 0 transition on the RXD pin in order to start the reception of data.
Mode 2
Mode 2 uses a total of 11 bits in asynchronous full-duplex communication, as illustrated in Figure 12-3. The 11 bits consist of 1 start
bit (a logic 0), 8 data bits, 1 programmable 9th bit, and one stop bit (a logic 1). Like mode 1, the transmissions occur on the TXD sig-
nal pin and receptions on RXD. For transmission purposes, the 9th bit can be stuffed as a logic 0 or 1. A common use is to put the par-
ity bit in this location. The 9th bit is transferred from the TB8 bit position in the SCON register (SCON0.3 or SCON1.3) during the write
to SBUF. Baud rates are generated as a fixed function of the crystal frequency, as described earlier in this section. Like mode 1, mode
2’s transmission begins after the first rollover of the divide-by-16 counter following a software write to SBUF. It begins by the start bit
being placed on the TXD pin. The data is then shifted out onto the pin LSb first, followed by the 9th bit, and finally the stop bit. The TI
bit (SCON0.1 or SCON1.1) is set when the stop bit is placed on the pin.
Reception begins when a falling edge is detected as part of the incoming start bit on the RXD pin. The RXD pin is then sampled accord-
ing to the baud-rate speed. The 9th bit is placed in the RB8 bit location in SCON (SCON0.2 or SCON1.2). When a stop bit has been
received, the data value is transferred to the SBUF receive register (hex address 99 or C1). The RI bit (SCON0.0 or SCON1.0) is set to
indicate that a byte has been received. At this time, the UART can receive another byte.
Once the baud-rate generator is active, reception can begin at any time. The REN bit (SCON0.4 or SCON1.4) must be set to a logic 1
to allow reception. The falling edge of a start bit on the RXD pin begins the reception process. Data must be shifted in at the selected
baud rate. At the middle of the 9th bit time, certain conditions must be met to load SBUF with the received data.
• RI must = 0, and either
• If SM2 = 0, the state of the 9th bit does not matter, or
• If SM2 = 1, the state of the 9th bit must = 1.
If these conditions are true, then SBUF is loaded with the received byte, RB8 is loaded with the 9th bit, and RI is set. If these condi-
tions are false, then the received data is lost (SBUF and RB8 not loaded) and RI is set. Regardless of the receive word status, after the
middle of the stop bit time, the receiver goes back to looking for a 1 to 0 transition on RXD.
Data is sampled in a similar fashion to mode 1 with the majority voting on three consecutive samples. Mode 2 uses the sample divide-
by-16 counter with either the oscillator divided by 2 or 4.
____________________________________________________________________________________________ 114
Ultra-High-Speed Flash
Microcontroller User’s Guide
SBUF
TRANSMIT SHIFT REGISTER
TIMER 2 P3.1 TXD
CLOCK
S0
START
TIMER 1 OVERFLOW LATCH PIN
LOAD
STOP
OVERFLOW
D7
D6
D5
D4
D3
D2
D1
D0
AVAILABLE TO SERIAL
1 0
DIVIDE-
PORT 0 ONLY
BY-2
SMOD_0 =
PCON.7 0 1
OR
SMOD_1 = DATA BUS
WDCON.7 LDSBUF
RDSBUF
0 1
TCLK = LOAD SHIFT
T2CON.4 SBUF
SERIAL
READ
SERIAL I/O
BUFFER CONTROL RD RECEIVE DATA BUFFER WR
SERIAL
DIVIDE- BUFFER
BAUD
RCLK = BY-16
CLOCK
T2CON.5 0 1 LOAD
RESET
RB8 =
INTS
SCONx.2
T1 R1
START
CLOCK
FLAG = FLAG = STOP
D7
D6
D5
D4
D3
D2
D1
D0
SCONx.1 SCONx.0
SI
SERIAL
INTERRUPT RECEIVE SHIFT REGISTER
TRANSMIT TIMING
LDSBUF
SHIFT
TXD
START D0 D1 D2 D3 D4 D5 D6 D7 STOP
TI
RECEIVE TIMING
RXD
START D0 D1 D2 D3 D4 D5 D6 D7 STOP
BIT DETECTOR
SAMPLING
SHIFT
RI
115 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
SBUF
TRANSMIT SHIFT REGISTER
P3.1 TXD
CLOCK
S0
START
OSC/2 = LATCH PIN
LOAD
STOP
CRYSTAL/2
D8
D7
D6
D5
D4
D3
D2
D1
D0
1 0
DIVIDE-
BY-2
SMOD_0 = TB8 =
PCON.7 0 1 SCONx.3
OR
SMOD_1 =
DATA BUS
WDCON.7 LDSBUF
RDSBUF
LOAD SHIFT
SBUF
SERIAL
READ
BUFFER RD RECEIVE DATA BUFFER WR
SERIAL
SERIAL I/O
CONTROL
DIVIDE- SHIFT BUFFER
BY-16 CLOCK
LOAD
RESET
RB8 =
INTS
SCONx.2
T1 R1
START
STOP
CLOCK
FLAG = FLAG =
D8
D7
D6
D5
D4
D3
D2
D1
D0
SCONx.1 SCONx.0
SI
SERIAL
INTERRUPT RECEIVE SHIFT REGISTER
TRANSMIT TIMING
LDSBUF
SHIFT
TXD
START D0 D1 D2 D3 D4 D5 D6 D7 TB8 STOP
TI
RECEIVE TIMING
RXD
START D0 D1 D2 D3 D4 D5 D6 D7 RB8 STOP
BIT DETECTOR
SAMPLING
SHIFT
RI
____________________________________________________________________________________________ 116
Ultra-High-Speed Flash
Microcontroller User’s Guide
Mode 3
Mode 3 has the same operation as mode 2, except for the baud-rate source. As shown in Figure 12-4, mode 3 can use timer 1 or 2 for
serial port 0 and timer 1 for serial port 1. The bit shifting and protocol are the same.
SBUF
TRANSMIT SHIFT REGISTER
TIMER 2 P3.1 TXD
CLOCK
S0
START
TIMER 1 OVERFLOW LATCH PIN
LOAD
STOP
OVERFLOW
D8
D7
D6
D5
D4
D3
D2
D1
D0
AVAILABLE TO SERIAL
1 0
DIVIDE-
PORT 0 ONLY
BY-2
TB8 =
SMOD_0 =
PCON.7 0 1 SCONx.3
OR
SMOD_1 =
DATA BUS
WDCON.7 LDSBUF
RDSBUF
0 1
TCLK = LOAD SHIFT
T2CON.4 SBUF
SERIAL
READ
SERIAL I/O
BUFFER
CONTROL
SCONx.3
T1 R1
START
CLOCK
STOP
FLAG = FLAG =
D8
D7
D6
D5
D4
D3
D2
D1
D0
SCONx.1 SCONx.0
SI
SERIAL
INTERRUPT RECEIVE SHIFT REGISTER
TRANSMIT TIMING
LDSBUF
SHIFT
TXD
START D0 D1 D2 D3 D4 D5 D6 D7 TB8 STOP
TI
RECEIVE TIMING
RXD
START D0 D1 D2 D3 D4 D5 D6 D7 RB8 STOP
BIT DETECTOR
SAMPLING
SHIFT
RI
117 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Note that an address of 11110000 reaches only microcontroller 1. An address of 11110001 reaches both microcontroller 1 and micro-
controller 2. An address of 11110010 reaches only microcontroller 3.
____________________________________________________________________________________________ 118
Ultra-High-Speed Flash
Microcontroller User’s Guide
The microcontroller also matches on any address that corresponds to the broadcast address. This is the logical OR of the SADDR and
SADEN registers, with any zeros defined as don’t cares. In most cases, the broadcast address is FFh.
The multiprocessor communication is always enabled. However, the SADEN registers default to 00h, which means all address bits are
“don’t care,” so all match. Thus, if no multiprocessor communication is used, these registers can be ignored.
PROTECTION SCHEME
Each bit mentioned above is protected against an accidental write by requiring the software to perform a procedure before writing the
bit. Timed access requires the software to write two specific values to the timed-access register during two consecutive instruction
cycles. The values AAh, then 55h, must be written in consecutive instructions to the TA register at SFR location C7h. If the writes are
performed correctly, the write-access window opens for three memory cycles. During this window, the software may modify a protect-
ed bit. The suggested code to open a timed-access window is:
MOV 0C7h, #0AAh
MOV 0C7h, #55h
The procedure to modify a timed-access-protected bit begins by writing the value AAh to the timed-access register (TA;C7h). The value
55h must then be written to the timed-access register within three memory cycles of writing AAh. This opens a three memory-cycle win-
dow, after the write of 55h, during which any timed-access protected bits may be modified. Failure to complete any of the required
steps also requires the procedure to begin again, starting with the write of AAh to the timed-access register. Attempts to modify timed-
access-protected bits after the window has closed are ignored. This is regardless of whether any bits were modified. Figure 13-1 illus-
trates a number of examples of correct and incorrect use of the timed-access procedure.
119 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
Three Memory Cycles Three Memory Cycles One Memory Cycle Two Memory Cycles
MOV 0C7h, #0AAh MOV 0C7h, #55h NOP SETB EWT
Three Memory Cycles Three Memory Cycles One Memory Cycle Three Memory Cycles
MOV 0C7h, #0AAh MOV 0C7h, #55H NOP MOV WDCON, #02h
*Modification of protected bit did not occur with 3 cycles of second write to TA register.
Three Memory Cycles Three Memory Cycles Two Memory Cycles Two Memory Cycles
MOV 0C7h, #0AAh MOV 0C7h, #55h SETB EWT SETB EWT
*Modification of second protected bit did not complete within 3 cycles of second write to
TA register.
____________________________________________________________________________________________ 120
Ultra-High-Speed Flash
Microcontroller User’s Guide
A transient occurs while the op code is being fetched for the first instruction. The transient causes 1 bit of the op code in the first instruc-
tion to be read as a 0 instead of 1. The resulting program is what the microcontroller would actually execute:
TABLE_READ:
C2D2 80 0A 00 SJMP 0BH ;RELATIVE JUMP BY 10 LOCATIONS
C2D5 79 FF MOV R1, #0FFH ;LOAD COUNTER
C2D7 78 90 MOV R0, #90H ;DESTINATION POINTER
LOOP:
C2D9 E0 MOVX A, @DPTR ;READ DATA BYTE
C2DA F6 MOV @R0, A ;STORE IT IN RAM
C2DB 06 INC R0 ;NEXT TABLE LOCATION
C2DC A3 INC DPTR ;NEXT DATA VALUE
C2DD D9 C2 D9 DJNZ R1, LOOP ;NEXT BYTE OR DONE ?
The resulting jump is to address C2DE. This is not even a real op code, but would be treated as such. The resulting fetch is the value
C2 D9. This is the op code for CLR D9h. The bit-addressable location D9h corresponds to the EWT. If the timed-access procedure did
not prevent it, this errant instruction would disable the watchdog. Note that the program execution is completely lost now. Real op
codes are being replaced by operands, data, and garbage. In the ultra-high-speed microcontroller, the watchdog recovers from this
state as soon as it times out, since it could not have been disabled in this way.
In the ultra-high-speed microcontroller it is very hard to contrive a situation that accidentally disables the watchdog. Note, the timed
access prevents accidentally writing a bit. It can not prevent accidentally calling the correct code that writes a bit. This is much more
unlikely, however.
d7 d6 d5 d4 d3 d2 d1 d0 Byte 2
SUBB A, Rn 1 0 0 1 1 n2 n1 n0 98-9F 1 1 (A) = (A) - (C) - (Rn)
1 0 0 1 0 1 0 1 95
SUBB A, direct 2 2 (A) = (A) - (C) - (direct)
a7 a6 a5 a4 a3 a2 a1 a0 Byte 2
SUBB A, @Ri 1 0 0 1 0 1 1 i 96-97 1 2 (A) = (A) - (C) - ((Ri))
1 0 0 1 0 1 0 0 94
SUBB A, #data 2 2 (A) = (A) - (C) - #data
d7 d6 d5 d4 d3 d2 d1 d0 Byte 2
INC A 0 0 0 0 0 1 0 0 04 1 1 (A) = (A) + 1
INC Rn 0 0 0 0 1 n2 n1 n0 08-0F 1 1 (Rn) = (Rn) + 1
0 0 0 0 0 1 0 1 05
INC direct 2 2* (direct) = (direct) + 1
a7 a6 a5 a4 a3 a2 a1 a0 Byte 2
INC @Ri 0 0 0 0 0 1 1 i 06-07 1 2 ((Ri)) = ((Ri)) + 1
INC DPTR 1 0 1 0 0 0 1 1 A3 1 1 (DPTR) = (DPTR) + 1
DEC A 0 0 0 1 0 1 0 0 14 1 1 (A) = (A) - 1
DEC Rn 0 0 0 1 1 n2 n1 n0 18-1F 1 1 (Rn) = (Rn) - 1
0 0 0 1 0 1 0 1 15
DEC direct 2 2* (direct) = (direct) -1
a7 a6 a5 a4 a3 a2 a1 a0 Byte 2
DEC @Ri 0 0 0 1 0 1 1 i 16-17 1 2 ((Ri)) = ((Ri)) - 1
MUL AB 1 0 1 0 0 1 0 0 A4 1 9 (B15–8 ), (A7–0 ) = (A) x (B)
DIV AB 1 0 0 0 0 1 0 0 84 1 10 (A15–8 ), (A7–0 ) = (A) / (B)
121 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
INSTRUCTION CODE
MNEMONIC D7 D6 D5 D4 D3 D2 D1 D0 HEX BYTE CYCLE EXPLANATION
Contents of accumulator are BCD,
ARITHMETIC OPER
IF [[(A3-0 ) > 9] OR
[(AC) = 1]] THEN
(A3-0 ) = (A3-0 ) + 6
DA A
1 1 0 1 0 1 0 0 D4 1 2 AND
IF [[(A7-4 ) > 9] OR
[(C) = 1]] THEN
(A7-4 ) = (A7-4 ) + 6
____________________________________________________________________________________________ 122
Ultra-High-Speed Flash
Microcontroller User’s Guide
INSTRUCTION CODE
MNEMONIC D7 D6 D5 D4 D3 D2 D1 D0 HEX BYTE CYCLE EXPLANATION
RL A
0 0 1 0 0 0 1 1 23 1 1 A7 A6 A5 A4 A3 A2 A1 A0
The contents of the accumulator are
rotated left by 1 bit.
RLC A
0 0 1 1 0 0 1 1 33 1 1
C A7 A6 A5 A4 A3 A 2 A1 A0
LOGICAL OPERATION
RRC A 0 0 0 1 0 0 1 1 13 1 1
C A7 A6 A5 A4 A3 A2 A0 A1
123 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
INSTRUCTION CODE
MNEMONIC D7 D6 D5 D4 D3 D2 D1 D0 HEX BYTE CYCLE EXPLANATION
0 1 1 1 0 1 0 1 75
MOV direct,
a7 a6 a5 a4 a3 a2 a1 a0 Byte 2 3 3 (direct) = #data
#data
d7 d6 d5 d4 d3 d2 d1 d0 Byte 3
MOV @Ri, A 1 1 1 1 0 1 1 i F6-F7 1 1 ((Ri)) = A
MOV @Ri, 1 0 1 0 0 1 1 i A6-A7
2 2 ((Ri)) = (direct)
direct a7 a6 a5 a4 a3 a2 a1 a0 Byte 2
MOV @Ri, 0 1 1 1 0 1 1 i 76-77
2 2 ((Ri)) = #data
#data d7 d6 d5 d4 d3 d2 d1 d0 Byte 2
1 0 0 1 0 0 0 0 90 (DPTR) = #data15-0
MOV DPTR,
d7 d6 d5 d4 d3 d2 d1 d0 Byte 2 3 3 (DPH) = #data15-8
#data16
d7 d6 d5 d4 d3 d2 d1 d0 Byte 3 (DPL) = #data7-0
MOVC A, @A +
DATA TRANSFER
INSTRUCTION CODE
MNEMONIC D7 D6 D5 D4 D3 D2 D1 D0 HEX BYTE CYCLE EXPLANATION
CLR C 1 1 0 0 0 0 1 1 C3 1 1 (C) = 0
1 1 0 0 0 0 1 0 C2
CLR bit 2 2* (bit) = 0
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
BOOLEAN VARIABLE MANIPULATION
SETB C 1 1 0 1 0 0 1 1 D3 1 1 (C) = 1
1 1 0 1 0 0 1 0 D2
SETB bit 2 2* (bit) = 1
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
CPL C 1 0 1 1 0 0 1 1 B3 1 1 (C) = (C)
1 0 1 1 0 0 1 0 B2
CPL bit 2 2* (bit) = (bit)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
1 0 0 0 0 0 1 0 82
ANL C, bit 2 2 (C) = (C) AND (bit)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
1 0 1 1 0 0 0 0 B0
ANL C, bit 2 2 (C) = (C) AND (bit)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
1 1 1 1 0 0 1 0 72
ORL C, bit 2 2 (C) = (C) OR (bit)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
1 0 1 0 0 0 0 0 A0
ORL C, bit 2 2 (C) = (C) OR (bit)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
1 0 1 0 0 0 1 0 A2
MOV C, bit 2 2 (C) = (bit)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
1 0 0 1 0 0 1 0 92
MOV bit, C 2 2 (bit) = (C)
b7 b6 b5 b4 b3 b2 b1 b0 Byte 2
____________________________________________________________________________________________ 124
Ultra-High-Speed Flash
Microcontroller User’s Guide
INSTRUCTION CODE
MNEMONIC D7 D6 D5 D4 D3 D2 D1 D0 HEX BYTE CYCLE EXPLANATION
(PC) = (PC) + 2
(SP) = (SP) + 1
1
a10 a9 a8 0 0 0 1 Byte 1 ((SP)) = (PC7-0 )
ACALL addr 11 a8 2 2
a7 a6 a5 a3 a2 a1 a0 Byte 2 (SP) = (SP) + 1
((SP)) = (PC15-8 )
(PC) = page address
(PC) = (PC) + 3
0 0 (SP) = (SP) + 1
0 1 0 0 1 0 12
a15 a14 ((SP)) = (PC7-0 )
LCALL addr 16 a13 a12 a11 a10 a9 a8 Byte 2 3 3
a7 a6 (SP) = (SP) + 1
a5 a5 a3 a2 a1 a0 Byte 3
((SP)) = (PC15-8 )
(PC) = addr15-0
PROGRAM BRANCHING
(PC15-8 ) = ((SP))
(SP) = (SP) - 1
RET 0 0 1 0 0 0 1 0 22 1 3
(PC7-0 ) = ((SP))
(SP) = (SP) - 1
(PC15-8 ) = ((SP))
(SP) = (SP) - 1
RETI 0 0 1 1 0 0 1 0 32 1 3
(PC7-0 ) = ((SP))
(SP) = (SP) - 1
a10 a9 a8 0 0 0 0 1 Byte 1 (PC) = (PC) + 2
AJMP addr 11 2 2
a7 a6 a5 a4 a3 a2 a1 a0 Byte 2 (PC10-0 ) = page address
0 0 0 0 0 0 1 0 02
LJMP addr 16 a15 a14 a13 a12 a11 a10 a9 a8 Byte 2 3 3 (PC) = addr15-0
a7 a6 a5 a4 a3 a2 a1 a0 Byte 3
1 0 0 0 0 0 0 0 80 (PC) = (PC) + 2
SJMP rel 2 3
r7 r6 r5 r4 r3 r2 r1 r0 Byte 2 (PC) = (PC) + rel
JMP @A +
0 1 1 1 0 0 1 1 73 1 3 (PC) = (A) + (DPTR)
DPTR
(PC) = (PC) + 2
1 0 0 0 0 0 0 0 60
JZ rel 2 3 IF (A) = 0 THEN
r7 r6 r5 r4 r3 r2 r1 r0 Byte 2
(PC) = (PC) + rel
(PC) = (PC) + 2
1 0 0 0 0 0 0 0 70
JNZ rel 2 3 IF (A) ≠ 0 THEN
r7 r6 r5 r4 r3 r2 r1 r0 Byte 2
(PC) = (PC) + rel
125 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
INSTRUCTION CODE
MNEMONIC D7 D6 D5 D4 D3 D2 D1 D0 HEX BYTE CYCLE EXPLANATION
(PC) = (PC) + 2
0 1 0 0 0 0 0 0 40
JC rel 2 3 IF (C) = 1 THEN
r7 r6 r5 r4 r3 r2 r1 r0 Byte 2
(PC) = (PC) + rel
(PC) = (PC) + 2
0 1 0 1 0 0 0 0 50
JNC rel 2 3 IF (C) ≠ 0 THEN
r7 r6 r5 r4 r3 r2 r1 r0 Byte 2
(PC) = (PC) + rel
0 0 1 0 0 0 0 0 20 (PC) = (PC) + 3
JB bit, rel b7 b6 b5 b4 b3 b2 b1 b0 Byte 2 3 4 IF (bit) = 1 THEN
r7 r6 r5 r4 r3 r2 r1 r0 Byte 3 (PC) = (PC) + rel
0 0 0 1 0 0 0 0 30 (PC) = (PC) + 3
JNB bit, rel b7 b6 b5 b4 b3 b2 b1 b0 Byte 2 3 4 IF (bit) = 0 THEN
r7 r6 r5 r4 r3 r2 r1 r0 Byte 3 (PC) = (PC) + rel
(PC) = (PC) + 3
0 0 0 1 0 0 0 0 10
IF (bit) = 1 THEN
JBC bit, rel b7 b6 b5 b4 b3 b2 b1 b0 Byte 2 3 4*
(bit) = 0 and (PC) =
r7 r6 r5 r4 r3 r2 r1 r0 Byte 3
(PC) + rel
(PC) = (PC) + 3
IF (direct) < (A)
THEN (PC) = (PC)
0 0 0 1 0 0 0 0 B5
+ rel and (C) = 0
CJNE A, direct, rel a7 a6 a5 a4 a3 a2 a1 a0 Byte 2 3 5
OR
r7 r6 r5 r4 r3 r2 r1 r0 Byte 3
IF (direct) > (A)
PROGRAM BRANCHING
* Note: One additional clock cycle is required if the PSW, SP, DPS, IE, EIE, IP0, IP1, EIP0, or EIP1 register is accessed by certain direct
addressing instructions marked with an *. Additionally, the JBC bit instruction requires one additional clock cycle to clear a bit if the
jump is actually taken.
____________________________________________________________________________________________ 126
Ultra-High-Speed Flash
Microcontroller User’s Guide
127 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
PROGRAM EXECUTION
INTERNAL MEMORY DISABLED EA\ =0
INTERNAL MEMORY ENABLED EA\ =1
N
RST = 1
N
DEVICE IN RESET
EA\ = 0 (INTERNAL MEMORY ENABLED)
N
DEVICE IN RESET
PSEN\ = 0 (INTERNAL MEMORY DISABLED)
AUTOBAUD ROUTINE
AWAITING <CR> CHARACTER ON RXD OF SERIAL PORT 0
Y
SERIAL COMMUNICATION WITH THE ROM LOADER CAN PSEN\
PROCEED AS ESTABLISHED ON SERIAL PORT 0 TOGGLED 0 1
N Y
POWER-ON
RESET
____________________________________________________________________________________________ 128
Ultra-High-Speed Flash
Microcontroller User’s Guide
TO PC
TD
ROIN ROOUT RXDO
RD
TOOUT DS232A TOIN TXDO
DTR
R1IN R1OUT
DS89C420
EA
PSEN
HC/AC125
AUTOBAUD-RATE DETECTION
The serial bootstrap loader can automatically detect, within certain limits, the external baud rate and configure itself to that speed. The
loader controls serial port 0 in mode 1 (asynchronous, 1 start bit, 8 data bits, no parity, 1 stop bit, full duplex), using timer 1 in 8-bit
autoreload mode with the serial port 0 doubler bit (PCON.7) set. For these settings, an equation to calculate possible serial loader
baud rates is provided as a function of crystal frequency and timer reload value. Table 15-1 shows baud rates generated using the
equation:
Crystal Frequency
Serial Loader_Baud rate =
192 x ( 256-Timer Reload )
** Timer reload values attempted by the loader:
FF, FE, FD, FC, FB, FA, F8, F6, F5, F4, F3, F0, EC, EA, E8,
E6, E0, DD, D8, D4, D0, CC, C0, BA, B0, A8, A0, 98, 80, 60, 40
When communicating with a PC COM port having a standard 8250/16450 UART, attempt to match the loader baud rate and PC COM
port baud rate within 3% in order to maintain a reliable communication channel. If baud rates cannot be matched exactly, it is suggest-
ed configuring the loader to the faster baud rate to avoid the possibility of overflowing the DS89C420 serial input buffer.
129 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
____________________________________________________________________________________________ 130
Ultra-High-Speed Flash
Microcontroller User’s Guide
Selected commands require arguments and some commands have optional arguments. In all cases, arguments are expected to be
hexadecimal numbers. In addition, an ASCII control-C character (^C) causes the serial loader to terminate any function currently being
executed and display the command line prompt. An incoming break character (defined as a received null character (00h) with the stop
bit = 0) causes the serial bootstrap loader to be restarted and the baud rate redetermined.
COMMAND LINE SYNTAX
Single-letter ASCII characters are recognized as commands by the bootstrap loader. Arguments are represented by hexadecimal num-
bers. A hexadecimal number is any sequence of hexadecimal characters. A hexadecimal character may be a digit, 0 through 9, or
one of the letters A through F. A byte is always the right-most two digits of a hexadecimal number. An address is always the right-most
four digits of a hexadecimal number.
The C, CX, D, and DX commands allow optional addresses to be entered. The syntax [begin-address [end-address]] is used to con-
vey the following meanings:
• No arguments: Begin-address is set to 0 and end-address is set to the range.
• One argument: Begin-address is set to the argument and end-address is set to the range.
• Two arguments: Begin-address is set to the first argument and end-address is set to the second argument. This second
address must not exceed the address value specified by the range.
In the second and third bullets above, an error message is generated if the end address is less than the begin address, either implic-
itly or explicitly. The 16kB flash memory can be addressed from 0 to 3FFFh, while the external RAM can be addressed from 0 to FFFFh.
Error messages are transmitted as soon as errors are detected. All messages are preceded by the two characters E:, and followed by
a mnemonic description.
Commands are not processed until an entire command line is entered and terminated with a <CR>. No command line may be greater
than 17 bytes. Since a command line is not processed until a <CR> is entered, the <delete> character can be used to make edits.
Lines longer than 17 characters return an error message and no action is taken for that command line.
Only legal characters are echoed back by the loader. The legal characters are: 0123456789, <:>, <space>, ABCDE-
FGHIJKLMNOPQRSTUVWXYZ, and <delete>. Backspace characters (<BS>) are converted to delete characters. The horizontal tab
character is converted to space. Lowercase alphabetic characters are converted to uppercase alphabetic.
The <delete> character is executed as a <BS> <space> <BS> when possible in command mode. This causes the character to be
overprinted on a hard-copy device. The <CR> character generates a <CR> <LF> pair.
131 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
COMMAND SUMMARIES
B
Return the CRC-16 (cyclic redundancy check) of the internal ROM code. This self-CRC computation should always return 0000h.
C [begin-address [end-address]]
Return the CRC-16 (cyclic redundancy check) of the flash memory. This computation is performed over the range unless option-
al start and end addresses are given. The CRC-16 algorithm is commonly used in data communications.
CX [begin-address [end-address]]
Return the CRC-16 (cyclic redundancy check) of the external RAM. This computation is performed over the range unless option-
al start and end addresses are given. The CRC-16 algorithm is commonly used in data communications.
D [begin-address [end-address]]
Dump flash memory in Intel hex format. An optional address range may be specified. Each record contains up to 32 data bytes.
The last line printed is the end-of-data record.
DX [begin-address [end-address]]
Dump external memory in Intel hex format. This command functions in the same manner as the D command with the exception
of the target memory being external.
K
Perform an erasure of the entire flash memory range, including security block, option control register, and bank-select bit.
L
Load standard ASCII Intel hex formatted data into flash memory. No lock bits may be set when attempting to load the internal flash
program memory. Only record types 00 and 01 are processed. Each record of the file is treated the same way. All characters are
discarded before the header character <:> is read. The rest of the record, defined by the length byte, is then processed. All char-
acters following the record checksum and prior to the next <:> are discarded. Control returns to the command prompt after an
Intel end record is encountered. Prior to programming each byte, the loader performs a preread of that flash memory location to
assess whether the new hex value can be written. After programming each byte, the loader reads the flash memory location again
to verify proper programming. The processing of each record is confirmed by an ACK/NAK response. New records should not be
transmitted until the ACK/NAK byte associated with the previous record has been received.
The ACK/NAK responses are as follows:
G–good record
A–hex record received, which contains an address not programmable by the L
command: address > 3FFFh (for flash); address > 3Fh (for encryption vector)
Example: record with address > 3FFFh, which would result in the NAK response <A>:
:07403000000012040080FEF5
F–flash write error
H–hex record received contained a nonhex character
L–record length > 20 bytes (type 0); record length > 0 bytes (type 1 EOF)
P–programming error—loader detected an attempt to write 1’s to 0’s
R–hex record contained a record type not supported by the DS89C420 loader
Example: record type other than 00 or 01, which would result in the NAK response <R>:
:020000040001F9
S – hex record contained an incorrect checksum
Example record with an incorrect checksum, which would result in the NAK response <S>:
:03000000024000BC
V–data read back does not match data that was written
____________________________________________________________________________________________ 132
Ultra-High-Speed Flash
Microcontroller User’s Guide
LB
Load blind of internal flash memory—Loads standard Intel hex-formatted data into internal flash memory. This command functions
in the same manner as the L command, except that the preprogramming assessment and postprogramming verification of the
flash memory are not executed by the loader. When using this command, the P and V NAK responses are not returned by the
loader. All other ACK/NAK responses are still generated by the loader.
LE
Load encryption vector—Loads standard Intel hex-formatted data into flash security block. This command functions in the same
manner as the L command, except that it operates on the flash security block (0–3Fh).
LX
Load external memory—Loads standard Intel hex-formatted data into external memory. This command functions similar to the L
command, except that it operates on the external memory (0–FFFFh) and can write without restriction to any address location in
the range. If an external page mode or MOVX stretch cycle different from the default setting is desired, the ACON or CKCON reg-
isters should be modified prior to execution of the LX command.
R
Read—Displays the values of the lock bits, option control register, address control register, clock control register, power manage-
ment register, Ports 0, 1, 2, 3, and the flash control register in the following format:
LB:XX OCR:XX ACON:XX CKCON:XX PMR:XX P0:XX P1:XX P2:XX P3:XX FCNTL:XX
V
Verify current contents of flash memory vs. the received Intel hex. This command operates similar to the load command, except
that it does not write to the flash memory; it compares the data byte(s) in the flash memory to the byte(s) in the data stream. The
same ACK/NAK response scheme is used during verify operations as is used for load operations.
VE
Verify encryption vector—Verifies current contents of the flash security block vs. the received Intel hex. This command works in the
same manner as the V command, but operates on the flash security block (0–3Fh).
VX
Verify external memory—Verifies current contents of external memory versus the received Intel hex. This command works in the
same manner as the ‘V’ command, but operates on external memory (0–FFFFh).
W [LB | OCR | ACON | CKCON | PMR | P0 | P1 | P2 | P3] byte
Writes byte to the requested register. Valid entries for LB are 1 (enable LB1), 3 (enable LB1, LB2), and 7 (enable LB1, LB2, LB3).
ACON register writes modify only bits 7, 6, 5. CKCON register writes modify only bits 2,1, 0. PMR register writes modify only bit 0.
P3 register writes modify only P3.7–P3.2 (P3.1 and P3.0 are not altered).
^C
Interrupt whatever is going on, clear all the buffers, put up a prompt, and wait for the next command. Anything in the type-ahead
buffer is removed. All output is stopped.
ERROR MESSAGES
E:ARGREQ
An argument or arguments are required for this command.
E:BADCMD
An invalid command letter was entered.
E:BADREG
This message is printed if a register other than OCR, ACON, CKCON, PMR, P0, P1, P2, or P3 is used as the argument for the W com-
mand.
133 ____________________________________________________________________________________________
Ultra-High-Speed Flash
Microcontroller User’s Guide
E:BADVAL
The requested value cannot be programmed into the OCR register because it contains 1’s in bit position(s) where 0’s have already
been programmed.
E:EXTARG
Extra data was encountered on the command line when it was not needed. Reenter the command.
E:ILLOPT
The optional parameters given were in error. If the start address is greater than the end address, either implicitly or explicitly, then an
error is printed. The range bit implicitly determines the maximum range.
E:LOCK BITS ENABLED
The requested operation cannot be performed due to the current lock bit settings.
E:LOCK BITS ALREADY SET
The requested lock bit setting cannot be programmed because a higher order lock bit has already been programmed.
E:NOTHEX
A nonhexadecimal character was found when expecting a hexadecimal character.
E:VALUE MUST BE 1, 3 OR 7
A value other than 1, 3, or 7 was entered when trying to write the lock bits.
PARALLEL PROGRAMMING MODE
The DS89C420 parallel program load mode is compatible with most industry-standard parallel programmers (Figure 15-3). The
DS89C420 data sheet contains the most comprehensive information relating to the parallel programming mode.
____________________________________________________________________________________________ 134
Ultra-High-Speed Flash
Microcontroller User’s Guide
:200000000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20D0
:0F0020002122232425262728292A2B2C2D2E2F79
:00000001FF
REVISION HISTORY
January 24, 2001 Original Issue
October 3, 2002 Revision 1
135 ____________________________________________________________________________________________