The P89LPC9321 is a single-chip microcontroller designed for applications demanding
high-integration, low cost solutions over a wide range of performance requirements. The
P89LPC9321 is based on a high performance processor architecture that executes
instructions in two to four clocks, six times the rate of standard 80C51 devices. Many
system-level functions have been incorporated into the P89LPC9321 in order to reduce
component count, board space, and system cost.
P0.0 to P0.7I/OPort 0: Port 0 is an 8-bit I/O port with a user-configurable output type. During reset
P0.0/CMP2/ KBI0 3I/OP0.0 — Port 0 bit 0.
P0.1/CIN2B/
KBI1
P0.2/CIN2A/
KBI2
P0.3/CIN1B/
KBI3
P0.4/CIN1A/
KBI4
P0.5/CMPREF/
KBI5
P0.6/CMP1/ KBI6 20I/OP0.6 — Port 0 bit 6. High current source.
P0.7/T1/KBI719I/OP0.7 — Port 0 bit 7. High current source.
P1.0 to P1.7I/O, I
Port 0 latches are configured in the input only mode with the internal pull-up
disabled. The operation of Port 0 pins as inputs and outputs depends upon the
port configuration selected. Each port pin is configured independently. Refer to
Section 4.1 “
The Keypad Interrupt feature operates with Port 0 pins.
All pins have Schmitt triggered inputs.
Port 0 also provides various special functions as described below:
Port 1: Port 1 is an 8-bit I/O port with a user-configurable output type, except for
[1]
three pins as noted below. During reset Port 1 latches are configured in the input
only mode with the internal pull-up disabled. The operation of the configurable
Port 1 pins as inputs and outputs depends upon the port configuration selected.
Each of the configurable port pins are programmed independently. Refer to
Section 4.1 “
used as outputs. P1.5 is input only.
All pins have Schmitt triggered inputs.
Port 1 also provides various special functions as described below:
Port configurations” for details.
Port configurations” for details. P1.2 to P1.3 are open drain when
P1.2/T0/SCL12I/OP1.2 — Port 1 bit 2 (open-drain when used as output).
P1.3/INT0
P1.4/INT1
P1.5/RST
P1.6/OCB5I/OP1.6 — Port 1 bit 6. High current source.
P1.7/OCC4I/OP1.7 — Port 1 bit 7. High current source.
P2.0 to P2.7I/OPort 2: Port 2 is an 8-bit I/O port with a user-configurable output type. During reset
P2.0/ICB1I/OP2.0 — Port 2 bit 0.
P2.1/OCD2I/OP2.1 — Port 2 bit 1.
P2.2/MOSI13I/OP2.2 — Port 2 bit 2.
P2.3/MISO14I/OP2.3 — Port 2 bit 3.
P2.4/SS
/SDA11I/OP1.3 — Port 1 bit 3 (open-drain when used as output).
10I/OP1.4 — Port 1 bit 4. High current source.
6IP1.5 — Port 1 bit 5 (input only).
15I/OP2.4 — Port 2 bit 4.
…continued
OTXD — Transmitter output for serial port.
IRXD — Receiver input for serial port.
I/OT0 — Timer/counter 0 external count input or overflow output (open-drain when
used as output).
2
I/OSCL — I
IINT0
I/OSDA — I
IINT1
IRST
functioning as a reset input, a LOW on this pin resets the microcontroller, causing
I/O ports and peripherals to take on their default states, and the processor begins
execution at address 0. Also used during a power-on sequence to force ISP
mode.
OOCB — Output Compare B
OOCC — Output Compare C.
Port 2 latches are configured in the input only mode with the internal pull-up
disabled. The operation of Port 2 pins as inputs and outputs depends upon the
port configuration selected. Each port pin is configured independently. Refer to
Section 4.1 “
All pins have Schmitt triggered inputs.
Port 2 also provides various special functions as described below:
IICB — Input Capture B.
OOCD — Output Compare D.
I/OMOSI — SPI master out slave in. When configured as master, this pin is output;
when configured as slave, this pin is input.
I/OMISO — When configured as master, this pin is input, when configured as slave,
this pin is output.
I/OSS
C-bus serial clock input/output.
— External interrupt 0 input.
2
C-bus serial data input/output.
— External interrupt 1 input.
— External Reset input during power-on or if selected via UCFG1. When
I/OSPICLK — SPI clock. When configured as master, this pin is output; when
configured as slave, this pin is input.
P2.6/OCA27I/OP2.6 — Port 2 bit 6.
OOCA — Output Compare A.
P2.7/ICA28I/OP2.7 — Port 2 bit 7.
IICA — Input Capture A.
P3.0 to P3.1I/OPort 3: Port 3 is a 2-bit I/O port with a user-configurable output type. During reset
Port 3 latches are configured in the input only mode with the internal pull-up
disabled. The operation of Port 3 pins as inputs and outputs depends upon the
port configuration selected. Each port pin is configured independently. Refer to
Section 4.1 “
All pins have Schmitt triggered inputs.
Port 3 also provides various special functions as described below:
P3.0/XTAL2/
CLKOUT
P3.1/XTAL18I/OP3.1 — Port 3 bit 1.
V
SS
V
DD
9I/OP3.0 — Port 3 bit 0.
OXTAL2 — Output from the oscillator amplifier (when a crystal oscillator option is
selected via the flash configuration.
OCLKOUT — CPU clock divided by 2 when enabled via SFR bit (ENCLK -TRIM.6).
It can be used if the CPU clock is the internal RC oscillator, watchdog oscillator or
external clock input, except when XTAL1/XTAL2 are used to generate clock
source for the RTC/system timer.
IXTAL1 — Input to the oscillator circuit and internal clock generator circuits (when
selected via the flash configuration). It can be a port pin if internal RC oscillator or
watchdog oscillator is used as the CPU clock source, and if XTAL1/XTAL2 are not
used to generate the clock for the RTC/system timer.
7IGround: 0 V reference.
21IPower supply: This is the power supply voltage for normal operation as well as
Idle and Power-down modes.
Port configurations” for details.
[1] Input/output for P1.0 to P1.4, P1.6, P1.7. Input for P1.5.
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
96HRCCLKENCLKTRIM.5TRIM.4TRIM.3TRIM.2TRIM.1TRIM.0
oscillator trim
register
A7HPRE2PRE1PRE0--WDRUNWDTOFWDCLK
control register
MSBLSBHexBinary
[5][6]
[4][6]
NXP Semiconductors
P89LPC9321 User manual
UM10310
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
[1] All ports are in input only (high-impedance) state after power-up.
[2] BRGR1 and BRGR0 must only be written if BRGEN in BRGCON SFR is logic 0. If any are written while BRGEN = 1, the result is unpredictable.
[3] The RSTSRC register reflects the cause of the UM10310 reset except BOIF bit. Upon a power-up reset, all reset source flags are cleared except POF and BOF; the power-on
[4] After reset, the value is 1110 01x1, i.e., PRE2 to PRE0 are all logic 1, WDRUN = 1 and WDCLK = 1. WDTOF bit is logic 1 after watchdog reset and is logic 0 after power-on reset.
[5] On power-on reset and watchdog reset, the TRIM SFR is initialized with a factory preprogrammed value. Other resets will not cause initialization of the TRIM register.
[6] The only reset sources that affect these SFRs are power-on reset and watchdog reset.
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xx xx xxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx x x
xxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx
[1] Extended SFRs are physically located on-chip but logically located in external data memory address space (XDAT A). The MOVX A,@DPTR and MOVX @DPTR,A instructions are
used to access these extended SFRs.
[2] The BOICFG1/0 will be copied from UCFG1.5 and UCFG1.3 when power-on reset.
[3] CLKCON register reset value comes from UCFG1 and UCFG2. The reset value of CLKCON.2 to CLKCON.0 come from UCFG1.2 to UCFG1.0 and reset value of CLKDBL bit
comes from UCFG2.7.
[4] On power-on reset and watchdog reset, the PGAxTRIM8X16X and PGAxTRIM2X4X registers are initialized with a factory preprogrammed value. Other resets will not cause
initialization.
P89LPC9321 User manual
UM10310
NXP Semiconductors
002aae090
0000h
03FFh
0400h
07FFh
0800h
0BFFh
0C00h
0FFFh
SECTOR 0
SECTOR 1
SECTOR 2
SECTOR 3
1000h
13FFh
1400h
17FFh
1800h
1BFFh
1C00h
1E00h
1FFFh
SECTOR 4
SECTOR 5
SECTOR 6
FFEFh
FF00h
IAP entry-
points
SECTOR 7
ISP CODE
(512B)
(1)
SPECIAL FUNCTION
REGISTERS
(DIRECTLY ADDRESSABLE)
128 BYTES ON-CHIP
DATA MEMORY (STACK,
DIRECT AND INDIR. ADDR.)
4 REG. BANKS R[7:0]
data memory
(DATA, IDATA)
data EEPROM
DATA
128 BYTES ON-CHIP
DATA MEMORY (STACK
AND INDIR. ADDR.)
IDATA (incl. DATA)
FFEFhFFh
80h
7Fh
00h
FF1Fh
FF00h
entry points for:
-51 ASM. code
-C code
IDATA routines
1FFFh
1E00h
entry points for:
-UART (auto-baud)
-I2C, SPI, etc.
(1)
ISP serial loader
entry
points
read-protected
IAP calls only
DATA EEPROM
(512 BYTES)
[SFR ACCESS]
01FFh
0000h
EXTENDED SFRs
FFFFh
FFB0h
RESERVED
01FFh
XDATA
(512 BYTES)
0000h
1.6 Memory organization
UM10310
P89LPC9321 User manual
Fig 6.P89LPC9321 memory map
The various P89LPC9321 memory spaces are as follows:
DATA — 128 bytes of internal data memory space (00h:7Fh) accessed via direct or
indirect addressing, using instruction other than MOVX and MOVC. All or part of the Stack
may be in this area.
IDATA — Indirect Data. 256 bytes of internal data memory space (00h:FFh) accessed via
indirect addressing using instructions other than MOVX and MOVC. All or part of the
Stack may be in this area. This area includes the DATA area and the 128 bytes
immediately above it.
SFR — Special Function Registers. Sele cted CPU registers and peripheral control and
status registers, accessible only via direct addressing.
XDATA — ‘External’ Data or Auxiliary RAM. Duplicates the classic 80C51 64 kB memory
space addressed via the MOVX instruction using the DPTR, R0, or R1. All or part of this
space could be implemented on-chip. The P89LPC9321 has 512 b ytes of on-chip XDATA
memory, plus extended SFRs located in XDATA.
CODE — 64 kB of Code memory space, accessed as part of program execution and via
the MOVC instruction. The P89LPC9321 has 8 kB of on-chip Code memory.
The P89LPC9321 also has 512 bytes of on-chip Data EEPROM that is accessed via
SFRs (see Section Section 17 “
Data EEPROM”).
NXP Semiconductors
Table 4.Data RAM arrangement
TypeData RAMSize (bytes)
DATADirectly and indirectly addressable memory128
IDATAIndirectly addressable memory256
XDATAAuxiliary (‘External Data’) on-chip memory that is accessed using
2. Clocks
2.1 Enhanced CPU
The P89LPC9321 uses an enhanced 80C51 CPU which runs at six times the speed of
standard 80C51 devices. A machine cycle consists of two CPU clock cycles, and most
instructions execute in one or two machine cycles.
2.2 Clock definitions
UM10310
P89LPC9321 User manual
512
the MOVX instructions
The P89LPC9321 device has several internal clocks as defined below:
OSCCLK — Input to the DIVM clock divider. OSCCLK is selected from one of four clock
sources and can also be optionally divided to a slower frequency (see Figure 8
Section 2.10 “
CPU Clock (CCLK) modification: DIVM register”). Note: f
the OSCCLK frequency.
CCLK — CPU clock; output of the DIVM clock divider. There are two CCLK cycles per
machine cycle, and most instructions are executed in one to two machine cycles (two or
four CCLK cycles).
RCCLK — The internal 7.373 MHz RC oscillator output.The clock doubler option, when
enabled, provides an output frequency of 14.746 MHz.
PCLK — Clock for the various peripheral devices and is
2.2.1Oscillator Clock (OSCCLK)
The P89LPC9351 provides several user-selectable oscillator options in generating the
CPU clock. This allows optimization for a range of needs from high precision to lowest
possible cost. These options are configured when the flash is programmed and include an
on-chip watchdog oscillator, an on-chip RC oscillator, an oscillator using an external
crystal, or an external clock source.
2.3 External crystal oscillator option
The external crystal oscillator can be optimized for low, medium, or high frequency
crystals covering a range from 20 kHz to 18 MHz. It can be the clock source of OSCCLK
and RTC. Low speed oscillator option can be the clock source of WDT.
CCLK
⁄2.
and
is defined as
osc
2.3.1Low speed oscillator option
This option supports an external crystal in the range of 20 kHz to 100 kHz. Ceramic
resonators are also supported in this configuration.
This option supports an external crystal in the range of 100 kHz to 4 MHz. Ceramic
resonators are also supported in this configuration.
2.3.3High speed oscillator option
This option supports an external crystal in the range of 4 MHz to 18 MHz. Ceramic
resonators are also supported in this configuration.
2.4 Clock output
The P89LPC9321 supports a user-selectable clock output function on the XTAL2 /
CLKOUT pin when the crystal oscillator is not being used. This condition occurs if a
different clock source has been selected (on-chip RC oscillator, watchdog oscillator,
external clock input on X1) and if the Real-time Clock and Watchdog Timer are not using
the crystal oscillator as their clock source. This allows external devices to synchronize to
the P89LPC9321. This output is enabled by the ENCLK bit in the TRIM register.
UM10310
P89LPC9321 User manual
The frequency of this clock output is
1
⁄2 that of the CCLK. If the clock output is not needed
in Idle mode, it may be turned off prior to entering Idle, saving additional power. Note: on
reset, the TRIM SFR is initialized with a factory preprogrammed value. Therefore when
setting or clearing the ENCLK bit, the user should retain the contents of other bits of the
TRIM register. This can be done by reading the contents of the TRIM register (into the
ACC for example), modifying bit 6, and writing this result back into the TRIM register.
Alternatively, the ‘ANL direct’ or ‘ORL direct’ instructions can be used to clear or set bit 6
of the TRIM register.
2.5 On-chip RC oscillator option
The P89LPC9321 has a 6-bit TRIM register that can be used to tune the frequency of the
RC oscillator. During reset, the TRIM value is initialized to a factory pre-programmed
value to adjust the oscillator frequency to 7.373 MHz ± 1 % at room temperature. (Note:
the initial value is better than 1 %; please refer to the P89LPC9321 data sheet for
behavior over temperature). End user applications can write to the TRIM register to adjust
the on-chip RC oscillator to other frequencies. Increasing the TRIM value will decrease
the oscillator frequency. When the clock doubler option is enabled (UCFG2.7 = 1), the
output frequency is doubled. If CCLK is 8 MHz or slower, the CLKLP SFR bit (AUXR1.7)
can be set to logic 1 to reduce power consumption. On reset, CLKLP is logic 0 allowing
highest performance access. This bit can then be se t in software if CCLK is runni ng at
8 MHz or slower. When clock doubler option is enabled, BOE1 bit (UCFG1.5) and BOE0
bit (UCFG1.3) are required to hold the device in reset at power-up until V
its specified level.
Table 5.On-chip RC oscillator trim register (TRIM - address 96h) bit allocation
Bit76543210
SymbolRCCLKENCLKTRIM.5TRIM.4TRIM.3TRIM.2TRIM.1TRIM.0
Reset00Bits 5:0 loaded with factory stored value during reset.
Table 6.On-chip RC oscillator trim register (TRIM - address 96h) bit description
Bit SymbolDescription
0TRIM.0Trim value. Determines the frequency of the internal RC oscillator. During reset,
1TRIM.1
2TRIM.2
3TRIM.3
these bits are loaded with a stored factory calibration value. When writing to either
bit 6 or bit 7 of this register, care should be taken to preserve the current TRIM value
by reading this register, modifying bits 6 or 7 as required, and writing the result to
this register.
4TRIM.4
5TRIM.5
CCLK
6ENCLKwhen = 1,
⁄2 is output on the XTAL2 pin provided the crystal oscillator is not
being used.
7RCCLKwhen = 1, selects the RC Oscillator output as the CPU clock (CCLK). This allows for
fast switching between any clock source and the internal RC oscillator without
needing to go through a reset cycle.
2.6 Watchdog oscillator option
The watchdog has a separate oscillator which has a frequency of 400 kHz, calibrated to
± 5 % at room temperature. This oscillator can be used to save power when a high clock
frequency is not needed.
2.7 External clock input option
In this configuration, the processor clock is derived from an external source driving the
XT AL1 / P3.1 pin. The rate may be from 0 Hz up to 18 MHz. The XTAL2 / P3.0 pin may be
used as a standard port pin or a clock output. When using an oscillator frequency above
12 Mhz, BOE1 bit (UCFG1.5) and BOE0 bit (UCFG1.3) are required to hold the device in
reset at power-up until V
Note: The oscillator must be configured in one of the following modes: Low frequency crystal,
medium frequency crystal, or high frequency crystal.
(1) A series resistor may be required to limit crystal drive levels. This is especially important for low
P89LPC9321 can implement clock source switch in any sources of watchdog oscillator,
7/14MHz IRC oscillator, external crystal oscillator and external clock input during code is
running. CLKOK bit in register CLKCON is read only and used to indicate the clock switch
status. When CLKOK is ‘0’, clock switch is processing, not completed. When CLKOK is
‘1’, clock switch is completed. When start new clock source switch, CLKOK is cleared
automatically. Notice that when CLKOK is ‘0’, Writing to CLKCON register is not allowed.
During reset, CLKCON register value comes from UCFG1 and UCFG2. Th e reset value of
CLKCON.2 to CLKCON.0 come from UCFG1.2 to UCFG1.0 and reset value of CLKDBL
bit comes from UCFG2.7.
CPU oscillator type selection for clock switch. See Section 2
FOSC0
information. Combinations other than those shown in Table 9
use should not be used.
internal RC oscillator.
= 0, disable the external crystal oscillator as the clock source of watchdog timer.
switch is processing and writing to register CLKCON is not allowed.
for additional
are reserved for future
NXP Semiconductors
UM10310
P89LPC9321 User manual
Table 9.Oscillator type selection for clock switch
FOSC[2:0] Oscillator configuration
111External clock input on XTAL1.
100Watchdog Oscillato r, 400 kHz ± 5 %.
011Internal RC oscillator, 7.373 MHz ± 1 %.
010Low frequency crystal, 20 kHz to 100 kHz.
001Medium frequency crystal or resonator, 100 kHz to 4 MHz.
000High frequency crystal or resonator, 4 MHz to 18 MHz.
2.9 Oscillator Clock (OSCCLK) wake-up delay
The P89LPC9321 has an internal wake-up timer that delays the clock until it stabilizes
depending on the clock source used. If the clock source is any of the three crystal
selections (low, medium and high frequencies) the delay is 1024 OSCCLK cycles plus
60 μsto100μs. If the clock source is the internal RC oscillator, the delay is
200 μsto300μs. If the clock source is watchdog oscillator or external clock, the delay is
32 OSCCLK cycles.
2.10 CPU Clock (CCLK) modification: DIVM register
The OSCCLK frequency can be divided down, by an integer, up to 510 times by
configuring a dividing register, DIVM, to provide CCLK. This produces the CCLK
frequency using the following formula:
2.1 1 Low power select
3. Interrupts
CCLK frequency = f
Where: f
is the frequency of OSCCLK, N is the value of DIVM.
osc
Since N ranges from 0 to 255, the CCLK frequency can be in the range of f
(for N = 0, CCLK = f
osc
osc
).
/ (2N)
osc
to f
osc
/510.
This feature makes it possible to temporarily run the CPU at a lower rate, reducing power
consumption. By dividing the clock, the CPU can retain the ability to respond to events
other than those that can cause interrupts (i.e. events that allow exiting the Idle mode) by
executing its normal program at a lower rate. This can often result in lower power
consumption than in Idle mode. This can allow bypassing the oscillator start-up time in
cases where Power-down mode would otherwise be used. The value of DIVM may be
changed by the program at any time without interrupting code execution.
The P89LPC9321 is designed to run at 18 MHz (CCLK) maximum. However, if CCLK is
8 MHz or slower, the CLKLP SFR bit (AUXR1.7) can be se t to a logic 1 to lower the power
consumption further. On any reset, CLKLP is logic 0 allowing highest performance. This
bit can then be set in software if CCLK is running at 8 MHz or slower.
The P89LPC9321 uses a four priority level interrupt structure. This allows great flexibility
in controlling the handling of the P89LPC9321’s 15 interrupt sources.
Each interrupt source can be individually enabled or disabled by setting or clearing a bit in
the interrupt enable registers IEN0 or IEN1. The IEN0 register also contains a glo bal
enable bit, EA, which enables all interrupts.
Each interrupt source can be individually programmed to one of four priority levels by
setting or clearing bits in the interrupt priority registers IP0, IP0H, IP1, and IP1H. An
interrupt service routine in progress can be interrupted by a higher priority interrupt, but
not by another interrupt of the same or lower priority. The highest priority interrupt service
cannot be interrupted by any other interrupt source. If two requests of different priority
levels are received simultaneously, the request of higher priority level is serviced.
If requests of the same priority level are pending at the start of an instruction cycle, an
internal polling sequence determines which request is serviced. This is called the
arbitration ranking. Note that the arbit ra tio n ra nk ing is only us ed for pen din g req ue sts of
the same priority level. Table 11
addresses, enable bits, priority bits, arbitration ranking, and whether each interrupt may
wake-up the CPU from a Power-down mode.
summarizes the interrupt sources, flag bits, vector
There are four SFRs associated with the four interrupt levels: IP0, IP0H, IP1, IP1H. Every
interrupt has two bits in IPx and IPxH (x = 0, 1) and can therefore be assigned to one of
four levels, as shown in Table 11
.
The P89LPC9321 has two external interrupt inputs in addition to the Keypad Interrupt
function. The two interrupt inputs are identical to those present on the standard 80C51
microcontrollers.
These external interrupts can be programmed to be level-triggered or edge-triggered by
clearing or setting bit IT1 or IT0 in Register TCON. If ITn = 0, external interrupt n is
triggered by a low level detected at the INTn
triggered. In this mode if consecutive samples of the INTn
pin. If ITn = 1, external interrupt n is edge
pin show a high level in one
cycle and a low level in the next cycle, interrupt request flag IEn in TCON is set, causing
an interrupt request.
Since the external interrupt pins are sample d once each machine cycle, an input high or
low level should be held for at least one machine cycle to ensure proper sampling. If the
external interrupt is edge-triggered, the external source has to hold the request pin high
for at least one machine cycle, and then hold it low for at least one machine cycle. This is
to ensure that the transition is detected and that interrupt request flag IEn is set. IEn is
automatically cleared by the CPU when the service routine is called.
If the external interrupt is level-triggered, the external source must h old the re quest a ctive
until the requested interrupt is generated. If the external interrupt is still asserted when the
interrupt service routine is completed, another interrupt will be generated. It is not
necessary to clear the interrupt flag IEn when the interrupt is level sensitive, it simply
tracks the input pin level.
If an external interrupt has been programmed as level-triggered and is enabled when the
P89LPC9321 is put into Power-down mode or Idle mode, the interrupt occurrence will
cause the processor to wake-up and resume operation. Refer to Section 5.3 “
Power
reduction modes” for details. Note: the external interrupt must be programmed as
level-triggered to wake-up from Power-down mode.
3.2 External Interrupt pin glitch suppression
Most of the P89LPC9321 pins have glitch suppression circuits to reject short glitches
(please refer to the P89LPC9321 data sheet, Dynamic characteristics for glitch filter
specifications). However, pins SDA/INT0
suppression circuits. Therefore, INT1
Table 11.Summary of interrupts
DescriptionInterrupt flag
External interrupt 0IE00003hEX0 (IEN0.0)IP0H.0, IP0.01 (highest)Yes
Timer 0 interruptTF0000BhET0 (IEN0.1)IP0H.1, IP0.14No
External interrupt 1IE10013hEX1 (IEN0.2)IP0H.2, IP0.27Yes
Timer 1 interruptTF1001BhET1 (IEN0.3)IP0H.3, IP0.310No
Serial port Tx and RxTI and RI0023hES/ESR (IEN0.4)IP0H.4, IP0.413No
Serial port RxRI
Brownout detectBOIF002BhEBO (IEN0.5)IP0H.5, IP0.52Yes
Watchdog timer/Real-time
clock
2
C interruptSI0033hEI2C (IEN1.0)IP0H.0, IP0.05No
I
KBI interruptKBIF003BhEKBI (IEN1.1)IP0H.0, IP0.08Yes
Comparators 1 and 2
interrupts
SPI interruptSPIF004BhESPI (IEN1.3)IP1H.3, IP1.314No
Capture/Compare Unit 005BhECCU(IEN1.4)IP1H.4, IP1.46No
Serial port TxTI006BhEST (IEN1.6)IP0H.0, IP0.012No
Data EEPROM write
The P89LPC9321 has four I/O ports: Port 0, Port 1, Port 2, and Port 3. Ports 0, 1,and 2
are 8-bit ports, and Port 3 is a 2-bit port. The exact number of I/O pins available depends
upon the clock and reset options chosen (see Table 12
Table 12.Number of I/O pins available
Clock sourceReset optionNumber of I/O
On-chip oscillator or watchdog
oscillator
External clock inputNo external reset (except during power up) 25
Low/medium/high speed oscillator
(external crystal or resonator)
No external reset (except during power up) 26
External RST
External RST
No external reset (except during power up) 24
External RST
).
pins
pin supported25
pin supported24
pin supported23
NXP Semiconductors
4.1 Port configurations
All but three I/O port pins on the P89LPC9321 may be configured by software to one of
four types on a pin-by-pin basis, as shown in Table 13
(standard 80C51 port outputs), push-pull, open drain, and input-only. Two configuration
registers for each port select the output type for each port pin.
UM10310
P89LPC9321 User manual
. These are: quasi-bidirectional
P1.5 (RST
P1.2 (SCL/T0) and P1.3 (SDA/INT0
) can only be an input and cannot be configured.
) may only be configured to be either input-only or
open drain.
Table 13.Port output configuration settings
PxM1.yPxM2.yPort output mode
00Quasi-bidirectional
01Push-pull
10Input only (high-impedance)
11Open drain
4.2 Quasi-bidirectional output configuration
Quasi-bidirectional outputs can be used both as an input and output without the need to
reconfigure the port. This is possible because when the port outputs a logic high, it is
weakly driven, allowing an external device to pull the pin low . When the pin is driven low, it
is driven strongly and able to sink a large current. There are three pull-up transistors in the
quasi-bidirectional output that serve different purposes.
One of these pull-ups, called the ‘very weak’ pull-up, is turned on whenever the port latch
for the pin contains a logic 1. This very weak pull-up sources a very small current that will
pull the pin high if it is left floating.
A second pull-up, called the ‘weak’ pull-up, is turned on when the port latch for the pin
contains a logic 1 and the pin itself is also at a logic 1 level. This pull-up provides the
primary source current for a quasi-bidirectional pin that is outputting a 1. If this pin is
pulled low by an external device, the weak pull-up turns of f, and only the very weak pu ll-up
remains on. In order to pull the pin low under these conditions, the external device has to
sink enough current to overpower the weak pull-up and pull the port pin below its input
threshold voltage.
The third pull-up is referred to as the ‘strong’ pull-up. This pull-up is used to speed up
low-to-high transitions on a quasi-bidirectional port pin when the port latch cha nges from a
logic 0 to a logic 1. When this occurs, the strong pull-up turns on for two CPU clocks
quickly pulling the port pin high.
The quasi-bidirectional port configuration is shown in Figure 10
.
Although the P89LPC9321 is a 3 V device most of the pins are 5 V-tolerant. If 5 V is
applied to a pin configured in quasi-bidirectional mode, there will be a current flowing from
the pin to V
causing extra power consumption. Therefore, applying 5 V to pins
DD
configured in quasi-bidirectional mode is discouraged.
A quasi-bidirectional port pin has a Schmitt-triggered input that also has a glitch
(Please refer to the P89LPC9321 data sheet, Dynamic characteristics for glitch filter
specifications).
UM10310
P89LPC9321 User manual
Fig 10. Quasi-bidirectional output.
4.3 Open drain output configuration
The open drain output configuration turns off all pull-ups and only drives the pull-down
transistor of the port pin when the port latch contains a logic 0. To be used as a logic
output, a port configured in this manner must have an external pull-up, typically a resistor
tied to V
The open drain port configuration is shown in Figure 11
An open drain port pin has a Schmitt-triggered input that also has a glitch suppression
circuit.
Please refer to the P89LPC9321 data sheet, Dynamic characteristics for glitch filter
specifications.
. The pull-down for this mode is the same as for the quasi-bidirectional mode.