Philips Semiconductor’s 51MX (Memory eXtension) core is based on an accelerated 80C51 architecture that executes
instructions at twice the rate of standard 80C51 devices. The linear, unsegmented address space of the 51MX core has been
expanded from the original 64 kilobytes (KB) limit to support up to 8 megabytes (MB) of program memory and 8 MB of data
memory. It retains full prog ram code compat ibility to enable design engin eers to re use 80C51 develo pment too ls, elim inating the
need to move to a new, unfamiliar architecture. The 51MX core retains 80C51 bus compatibility to allow for the continued use of
80C51-interfaced peripherals and Application-Specific Integrated Circuits (ASICs). However, by entering the Extended
Addressing Mode in order to access either data or code beyond 64 KB, the bus interface changes.
The 51MX core is completely backward compatible with the 80C51: code written for the 80C51 may be run on 51MX-based
derivatives with no changes.
Summary of differences between the classic 80C51 architecture and the 51MX core:
• Program Counter: The Program Counter is extended to 23 bits.
• Extended Data Pointer: A 23-bit Extended Data Poi nter cal le d th e EPTR h as b ee n ad ded in order to allow simp le a dju stment
to existing assembly language programs that must be expanded to address more than 64 KB of data memory.
• Stack: Two independent alte rnate Stack mo des are adde d. The first causes addresses pu shed onto the Stac k by interrupts to
be expanded to 23 bits. The second allows Stack extension into a larger memory space.
• Instruction set: A small number of instructions have extended addressing modes to allow full use of extended code and data
addressing.
• Addressing Modes: A new addre ssing mo de, Univers al Pointe r mode, is adde d that al lows acc essi ng all of the data and cod e
areas except for SFRs using a single instruction. This mode produces major improvements in size and performance of
compiled programs.
• Six clock cycles per machine cycle.
The 51MX core is described in more details in the 51MX Architecture Reference.
1.2P87C51MX2 MICROCONTROLLERS
The P87C51Mx2 represe nts the first micr ocontroller based on the 51MX core. The P87 C51MC2 featur es 96 KB of OTP program
memory and 3 KB of data SRAM, while the P87C51MB2 has 64 KB of OTP and 2 KB of RAM. In addition, both devices are
equipped with a Programm ab le Counter Array, a watchdog timer that c an be co nfi gure d to d iffe rent time ranges, as well as two
enhanced UARTs.
The P87C51Mx2 provide s greater functionality , increased performa nce, and overall lowe r system cost. By offering an embedded
memory solution combined with the enhancements to manage the memory extension, the P87C51Mx2 eliminates the need for
software workarounds. The increased pro gram me mory enable s design eng ineers to develo p more compl ex progra ms in a highlevel language like C, for example, without struggling to contain the program within the traditional 64 KB of program memory.
These enhancements also greatly improve C language efficiency for code sizes below 64 KB.
KEY FEATURES
• 23-bit program memory space and 23-bit data memory space
• 96 KB or 64 KB of on-chip OTP
• 3 KB or 2 KB of on-chip RAM
• Up to 24 MHz CPU clock with 6 cloc k cycles per machine cycle
1Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
• Programmable Counter Array (PCA)
• Two full-duplex enhanced UARTs
KEY BENEFITS
• Increases program/data address range to 8 MB each
• Enhances performance and efficiency for C programs
• Fully 80C 51-compatible microcontroller
• Provides seamless and compelling upgrade path from classic 80C51
• Preserves 80C51 code base, investment/knowledge, and peripherals & ASICs
• Supported by 80C51 development and programming tools
• The P87C51Mx2 makes it possible to develop applications at a lower cost and with a reduced time-to-market
COMPLETE FEATURES
•Fully static
• Up to 24 MHz CPU clock with 6 cloc k cycles per machine cycle
• 96 KB or 64 KB of on-chip OTP
• 3 KB or 2 KB of on-chip RAM
• 23-bit program memory space and 23-bit data memory space
• Four interrupt priority levels
• 32 I/O lines (4 ports)
• Three Timers: Timer0, Timer1 and Timer2
• Two full-duplex enhanced UARTs with baud rate generator
• Framing error detection
• Automatic address recognition
• Power control modes
• Clock can be stopped and resumed
• Idle mode
• Power down mode
• Second D PTR registe r
• Asynchronous port reset
• Programmable Counter Array (PCA) (compatible with 8xC51Rx+) with five Capture/Compare modules
• Low EMI (inhibit ALE)
• Watchdog timer with programmable prescaler for different time ranges (compatible with 8xC66x with added prescaler)
80C51 COMPATIBILITY FEATURES OF THE 51MX CORE
• 100% binary compatibility with the classic 80C51 so that existing code is completely reusable
• Linear program and data address range expanded to support up to 8 MB each
• Program counter and data pointers expanded to 23 bits
• Stack pointer extended to 16 bits
2Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
1.3P87C51MX2 LOGIC SYMBOL
V
DD
Data Bus
PORT0
Address Bus 0-7
RXD0
TXD0
INT0
INT1
T0
T1
WR
RD
PORT3
RXD1
TXD1
RST
/Vpp
EA
PSEN
ALE/PROG
P87C51Mx2
V
SS
T2
T2EX
ECI
CEX0
PORT1
CEX1
CEX2
CEX3
CEX4
PORT2
Address Bus 8-15
XTAL2
XTAL1
Address Bus 16-22
Figure 1: P87C51Mx2 Logic Symbol
3Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
1.4P87C51MX2 BLOCK DIAGRAM
High Performance
80C51 CPU
(51MX Core)
96KB / 64KB
Code OTP
3KB / 2KB
Data RAM
Port 3
Port 2
Port 1
UART 0
Internal Bus
Baud Rate
Generator
UART 1
Timer0
Timer1
Watchdog Timer
Crystal or
Resonator
Port 0
Oscillator
Figure 2: P87C51Mx2 Block Diagram
4Preliminary 2002 June 28
PCA
(Programmable
Counter Array)
Timer2
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
2MEMORY ORGANIZATION
2.1PROGRAMMER’S MODELS AND MEMORY MAPS
The P87C51Mx2 retain s all of the 80C 51 memory s paces. Additiona l memory sp ace has been a dded transpare ntly as part of the
means for allowing extended addressing. The basic memory spaces include code memory (which may be on-chip, off-chip, or
both); external data memory ; Special Function Reg isters; and inter nal data memory, whic h includes on-chip RAM, registers, and
stack. Provision is made for internal data memory to be extended, allowing a larger processor stack.
The P87C51Mx2 programmer’s model and memory map is shown in Figure 3.
CODE
On-Chip and/or
Off-Chip
Code Memory
8 MB Code
Memory Space
7F:FFFFh
00:0000h
Two 24-bit Universal Pointers
23-bit Extended Data Pointer
Extended SFRs
Special Function
Registers
(directly addressable)
R5R6R7
R1R2R3
23-bit Program Counter
Two 16-bit DPTRs
16-bit Stack Pointer
EDATA
(includes DATA & IDATA)
Extended Data
Memory
(stack and indirect
addressing)
IDATA
(includes DATA)
256 Byte On-Chip
Data Memory
(stack and indirect
addressing)
DATA
128 Byte On-Chip
Data Memory
(stack, direct and indirect
addressing)
Four Register Banks
R0 - R7
Data Memory Space
(DATA, IDATA, EDATA)
HDATA
(includes XDATA)
7E:FFFFh
ABPSW
4FFh
Off-Chip
Data Memory
100h
FFh
00:07FFh
80h
7Fh
XDATA
1792 Bytes On-Chip
Data Memory
(P87C51MC2)
XDATA
00:06FFh
00:0300h
00:02FFh
768 Bytes On-Chip
Data Memory
00h
(P87C51MB2)
00:0000h
8 MB - 64 KB External
Data Memory Space
(XDATA, HDATA)
Figure 3: P87C51MB2/C2 Programmer’s Model and Memory Map
5Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Detailed descriptions of each of the various 51MX memory spaces may be found in the following summary.
DATA128 bytes of internal data memory space (00h...7Fh) accessed via direct or indirect addressing, using instructions
other than MOVX and MOVC. All or part of the Stack may be in this area.
IDATAIndirect 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.
EDATAExtended Data. This is a superset of DATA and IDATA areas. Both P87C51MB2 and P87C51MC2 have 1280 bytes
of SRAM in EDATA memory. The added area may be accessed only as Stack and via indirect addressing using
Universal Pointers. The Stack may reside in the extended area if enabled to do so.
SFRSpecial Function Registers. Selected CPU registers and peripheral control and status registers, accessible only via
direct addressing (addresses in range 80h...FFh). This includes the new 51MX extended SFRs.
XDATA"External" Data. Duplicates the classic 80C51 64 KB memory space addressed via the MOVX instruction using the
DPTR, R0, or R1. On-chip XDATA can be disabled under program control. Also, XDATA may be placed in external
devices. P87C51MB2 has 768 bytes of on-chip XDATA memory space and P87C51MC2 has 1792 bytes of on-chip
XDATA memory space.
HDATA"High" Data. This is a superset of XDATA and may include up to 8,323,072 bytes (8 MB - 64 KB) of memory space
addressed via the MOVX instruction u s ing the EPTR, DPTR, R0, or R1. Non XDATA portion of HDATA is placed in
external devices.
CODEUp to 8 MB of Code memory, accessed as part of program execution and via the MOVC instruction.
All of these spaces except the SFR space may also be accessed through use of Universal Pointer addressing with the EMOV
instruction. This feature is detailed in a subsequent section.
2.2DATA MEMORY (DATA, IDATA, AND EDATA)
The standard 80C51 internal data memory consists of 256 bytes of DATA/IDATA RAM, and is always entirely on-chip. In this
space are the data reg isters R 0 through R7, the de fault s tack, a bit address able RA M area, an d genera l purpos e data RAM. On
the top of the DATA/IDATA memory space is a 1 KB block of RAM that can be accessed as stack or via indirect addressing.
Alltogether this forms E DAT A RA M o f 12 80 b yte s. The different portions of the data m em ory are ac ces sed i n di fferent manners
as described in the following sections.
2.2.1REGISTERS R0 - R7
General purpose registers R0 thro ug h R7 a ll ow q ui ck , e ffi cie nt ac ce ss to a small number of internal data m emory loc ati ons . For
example, the instruction:
MOVA,R0
uses one byte of code and executes in one machine cycle. Using direct addressing to accomplish the same result as in:
MOVA,10h
requires two bytes of code me mory and execut es in two machine cyc les. Indirect addres sing further require s setup of the pointer
register, etc.
These registers are “bank ed”. The re are fou r grou ps of reg isters, an y one of whic h may b e sele cted to re presen t R0 throug h R7
at any particular time. Th is feature m ay be used to mi nimize th e time required fo r context s witching du ring an interru pt service or
a subroutine, or to provide more register space for complicated algorithms.
The registers are no different from other internal data memory locations except that they can be addressed in "shorthand"
notation as "R0", "R1", etc. Instructions addressing the internal data memory by other means, such as direct or indirect
addressing, are quite capable of accessing the same physical locations as the registers in any of the four banks.
6Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
2.2.2BIT ADDRESSABLE RAM
Internal data memory locations 20 hex through 2F hex may be accessed as both bytes and bits. This allows a convenient and
efficient way to manipulate individual flag bits without using much memory space. The bottom bit of the byte at address 20h is
bit number 00h, the next bit in the same byt e is bi t num ber 01 h, etc . The fin al bi t, bit 7 of the byte at addre ss 2Fh, is bit number
7Fh (127 decimal). Bit numbers above this refer to bits in Special Function Registers.
This code:
SETB20h.1
CPL20h.2
JNB20h.2, LABEL1
sets bit 1 at address 20 hex, complements bit 2 in the same byte, then branches if the second bit is not equal to 1. In an actual
program, these bits would normally be given names and referred to by those names in the bit manipulation instructions.
2.2.3EXTENDED DATA ME MORY (EDATA)
The 51MX architecture allows for extension of the internal data memory space beyond the traditional 256 byte limit of classic
80C51s. This space can be used as an extended or alternative processor stack space, or can be used as general purpose
storage under program control. Other than Stack Pointer based access to this space, which is automatic if Extended Stack
Memory Mode is enabled (see the following Stack section), this memory is addressed only using the new Universal Pointer
feature. Universal Pointers are described in a later section.
Both P87C51MB2 and P87C51MC2 have 1280 bytes of SRAM in EDATA memory.
2.2.4STACK
The processor stack pr ovide s a mean s to sto re interru pt and s ubrouti ne return a ddress es, as well as te mporar y data. Th e stac k
grows upwards, fro m lower addresse s towards higher addresses. The current Stack Poin ter always points to the last ite m pushed
on the stack, unless the stack is empty. Prior to a push operation, the Stack Pointer is incremented, then data is written to
memory. When the stack is popped, the reverse procedure is used. First, data is read from memory, then the Stack Pointer is
decremented.
The default configurat ion of the 51 MX stack is iden tical to the cl assic 80C5 1 stack imp lementati on. When inte rrupt or subrouti ne
addresses are pushed onto the stack, onl y the lower 16 bi ts of the Progra m Coun ter are stored. Thi s defaul t 80C51 mode stack
operation is shown in Figure 4.
7Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
0083h
0082h
Final SP Value (afte r ACALL,
LCALL or Interrupt)
Initial SP Value (before
ACALL, LCALL, or interrupt)
This figure applies to th e ACALL and
LCALL instructions in all modes. In
80C51 stack mo d e, i t al so applies to
interrupt processing.
Figure 4: Return Address Storage on the Stack (80C51 Mode)
PCH (PC.15-8)
PCL (PC.7-0)
0081h
0080h
007Fh
There are two configuratio n op tions fo r the stac k. For purp oses of backwa rd comp atibil ity with the class ic 80C5 1, both al ternate
modes are disabled by a c hip re set. Th e first option , Exten ded Int errupt Fra me Mo de, ca uses interru pts to p ush the e ntire 2 3-bi t
Program Counter onto the stack (as three bytes), and the RETI instruction to pop all 23-bits as a return address, as shown in
Figure 5. The upper bit of the stack byte containing the most significant byte of the Program Counter is forced to a "1" to be
consistent with Universal Pointer addressing.
Storing the full 23-bit Program Counter value is a requirement for systems that include more than 64 KB of program, since an
interrupt could occur at any point in the program. The Extended Interrupt Frame Mode changes the operation of interrupts and
the RETI instruct ion on ly, whi le oth er cal ls and returns are n ot affe cted. Sp ecial exte nded c all a nd retur n inst ruction s all ow large
programs to trave rse the entire code sp ac e w i th ful l 2 3-bi t return addresses. T he Ext end ed Interrupt Frame Mod e i s ena bl ed by
setting the EIFM bit in the MXCON register.
This figure applies to interrupt
services in Extended Interrupt Frame
Mode, as well as the ECALL
instruction in all modes.
The upper bit of the byte containing
PCE is forced to a "1" in order to be
consistent with Universal Pointers.
PCE (PC.22-16)
PCH (PC.15-8)
PCL (PC.7-0)
0083h
0082h
0081h
0080h
007Fh
Final SP Value (after
ECALL or interrupt)
Initial SP Value (before
ECALL or interrupt)
Figure 5: Extended Return Address Storage on the Stack
8Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
The second stack option, Extended Stack Memory Mode, allows for stack extension beyond the 256 byte limit of the classic
80C51 family. Stack extension is accomplished by increasing the Stack Pointer to 16 bits in size and allowing it to address the
entire EDATA memory rather than just the standard 256 byte internal data memory. Stack extension has no effect on the data
that is stored on the stack, it will continue to be stored as shown on in figures 4 and 5. The Extended Stack Memory Mode is
enabled by setting the ESMM bit in the MXCON register.
If the Stack Point er i s not in itia li zed b y s of tw are, the s tac k w ill be gi n a t on-chip RAM address 8, just as for the 80 C51. Als o note
that in Extended Stack Memory Mode, both MB2 and MC2 parts have 1KB of RAM on the top of DATA/IDATA space available
for the stack.
The stack mode bits ESMM and EIFM are shown in Figure 6. Note that the stack mode bits are intended to be set once during
program initialization and not altered after that point. Changing stack modes dynamically may cause stack synchronization
problems.
MXCON
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
MXCON.7 - 3-Reserved. Programs should not write a 1 to these bits.
MXCON.2EAMEnabl es Extended Add ressing Mod e, in connecti on with a non-volat ile user config uration
MXCON.1ESMMEnables the Extende d Stack Me mory M ode. W hen ESMM = 0, the Stack Pointer i s 8 bit s
MXCON.0EIFMEnables the Extended Interrupt Frame Mode. When EIFM = 0, an interrupt service will
Address: FFh (51MX Extended SFR Space)
76543210
-----EAMESMMEIFM
bit. The logical OR of the SFR bit and the non-volatile conf iguration bit deter mines whether
code and data addressing beyond 64 KB is allowed. The same logical OR value will be
read from this bit by software. When 0, all addressing (on-chip and off-chip) is limited to
64 KB each of code and data. When 1, 51MX addressing capabilities are extended
beyond boundary of 64 KB to 8 MB each of code and data, and upper address bits are
multiplexed on Port 2 for external code and/or data accesses. Refer to the External Bus
section for additional details.
EAM must be set to EAM=1 if at least one of the next two statements is true:
- there is executable code or constants in CODE space are above 64 KB
- address of data byte that has to be accessed in HDA TA is above 64 KB
in width and the sta ck is located in the IDATA m emory space. W hen ESMM = 1, th e Stack
Pointer is increased to 16-bits in width and the stack may be located anywhere in the
EDATA space. ESMM is independent of EAM and EIFM bits.
cause only the lower 16 bits of the PC to be pushed onto the stack, and an RETI
instruction will restore only the lower 16 bits of the PC. When EIFM = 1, an interrupt
service will cause all 23 bits of the PC to be pushed onto the stack, while an RETI
instruction will restore all 23 bits of the PC. EIFM must
allows execution beyond the first 64 KB of code memory.
be set to one if the application
Figure 6: MX Configuration Register (MXCON)
9Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
2.2.5GENERAL P URPOSE RAM
Portions of the intern al data mem ory tha t are not used i n a parti cular a pplic ation a s registers , stac k, or bit addr essable locations
may be considered general purpose RAM and used in any desired manner.
The lower 128 bytes of the internal data memory (DATA) may be accessed using either direct or indirect addressing. Direct
addressing incorporates the entire address within the instruction. For example, the instruction:
MOV31h,#10
will store the value 10 (decimal) in location 31 hex. Direct addresses above 128 will access the Special Function Registers rather
than the internal data memory.
Indirect addressing takes an address from either R0 or R1 of the current register bank and uses it to identify a location in the
internal data memory. The ent ire 256 byt e internal d ata memo ry space (I DATA) may be a ccessed us ing indire ct addres sing. For
example, the instruction seq uen ce :
MOVR0,#90h
MOVA,@R0
will cause the conte nts of locatio n 90 hex to be loa ded into the accum ulator. It is typ ical with the classic 80C51 to c ause the stack
to be located in the upper area, leaving more general purpose RAM in the lower area that may be accessed using both direct
and indirect add ressing. With t he 51MX, the stack may b e extended a nd moved c ompletely ou t of the low er 256 byte s of memory.
8 Bytes
7F
77
6F
67
5F
57
4F
47
3F
37
bit 7F …
2F
27
1F
17
0F
07
Figure 7: Internal Data Memory, Lower 128 Bytes
bank 3
bank 2
bank 1
bank 0
… bit 0
78
70
68
60
58
50
48
40
38
30
28
20
18
10
08
00
Undedicated
Area
Bit Addressable
Segment
Register
Banks
10Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
2.3SPECIAL FUNCTION REGISTERS (SFRS)
Special Function Registers (SFRs) provide a means for the processor to access internal control registers, peripheral devices,
and I/O ports. An SFR address is always contained entirely within an instruction.
The standard SFR sp ace is 1 28 bytes in size . SFRs are i mplemen ted in each 51MX dev ice as n eeded in order to pro vide con trol
for peripherals or access to CPU features and func tions. Undefined SFR s are considered "res erved" and should not b e accessed
by user prog rams.
Sixteen addresses in the SFR space are both byte- and bit-addressable. The bit-addressable SFRs are those whose address
ends in 0h or 8h (i.e. 80h, 88h, ..., F8h). Bit addressing allows direct control and testing of bits in those SFRs.
All 51MX devices also have ad ditional 128 by tes of extended SFRs as discussed in the "51MX Architectu re Reference". Figure s
8 and 9 show the SFR and the Extended SFR maps for P87C51MB2/C2 parts.
The XDATA space on the 51MX is the same as the 64 KB external data memory space on the classic 80C51.
On-chip XDATA memory can be disabled under program control via the EXTRAM bit in the AUXR register. Accesses above
implemented on-chip XDATA w i ll b e rou ted to th e ex ter nal bus . If o n-c hip XDATA m em ory is dis ab led , al l XDATA a cc es ses wil l
be routed to the external bus. P87C51MB2 has 768 bytes of on-chip XDATA, while P87C51MC2 has 1792 bytes of on-chip
XDATA memory.
2.5HIGH DATA MEMORY (HDATA)
The 51MX architecture supports up to an 8 MB data memory space, using 23-bit addressing. The entire 8 megabyte space
except for the 64 KB EDATA space is called HDATA. The XDATA space comprises the lower 64 KB of HDATA.
Data Pointers
The 51MX adds an addition al 23-bit Extended Data Pointer (EPTR) in order to allow a simple metho d of extending existing 80C51
programs to use mo re than 64 KB of data mem ory. If we wa nt to access a sin gle d ata by te from HDATA RAM locate d abo ve the
first 64 KB, EAM bit in MXCON sfr must be set to EAM=1.
All 80C51 instructions that use the DPTR have an 51MX variant that uses the EPTR. The 23-bit EPTR is comprised of (in order)
EPH, EPM, and EPL. Figures 10 and 11 show examples of indirect accesses to data memory using the DPTR and the EPTR
respectively. Since th e EPTR i s a 23 -bit va lue , th e 8 th b it o f EPH is not used. If read, it will ret urn a 1, like other unimplemented
bits in SFRs. Use of the EPTR allows access to the entire HDATA space, including XDATA.
12Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
At any point in time, one specific Data Pointer is active and is used by instructions that reference the DPTR. The active DPTR
may be changed by altering th e Data Pointer Select (DPS) bit. The DPS bit occupies the bo ttom bit of the AUXR 1 re gis ter. The
DPS bit applies only to the two DPTRs, not to the EPTR.
In the indirect addressing mode, the currently active DPTR or the EPTR provides a data memory address for accessing the
XDATA and HDATA space res pe ctive ly . Whe n th e D PTR i s used for a ddre ss in g, o nly the XDATA s pac e i s a vaila ble . Whe n th e
EPTR is used for addressing , the entire HD ATA spac e (which inc ludes the XDATA sp ace) may be ac cess ed. If the EPTR value
exceeds 7E:FFFF (the limit of HDATA), data accesses using EPTR will yield undefined results. The reason for limiting HDATA
addresses is to keep the add ressing uniform for EPTR addressing and Un iversal Pointer addres sing (which is expl ained in a later
section of this document).
Example Instruction:
MOVX @DPTR,A
Figure 10: External Data Memory Access using Indirect Addressing with DPTR
Example Instruction:
MOVX A,@EPTR
DPS
0
Data Pointers
0 = A17Ch
1 = 2962h
(00:A17Ch)
External Data
Memory
Location
00:A17Ch:
33h
External Data
Memory
Accumulator
33h
EPTR
0 = 01:1034h
Figure 11: External Data Memory Access using Indirect Addressing with EPTR
Location
01:1034h:
3Bh
Accumulator
13Preliminary 2002 June 28
3Bh
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
2.6PROGRAM MEMORY (CODE)
The 80C51, and th us the 51M X, ar e "Harv ard" a rchite ctures , mea ning t hat the cod e and data space s are separ ated. I f th ere is a
single byte of executable code above 64 KB, EAM bit in MXCON sfr must be set to EAM=1. Also, if there is constant in CODE
space above 64 KB boundary that is read by the application, EAM must be set to EAM=1, too.
The 51MX expands t he 80C5 1 Program C ounter t o 23 bits , providi ng a con tiguous, unsegme nted line ar code spa ce that m ay be
as large as 8 MB. On-chip space begi ns at cod e address 0 and exten ds to the limit of the on-chip code me mory. Above th at, code
will be fetched from off-chip. The 51MX architecture allows for an external bus which supports:
• Mixed mode (some code and/or data memory off-chip).
• Single-chip operation (no external bus connection).
• ROMless operation (no use of on-chip code memory).
In some cases, c ode memory m ay be address ed as data. Exte nded instruct ion address m odes provide access to th e entire code
space of 8 MB thro ugh th e use o f inde xed i ndirect add ressing. The c urrentl y act ive DP TR, th e EP TR, a U niversa l P ointer, or the
Program Counter may be used as the base address. Examples of the various code memory addressing modes are shown in
figures 12 through 14.
Following a reset, t he 51MX begin s code execut ion like a c lassic 80C51 , at address 00:0000h. Similarly, the in terrupt vectors are
placed just above the res et addre ss, start ing at add ress 00:0 003h. I t is im portan t to not e that f irst in struct ion (located at a ddress
0) should not be an EJMP instruction. EJMP is a 5 byte instruction and would overlap any instructions intended for the external
interrupt 0 vector address.
Example Instruction:
MOVC A,@A+PC
Figure 12: Code Memory Access using Indexed Indirect Addressing with the Program Counter
PC
3E:97FFh
Accumulator
D3h
(3E:98D2h)
+
Code
Memory
Location
3E:98D2h:
70h
Accumulator
70h
14Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Example Instruction:
MOVC A,@A+DPTR
executed at address 01:59B3
DPS
1
Example Instruction:
MOVC A,@A+EPTR
Data Pointers
0 = C340h
1 = FF0Ch
Figure 13: Code Memory Access using Indexe d Indir ect Addr es sing with DPTR
Accumulator
A2h
(FFAEh)
+
Upper 7 bits of
Program Counter
(01h)
01:FFAEh
01:FFAEh:
Code
Memory
Code
Memory
Location
C1h
Accumulator
C1h
Accumulator
CDh
EPTR
12:B109h
(12:B1D6h)
+
Figure 14: Code Memory Access using Indexed Indirect Addressing with EPTR
Location
12:B1D6h:
55h
Accumulator
55h
2.7UNIVERSAL POINTERS
A new addressing mode called Universal Pointer mode has been added to the 51MX, specifically for the purpose of greatly
enhancing C langua ge code density and performance. This addressing mo de allows access to any of the on-chip or off-chip code
and data spaces usi ng one i nstruc tion, w ithou t the ne ed to kn ow in advan ce whic h of the differe nt spac es the data w ill re side in.
This includes the DATA, IDATA, EDATA, XDATA, HDATA, and CODE spaces. The SFR space is the only space that may not
be accessed using the Universal Pointer mode.
15Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
The Universal Pointer addressing mode uses a new set of pointer registers for two reasons. The first is that 24-bit pointers are
needed in order to allow address ing both the 8 MB code space and the 8 MB data spac e. The other reason is that it is much more
efficient to manipulate multi-byte pointer values in registers than it is in SFRs. C compilers typically already perform pointer
manipulation in registers, then move the result to a Data Pointer for use.
Two Universal Pointers are supported: PR0 and PR1. The pointer PR0 is composed of registers R1, R2, and R3 of the current
register bank, while PR1 is composed of registers R5, R6, and R7 of the current register bank, as shown in Figure 15.
PR0
MSBLSB
R3R2R1
Figure 15: Universal Pointer Registers
In order to access all of the various memory spaces in a single unified manner, they must all be mapped into a new "view" that
allows 16 MB of total memory space. This new view is called the Universal Memory Map.
The XDATA space is placed at th e bottom of this ne w addres s map. Th e HDATA sp ace co ntinue s abov e XDATA. The sta ndard
internal data memory space s (DATA and IDATA) are above HD ATA, followed by the remainder of the EDATA sp ace. Finally, the
code memory occupies the top of the map.
Thus, the most significant bit of the Universal Pointer determines whether code or data memory is accessed. By placing the
XDATA space at the bottom of the Universal Memory Map, Universal Pointer addresses 00:0000 through 00:FFFF can
correspond to the classic 80C5 1 ex tern al da ta m em ory spa ce . Thi s al lows for full backward compatibili ty fo r co de th at do es not
need more than 64 KB o f exte rnal da ta spac e. The Univers al Me mory M ap is shown i n Figu re 16, w hile the sta ndard v iew of th e
memory spaces and how they relate to Universal Pointer values are shown in Figure 17.
The Universal Pointers are used only by a new 51MX instruction called EMOV. The EMOV instruction allows moving data via
one of the Univers al Poin ters i nto or out of t he ac cumul ator. In eithe r case , a di splac ement of 0, 1, 2, o r 3 may als o be spec ified,
which is added to th e pointer pr ior to its use. T he displace ment allows C c ompiler acc ess of variables of up to 4 b ytes in size (e. g.
Long Integers) without the need to alter the pointer value. An example of Universal Pointer usage is shown in Figure 18. Note
that it is not possible to store a value to the CODE area of the Universal Memory Map.
MSBLSB
R7R6R5
PR1
Another new instruction is added to allow incrementing one of the Universal Pointers by a value from 1 to 4. This allows the
pointer to be advanced past the last data element accessed, to the next data element.
16Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Memory SpaceAddressing Modes
FF:FFFFh
CODE
EDATA
IDATA
DATA
Up to 8 MB
on-Chip and/or off-Chip
program memory
Up to 64 KB - 256 bytes
on-chip and/or off-chip da ta
accessed as Stack and via
Universal Pointer only
Upper 128 bytes
on-chip indirectly address ed
RAM
Lower 128 bytes
on-chip directly & indirectly
addressed RAM
80:0000h
7F:FFFFh
7F:0100h
7F:00FFh
7F:0080h
7F:007Fh
7F:0000h
7E:FFFFh
PC, PC relative addressing
DPTR (lower 64 KB of Code )
EPTR
Universal Pointers: PR0, PR1
on-chip, lower 64 KB
off-chip via use of P2)
DPTR (XDATA access only)
EPTR (HDATA access)
Universal Pointers: PR0, PR1
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
16MB
CODE
CODE
EDATA
IDATA
DATA
8MB
DATA,
IDATA,
EDATA
HDATA
HDATA,
XDATA
XDATA
0
24-bit Addressing using PR1 and PR2Standard Memory Map
Figure 17: Mapping of other Addressing Modes to Universal Pointer Addressing
18Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Example Instruction:
EMOV @PR0+1,A
1
PR0
12:C340h
(12:C341h)
+
Figure 18: Memory Access using Universal Pointer Addressing
Universal Pointers a re desi gned prim arily to fa cilitate a ddressing in Extend ed Addressing Mode, wi th the EAM bi t in MXCON s et
to one. However, Universal Pointers may still be used when EAM = 0. In this case, Universal Pointer addressi ng can access only
the bottom 64 KB of the Code sp ace, th e 64 KB XD ATA space, a nd the 64 KB EDATA sp ace. The U niver sal Poi nter value s that
point to these areas do not change. When EAM = 0, Universal Pointer accesses outside of these areas are not accessible and
will return a value of FF hex.
Universal
Memory Map
Location
12:C341h:
39h
Accumulator
39h
19Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
351MX INSTRUCTIONS
The 51MX instruction set is a a true binary-level superset of the classic 80C51, designed to be fully compatible with previously
written 80C51 code. The changes to the instruction set are all related to the expanded address space. Some details of existing
instructions have been altered , and some instru ction s have had an extended mode added. In the la tter case, the alternate mo de
of the instruction is activated by preceding the instruction with a special one-byte prefix code, A5h.
An important goal i n t he i mp lem en tat ion of the 51MX was to ke ep the same timing relation sh ip o f ex is ti ng 8 0C 51 in structions to
existing devices. Any 80C51 instruction executed on the 51MX will take the same number of machine cycles to execute.
80C51 InstructionEffect of Extended Addressing
All relative branches
Includes SJMP and all cond itional branches . These instruct ions may cross a 64 KB bound ary if they
are located within branch range of the boundary.
ACALL addr11
AJMPaddr11
JMP@A+DPTR
MOVC A,@A+DPTR
MOVC A,@A+PC
MOVX @DPTR,AThe active DPTR points to an address in the 64 KB XDATA memory.
MOVX A,@DPTRThe active DPTR points to an address in the 64 KB XDATA memory.
RET
RETI
LCALL addr16
This instruction wil l cross a 64 KB bo undary if it is loc ated such tha t the next inst ruction in seq uence
is across the boundary.
This instruction wil l cross a 64 KB bo undary if it is loc ated such tha t the next inst ruction in seq uence
is across the boundary.
The lower 16-bits of the Program Counter are replaced with the value formed by the sum of the
Accumulator and the active DPTR. This instruction will cro ss a 64 KB b oundary if it is loc ate d suc h
that the next instruction in sequence is across the boundary.
The address formed by replacing the lower 16-bits of the Program Counter with the value formed
by the sum of the Ac cumulato r and the active D PTR is us ed to ac cess c ode memo ry. The PC v alue
used is that of the instruction following MOVC.
The sum of the Accumula tor and the 23 -bit Progr am Counter fo rms the 23-b it address us ed to read
the code memory. The PC value used is that of the instruction following MOVC.
Replaces the lower 16 bits of the Program Counter with a 16-bit address from the Stack. This
instruction will cross a 64 KB boundary if it is located such that the next instruction in sequence is
across the boundary.
When the extended interrupt frame mode is not ena ble d, th is ins tru cti on r eplaces the lower 16 bits
of the Program Counter with a 16-bit address from the Stack. This will cause a 64 KB boundary to
be crossed if the instruction is located such that the next instruction in sequence is across the
boundary. If the extended interrupt frame mode is enabled, a 23-bit address is loaded into the PC
from the stack.
Replaces the lower 16 bi ts of the Program Counter with th e 16-bit address. This instruction will cross
a 64 KB boundary if it is located such that the next instruction in sequence is across the boundary.
LJMPaddr16
Replaces the lower 16 bi ts of the Program Counter with th e 16-bit address. This instruction will cross
a 64 KB boundary if it is located such that the next instruction in sequence is across the boundary.
Table 1: Instructions Affected by Extended Address Space
20Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
80C51 Instruction
LCALL addr16
LJMPaddr16
JMP@A+DPTR
MOVC A,@A+DPTR
MOVX @DPTR,A
MOVX A,@DPTR
INCDPTR
MOVDPTR,#data16
RET
ORLA,Rn
ANLA,Rn
XRLA,Rn
51MX Effect
Without Prefix
Load a 16-bit address into the
Program Counter.
Load a 16-bit address into the
Program Counter.
The lower 16-bits of the
Program Counter are replac ed
with the sum of the
Accumulator and the active
DPTR.
Code memory is accessed
using the address form ed by
replacing the lower 16-bits of
the Program Counter with the
sum of the Accumulator and
the active DPTR.
The active DPTR points to an
address in the 64 KB XDATA
memory.
The active DPTR points to an
address in the 64 KB XDATA
memory.
Increment the active Data
Pointer.
Load a 16-bit value into the
active Data Pointer.
Load a 16-bit address into the
Program Counter from the
Stack.
Logically OR Register n to the
Accumulator.
Logically AND Regis ter n to the
Accumulator.
Exclusive OR Reg ister n to the
Accumulator.
51MX Enhancement
(these instructions use
the prefix byte)
ECALL addr23
EJMP addr23
JMP@A+EPTR
MOVC A,@A+EPTR
MOVX @EPTR,A
MOVX A,@EPTR
INCEPTRIncrement the 23 bit EPTR.
MOVEPTR,#data23Load a 23-bit value into the EPTR.
ERET
EMOV A,@PRi+disp
EMOV @PRi+disp,A
ADDPRi,#data2
Load a 23-bit address into the Program
Counter.
Load a 23-bit address into the Program
Counter.
The Program Counter is loaded with the
value formed by th e sum of the Accumu lator
and the EPTR.
Code memory is accessed using the
address formed by the sum of the
Accumulator and the EPTR.
The EPTR points to an addre ss anywhere in
HDATA memory (not DATA, IDATA, or
EDATA).
The EPTR points to an addre ss anywhere in
HDATA memory (not DATA, IDATA, or
EDATA).
Load a 23-bit address into the Program
Counter from the Stack.
Load the Accumulator with the value from
the Universal Memory Map at the address
formed by PR0 or PR1plus the
displacement (a value fr om 0 to 3).
Load the Universal Memory Map address
formed by PR0 or PR1 plus the
displacement (a value from 0 to 3) with the
contents of the Accumulator.
Add an immediate data va lue fr om 1 to 4 to
the specified Univers al Pointer. This is a 24bit addition.
51MX Effect with Prefix
Table 2: Enhancements to the 80C51 Instruction Set Enabled by the Prefix Byte
21Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
3.1INSTRUCTION SET SUMMARY
The following tabl e summarizes the entire 5 1MX instruc tion set. The instruction s are groupe d by type, and instruct ions that s hare
operand formats are combined. 51MX extended instructions and operand combinations are designated by
Data Movement Arithmetic & Logic Program Control Bit Operations
This 51MX opcode char t consists of four page s. The first two pages are identical to a cl assic 80C51 opc ode chart exce pt that the
A5h opcode is marked as the MX extended instruction prefix value. The third and fourth pages show instruction encoding that
follows the A5h prefix. These instructions are unique to the 51MX, and are divided into several types as shown below.
Contents of Each Table Entry:
opcode bytes/cycles
instruction mnemonic
operand(s)
51MX Extended Instruction Types:
Unmodified
80C51
Instruction
New MX
Instructions
Extended
Addressing
Instructions
Extended SFR
Addressing
Operand Definitions Used in the Tables:
addr11 : 11-bit addressbit : addressable bit#d8 : 8-bit immediate data
addr16 : 16-bit addressdir : direct address#d16 : 16-bit immediate data
addr23 : 23-bit addressrel8 : 8-bit relative address#d23 : 23-bit immediate data
These instructions are identical to classic 80C51 instructions and thus
appear only on the first two pages of the opcode chart.
These instructions are ne w to the 51MX. All are related to the Uni versal
Pointers.
These instructions incorporate extended addressing, and are modified
versions of classic 80C51 instructions.
These instructions allow access to the e xpanded SFR space. These a re
not actually new instructions, but are classic 80C51 instructions whose
function are altered by the A5h opcode.
23Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
00 1/1
NOP
01 2/2
AJMP
addr11
02 3/2
LJMP
addr16
03 1/1
RR
A
04 1/1
INC
A
05 2/1
INC
dir
06 1/1
INC
@R0
07 1/1
INC
@R1
08 1/1
INC
R0
09 1/1
INC
R1
0A 1/1
INC
R2
0B 1/1
INC
R3
0C 1/1
INC
R4
0D 1/1
INC
R5
0E 1/1
INC
R6
0F 1/1
INC
R7
10 3/2
JBC
bit,rel8
11 2/2
ACALL
addr11
12 3/2
LCALL
addr16
13 1/1
RRC
A
14 1/1
DEC
A
15 2/1
DEC
dir
16 1/1
DEC
@R0
17 1/1
DEC
@R1
18 1/1
DEC
R0
19 1/1
DEC
R1
1A 1/1
DEC
R2
1B 1/1
DEC
R3
1C 1/1
DEC
R4
1D 1/1
DEC
R5
1E 1/1
DEC
R6
1F 1/1
DEC
R7
20 3/2
JB
bit,rel8
21 2/2
AJMP
addr11
22 1/2
RET
23 1/1
RL
A
24 2/1
ADD
A,#d8
25 2/1
ADD
A,dir
26 1/1
ADD
A,@R0
27 1/1
ADD
A,@R1
28 1/1
ADD
A,R0
29 1/1
ADD
A,R1
2A 1/1
ADD
A,R2
2B 1/1
ADD
A,R3
2C 1/1
ADD
A,R4
2D 1/1
ADD
A,R5
2E 1/1
ADD
A,R6
2F 1/1
ADD
A,R7
30 3/2
JNB
bit,rel8
31 2/2
ACALL
addr11
32 1/2
RETI
33 1/1
RLC
A
34 2/1
ADDC
A,#d8
35 2/1
ADDC
A,dir
36 1/1
ADDC
A,@R0
37 1/1
ADDC
A,@R1
38 1/1
ADDC
A,R0
39 1/1
ADDC
A,R1
3A 1/1
ADDC
A,R2
3B 1/1
ADDC
A,R3
3C 1/1
ADDC
A,R4
3D 1/1
ADDC
A,R5
3E 1/1
ADDC
A,R6
3F 1/1
ADDC
A,R7
40 2/2
JC
rel8
41 2/2
AJMP
addr11
42 2/1
ORL
dir,A
43 3/2
ORL
dir,#d8
44 2/1
ORL
A,#d8
45 2/1
ORL
A,dir
46 1/1
ORL
A,@R0
47 1/1
ORL
A,@R1
48 1/1
ORL
A,R0
49 1/1
ORL
A,R1
4A 1/1
ORL
A,R2
4B 1/1
ORL
A,R3
4C 1/1
ORL
A,R4
4D 1/1
ORL
A,R5
4E 1/1
ORL
A,R6
4F 1/1
ORL
A,R7
50 2/2
JNC
rel8
51 2/2
ACALL
addr11
52 2/1
ANL
dir,A
53 3/2
ANL
dir,#d8
54 2/1
ANL
A,#d8
55 2/1
ANL
A,dir
56 1/1
ANL
A,@R0
57 1/1
ANL
A,@R1
58 1/1
ANL
A,R0
59 1/1
ANL
A,R1
5A 1/1
ANL
A,R2
5B 1/1
ANL
A,R3
5C 1/1
ANL
A,R4
5D 1/1
ANL
A,R5
5E 1/1
ANL
A,R6
5F 1/1
ANL
A,R7
60 2/2
JZ
rel8
61 2/2
AJMP
addr11
62 2/1
XRL
dir,A
63 3/2
XRL
dir,#d8
64 2/1
XRL
A,#d8
65 2/1
XRL
A,dir
66 1/1
XRL
A,@R0
67 1/1
XRL
A,@R1
68 1/1
XRL
A,R0
69 1/1
XRL
A,R1
6A 1/1
XRL
A,R2
6B 1/1
XRL
A,R3
6C 1/1
XRL
A,R4
6D 1/1
XRL
A,R5
6E 1/1
XRL
A,R6
6F 1/1
XRL
A,R7
70 2/2
JNZ
rel8
71 2/2
ACALL
addr11
72 2/2
ORL
C,bit
73 1/2
JMP
@A+DPTR
74 2/1
MOV
A,#d8
75 3/2
MOV
dir,#d8
76 2/1
MOV
@R0,#d8
77 2/1
MOV
@R1,#d8
78 2/1
MOV
R0,#d8
79 2/1
MOV
R1,#d8
7A 2/1
MOV
R2,#d8
7B 2/1
MOV
R3,#d8
7C 2/1
MOV
R4,#d8
7D 2/1
MOV
R5,#d8
7E 2/1
MOV
R6,#d8
7F 2/1
MOV
R7,#d8
Table 4: 51MX Operation Code Chart: Part 1
24Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
80 2/2
SJMP
rel8
81 2/2
AJMP
addr11
82 2/2
ANL
C,bit
83 1/2
MOVC
A,@A+PC
84 1/4
DIV
AB
85 3/2
MOV
dir,dir
86 2/2
MOV
dir,@R0
87 2/2
MOV
dir,@R1
88 2/2
MOV
dir,R0
89 2/2
MOV
dir,R1
8A 2/2
MOV
dir,R2
8B 2/2
MOV
dir,R3
8C 2/2
MOV
dir,R4
8D 2/2
MOV
dir,R5
8E 2/2
MOV
dir,R6
8F 2/2
MOV
dir,R7
90 3/2
MOV
DPTR,#d16
91 2/2
ACALL
addr11
92 2/2
MOV
bit,C
93 1/2
MOVC
A,@A+DPTR
94 2/1
SUBB
A,#d8
95 2/1
SUBB
A,dir
96 1/1
SUBB
A,@R0
97 1/1
SUBB
A,@R1
98 1/1
SUBB
A,R0
99 1/1
SUBB
A,R1
9A 1/1
SUBB
A,R2
9B 1/1
SUBB
A,R3
9C 1/1
SUBB
A,R4
9D 1/1
SUBB
A,R5
9E 1/1
SUBB
A,R6
9F 1/1
SUBB
A,R7
A0 2/2
ORL
C,/bit
A1 2/2
AJMP
addr11
A2 2/1
MOV
C,bit
A3 1/2
INC
DPTR
A4 1/4
MUL
AB
A5 -/(MX extension
prefix)
A6 2/2
MOV
@R0,dir
A7 2/2
MOV
@R1,dir
A8 2/2
MOV
R0,dir
A9 2/2
MOV
R1,dir
AA 2/2
MOV
R2,dir
AB 2/2
MOV
R3,dir
AC 2/2
MOV
R4,dir
AD 2/2
MOV
R5,dir
AE 2/2
MOV
R6,dir
AF 2/2
MOV
R7,dir
B0 2/2
ANL
C,/bit
B1 2/2
ACALL
addr11
B2 2/1
CPL
bit
B3 1/1
CPL
C
B4 3/2
CJNE
A,#d8,rel8
B5 3/2
CJNE
A,dir,rel8
B6 3/2
CJNE
@R0,#d8,rel8
B7 3/2
CJNE
@R1,#d8,rel8
B8 3/2
CJNE
R0,#d8,rel8
B9 3/2
CJNE
R1,#d8,rel8
BA 3/2
CJNE
R2,#d8,rel8
BB 3/2
CJNE
R3,#d8,rel8
BC 3/2
CJNE
R4,#d8,rel8
BD 3/2
CJNE
R5,#d8,rel8
BE 3/2
CJNE
R6,#d8,rel8
BF 3/2
CJNE
R7,#d8,rel8
C0 2/2
PUSH
dir
C1 2/2
AJMP
addr11
C2 2/1
CLR
bit
C3 1/1
CLR
C
C4 1/1
SWAP
A
C5 2/1
XCH
A,dir
C6 1/1
XCH
A,@R0
C7 1/1
XCH
A,@R1
C8 1/1
XCH
A,R0
C9 1/1
XCH
A,R1
CA 1/1
XCH
A,R2
CB 1/1
XCH
A,R3
CC 1/1
XCH
A,R4
CD 1/1
XCH
A,R5
CE 1/1
XCH
A,R6
CF 1/1
XCH
A,R7
D0 2/2
POP
dir
D1 2/2
ACALL
addr11
D2 2/1
SETB
bit
D3 1/1
SETB
C
D4 1/1
DA
A
D5 3/2
DJNZ
dir,rel8
D6 1/1
XCHD
A,@R0
D7 1/1
XCHD
A,@R1
D8 2/2
DJNZ
R0,rel8
D9 2/2
DJNZ
R1,rel8
DA 2/2
DJNZ
R2,rel8
DB 2/2
DJNZ
R3,rel8
DC 2/2
DJNZ
R4,rel8
DD 2/2
DJNZ
R5,rel8
DE 2/2
DJNZ
R6,rel8
DF 2/2
DJNZ
R7,rel8
E0 1/2
MOVX
A,@DPTR
E1 2/2
AJMP
addr11
E2 1/2
MOVX
A,@R0
E3 1/2
MOVX
A,@R1
E4 1/1
CLR
A
E5 2/1
MOV
A,dir
E6 1/1
MOV
A,@R0
E7 1/1
MOV
A,@R1
E8 1/1
MOV
A,R0
E9 1/1
MOV
A,R1
EA 1/1
MOV
A,R2
EB 1/1
MOV
A,R3
EC 1/1
MOV
A,R4
ED 1/1
MOV
A,R5
EE 1/1
MOV
A,R6
EF 1/1
MOV
A,R7
F0 1/2
MOVX
@DPTR,A
F1 2/2
ACALL
addr11
F2 1/2
MOVX
@R0,A
F3 1/2
MOVX
@R1,A
F4 1/1
CPL
A
F5 2/1
MOV
dir,A
F6 1/1
MOV
@R0,A
F7 1/1
MOV
@R1,A
F8 1/1
MOV
R0,A
F9 1/1
MOV
R1,A
FA 1/1
MOV
R2,A
FB 1/1
MOV
R3,A
FC 1/1
MOV
R4,A
FD 1/1
MOV
R5,A
FE 1/1
MOV
R6,A
FF 1/1
MOV
R7,A
Table 5: 51MX Operation Code Chart: Part 2
25Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
02 5/4
EJMP
addr23
05 3/2
INC
dir
10 4/3
JBC
bit,rel8
12 5/4
ECALL
addr23
15 3/2
DEC
dir
20 4/3
JB
bit,rel8
22 2/4
ERET
25 3/2
ADD
A,dir
30 4/3
JNB
bit,rel8
35 3/2
ADDC
A,dir
42 3/2
ORL
dir,A
43 4/3
ORL
dir,#d8
45 3/2
ORL
A,dir
48 2/4
EMOV
A,@PR0+0
49 2/4
EMOV
A,@PR0+1
4A 2/4
EMOV
A,@PR0+2
4B 2/4
EMOV
A,@PR0+3
4C 2/4
EMOV
A,@PR1+0
4D 2/4
EMOV
A,@PR1+1
4E 2/4
EMOV
A,@PR1+2
4F 2/4
EMOV
A,@PR1+3
52 3/2
ANL
dir,A
53 4/3
ANL
dir,#d8
55 3/2
ANL
A,dir
58 2/4
EMOV
@PR0+0,A
59 2/4
EMOV
@PR0+1,A
5A 2/4
EMOV
@PR0+2,A
5B 2/4
EMOV
@PR0+3,A
5C 2/4
EMOV
@PR1+0,A
5D 2/4
EMOV
@PR1+1,A
5E 2/4
EMOV
@PR1+2,A
5F 2/4
EMOV
@PR1+3,A
62 3/2
XRL
dir,A
63 4/3
XRL
dir,#d8
65 3/2
XRL
A,dir
68 2/4
ADD
PR0,#4
69 2/4
ADD
PR0,#1
6A 2/4
ADD
PR0,#2
6B 2/4
ADD
PR0,#3
6C 2/4
ADD
PR1,#4
6D 2/4
ADD
PR1,#1
6E 2/4
ADD
PR1,#2
6F 2/4
ADD
PR1,#3
72 3/3
ORL
C,bit
73 2/2
JMP
@A+EPTR
75 4/3
MOV
dir,#d8
Table 6: 51MX Operation Code Chart: Part 3
26Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
82 3/3
ANL
C,bit
85 4/3
MOV
dir,dir
86 3/3
MOV
dir,@R0
87 3/3
MOV
dir,@R1
88 3/3
MOV
dir,R0
89 3/3
MOV
dir,R1
8A 3/3
MOV
dir,R2
8B 3/3
MOV
dir,R3
8C 3/3
MOV
dir,R4
8D 3/3
MOV
dir,R5
8E 3/3
MOV
dir,R6
8F 3/3
MOV
dir,R7
90 5/4
MOV
EPTR,#d23
92 3/3
MOV
bit,C
93 2/4
MOVC
A,@A+EPTR
95 3/2
SUBB
A,dir
A0 3/3
ORL
C,/bit
A2 3/2
MOV
C,bit
A3 2/2
INC
EPTR
A6 3/3
MOV
@R0,dir
A7 3/3
MOV
@R1,dir
A8 3/3
MOV
R0,dir
A9 3/3
MOV
R1,dir
AA 3/3
MOV
R2,dir
AB 3/3
MOV
R3,dir
AC 3/3
MOV
R4,dir
AD 3/3
MOV
R5,dir
AE 3/3
MOV
R6,dir
AF 3/3
MOV
R7,dir
B0 3/3
ANL
C,/bit
B2 3/2
CPL
bit
B5 4/3
CJNE
A,dir,rel8
C0 3/3
PUSH
dir
C2 3/2
CLR
bit
C5 3/2
XCH
A,dir
D0 3/3
POP
dir
D2 3/2
SETB
bit
D5 4/3
DJNZ
dir,rel8
E0 2/4
MOVX
A,@EPTR
E5 3/2
MOV
A,dir
F0 2/4
MOVX
@EPTR,A
F5 3/2
MOV
dir,A
Table 7: 51MX Operation Code Chart: Part 4
27Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
4EXTERNAL BUS
The external bus provides add res s inf ormation to external devices, and initia tes cod e read, data read , or data w rite opera tio ns.
In 51MX devices, the external bus duplicates the classic 80C51 multiplexed external bus, but allows increasing the address
output to 23 bits.
4.1MULTIPLEXED EXTERNAL BUS
The 51MX external bus supports 8-bit data transfers and up to 23 address lines. The number of address lines available is
configurable, and depends on the setting of the EAM bit in the MXCON register.
The default for an unprogrammed part following reset is 16 address bits. This provides drop-in compatibility in existing 80C51
sockets. A non-volatile configuration bit allows pre-selecting a 23-bit address size at the time that the part is programmed.
Software may later enable the extended addressing mode even if the pre-programmed configuration does not.
The non-volatile address configuration is im ple me nte d u sin g EPR OM tec hn olo gy . Th e c onfiguration is comprised of a single bit
that enables multiplexing of the 7 extended address bits on Port 2. If the non-volatile configuration bit is not programmed,
extended addressing may be enabled at run time via the EAM bit in the MXCON SFR. Software may write a 1 to MXCON,
changing the def ault configurati on. Typically , this would be done a single time. If softwar e reads the EAM bit in MXCON, the value
will be the logical OR of the non-volatile configuration bit and the MXCON.EAM bit value. It is not recommended to change the
address configuration dynamically during program execution (for example: changing EAM=1 to EAM=0 changes external
memory bus interfac e and preve nts c ore from ex ecuti ng co de abo ve th e 64 KB bounda ry). The enco ding o f the c onfig uration bit
is such that an unprogrammed device is configured for 16 address lines.
When the full 23-bit address is multiplex ed on Port 2 (when the EAM bit in MXCON = 1), the high order addre ss informatio n (bits
A22 through A16) must be latched externally in the same manner as the low order bits (A7 through A0) on Port 0. The middle
address bits (A15 through A8 ) appe ar on Port 2 aft er ALE go es low. If ex ten ded addressing is not enabled , Port 2 b eha ve s ju st
as on a classic 80C51. An example of Port 2 address multiplexing is shown in Figure 19.
There are two special cases for Port 2 multiplexing when extended addressing is enabled: MOVX @Ri and MOVX @DPTR.
These instructions do not supply a source for a full 23-bit external address. Where program memory is involved (jumps and
MOVC), any "missing" addre ss bits are supplied by the Program Counter (se e Table 1). For MOVX, th e additional bi ts are forced
to zeroes to complete the addres s. So, MOVX @Ri will output a 23-bit add ress composed of seven zeroes for the upper address,
Port 2 SFR contents for the middle byte of the ad dress, and Ri conten ts for the bottom byte. Similarly, MOVX @DPTR will output
a 23-bit address composed of seven zeroes for the upper address and the current DPTR contents for the middle and bottom
bytes of the address.
If we have a single-chip application with code exceeding 64 KB (and thus having EAM=1) and if an old 51 bus interface has to
be preserved, instead of using MOVX @Ri,A the instruction EMOV @PRi,A should be used. If we load the content of P2 sfr to
R3 and R2, exe cutio n of i nstruc tion EMOV @ PR0 ,A will have exac tly t he sa me outpu t in a sy stem with EAM =1 as it i s in case of
MOVX @R0,A in a design with standard 51bus interface.
Some 51MX appli cations may use extended addressin g and rel y on s oftware setting t he EAM bi t in MXC ON (i.e. the non -volatile
address configuration bit is not prog ram me d). If su ch an app lic ati on is set up suc h tha t the fi rst co de exec ute d upo n res et is offchip, then the instruction that sets the EAM bit in MXCON must be located at or below address 00FBh. This is to prevent the
external bus from supplying a 16-bit address when a 23-bit address is required. If the Program Counter were to reach address
0100h while EAM = 0, the apparent address (to external hardware that is expecting a 23-bit address) would become 01:0100.
28Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
S1S2S3S4S5S6S1S2
ALE
P2
P0
high
address
low
address
middle
address
instruction
data in
high
address
low
address
middle
address
instruction
data in
low
address
PSEN
Figure 19: Example of External Code Memory Read Cycles using 23 Address Bits
The standard control signals and their functions for the external bus are as follows:
Signal name
Function
ALEAddress Latch Enable. This signal directs an external address latch to store the multiplexed portion of the
address for the next bus operation. This may be either a data address or a code address.
PSEN
Program Store Enable. Indicates that the processor is reading code from the bus. Typically connected to the
Output Enable pin of external EPROMs or other memory devices. External bus addresses for code memory
may range from 00:0000 through 7F:FFFF. In the Universal Memory Map, these correspond to addresses
80:0000 through FF:FFFF
RD
WR
Read. The external data read strobe. Typically connected to the RD pin of external peripheral devices.
Write. The write strobe for external data. Typically connected to the WR pin of external peripheral devices.
External bus addresses for data memory may range from 00:0000 through 7E:FFFF, which matches Universal Memory Map
addresses. If on-chip XDAT A is enabled , it will c ause an addres sing disco ntinuity i n the extern al data addre ss space. Th e DATA
and IDATA spaces are always on-chip, and therefore always create such an addressing discontinuity.
29Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
5INTERRUPT PROCESSING
The P87C51Mx2 uses a four priority level interrupt structure. This allows great flexibility in controlling the handling of the many
interrupt sources. The P87C51Mx2 has ten interrupt sources.
Each interrupt source can be individually enabled or disabled by setting or clearing a bit in registers IEN0 or IEN1. The IEN0
register also contains a global disable bit, EA, which disables all interrupts at once.
Each interrupt source can be individually programmed to one of four priority levels by setting or clearing bits in the IP0, IP0H,
IP1, and IP1H registers. An i nterrupt service routine in prog ress can be interrupted by a higher priority interrup t, but not by another
interrupt of the same or lower priority. The highest priority interrupt service cannot be interrupted by any other interrupt source.
So, 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 received simultaneously, an internal polling sequence determines which request is
serviced. This is c al led th e a r bi trati on ran ki ng. N ote th at the arb itra t io n ra nk ing i s onl y us ed to resolve simultaneo us requests of
the same priority level.
Table 8 summarize s the inte rrupt sourc es, flag bits, ve ctor addres ses, en able bits , priority bits, pol ling prior ity, and w hether each
interrupt may wake up the CPU from Power Down mode.
Description
Interrupt
Flag Bit(s)
Vector
Address
Interrupt
Enable Bit(s)
Interrupt
Priority
Polling
Priority
Power Down
Wakeup
External Interrupt 0IE00003hEX0 (IEN0.0)IP0H.0, IP0.01 (highest)Yes
Timer 0 InterruptTF0000BhET0 (IEN0.1)IP0H.1, IP0.12No
External Interrupt 1IE10013hEX1 (IEN0.2)IP0H.2, IP0.23Yes
Timer 1 InterruptTF1001BhET1 (IEN0.3)IP0H.3, IP0.34No
Serial Port 0 Tx and Rx
Serial Port 0 Rx
1
1,5
TI_0 & RI_0
RI_0
5
0023hES0(IEN0.4)IP0H.4, IP0.46No
Timer 2 InterruptTF2, EXF20 02BhET2 (IEN0.5)IP0H.5, IP0.57No
PCA interruptCF, CCFn*0033hEC (IEN0.6)IP0H.6, IP0.65No
Serial Port 1 Tx and Rx
Serial Port 1 Rx
Serial Port 0 Tx
Serial Port 1 Tx
1. S0STAT.5 = 0 selects combined Serial Port 0 Tx and Rx interrupt; S0ST AT.5 = 1 selec ts Serial Port 0 Rx interrupt o nly (and
TX interrupt will be different, see Note 3 below).
2. S1STAT.5 = 0 selects combined Serial Port 1 Tx and Rx interrupt; S1ST AT.5 = 1 selec ts Serial Port 1 Rx interrupt o nly (and
TX interrupt will be different, see Note 4 below).
3. This interrupt is used as Serial Port 0 Tx interrupt if and only if S0STAT.5 = 1, and is disabled otherwise.
4. This interrupt is used as Serial Port 1 Tx interrupt if and only if S1STAT.5 = 1, and is disabled otherwise.
5. If S0STAT.0 = 1, the following Serial Port 0 additional flag bits can cause this interrupt: FE_0, BR_0, OE_0.
6. If S1STAT.0 = 1, the following Serial Port 1 additional flag bits can cause this interrupt: FE_1, BR_1, OE_1.
IEN1.7-3-Reserved for future use. Should be set to 0 by user programs.
IEN1.2ES1TIf S1STAT.5 = 1, it is Serial Port 1 Transmit Interrupt Enable. If S1STAT.5 = 0, this
interrupt is disabled anyway.
IEN1.1ES0TIf S0STAT.5 = 1, it is Serial Port 0 Transmit Interrupt Enable. If S0STAT.5 = 0, this
interrupt is disabled anyway.
IEN1.0ES1/ES1RSerial Port 1 Combined Interrupt Enable (S1STAT.5 = 0)/Serial Port 1 Receive Interrupt
Enable (S1STAT.5 = 1).
Figure 21: Interrupt Enable Register IEN1
31Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
IP0
Bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
IP0.7-Reserved for future use. Should be set to 0 by user programs.
IP0.6PPCPCA Interrupt Priority bit Low Bit.
IP0.5PT2Timer 2 Interrupt Priority Low Bit.
IP0.4PS0/PS0RSerial Port 0 Combined Interrupt (S0STAT.5 = 0)/Receive Interrupt (S0STAT.5 = 1)
IP0H.7-Reserved for future use. Should be set to 0 by user programs.
IP0H.6PPCHPCA Interrupt Priority bit High Bit.
IP0H.5PT2HTimer 2 Interrupt Priority High Bit.
IP0H.4PS0H/PS0RHSerial Port 0 Combined Interrupt (S0STAT.5 = 0)/Receive Interrupt (S0STAT.5 = 1)
Priority High Bit.
IP0H.3PT1HTimer 1 Interrupt Priority High Bit.
IP0H.2PX1HExternal Interrupt 1 Priority High Bit.
IP0H.1PT0HTimer 0 Interrupt Priority High Bit.
IP0H.0PX0HExternal Interrupt 0 Priority High Bit.
Figure 23: Interrupt Priority High Byte IP0H
32Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
IP1
Bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
IP1.7-3-Reserved for future use. Should be set to 0 by user programs.
IP1.2PS1TSerial Port 1 transmit Interrupt (S1STAT.5 = 1) Priority Low Bit.
IP1.1PS0TSerial Port 0 transmit Interrupt (S0STAT.5 = 1) Priority Low Bit.
IP1.0PS1/PS1RSerial Port 1 combined Interrupt (S1STAT.5 = 0)/receive Interrupt (S1STAT.5 = 1) Priority
IP1H
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
IP1H.7-3-Reserved for future use. Should be set to 0 by user programs.
IP1H.2PS1THSerial Port 1 transmit Interrupt (S1STAT.5 = 1) Priority High Bit.
IP1H.1PS0THSerial Port 0 transmit Interrupt (S0STAT.5 = 1) Priority High Bit.
IP1H.0PS1H/PS1RHSerial Port 1 combined Interrupt (S1STAT.5 = 0)/receive Interrupt (S1STAT.5 = 1) Priority
Address: F8H
Address: F7H
76543210
-----PS1TPS0T
Low Bit.
Figure 24: Interrupt Priority Register 1
76543210
-----PS1THPS0TH
High Bit.
PS1/PS1R
PS1H/PS1RH
Figure 25: Interrupt Priority Register 1 High Byte
33Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6P87C51MX2 PORTS, POWER CONTROL AND
PERIPHERALS
6.1SPECIAL FUNCTION REGISTERS
Note: Special Function Registers (SFRs) accesses are restricted in the following ways:
1. User must NOT attempt to access any SFR locations not defined.
2. Accesses to any defined SFR locations must be strictly for the functions for the SFRs.
3. SFR bits labeled ’-’, ’0’ or ’1’ can ONLY be written and read as follows:
- ’-’ MUST be written with ’0’, but can return any value when read (even if it was written with ’0’). It is a reserved bit and may
be used in future derivatives.
- ’0’ MUST be written with ’0’, and will return a ’0’ when read.
- ’1’ MUST be written with ’1’, and will return a ’1’ when read.
Special Function Registers
SYMBOLDESCRIPTION
ACC*AccumulatorE0H00H
AUXR#Auxiliary Function Register 8EH------EXTRAMAO00H
AUXR1#Auxiliary Function Register 1A2H---LPEPGF20-DPS00H
S0BUFSerial Port 0 Data Buffer Register99HxxH
S0ADDRSerial Port 0 Address RegisterA9H00H
S0ADENSerial Port 0 Address EnableB9H00H
S0STAT# Serial Port 0 Status
8CH
‡
DBMOD_
0
INTLO_0 CIDIS_0 DBISEL_0FE_0BR_0OE_0STINT_000H
&
%
S1CON#* Serial Port 1 Control
80H
S1BUF#Serial Port 1 Data buffer Register81H
S1ADDR# Serial Port 1 Address Register82H
S1ADEN# Serial Port 1 Address Enable83H
S1STAT# Serial Port 1 Status
SPStack Pointer (or Stack Pointer
Low Byte When EDATA
84H
81H
Supported)
SPE#Stack Pointer HighFBH
TCON*Timer Control Register88H
‡
‡
‡
‡
‡
‡
‡
87
SM0_1/
FE_1
DBMOD_
1
‡
86
‡
85
‡
84
‡
83
‡
82
SM1_1SM2_1REN_1TB8_1RB8_1TI_1RI_100H
INTLO_1 CIDIS_1 DBISEL1FE_1BR_1OE_1STINT_100H
8F8E8D8C8B8A8988
TF1TR1TF0TR0IE1IT1IE0IT0
36Preliminary 2002 June 28
‡
81
‡
80
XXH
00H
00H
%
00H
00H
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Special Function Registers (Continued)
SYMBOLDESCRIPTION
T2CON#* Time r2 Control RegisterC8H
T2MOD#Timer2 Mode C ont rolC9H
T H0T im er 0 Hi g h8 CH00H
T H1T im er 1 Hi g h8 DH00H
T H2T im er 2 Hi g hCD H00H
TL0Timer 0 Low8AH00H
TL1Timer 1 Low8BH00H
TL2Timer 2 LowCCH00H
TMODTimer 0 and 1 Mode89HGATEC/TM1M0GATEC/TM1M000H
WDTRST# Watchdog Ti m er Rese tA6HFFH
WDCON# Watchdog Timer Cont rol8F H
DIRECT
ADDRESS
‡
MSB
CFCECDCCCBCAC9C8
TF2EXF2RCLKTCLKEXEN2TR2C/T2
BIT ADDRESS, SYMBOL, OR ALTERNATE PORT FUNCTION
LSB
CP/RL2
------T2OEDCEN
-----WDPRE2WDPRE1WDPRE000H
Reset
Value
00H
00H
%
%
Notes:
* SFRs are bit addressable.
# SFRs are modified from or added to the 80C51 SFRs.
‡ Extended SFRs accessed by preceeding the instruction with MX escape (opcode A5h).
- Reserved bits, must be written with 0’s.
& Power on reset is 10H. Other reset is 00H.
% The unimplemented bits (labeled ’-’) in the SFRs are ’X’s (unknown) at all times. ’1’s should NOT be written to these bits, as
they may be used for other purposes in future derivatives. The reset values shown for these bits are ’0’s although they are
unknown when read.
% The unimplemented bits (labeled ’-’) in the SFRs are ’X’s (unknown) at all times. ’1’s should NOT be written to these bits, as
they may be used for other purposes in future derivatives. The reset values shown for these bits are ’0’s although they are
unknown when read.
6.2P87C51MX2 PORTS
6.2.1PORTS 0, 1, 2, 3
Ports 0, 1, 2, 3 are the same as the ports in a convention al 80C51 device. They are loc ated at the same bit-addressa ble locations
of 80H, 90H, A0H, and B0H in the conventional SFR space.
6.2.2PORT 4
The P87C51Mx2 has an additional port called Port 4. This port is currently not available as general purpose I/O.
The table below shows function of Port 4:
37Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
P4.0RXD1
P4.1TXD1
Serial input port 1 (with pull-up)
Serial output port 1 (with pull-up)
6.3P87C51MX2 LOW POWER MODES
6.3.1STOP CLOCK MODE
The static desig n enables the cloc k speed to be reduce d down to 0 M Hz (sto pped). When the osci llator is st opped, th e RAM and
Special Function Registers retain their values. This mode allows step-by-step utilization and permits reduced system power
consumption by lowering the clock frequency down to any value. For lowest power consumption the Power Down mode is
suggested.
6.3.2IDLE MODE
In the idle mode (see Table 9), the CPU puts itself to sleep while all of the on-chip peripherals stay active. The instruction to
invoke the idle mode is the last instruction executed in the normal operating mode before the idle mode is activated. The CPU
contents, the on-chip RAM, and all of the special function registers remain intact during this mode. The idle mode can be
terminated either b y any enabl ed interrup t (at whic h time th e process i s picked up at the interrupt s ervice rout ine and con tinued),
or by a hardware reset which starts the processor in the same manner as a power-on reset.
Idle mode is entered by setting the IDL bit in the PCON register.
6.3.3POWER-DOWN MODE
To save even more power, a Power Down mode (see Table 9) can be invoked by software. In this mode, the oscillator is stopped
and the instruction that invoked Power Down is the last instruction executed.
The Power Down mode stops the oscillator in ord er to absolut ely minimize po wer consumptio n. Power Down mo de is entered by
setting the PD bit in the PCON register.
The processor can be made to exit Power Down m ode via Reset or one of th e externa l interru pt inputs (INT0, INT1 - c onfigured
to be level sensi tive only). Thi s will occur i f the interrupt i s enabled and its priority is higher than a ny interrupt cur rently in progress.
While having the MX part in Power Down Mode and driving Reset high (or external interrupt line low), the oscillator dedicated
analog subsystem inside of microcontroller will be enabled. However, only when the wake-up pulse on reset/external interrupt
line is ended, th e rest of micr ocont roller wi ll be s uppli ed w ith the syst em cl ock, and co ntinue to ope rate. Th e durati on of a n input
pulse on reset/external interrupt pin in order to wake the part from Power Down Mode depends solely on external oscillator’s
circuit components. At the end of wa ke-up pr ocedu re, reset/e xt ernal int errupt lin e can be bro ught to no n-activ e leve l as soon as
input at XTAL1 pin achieves stable frequency, duty cycle and amplitude. If an external interrupt caused the part to wake up,
execution of forced jump (that directs code execution to the proper interrupt service routine) will end Power Down Mode.
By exiting Power Down mode via external interrupt, the core automatically clears the PD bit and thus enables a new entry into
Power Down Mode. Once the interrupt is serviced, the next instruction to be executed after RETI will be the one following the
instruction that put the device into Power Down Mode.
In Power Down mode, the power supply voltage may be reduced to the RAM keep-alive voltage V
contents at the point where Power Down mode was entered. SFR contents are not guaranteed after V
, therefore it is recommended to wake up the processor via Reset in this case (since Reset redefines all SFRs - including
V
RAM
PD bit, but doesn’t change on-chip RAM). V
exited.
must be raised to within the operating range before the Power Down mode is
DD
. This retains the RAM
RAM
has been lowered to
DD
38Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
MODEProgram MemoryALEPSEN
PORT 0PORT 1PORT 2PORT 3
IdleInternal11DataDataDataData
IdleExternal11FloatDataAddressData
Power DownInternal00DataDataDataData
Power DownExternal00FloatDataDataD ata
Table 9: External Pin Status During Idle and Power Down Modes
PCON
Reset Value
Power Control Register
76543210
SMOD1SMOD0-POFGF1GF0PDIDL
00-*0000
*
-Reset Value: 000*0000B
(* See description below for PCON.4 reset value)
BITSYMBOLFUNCTION
PCON.7SMOD1Baud Rate Control bit fo r serial port (UART). Whe n 0, the baud rate for UART i s the in put
rate (T1 timer or baud rate generator, as determined by the BRGCON extended SFR)
divided by two. When 1, the baud rate for UART is the input rate (T1 timer or baud rate
generator).
PCON.6SMOD0Framing Error Location:
- When 0, bit 7 of SCON functions as SM0 for the UART.
- When 1, bit 7 of SCON is the framing error status for the UART.
This bit also determines the location of the UART reception interrupt RI occurs (see
description on RI in Fi gure 43).
PCON.5-Reserved for future use. Should be set to 0 by user programs.
PCON.4POFPower On Flag. (Reset value = 1 for power-on reset only.)
PCON.3GF1General purpose flag 1. May be read or written by user software, but has no effect on
operation.
PCON.2GF0General purpose flag 0. May be read or written by user software, but has no effect on
operation.
PCON.1PDPower Down control bit. Setting this bit activates Power Down mode operation. Cleared
when the Power Down mode is terminated (see text).
PCON.0IDLIdle mode control bit. Settin g this b it activates Idle m ode opera tion. Cl eared when the Idle
mode is terminated (see text).
Figure 26: Power Control Register (PCON)
39Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6.3.4POWER-ON FLAG
The Power On Flag (POF) is set by on-chip circuitry when the VDD level on the P87C51Mx2 rises from 0V. The POF bit has to
be cleared by software allowing a user to determine if the reset is the result of a power-on or a warm start after powerdown.
6.3.5DESIGN CONSIDERATION
When the idle mode is terminated by a hardware reset, the device normally resumes program execution, from where it left off,
up to two machine cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to internal RAM in
this event, but acces s to th e port pi ns is n ot inhi bited. To elim inate t he pos sibil ity of a n unex pected write w hen Idl e is terminated
by reset, the instruction following the one that invokes Idle should not be one that writes to a port pin or to external memory.
6.3.6ONCE™
The ONCE (“On-Circu it Emu lation ”) Mode facil itates testi ng and debug ging o f syst ems w ithout the de vice havin g to b e remo ved
from the circuit. The ONCE Mode is invoked by:
1. Pull ALE low while the device is in reset and PSEN
2. Hold ALE low as RST is deactivated.
While the device is in ONCE Mode, the Port 0 pins go into a float state, and the other port pins and ALE and PSEN
pulled high. The os c ill ato r ci rcuit remains active. Whil e the device is in this m ode , an em ula tor o r tes t CP U c an b e us ed to drive
the circuit. Normal operation is restored when a normal reset is applied.
MODE
is high;
are weakly
6.3.7 LOW POWER EPROM OPERATION (LPEP)
Microcontroller con tains some ana log circuits that a re not required when VCC is less than 3.6 V, but are required for a VCC greater
than 3.6 V. The LPEP bit (AUXR.4), when set, will powerdown these analog circuits resulting in a reduced supply current. This
bit should be set ONLY for applications that operate at a VCC less than 3.6 V.
If LPEP=1 with V
greater than 3.6 V, readings from internal RAM will be invalid and the part itself can be damaged.
CC
6.4TIMERS/COUNTERS 0 AND 1
The two 16-bit T imer/Counter re gisters: T ime r 0 and T imer 1 can be co nfigured to opera te either as tim ers or event coun ters (see
Figure 27).
In the "Timer" function, the register is incremented every machine cycle. Thus, one can think of it as counting machine cycles.
Since a machine cycle consists of 6 oscillator periods, the count rate is 1/6 of the oscillator frequency.
In the "Counter" fu nction , the r egiste r is incr ement ed in respon se to a 1-to-0 trans ition at its corres pondi ng extern al input pin, T0
or T1. In this function, the external input is sampled once every machine cycle.
When the samples show a hi gh in one cycl e and a low in the ne xt cycle, the count is increme nted. The new count value appears
in the register in the machine cycle following the one in which the transition was detected. Since it takes 2 machine cycles (12
oscillator periods) to recognize a 1-to-0 transition, the maximum count rate is 1/12 of the oscillator frequency. There are no
restrictions on the duty cycle of the external input signal, but to ensure that a given level is sampled at least once before it
changes, it shoul d be hel d fo r at le as t on e ful l c yc le. In ad di tion to the "Timer" or "Cou nte r" s ele ct ion, Timer 0 and Timer 1 have
four operating modes from which to select.
The "Timer" or "Counter" function is selected by control bits C/T in the Special Function Register TMOD. These two Timer/
Counters have fou r operating modes, whic h are selec ted by bit-p airs (M1, M 0) in TMOD. Modes 0, 1, and 2 are th e same for b oth
Timers/Counters. Mode 3 is different. The four operating modes are described in the following text.
40Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
TMOD
Not bit addressable
Reset Source( s): A ny source
Reset Value: 00000000B
M1M0OPERATING
008048 Timer “TLx” serves as 5-bit prescaler.
0116-bit Timer/Counter “THx” and “TLx” are cascaded; there is no prescaler.
108-bit auto-reload Timer/Counter “THx” holds a value which is to be reloaded into “TLx”
11(Timer 0) TL0 is an 8-bit Timer/Counter controlled by the standard Timer 0 control bits.
Address: 89h
T1/T0Bits controling Timer1/Timer0
GATEGating control when set. Timer/Counter “x” is enabled only while “INTx” pin is high and
C/T
Figure 27: Timer/Counter Mode Control Register (TMOD)
76543210
T1GATE T1C/T
“TRx” control pin is set. when cleared Timer “x” is enabled whenever “TRx” control bit is
set.
Gating Timer or Counter Selector cleared for Timer operation (input from internal system
clock.) Set for Counter operation (input from “Tx” input pin).
each time it overflows.
TH0 is an 8-bit timer only controlled by Timer 1 control bits.
(Timer 1) Timer/Counter 1 stopped.
T1M1T1M0T0GATET0C/TT0M1T0M0
6.4.1MODE 0
Putting either Timer into Mod e 0 mak es it lo ok like a n 8048 Ti mer, wh ich is an 8-bit C ounter with a divid e-by-32 p rescaler. Figure
29 shows Mode 0 operation.
In this mode, the Timer register is configured as a 13-bit register. As the count rolls over from all 1s to all 0s, it sets the Timer
interrupt flag TFn. The count input is enabled to the Timer when TRn = 1 and either GATE = 0 or INTn
allows the Timer to be contro lled by external input INTn
Function Register TCON (Figure 28). The GATE bit is in the TMOD register.
The 13-bit register cons ists o f all 8 bits of TH n and t he lower 5 b its of TLn . Th e uppe r 3 bits of TLn are in determi nate a nd should
be ignored. Setting the run flag (TRn) does not clear the registers.
Mode 0 operation is the same for Timer 0 and Timer 1 (see Figure 29). There are two different GATE bits, one for Timer 1
(TMOD.7) and one for Timer 0 (TMOD.3).
, to facilitate pulse width me asurements). TRn is a contro l bit in the Special
= 1. (Setting GATE = 1
6.4.2MODE 1
Mode 1 is the same as Mode 0, except that all 16 bits of the timer register (THn and TLn) are used. See Figure 30.
6.4.3MODE 2
Mode 2 configures the Timer regis ter as an 8 -bit Counter (T Ln) with au tomatic r eload, as sho wn in Fig ure 31. Overfl ow from TLn
not only sets TFn, but also reloads TLn with the contents of THn, which must be preset by software. The reload leaves THn
unchanged. Mode 2 operation is the same for Timer 0 and Timer 1.
41Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6.4.4MODE 3
When Timer 1 is in Mode 3 it is stopped (holds its count). The effect is the same as setting TR1 = 0.
Timer 0 in Mode 3 e st abl is hes TL 0 a nd TH 0 as tw o sep ara te 8 - bi t c oun ters . Th e log ic for Mo de 3 on Timer 0 is shown in Fi gure
32. TL0 uses the Timer 0 control bits: T0C/T, T0GATE, TR0, INT0, and TF0. TH0 is locked into a tim er function (counting mac hine
cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls the “Timer 1” interrupt.
Mode 3 is provided fo r ap pli ca tio ns that require an extra 8-b it timer. With Timer 0 in Mo de 3 , an P87C5 1M B2/M C 2 c an loo k l ike
it has an additional Timer.
Note: When Timer 0 is in Mode 3, Timer 1 can be turn ed on and off by switc hi ng it int o and out of its own Mode 3. It can still be
used by the serial port as a baud rate generator, or in any application not requiring an interrupt.
TCON
Bit addressable
Reset Source (s) : An y reset
Reset Value: 00000000B
BITSYMBOLFUNCTION
TCON.7TF1Timer 1 overflow flag. Set by ha rdwa re on Timer/Counter overflow. C lea red by ha rdware
TCON.6TR1Timer 1 Run control bit. Set/cleared by software to turn Timer/Counter 1 on/off.
TCON.5TF0Timer 0 overflow flag. Set by ha rdwa re on Timer/Counter overflow. C lea red by ha rdware
TCON.4TR0Timer 0 Run control bit. Set/cleared by software to turn Timer/Counter 0 on/off.
TCON.3IE1Interrupt 1 Edge flag. Set by hardware when external interrupt 1 edge is detected. Cleared
TCON.2IT1Interrupt 1 Type control bit. Set/cleared by software to specify falling edge/low level
TCON.1IE0Interrupt 0 Edge flag. Set by hardware when external interrupt 0 edge is detected. Cleared
TCON.0IT0Interrupt 0 Type control bit. Set/cleared by software to specify falling edge/low level
Address: 88h
76543210
TF1TR1TF0TR0IE1IT1IE0IT0
when the processor vectors to interrupt routine, or by software.
when the processor vectors to interrupt routine, or by software.
by hardware when the interrupt is processed, or by software.
triggered external interrupts.
by hardware when the interrupt is processed, or by software.
triggered external interrupts.
Figure 28: Timer/Counter Control Register (TCON)
42Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Osc / 6
Tn Pin
INTn
Osc / 6
Tn Pin
Gate
INTn
TRn
Gate
Pin
TRn
Pin
= 0
C/T
C/T = 1
Figure 29: Timer/Counter 0 or 1 in Mode 0 (13-Bit Counter)
= 0
C/T
C/T = 1
Control
Control
TLn
(5-bits)
TLn
(8-bits)
(8-bits)
(8-bits)
Overflow
THn
Overflow
THn
TFn
TFn
Interrupt
Interrupt
Osc / 6
Tn Pin
Gate
INTn
TRn
Pin
Figure 30: Timer/Counter 0 or 1 in Mode 1 (16-Bit Counter)
= 0
C/T
= 1
C/T
Figure 31: Timer/Counter 0 or 1 in Mode 2 (8-Bit Auto-Reload)
Timer 2 is a 16-bit Timer/Counter which can operate as either an event timer or an event counter, as selected by C/T2 in the
special function register T2CON. Timer 2 has three operating modes: Capture, Auto-reload (up or down counting), and Baud
Rate Generator, which a re selected by bits in the T2CON as shown in Figure 33.
6.5.1CAPTURE MODE
I
n the capture mode there a re two options whi ch are selec ted by bit EXEN2 in T 2CON. If EXEN2=0, then timer 2 is a 16 -bit timer
or counter (as selected by C/T
to generate an interrupt (by enabling the Timer 2 interrupt bit in the IE register). If EXEN2= 1, Timer 2 operates as described
above, but with the added feature tha t a 1- to -0 transition at external input T2EX causes the current value in the Timer 2 registers,
TL2 and TH2, to be captured into registers RCAP2L and RCAP2H, respectively. In addition, the transition at T2EX causes bit
EXF2 in T2CON to be set, and EX F2 like TF2 ca n gen erate a n inte rrupt (w hich v ectors to th e sa me lo cation as Timer 2 ove rflow
interrupt. The Timer 2 interrupt service routine can interrogate TF2 and EXF2 to determine which event caused the interrupt).
The capture mode is il lustrated in Figure 35 . (There is no re load valu e for TL2 and TH2 in this mod e. Even when a capture e vent
occurs from T2EX, the counter keeps on counting T2EX pin transitions or osc/6 pulses.)
2 in T2CON) which, upon overflowing sets bit TF2, the timer 2 overflow bit. This bit can be used
6.5.2AUTO-RELOAD MODE (UP OR DOWN COUNTER)
In the 16-bit auto-reload mode, Timer 2 can be configured as either a timer or counter (via C/T2 in T2CON), then programmed
to count up or down. The counting direction is determined by bit DCEN (Down Counter Enable) which is located in the T2MOD
register (see Figure 34). When reset is applied, DCEN = 0 and Timer 2 will default to counting up. If the DCEN bit is set, Timer
2 can count up or down depending on the value of the T2EX pin.
Figure 36 shows Timer 2 counting up automatically (DCEN = 0). In this mode, there are two options selected by bit EXEN2 in
T2CON register. If EXEN2=0, then Timer 2 counts up to 0FFFFH and sets the TF2 (Overfl ow Flag) bit upon o verflow. This caus es
the Timer 2 registers to be reloaded with the 16-bit value in RCAP2L and RCAP2H. The values in RCAP2L and RCAP2H are
preset by software means.
44Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
If EXEN2=1, then a 16-bit reload can be triggered either by an overflow or by a 1-to-0 transition at input T2EX. This transition
also sets the EXF2 bit. The Timer 2 interrupt, if enabled, can be generated when either TF2 or EXF2 is 1.
In Figure 37, DCEN=1 . Timer 2 is ena bled to count u p or down. This m ode allows pin T2EX to control th e direction of coun t. When
a logic 1 is applied at pin T2EX Timer 2 will count up. Timer 2 will overflow at 0FFFFH and set the TF2 flag, which can then
generate an interru pt, if t he inte rrupt is enab led. Th is ti mer ov erflow a lso caus es th e 16-bi t val ue in RCAP2L a nd RCAP2H to be
reloaded into the timer registers TL2 and TH2.
When a logic 0 is applied at pin T2EX this causes Timer 2 to count down. The timer will underflow when TL2 and TH2 become
equal to the value stored in RCAP2L and RCAP2H. Tim er 2 under flow sets th e TF2 flag a nd cause s 0FFFFH to b e reloaded int o
the timer registers TL2 and TH2. The external flag EXF2 toggles when Timer 2 underflows or overflows. This EXF2 bit can be
used as a 17th bit of resolution if needed.
6.5.3PROGRAMMABLE CLOCK-OUT
A 50% duty cycle clock can be programmed to come out on P1.0. This pin, besides being a regular I/O pin, has two additional
functions. It can be programmed:
1. To input the external clock for Timer/Counter 2, or;
2. To output a 50% duty cycle clock ranging from 122Hz to 8MHz at a 16MHz operating frequency.
To configure the Timer/Counter 2 as a clock generator, bit C/T
set. Bit TR2 (T2CON.2) also must be set to start the timer.
The Clock-Out frequency depends on the oscillator frequency and the reload value of Timer 2 capture registers (RCAP2H,
RCAP2L) as shown in this equation:
2 (in T2CON) must be cleared and bit T20E in T2MOD must be
–
,()
Where (RCAP2H,RCAP2L) = the content of RCAP2H and RCAP2L taken as a 16-bit unsigned integer. The "6" in the
denominator of the above equation indicates six oscillator cycles per machine cycle.
In the Clock-Out mode Tim er 2 roll-overs will not generate an inter rupt. This is si milar to when it is us ed as a baud-rate generator.
It is possible to use Timer 2 as a baud-rate generator and a clock generator simultaneously. Note that the equations for baud-
rate and the Clock-Out frequency are different.
45Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
T2CON
Bit addressable
Reset Value: 00h
Address: C8h
76543210
TF2EXF2RCLKTCLKEXEN2TR2C/T
2CP/RL2
BITSYMBOLFUNCTION
T2CON.7TF2Timer 2 overflow flag set by a Timer 2 over flow and must be cleared by software . TF2 will
not be set when either RCLK or TCLK = 1.
T2CON.6EXF2Timer 2 external flag set when either a capture or reload i s caused by a nega tive transition
on T2EX and EXEN2 = 1. When Timer 2 inte rrupt is enabled, EXF 2 = 1 will caus e the CPU
to vector to the Timer 2 interrupt routine. EXF2 must be cleared by software.
Microcontroller’s hardware will need three consecutive machine cycles in order to
recognize falling edge on T2 EX and set EXF2=1: in th e first ma chine cycl e pin T2EX ha s
to be sampled as "1"; i n th e seco nd ma chine cycl e it has to be sampl ed as "0" , and i n the
third machine cycle EXF2 will be set to 1.
T2CON.5RCLKReceive clock flag. When set, causes the serial port 0 (UART 0) to use Timer 2 overflow
pulses for its receive clock in modes 1 and 3 (unless SBRGS - BRGCON.1 is set to ’1’).
RCLK = 0 causes Timer 1 overflow to be used for the receive clock. (See section on
"UARTs").
T2CON.4TCLKTransmit clock fla g. When s et, cau ses the seri al port 0 (UART 0) to use Timer 2 overf low
pulses for its transmit c lockN in modes 1 an d 3 (unless SBRGS - BR GCON.1 is set to ’1 ’).
TCLK = 0 causes Timer 1 overflows to be used for the transmit clock. (See section on
"UARTs").
T2CON.3EXEN2Timer 2 external enable flag. When set, allo ws a cap ture or rel oa d to o cc ur a s a res ult of
a negative transition o n T2EX if Ti mer 2 is no t being used to clock the serial port . EXEN2
= 0 causes Timer 2 to ignore events at T2EX
.
T2CON.2TR2Start/stop control for Timer 2. A logic 1 enables the timer to run.
T2CON.1C/T
T2CON.0CP/RL2Capture/Reload flag. When set, captures will occur on negative transitions at T2EX if
EXEN2 = 1. When cleared, auto-reloads will occur either with Timer 2 overflows or
negative transitions at T2EX when EXEN2 = 1. When either RCLK = 1 or TCLK = 1, this
bit is ignored and the timer is forced to auto-reload on Timer 2 overflow.
Figure 33: Timer/Counter 2 (T2CON) Control Register
RCLK+TCLKCP/RL2TR2MODE
00116-BIT auto reload
01116-bit capture
1X1Baud rate generator for UART 0
XX0off
Table 10: Timer 2 operating mode
46Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
T2MOD
Not bit addressable
Reset Value: XXXXXX00B
BITSYMBOLFUNCTION
T2MOD.7-2-Reserved for future use. Should be set to 0 by user programs.*
T2MOD.1T2OET imer 2 Output Enable bit.
T2MOD.0DCENDown Count Enable bit. When set, this allows timer2 to be configured as an up/down
* User software should not write 1s to reserved bits. These bits may be used in future 8051 family products to invoke new
features. In that case, the reset or inactive value of the new bit will be 0, and its active value will be 1. The value read from
a reserved bit is indeterminate
Address: C9h
76543210
------T2OEDCEN
counter.
.
Figure 34: Timer 2 Mode (T2MOD) Control Register
6.5.4BAUD RATE GENERATOR MODE FOR UART 0 (SERIAL PORT 0)
When serial port 0 (UART 0) doesn’ t use the indepen dent baud rate generator (S0BRGS = 0, S0BRGS is BR GCON.1), bits TCL K
and/or RCLK in T2CON allow the serial port 0 (UART 0) transmit and receive baud rates to be derived from either Timer 1 or
Timer 2. Refer to the section on UARTs for details. Assume that S0BRGS = 0, when TCLK= 0, Timer 1 is used as the UART 0
transmit baud rate ge nerator. whe n TCLK = 1, Ti mer 2 is us ed as the UAR T 0 tra nsmit ba ud rate genera tor. RCLK h as the sa me
effect for the UART 0 receive ba ud rate. Wi th thes e two bits, the seria l port can have differe nt recei ve and tra nsmit bau d rates –
Timer 1, Timer 2 or baud rate generator.
Figure 38 shows Timer 2 in baud rate generator mode. The baud rate generation mode is like the auto-reload mode,in that a
rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which are
preset by software.
The baud rates in modes 1 and 3 are determined by Timer 2’s overflow rate given below:
Modes 1 and 3 Baud Rates
The timer can be configured for either “timer” or “counter” operation. In many applications, it is configured for “timer” operation
2=0). Timer operation is different for Timer 2 when it is being used as a baud rate generator.
(C/T
Usually, as a timer it would increment every machine cycle (i.e., 1 / 6 the oscillator frequency). As a baud rate generator, it
increments at the oscillator frequency. Thus the baud rate formula is as follows:
Modes 1 and 3 Baud Rates =
Oscillator Frequency / (16 X (65536 - (RCAP2H, RCAP2L)))
Where: (RCAP2H, RCAP2L)= The content of RCAP2H and RCAP2L taken as a 16-bit unsigned integer.
The Timer 2 as a baud rate ge nerator mod e is valid only if RCLK and /or TCLK = 1 in T2CON registe r. Note that a rollover in TH 2
does not set TF2, and will not generate an interrupt. Thus, the Timer 2 interrupt does not have to be disabled when Timer 2 is
in the baud rate generator mode. Also if the EXEN2 (T2 externa l enabl e flag) is set , a 1-to-0 tra nsition in T2EX (Timer/co unter 2
trigger input) will set EXF2 (T2 external fl ag) but wi ll not cause a reload from (RCAP2H, RCAP2L ) to (TH2,TL2). The refore whe n
Timer 2 is in use as a baud rate generator, T2EX can be used as an additional external interrupt, if needed.
When Timer 2 is in the baud rate generator mode, one should not try to read or write TH2 and TL2. Under these conditions, a
read or write of TH2 or TL2 may not be accurate. The RCAP2 registers may be read, but should not be written to, because a
Timer 2 Overflow Rate/16
=
47Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
write might overlap a reload and cause write and/or reload errors. The timer should be turned off (clear TR2) before accessing
the Timer 2 or RCAP2 registers. Table 11 shows commonly used baud rates and how they can be obtained from Timer 2.
6.5.5SUMMARY OF BAUD RATE EQUATIONS
Timer 2 is in baud rate generating mode. If Timer 2 is being clocked through pin T2(P1.0) the baud rate is:
Baud Rate
If Timer 2 is being clocked internally , the baud rate is:
Baud Rate
Where f
To obtain the reload value for RCAP2H and RCAP2L, the above equation can be rewritten as:
= Oscillator Frequency
OSC
RCAP2H, RCAP2L = 65536 - f
Timer 2 Overflow Rate / 16
=
f
/ (16 x (65536 - (RCAP2H, RCAP2L)))
=
OSC
/ (16 x Baud Rate)
OSC
6.5.6TIMER/COUNTER 2 SET-UP
Except for the baud rate generator mode, the values given for T2CON do not include the setting of the TR2 bit. Therefore, bit
TR2 must be set, separately, to turn the timer on.
Table 11: Timer 2 Generated Commonly Used Baud Rates
Baud rate generator for UART 0 (if S0BRGS
(BRGCON.1) = 0)
48Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
T2 Pin
T2EX Pin
OSC
6
÷
Transition
Detector
C/T
C/T
2 = 0
2 = 1
TL2
(8-bit)
CONTROL
TR2
CAPTURE
RCAP2LRCAP2H
CONTROL
EXEN2
Figure 35: Timer 2 in Capture Mode
TH2
(8-bit)
TF2
Timer 2
Interrupt
EXF2
T2 Pin
T2EX Pin
OSC
6
÷
Transition
Detector
C/T
2 = 0
C/T
2 = 1
EXEN2
TR2
CONTROL
CONTROL
RELOAD
TL2
(8-bit)
RCAP2LRCAP2H
RCAP2L
TH2
(8-bit)
Figure 36: Timer 2 in Auto Reload Mode (DCEN = 0).
TF2
EXF2
Timer 2
Interrupt
49Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
TOGGLE
(DOWN COUNTING RELOAD VALUE)
FFHFFH
EXF2
OSC
T2 Pin
÷
OSC
6
C/T
2 = 0
C/T
2 = 1
TR2
CONTROL
TL2
(8-bit)
RCAP2LRCAP2H
(UP COUNTING RELOAD VALUE)T2EX PIN
(8-bit)
TH2
OVERFLOW
COUNT DIRECTION
1 = UP
0 = DOWN
TF2
Timer 2
Interrupt
Figure 37: Timer 2 in Auto Reload Mode (DCEN = 1).
2
÷
C/T
2 = 0
TL2
(8-bit)
TH2
(8-bit)
TX/RX Baud Rate (See section "Baud
Rate Generator and Selection")
T2 Pin
T2EX Pin
TR2
CONTROL
CONTROL
EXEN2
RCAP2LRCAP2H
EXF2
Timer 2
Interrupt
C/T
Transition
Detector
2 = 1
Figure 38: Timer 2 in Baud Rate Generator Mode
50Preliminary 2002 June 28
RELOAD
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6.6UARTS
The P87C51Mx2 includes two enhanced UARTs with one independent Baud Rate Generator. They are compatible with the
enhanced UART based on the 8xC51Rx+ except the baud rate generator. The first UART (UART 0) can select using Timer1
overflow, Timer2 overflow or the independent Baud Rate Generator. The second UART (UART 1) only uses the independent
Baud Rate Generator t o generate its baud rate. Besides the baud rate generation, enhanc ements over the standa rd 80C51 UART
include Framing Error detection, automatic address recognition, selectable double buffering and several interrupt options. The
two UARTs are called UARTs 0 and 1 to correspond to the serial port assignments.
Each serial port can be operated in 4 modes:
6.6.1MODE 0
Serial data enters an d exit s through R xD_n. Tx D_n outpu ts the s hift cloc k. 8 bit s are tran smitted or received , LSB fi rst. The b aud
rate is fixed at 1/6 of the CPU clock frequency.
6.6.2MODE 1
10 bits are transmitted (throu gh TxD) or received (through R xD): a start bit (logical 0), 8 dat a bits (LSB first), and a stop bit (logical
1). When data is receive d, the stop bit is stored in RB8_0/RB8_ 1 in Specia l Function Register S0CON/S1CON . For UART 0, th e
baud rate is variable and i s determin ed by the Timer 1/2 (see T2CON .5-4) over flow rate or th e Baud Rate Genera tor (describ ed
later in section on "Ba ud Ra te Genera tor and Se lecti on"). Th e Baud Rat e Gene rator is the onl y sou rce for b aud rate for UART 1.
6.6.3MODE 2
11 bits are transmitted (thro ugh TxD ) or re cei ve d (thro ug h RxD) : start bi t (logical 0), 8 data bits (LSB first), a programmable 9th
data bit, and a stop bit (logica l 1). When data is tran smitt ed, the 9th data bit (TB8 in SCON) can be assig ned the va lue of 0 or 1.
Or, for example, the parity bit (P, in the PSW) could be moved into TB8. When data is received, the 9th data bit goes into RB8
in Special Function Regi ster S0CON/ S1CON, while the stop bit is ign ored. For UART 0, the ba ud rate is progra mmable to ei ther
1/16 or 1/32 of th e CPU cl ock frequ ency, a s determi ned by the SMOD1 bit in PCO N. For UART 1, the baud rat e is from th e Baud
Rate Generator.
6.6.4MODE 3
11 bits are transm itted (throu gh TxD) or receive d (through RxD): a start bit (logical 0), 8 da ta bits (LSB f irst), a programmab le 9th
data bit, and a stop bit (logic al 1). In fa ct, Mod e 3 is the same as Mo de 2 in all respects excep t baud rate . For UART 0, th e baud
rate in Mode 3 is variable and is determined by the Timer 1/2 (see T2CON.5-4) overflow rate or the Baud Rate Generator
(described later in section on "Baud Rate Generator and Selection"). Baud Rate Generator is the only source for baud rate for
UART 1.
In all four modes, transmission is initiated by any instruction that uses S0BUF/S1BUF as a destination register. Reception is
initiated in Mode 0 by the condition RI_0/RI_1 = 0 and REN_0/REN_1 = 1. Reception is initiated in the other modes by the
incoming start bit if REN_0/REN_1 = 1.
6.6.5SFR AND EX TENDED SFR SPACES
The regular UART 0 SFRs and contro l bits are in the regu lar SFR sp ac e. H owev er, ex ten ded con trol and UA RT 1 regis te rs are
in the MX extended SFR spac e.
PCONPower Control87H
T2CONTimer2 ControlC8H
S0CONSerial Port 0 Control98H
S0BUFSerial Port 0 Data Buffer99H
S0ADDRSerial Port 0 AddressA9H
S0ADENSerial Port 0 Address EnableB9H
S0STATSerial Port 0 Status8CH
S1CONSerial Port 1 Control80H
S1BUFSerial Port 1 Data Buffer81H
S1ADDRSerial Port 1 Address82H
S1ADENSerial Port 1 Address Enable83H
S1STATSerial Port 1 Status84H
BRGR1Baud Rate G enerator Rate High Byte87H
BRGR0Baud Rate Generator Rate Low Byte86H
BRGCONBaud Rate Generator Control85H
Table 12: SFR/Extended SFR Locations for UARTs.
6.6.6BAUD RATE GENERATOR AND SELECTION
The P87C51Mx2 enhanc ed UAR Ts hav e one ass oc ia ted inde pen den t Baud Ra te Generator. The baud rate is determined by a
baud-rate preprogrammed into the BRGR1 and BRGR0 SFRs in the extended SFR space. (BRGR1.7-0, BRGR0.7-4) together
form a 12-bit baud rat e di vi so r va lue (BRATE11-0) that works in a s im ila r ma nn er as Ti mer 1/2, but if the baud rate gen erat or is
used, Timer 1/2 can be used for other timing functions.
UART 0 can use either Timer 1/2 (see T2CON.5-4) or the baud rate generator output (as determined by BRGCON.2-1 in the
extended SFR spac e), whil e U AR T 1 onl y us es the baud rate generator . N ot e th at in U AR T 0 , Ti me r T1 is fu rther divided by 2 if
the SMOD1 bit (PCON.7) is cl eare d. T2 (for UA RT 0) and the i nde pen dent Baud Rate Generator (for both UAR Ts ) will be us ed
as is, without the divided by 2 option (see Figure 42).
BRGR0
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
BRGR0.7-4BRATE3-0Baud rate divisor bits 3-0.
BRGR0.3-0-Reserved for future use. Should be set to 0 by user programs.
The effective baud rate is a 16-bit value.The baud rate SFRs, BRGR1 and
BRGR0 must only be loaded when the Baud Rate Generator is disabled (the BRGEN bit in the BRGCON register is ’0’). This
avoids the loading of an in teri m valu e (when only one of BR GR1 and BR GR0 is written) to the baud rate gene rator .
If any of BRGR0 or BRGR1 is written if BRGEN = 1, result is unpredictable.)
S0CON.7
(SM0_0)
S0CON.6
(SM1_0)
T2CON.5/4
(RCLK - Receive
TCLK - Transmit)
PCON.7
(SMOD1)
BRGCON.1
(S0BRGS)
00XXXf
00XT1_rate/32
01XT1_rate/16
01
1X0T2_rate/16
1X1 f
10X0X f
10X1X f
00XT1_rate/32
01XT1_rate/16
11
1X0T2_rate/16
1X1 f
Receive/Transmit Baud Rate for UART 0
/6
OSC
*
*
*
/(BRATE×16+16)
OSC
/32
OSC
/16
OSC
*
*
*
/(BRATE×16+16)
OSC
(CAUTION:
*
*
* Receiver and transmit clocks can be different.
Table 13: Baud Rate Generation for UART 0. Use T 2CON.5 (RCLK) in Receive Baud Rate Selection, T 2CON.4 (TCLK)
in Transmit Baud Rate Selection
53Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
S1CON.7
(SM0_1)
00f
01f
10f
11f
S1CON.6
(SM1_1)
Baud Rate for UART 1
/6
OSC
/(BRATE×16+16)
OSC
/(BRATE×16+16)
OSC
/(BRATE×16+16)
OSC
*
*
*
* UART 1 has the same receive and tran sm it bau d rate.
Table 14: Baud Rate Generation for UART 1.
BRGCON
Not bit addressable
Reset Value: 00h
Address: 85h (MX Extended SFR Space)
76543210
------S0BRGS BRGEN
BITSYMBOLFUNCTION
BRGCON.7-2-Reserved for future use. Should be set to 0 by user programs.
BRGCON.1S0BRGS(For UART 0 only) Used in combination with the RCL K and TCL K in decid ing the rec eive
and transmit baud rates to UART 0 in modes 1 & 3 (see Table 13 for details).
bit is SM0_n, which with SM1_n, defines the serial port mod e. If SMOD0 = 1, this bit is FE
(Framing Error). FE is set by the receiver when an invalid stop bit is detected. Once set,
this bit cannot be cleared by valid frames but is cleared by software. (Note: It is
recommended to set up UART mode bits SM0_n and SM1_n before setting SMOD0 to
’1’.)
SM0_n, SM1_n
0 00: shift registerCPU cloc k/6CPU clock/6
0 11: 8-bit UARTVariable (see Table 13)Baud Rate Generator (see Table 14)
1 02: 9-bit UARTCPU clock/32 or CPU clock/16Baud Rate Generator (see Table 14)
1 13: 9-bit UART Variable (see Table 13)Baud Rate Generator (see Table 14)
UART ModeUART 0 Baud RateUART 1 Baud Rate
SM2_n is set to 1, then Rl_n will n ot be activate d if t he received 9th d ata bi t (RB8 _n) is 0.
In Mode 1, if SM2_n=1 then RI_n wil l not be activ ated if a valid s top bit w as not rece ive d.
In Mode 0, SM2_n should be 0.
reception.
desired.
the stop bit that was received. In Mode 0, RB8_n is undefined.
the stop bit (see de scription of INTLO bit in SnSTAT re gis te r) in the other modes, in an y
serial transmission. Must be cleared by software.
approximately halfway through the stop bit time in Mode 1. Fo r Mode 2 or Mode 3, if
SMOD0 = 0, it is set near t he middle of the 9th d ata bit (bit 8); if SMOD0 = 1, it is set nearly
the middle o f the stop bit. (See SM2_n for exceptions). Must be cleared by software.
SM1_nSM2_nREN_nTB8_nRB8_nTI_nRI_n
Figure 43: Serial Port Control Register (SnCON)
6.6.7FRAMING ERROR
Framing error (FE_n) is rep orted in th e status reg ister (SnSTAT). In addition , if SMOD0 (PCON.6) is 1, framin g errors fo r UARTs
0 and 1 can be made avai lable to the S0CON.7 and S1C ON.7 resp ectively. If SM OD0 is 0, S0C ON.7 and S1CO N.7 are SM0 for
UARTs 0 and 1 respectively. It is recommended that SM0_n and SM1_n (SnCON.7-6) are set up before SMOD0 is set to ’1’.
It should also be noted that a break detect (setting of BR_n) also sets FE_n.
55Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6.6.8STATUS REGISTER
Each of the enhanced UARTs contains a status register. The status register also contains some control bits:
• DBMOD_n (n = 0, 1) - The e nhanc ed UART inclu des do uble b uffering . In orde r to be c ompatibl e wi th existi ng 80C 51 devic es,
this bit is reset to ’0’ to disable double buffering.
• INTLO_n - For modes 1, 2 and 3, the UART allows Tx interrupt to occur at the beginning or end of the STOP bit. This bit is
reset to ’0’ to select Tx to be issued at the beginning of the STOP bit. Note that in the case of single buffering, if Tx interrupt
occurs at the end of a STOP bit, a gap may exist before the next start bit. For UART mode 0, this bit must be cleared to ’0’.
• CIDIS_n (n = 0, 1) - The UART can issue combined Tx/Rx interrupt (conventional 80C51 UART) or have separate Tx and Rx
interrupts. This bit is reset to ’0’ to select combined interrupt.
• DBISEL_n (n = 0, 1) - This is only used when the co rres pon di ng DB MOD _n = 1. If DBM OD _n = 0, thi s bi t must be c lea red to
’0’ for future comp atibil ity. Th is bit control s the n umber of interr upts th at can occur when dou ble bu fferi ng is enable d. If ’0’, the
number of Tx interrupts must be the same as the number of chara cters sent. If ’1’, an addi tional interrupt is sent at the be ginning
(INTLO_n = 0) or the end (INTLO_n = 1) of the STOP bit when there is no more data in the double buffer. This last interrupt
can be used to indicate that all transmit operations are over.
• STINT_n (n = 0,1) - If ’1’, FE_n, BR_n and OE_n can cause interrupt (refer to Figure 44).
The bits DBMOD_n and DBISEL _n are discussed further in sectio n "D ou ble Buffe ring ". IN TL O_ n beh av es in the same manner
regardless of single of double buffering, but the first interrupt occ urs different. It is also explained in the sec tion "Double Buffering".
CIDIS_n is not related to double buffering.
56Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
SnSTAT
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
SnSTAT.7DBMOD_n0: Double buffering disabled; 1: Double buffering enabled.
SnSTAT. 6INTLO_nTransmit interrupt posi tion for UAR T mode 1, 2 or 3. 0: Tx interru pt issued at b eginning of
SnSTAT.5CIDIS_n0: Combined Tx/Rx interrupt for Serial Port n; 1: Rx and Tx interrupts are separate.
SnSTAT.4DBISEL_nDouble buffering transmit interrupt select - used only if double buffering is enabled
SnSTAT.3FE_nFraming Error flag is set when the receiver fails to see a valid STOP bit at the end of the
SnSTAT.2BR_nBreak Detect flag is set if a character is received with all bits (including STOP bit) being
SnSTAT.1OE_nOverrun Error flag is set if a new character is rece ived i n the rec eiver buffer whi le it i s still
stop bit; 1: Tx interrupt issued at end of stop bit. Must be ’0’ for mode 0
(DBMOD_n set to ’1’), must be ’0’ when double buffering is disabled:
0:There is only one transmit interrupt generated per character written to SnBUF.
1:One transmit interru pt is generated after each c haracter writte n to SnBUF, and the re
is also one more transmit interrupt generated at the STOP bit of the last character
sent (i.e., no more data in buffer).
Note that except for the first character written (when buffer is empty), the location of the
transmit interrupt is determined by INTLO_n. When the first character is written, the
transmit interrupt is generated immediately after the SnBUF is written.
frame. It is also set with BR_n if a break is detected. Cleared by software.
logic ’0’. Thus it gi ve s a "Start of Break D etec t" on bi t 8 for Mode 1 and bit 9 for Mo des 2
and 3. The break detect feature operates indpendently of the UARTs and provides the
START of Break Detect status bit that a user program may poll. Cleared by software.
full, i.e., when bit 8 of a new byte is received while RI in SnCON is still set. If an overrun
occurs, SnBUF retains the old data and the new character received is lost. Cleared by
software.
0:FE_n, BR_n, OE_n cannot cause any interrupt.
1:FE_n, BR_n, OE_n can cause interrupt. The interrupt used i s shared with RI_n
(CIDIS_n = 1) or combined TI_n/RI_n (CIDIS_n = 0).
INTLO_n CIDIS_n
DBISEL_n
FE_nBR_nOE_nSTINT_n
Figure 44: Serial Port Status Register (SnSTAT)
6.6.9MORE ABOUT UART MODE 1
Reception is init iated by a de tected 1-to-0 t ransition at Rx D. For this purpose RxD is sampled at a rate of 16 tim es whatever b aud
rate has been establis hed. Whe n a transi tion is de tected , the divi de-by- 16 co unter is immed iately reset to ali gn its rol lovers with
the boundaries of the incoming bit times.
The 16 states of the counter divi de each bit time into 16ths . At the 7th, 8th, and 9th counter sta tes of each bit time, the bit detector
samples the value of RxD. The value accepted is the value that was seen in at least 2 of the 3 samples. This is done for noise
rejection. If the value accep ted during the f irst bit time is not 0, the rece ive cir cuits are reset and the un it goes back to look ing for
another 1-to-0 transition. This is to provide rejection of false start bits. If the start bit proves valid, it is shifted into the input shift
register, and reception of the rest of the frame will proceed.
57Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
The signal to loa d SBUF a nd RB8 (RB8_0 for UART 0 or R B8_ 1 f or UART 1), and to se t RI (RI_0 for UART 0 or R I_1 f or U ART
1), will be generated if, and only if, the following conditions are met at the time the final shift pulse is generated: (a) RI = 0, and
(b) Either SM2 (SM2_0 for UART 0 or SM2_1 for UART 1) = 0, or the received stop bit = 1.
If either of these two conditions is not met, the received frame is irretrievably lost. If both conditions are met, the stop bit goes
into RB8, the 8 data bits go into SBUF, and RI is activated.
6.6.10MORE ABOUT UART MODES 2 AND 3
Reception is performed in the same manner as in mode 1.
The signal to load SBUF a nd RB8, and to s et RI, will be generat ed if, an d only i f, the fol lowi ng con ditions are met at th e time th e
final shift pulse is generated: (a) RI = 0, and (b) Either SM2 = 0, or the received 9th data bit = 1.
If either of these conditions is not met, the received frame is irretrievably lost, and RI is not set. If both conditions are met, the
received 9th data bit goes into RB8, and the first 8 data bits go into SBUF.
Figure 45: Serial Port Mode 0 (Only Single Transmit Buffering Case Is Shown)
58Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
TX Clock
Write to SBUF
Shift
TxD
TI
RX Clock
RxD
Shift
RI
TX Clock
Write to SBUF
Shift
TxD
TI
D0D1D5D2D6D3D4D7
INTLO_n = 0
D0D1D5D2D6D3D4D7
÷ 16 Reset
Start BitStop Bit
Start Bit
Figure 46: Serial Port Mode 1 (Only Single Transmit Buffering Case Is Shown)
Start BitStop Bit
D0D1D5D2D6D3D4D7
Stop Bit
TB8
INTLO_n = 0
Transmit
INTLO_n = 1
Receive
Transmit
INTLO_n = 1
RX Clock
RxD
Shift
RI
÷ 16 Reset
Start Bit
D0D1D5D2D6D3D4D7
SMOD0 = 0
RB8
Figure 47: Serial Port Mode 2 or 3 (Only Single Transmit Buffering Case Is Shown)
59Preliminary 2002 June 28
Stop Bit
Receive
SMOD0 = 1
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6.6.11DOUBLE BUFFERING
Each of the P87CMx2's UARTs optiona lly has the abi lity to buffer the next character to be transmitted while the cu rrent character
is still being shifted out of the transmit shift register. The advantage of double buffering comes when it is desired to transmit a
string of characters with on ly a s in gle Sto p Bi t b etwee n c ha rac ters . I n o r der to a ccom pl is h th is on the ori gi nal 80 C51 UART the
next character be l oaded w hile the Stop Bit o f the prev ious chara cter was being sent. Dou ble buffe ring allo ws the ne xt chara cter
to be loaded at any time from the beginning o f the Start bit to the end of the Stop Bit of the prev ious charact er. If double buffering
is disabled the UART is compatible with the conventional 80C51 UART.
Double buffering is enabled by setting the DBMOD_n (SnSTAT.7) SFR bit to ’1’. If disabled (DBMOD_n = 0), the UART is
compatible with the conventional 80C51 UART. If enabled, the UART allows writing to SnBUF while the previous data is being
shifted out.
Transmit Interrupts with Double Buffering.
either the beginnin g or the end of th e Stop Bi t. The pu rpose of the in terrupt i s to let the user p rogra m know w hen the UART ca n
accept another cha racter. As a re sult the timin g of the interru pt has been cha nged when do uble buffering is enabled. A n interrupt
is generated each time dat a is tran sferred from the b uffer reg ister to t he trans mit sh ift regis ter. Thu s if the U ART tr ansmi t is idl e
an interrupt will be generated as soon as the buffer register is loaded. If the UART is transmitting a character when the buffer
register is loaded, an in terru pt w il l no t occur until the beginning of the Stop Bit of th e cu rren t character. Note that if the buffer is
loaded anytime before the end of the Stop Bit characters will be transmitted without extra Stop Bit time. Also if a character is
loaded into the buffer during the stop bit the interrupt will occur when the buffer is loaded.
There is one additional feature with respect to the occurrence of interrupts when double buffering is enabled. If the DBISEL_n
SFR bit is a '0' an in terrupt occurs on ly when data i s transferred f rom the buffer to the transmi t shift regis ter. Thus each c haracter
generates a singl e inte rrupt. Th e opera tion i s iden tical if D BISEL_n is a '1.' As l ong as the b uffer reg ister i s fill ed befo re the stop
bit is reached. If DBISEL_n is a '0' and the INTLO_n SFR bit is a '1' an interrupt will occur at the end of the Stop Bit of the last
character if the b uffe r reg is ter i s em pty . If If D BISEL _n is a ' 0 ' a nd the INTL O_ n SFR bit is a '0', an int errup t w il l b e g ene rated at
the beginning of the Stop Bi t if the tra ns mi t buff er regi st er is emp ty. Note that in this case if the transmit b uffe r is lo ade d bef ore
the end of the st op bit another interrupt will b e g ene rate d a nd the UART will transm it this new character w ith out len gth eni ng the
Stop Bit.
Without double buffering the transmit interrupt can be selected to occur at
60Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
TxDn
Write to
SnBUF
Tx Interrupt
Single Buffering (DBMOD_n/SnSTAT.7 = 0), Early Interrupt (INTLO_n/SnSTAT.6 = 0) is Shown
TxDn
Write to
SnBUF
Tx Interrupt
Double Buffering (DBMOD _n/Sn STAT. 7 = 1), Earl y Int errupt (INTLO _n/SnS TAT.6 = 0) i s Sh own,
No Ending Tx Interrupt (DBISEL_n/SnSTAT.4 = 0)
TxDn
Write to
SnBUF
Tx Interrupt
Double Buffering (DBMOD _n/Sn STAT. 7 = 1), Earl y Int errupt (INTLO _n/SnS TAT.6 = 0) i s Sh own,
With Ending Tx Interrupt (DBISEL_n/SnSTAT.4 = 1)
Figure 48: Transmission with and without Double Buffering (8-Bit Case)
The 9th Bit (Bit 8) in Double Buffering.
before or after SnBUF is written, as long as TB8 is updated some time before that bit is shifted out. TB8 must not be changed
until the bit is shifted out, as indicated by the Tx interrupt.
If double buffering is enabled, TB8 MUST be updated before SnBUF is written, as TB8 will be double-buffered together with
SnBUF data. The operation described in the section "Transmit Interrupts with Double Buffering" becomes as follows:
1. The double buffer is empty initially.
2. The CPU writes to TB8.
3. The CPU writes to SnBUF.
4. The SnBUF/TB8 data is loaded to the shift register and a Tx interrupt is generated immediately.
5. If there is more data, go to 7, else continue on 6.
6. If there is no more data, then:
- If DBISEL_n is ’0’, no more interrupt will occur.
- If DBISEL_n is ’1’ and INTLO_n is ’0’, a Tx interrupt will occur at the beginning of the STOP bit of the data currently in the
shifter (which is also the last data).
- If DBISEL_n is ’1’ and INTLO_n is ’1’ (U ART mo de 1, 2 or 3) , a Tx inter rupt will oc cur at the end of the ST OP bi t of the data
currently in the shifter (which is also the last data).
7. If there is more data, the CPU writes to TB8 again.
8. The CPU writes to SnBUF again. Then:
If double buffering is disabled (DBMOD_n, i.e . SnSTAT.7 = 0), TB8 can be written
61Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
- If INTLO_n is ’0’, the new data will be loaded and a Tx interrupt will occur at the beginning of the STOP bit of the data cur-
rently in the shifter.
- If INTLO_n is ’1’ (UART m ode 1, 2 or 3), the n ew data w ill be lo aded an d a T x interrupt w ill o ccur at the e nd of th e STO P bit
of the data currently in the shifter.
Go to 4.
Note that if DBISEL_n is ’1 ’ and when the CPU is writing to SnBUF a bout the same ti me the STOP b it of the last da ta is shifted
out, there can be an uncertainty of whether a Tx interrupt is generated already with the UART not knowing whether there is
any more data following.
6.6.12MULTIPROCESSOR COMMUNICATIONS
UART modes 2 and 3 have a special provision for multiprocessor communications. In these modes, 9 data bits are received or
transmitted. When da ta is receiv ed, th e 9th b it is stored in R B8_n. T he UART ca n be p rogram med suc h that when the s top bit is
received, the serial port interrupt will be activated only if RB8_n = 1. This feature is enabled by setting bit SM2 in SCON. One
way to use this feature in multiprocessor systems is as follows:
When the master processor wants to transmit a block of data to one of several slaves, it first sends out an address byte which
identifies the targe t slav e. An addres s byt e diffe rs from a da ta by te in t hat the 9 th bit is 1 in an addres s by te and 0 in a data byte .
With SM2 = 1, no slave will be in terru pte d by a data by te. An a ddre ss byt e, ho w eve r, will interrupt all slaves, so that eac h s lave
can examine the re ceived byte and see i f it is b eing addre ssed. Th e addressed slave w ill cl ear its SM2 bit and prepare to receive
the data bytes that follow. The slaves that weren’t being addressed leave their SM2 bits set and go on about their business,
ignoring the subsequent data bytes.
SM2 has no effect in Mode 0, and in Mode 1 can be used to check the validity of the stop bit, although this is better done with
the Framing Error flag. In a Mode 1 reception, if SM2 = 1, the receive interrupt will not be activated unless a valid stop bit is
received.
6.6.13AUTOMATIC ADDRESS RECOGNITION
Automatic Address Recognition is a feature which allows the UART to recognize certain addresses in the serial bit stream by
using hardware to make the comparisons. This feature saves a great deal of software overhead by eliminating the need for the
software to examine every serial address whic h passes by the serial port. Th is feature is enabled by setting the SM2 bit i n SCON.
In the 9 bit UART modes, mode 2 and mode 3, the Receive Interrupt flag (RI) will be automatically set when the received byte
contains either the “Given” address or the “Broadcast” address. The 9 bit mode requires that the 9th information bit is a 1 to
indicate that the received information is an address and not data.
Using the Automatic Address Recognition feature allows a master to selectively communicate with one or more slaves by
invoking the Given slave ad dress or add resses. Al l of the sla ves may be c ontacted by using t he Broadcast ad dress. Tw o special
Function Registers are used to define the slave’s address, SADDR, and the address mask, SADEN. SADEN is used to define
which bits in the SADDR are to be used and which bits are “don’t care”. The SADEN mask can be logically ANDed with the
SADDR to create the “Given” address which the master will use for addressing each of the slaves. Use of the Given address
allows multiple slaves to be recognized while excluding others. The following examples will help to show the versatility of this
scheme:
Slave 0 SADDR = 1100 0000
Slave 1 SADDR = 1100 0000
In the above example SADDR is the same and the SADEN data is used to differentiate between the two slaves. Slave 0 requires
a 0 in bit 0 and it ignores bi t 1. Slave 1 requires a 0 in bi t 1 and bi t 0 is ig nored. A uni que addre ss for Sla ve 0 would be 1100 0010
since slave 1 requires a 0 in bi t 1. A un ique address for slave 1 would be 11 00 0 001 sin ce a 1 in bi t 0 will exc lu de s lav e 0. Both
slaves can be selected at the same time by an address which has bit 0 = 0 (for slave 0) and bit 1 = 0 (for slave 1). Thus, both
could be addressed with 1100 0000.
In a more complex system the following could be used to select slaves 1 and 2 while excluding slave 0:
SADEN = 1111 1101
Given= 1100 00X0
SADEN = 1111 1110
Given= 1100 000X
62Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
16383 prescalefactor
×
P87C51Mx2Extended Address Range Micr ocontroller
Slave 0 SADDR = 1110 0000
Slave 1 SADDR = 1110 0000
Slave 2 SADDR = 1110 0000
In the above example the differentiation among the 3 slaves is in the lower 3 address bits. Slave 0 requires that bit 0 = 0 and it
can be uniquely addresse d by 1110 011 0. Slave 1 requ ires tha t bit 1 = 0 and it can be uniq uely ad dresse d by 1110 01 01. Slave
2 requires that bit 2 = 0 and its unique address is 1110 0011. To select Slaves 0 and 1 and exclude Slave 2 use address 1110
0100, since it is necessary to make bit 2 = 1 to exclude slave 2. The Broadcast Address for each slave is created by taking the
logical OR of SADDR and SADEN. Zeros in this result are treated as don’t-cares. In most cases, interpreting the don’t-cares as
ones, the broadcast address will be FF hexadecimal. Upon reset SADDR and SADEN are loaded with 0s. This produces a given
address of all “don’t cares” as w ell as a Broad cast addres s of all “don’ t cares”. This effectively disables t he Automatic Addressing
mode and allows the microcontroller to use standard UART drivers which do not make use of this feature.
SADEN = 1111 1001
Given= 1110 0XX0
SADEN = 1111 1010
Given= 1110 0X0X
SADEN = 1111 1100
Given= 1110 00XX
6.7WATCHDOG TIMER
The watchdog timer subsystem protects the system from incorrect code execution over a longer period of time by causing a
system reset when the wat chdog timer un derflows as a res ult of a fa ilure o f software to feed th e time r prior to th e timer re aching
its terminal count.
For the P87C51Mx2, th e watchdog timer i s compa tible with the wa tchdog ti mer in 8 9C51Rx2. In addit ion, it h as a pres caler of up
to 1024 times (default without prescaling) that support longer watchdog timeout.
The WDT consists of a 14-bit co unter and Watchdo g Timer Reset(WD TRST) SFR. The prescaler is determined by the watchdog
control (WDCON) SFR in the MX extended SFR space.
6.7.1WATCHDOG FUNCTION
The time interval of the watchdog timer can be calculated as:
timeoutperiod
In other words, after a feed sequ ence, the w atchd og tim er time o ut will oc cur a fter machine cycles and
will cause a watchdog reset, unless the next feed sequence occurs before the time out.
16383 prescalefactor×6
--------------------------------------------------------------------=
f
OSC
×
6.7.2FEED SEQUENCE
WDT is disabled after reset of the microcontroller. To enable the WDT, user must write 01EH and 0E1H in sequence to the
WDTRST register. Once the WD T is en abl ed , use r mu st fe ed the watchdog in by writing 01EH and 0E1H to WDTRST before a
WDT timeout to avoid WDT overflow. When WDT overflows, it will drive an reset HIGH pulse at the RST pin. After WDT is
enabled, it cannot be disabled unless reset.
The following code is recommended for a feed sequence:
CLREA;Disable all interrupts, avoid interrupt in between two parts of feed
;sequence.
63Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
MOVWDTRST,#01Eh;Feed sequence first part
MOVWDTRST,#0E1h;Feed sequence second part
SETBEA;Enable interrupts.
Note that:
• Upon a power up or any reset, including WDT reset, the watch dog timer is disabled. Executing the feed sequence once will
start the WDT. Once started, it cannot be disabled until reset again.
• The watchdog is enabled by a write of 1Eh followed by a write of E1h to the WDTRST register. Before the first 1Eh is written
to WDTRST, a write of any pattern (other than 1Eh) will not cause a reset. Once an 1Eh is written to the WDTRST register,
any write of a pattern other than 1Eh or E1h to the WDTRST register will cause a watchdog reset.
• The triggering event to restart the WDT is the second part (writing E1h to the WDTRST SFR) of the feed sequence.
• Refer to Figure 49 for details of WDT operations, including effects of illegal feed patterns to the WDTRST SFR.
64Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Any Reset
WDT disabled. Wait for next
write to the WDTRST SFR
No
=1Eh
=E1h
Written 01Eh to the
WDTRST SFR?
Yes
WDT disabled. Wait for next
write to the WDTRST SFR
Value written to the
WDTRST SFR?
=E1h
Start WDT
WDT enabled. Wait for next
write to the WDTRST SFR
Value written to the
WDTRST SFR?
=1Eh
Neither 1E h nor E1h
Time out
Neither 1Eh nor E1h
WDT Reset
=1Ehh
WDT enabled. Wait for next
write to the WDTRST SFR
Time out
Written 0E1h to the
WDTRST SFR?
=E1h
Restart WDT
Figure 49: Watchdog Timer State Transitions
Neither 1Eh nor E1h
65Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
6.7.3WDT CONTROL
The P87C51Mx2 has a control register in the MX extended SFR space. It has a 3-bit prescaler control to select the prescale
factor for the watchdo g time r clock . WDCON shou ld be loade d with selec ted v alue b efore W DT is t urned on. Writing to WDCO N
while WDT is enabled will result in unpredictable behavior.
6.7.4WATCHDOG RESET WIDT H
When the WDT times out, a reset will occur, and the external reset (RST) pin will be driven high for 98 clock cycles.
WDCON
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
WDCON.7-3-Reserved for future use. Should be set to 0 by user programs.
WDCON.2-0WDPRE2-0Select WDT presecale factor. Note that the value written to these bits will not be
immediately available to be read until after a WDT feed sequence.
Figure 50: WDCON Register
Table 15: WDT Prescale Selection
6.7.5READING FROM THE WDCON SFR
It should be noted that value written to the WDCON register will not be immediately available to be read until after a successful
feed sequence. Any read before a feed sequence will fetch the old value.
6.7.6SOFTWARE RESET VIA WATCHDOG TIMER FEED SEQUENCE
The following instruc tions wil l resul t in a software rese t via the watchdog timer res et, even if one or more interrup ts occu r during
those instructions:
MOVWDTRST,#01Eh;Feed sequence first part
MOVWDTRST,#0AAh;Any pattern other than 1Eh or E1h (not necessarily AAh) will perform a
;WDT reset
66Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
This software reset will be performing the same function as a WDT reset, where a reset pulse will also be generated to reset
external circuitries.
6.8ADDITIONAL FEATURES
AUXR
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
AUXR.7-2-Reserved for future use. Should be set to 0 by user programs.
AUXR.1EXTRAMInternal/External R AM access using MO VX @Ri/@DPTR. When 0, i nternal XRAM access
AUXR.0AODisable/Enable ALE. When 0, ALE is emitted at a constant rate of 1/3 the oscillator
Address: 8EH
76543210
------EXTRAMAO
is selected. When 1, external data memory is selected. (Refer to "51MX Architecture
Reference").
frequency. When 1, ALE is active only during a MOVX or MOVC instruction that is
targeting .
Figure 51: AUXR Register
6.8.1EXPANDED DATA RAM ADDRESSING
The P87C51Mx2 has expanded data RAM addressing capability. Details of the data memory structure are explained in "51MX
Architecture Reference".
The device has on-chip data memory that is mapped into the following segments:
• Address 0000H-007FH are directly and indirectly addressable (DATA memory).
• Address 0080H-00FFH are indirectly addressable as RAM (IDATA memory). Note: When 000080H-0000FFH is directly
addressed, SFRs will be accessed.
• Address 0100H-04FFH (for MB2/MC2) are extended indirectly addressable RAM (part of EDATA memory).
• There are also 768 bytes of XDATA memory (locations 000000H-0002FFH) for MB2, and 1,792 bytes of XDATA memory
(locations 000000H-0006FFH) for MC2. If EXTRAM = 0, this internal XDATA memory location is selected in a MOVX
instruction to/from locations 000000H-0002FFH (for MB2) or 000000H-0006FFH (for MC2), and external memory will be
accessed above t hese loc ations . If EXTR AM = 1, the interna l XDATA RAM wi ll no t be us ed, al l MOVX in struc tions will ac cess
external data memory.
67Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
AUXR1
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
AUXR1.7-5-Reserved for future use. Should be set to 0 by user programs.
AUXR1.4LPEPLPEP can be set to one for applications where V
AUXR1.3GF2General purpose user-defined flag.
AUXR1.20This bit contains a hard-wired 0. Allows toggling of the DPS bit by incrementing AUXR1,
AUXR1.1-Reserved for future use. Should be set to 0 by user programs.
AUXR1.0DPSData Pointer Select. Chooses one of two Data Pointers for us e by the pro gram . See text
Address: A2h
76543210
---LPEPGF20-DPS
< 4V (reduces power consumption).
CC
without interfering with other bits in the register.
for details.
Figure 52: AUXR1 Register
6.8.2DUAL DATA POINTERS
The dual Data Pointer (DPTR) adds to the ways in which the processor can specify the address used with certain instructions.
The DPS bit in the AUXR1 register sele cts one of the two Data Poi nters. The DPTR that is not curr ently selected is not accessible
to software unless the DPS bit is toggled.
Specific instructions affected by the Data Pointer selection are:
• INCDPTRIncrements the Data Pointer by 1.
• JMP @A+DPTRJump indirect relative to DPTR value.
• MOV DPTR, #data16Load the Data Pointer with a 16-bit constant.
• MOVC A, @A+DPTRMove code byte relative to DPTR to the accumulator.
• MOVX A, @DPTRMove data byte from data memory, relative to DPTR, to the accumulator.
• MOVX @DPTR, AMove data byte from the accumulator to data memory, relative to DPTR.
Also, any instructi on that reads or manip ula tes th e DP H and D PL regi sters (the upper and l ower by tes of the c urren t D PTR ) will
be affected by the setting of DPS. Bit 2 of AUXR1 is permanently wired as a logic 0. This is so that the DPS bit may be toggled
(thereby switching Data Pointers) simply by incrementing the AUXR1 register, without the possibility of inadvertently altering
other bits in the register.
6.9PROGRAMMABLE COUNTER ARRAY (PCA)
The Programmable Counter Array available on the P87C51Mx2 is compatible with 89C51Rx2. The PCA includes a special 16bit Timer that has five 16-bit capture/compare modules associated with it. Each of the modules can be programmed to operate
in one of four modes: rising and/or falling edge capture, software timer, high-speed output, or pulse width modulator. Each
module has a pin as sociated wi th it in port 1. Module 0 is connected t o P1.3(CEX0), modu le 1 to P1.4(CEX1), etc. The PCA ti mer
is a common time base for all five modules and can be programmed to run at: 1/6 the oscillator frequency, 1/2 the oscillator
frequency, the Timer 0 overflow, or the input on the ECI pin (P1.2). The timer count source is determined from the CPS1 and
CPS0 bits in the CMOD SFR (see Figure 55).
In the CMOD SFR there are three additional bits associated with the PCA. They are CIDL which allows the PCA to stop during
idle mode, WDTE which enables or disables the watchdog function on module 4, and ECF which when set causes an interrupt
and the PCA overflow flag CF (in the CCON SFR) to be set when the PCA timer overflows.
The watchdog timer function is implemented in module 4.
The CCON SFR contains the run contro l bit for the PCA and the flags for the PCA timer (CF) and each modul e. To run the PCA
the CR bit (CCON.6) must be set by software. The PC A is shut off by clea ring this bit. The CF bit (CCON. 7) is set when the PCA
counter overflows and an interrupt will be generated if the ECF bit in the CMOD register is set. The CF bit can only be cleared
by software. Bits 0 through 4 of the CC ON regist er are the flag s for the module s (bit 0 for mod ule 0, bit 1 for mo dule 1, etc .) and
are set by hardware when eith er a match or a capture occurs . These flags can only be cl eared by software. All the mod ules share
one interrupt vector. The PCA interrupt system is shown in Figure 54.
Each module in the PCA has a specia l function regist er associated wit h it. These registers are: CC APM0 for module 0, CCAP M1
for module 1, etc. Th e registers cont ain the bits that cont rol the mode that e ach module will o perate in. The ECCF bit (CCAPMn.0
where n=0, 1, 2, 3, or 4 depending on the module) enables the CCF flag in the CCON SFR to generate an interrupt wh en a match
or compare occurs in the associated module. PWM (CCAPMn.1) enables the pulse width modulation mode. The TOG bit
(CCAPMn.2) when set causes the CEX output associated with the module to toggle when there is a match between the PCA
counter and the module’s capture/compare register. The match bit MAT (CCAPMn.3) when set will cause the CCFn bit in the
CCON register to be set when there is a match between the PCA counter and the module’s capture/compare register.
The next two bits CAPN (CCAPMn.4) and CAPP (CCAPMn.5) determine the edge that a capture input will be active on. The
CAPN bit enables the negative edg e, and the CAPP bit enable s the positive ed ge. If both bits are se t both edges will be en abled
and a capture will occur for either transition. The last bit in the register ECOM (CCAPMn.6) when set enables the comparator
function.
There are two additiona l registers associate d with eac h of the PCA mo dules. The y are CCAPnH an d CCAPnL and these are th e
registers that st ore the 16 -bit count whe n a capture occurs or a compare should oc cur. When a m odule is u sed in the PWM mode
these registers are used to control the duty cycle of the output.
69Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
PCA TIMER/COUNTER
MODULE0
MODULE1
MODULE2
MODULE3
MODULE4
CMOD.0CCAPMn.0
CFCR-CCF4CCF3CCF2CCF1CCF0
ECFECCFn
Figure 54: PCA Interrupt System
IE.6
EC
IE.7
EA
CCON
(D8h)
TO
INTERRUPT
PRIORITY
DECODER
CMOD
Address: D9H
76543210
CIDLWDTE---CPS1CPS0ECF
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
CMOD.7CIDLCounter Idle Control: CIDL = 0 program s the PCA Co unter to cont inue f unctioni ng durin g
Idle Mode. CIDL = 1 program it to be gated off during idle.
CMOD.6WDTEWatchdog Timer Enable: WDTE = 0 disables watchdog timer function on module 4.
WDTE = 1 enable it.
CMOD.5-3-Reserved for future use. Should be set to 0 by user programs.
CMOD.2-1CPS1,CPS0PCA Count Pulse Select:
CPS1
000 Internal Clock, f
0 11 Internal Clock, f
CPS0Select PCA Input_______________
/ 6
OSC
/ 2
OSC
102 Timer 0 Overflow
113 External Clock at ECI/P1.2 pin ( max rate = f
OSC
/4)
CMOD.0ECFPCA Enable Counter Overflow I nterrupt: EC F = 1 en ables CF b it in CC ON to generate an
interrupt. ECF = 0 disabled that function.
Figure 55: CMOD: PCA Counter Mode Register
70Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
CCON
Address: 0D8H
Bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
CCON.7CFPCA Counter Overflow Flag. Set by hardware when the counter rolls over. CF flags an
CCON.6CRPCA Counter Run Control Bit. Set by software to turn the PCA counter on. Must be cleared
CCON.5-Reserved for future use. Should be set to 0 by user programs.
CCON.4CCF4PCA Module 4 Interrupt Flag. Set by hardware when a match or capture occurs. Must be
CCON.3CCF3PCA Module 3 Interrupt Flag. Set by hardware when a match or capture occurs. Must be
CCON.2CCF2PCA Module 2 Interrupt Flag. Set by hardware when a match or capture occurs. Must be
CCON.1CCF1PCA Module 1 Interrupt Flag. Set by hardware when a match or capture occurs. Must be
CCON.0CCF0PCA Module 0 Interrupt Flag. Set by hardware when a match or capture occurs. Must be
76543210
CFCR-CCF4CCF3CCF 2CCF1CCF0
interrupt if bit ECF in CMOD is set. CF may be set by either hardw are or software but can
only be cleared by software.
by software to turn the PCA counter off.
cleared by software.
cleared by software.
cleared by software.
cleared by software.
cleared by software.
Figure 56: PCA Counter Control Register
71Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
CCAPMn
Address: CCAPM0 0DAH
CCAPM1 0DBH
CCAPM2 0DCH
CCAPM3 0DDH
CCAPM4 0DEH
Not bit addressable
Reset Value: 00h
BITSYMBOLFUNCTION
CCAPMn.7-Reserved for future use. Should be set to 0 by user programs.
CCAPMn.6ECOMnEnable Comparator. ECOMn = 1 enables the comparator function.
CCAPMn.5CAPPnCapture Positive, CAPPn = 1 enables positive edge capture.
CCAPMn.4CAPNnCapture Negative, CAPNn = 1 enables negative edge capture.
CCAPMn.3MATnMatch. When MATn = 1 a m atc h o f th e PC A co unte r w it h th is m odu le’ s co mp are/ capture
CCAPMn.2TOGn
CCAPMn.1PWMnPulse Width Modulation Mode. PWMn = 1 enables the CEXn pin to be used as a pulse
CCAPMn.0E CCFnEnable CCF Interrupt. Enables compare/capture flag CCFn in th e CCON register to
76543210
-ECOMnCAPPnCAPNnMATnTOGnPWMnECCFn
register causes the CCFn bit in CCON to be set, flagging an interrupt.
T
oggle. When TOGn = 1, a matc h of the PCA co unter with th is module ’s compare/ capture
100110x 16-bit high speed output
10000108-bit PWM
1001x0xWatchdog timer
Table 16: PCA Module Modes (CCAPMn Register)
16-bit capture by a positive-edge
trigger on CEXn
16-bit capture by a negative-edge
trigger on CEXn
16-bit capture by any transistion on
CEXn
6.9.1PCA CAPTURE MODE
To use one of the PCA modules in the capture mode either one or both of the CCAPM bits CAPN and CAPP for that module
must be set. The extern al CEX input for the mod ule (on port 1) is sa mpled for a transi tion. When a valid transition occu rs the PCA
hardware loads the v alue of the PCA c ounter register s (CH and CL) i nto the modul e’s capture regi sters (CCAPn L and CCAPnH).
72Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
If the CCFn bit for the module in the CCON SFR and the ECCFn bit in the CCAPMn SFR are set then an interrupt will be
generated.
6.9.216-BIT SOFTWARE TIMER MODE
The PCA modules can be used as software timers by setting both the ECOM and MAT bits in the modules CCAPMn register.
The PCA timer will be compared to the module’s capture registers and when a match occurs an interrupt will occur if the CCFn
(CCON SFR) and the ECCFn (CCAPMn SFR) bits for the module are both set.
6.9.3HIGH SPEED OUTPUT MODE
In this mode the CEX output (on port 1) associated with the PCA module will toggle each time a match occurs between the PCA
counter and the mod ule’s capture regi sters. To a ctivate this mod e the TOG, MAT , and ECOM bits i n the module’ s CCAPMn SFR
must be set.
6.9.4PULSE WIDTH MODULATOR MODE
All of the PCA module s can be used as PWM output s. The freq uency of the output depen ds on the source fo r the PC A time r. All
of the modules will have the same frequency of output because they all share the PCA timer. The duty cycle of each module is
independently varia bl e us in g th e m od ule ’s ca ptu r e re gis ter C CAPnL. Whe n th e v al ue o f th e PCA C L SFR i s l es s t han the va lu e
in the module’s CCAPnL SFR the ou tput will be low, when it is equa l to or greater than the output will be high. When CL overflows
from FF to 00, CCAPnL is reloaded with the value in CCAPnH. this allows updating the PWM without glitches. The PWM and
ECOM bits in the module’s CCAPMn reg ister must be set to enable the PWM mode.
6.9.5PCA WATCHDOG TIMER
An on-board watchdog timer is available with the PCA to improve the reliability of the system without increasing chip count.
Watchdog timers are use ful for sy stem s that are susc eptibl e to nois e, power gl itche s, or ele ctrostatic disc harge. M odule 4 is the
only PCA module that can be programmed as a watchdog . However, this module ca n still be used for other modes if the watchdog
is not needed. Figure 58 sh ows a diagram of how the w atchdog works . The user pre -loads a 16-b it value in the compare re gisters.
Just like the othe r compare modes, this 16-bit va lue is compared to the PCA time r value. If a ma tch is allowed to occur, an internal
reset will be generated. This will not cause the RST pin to be driven high.
73Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
WRITE
TO
CCAP4H
WRITE
TO
CCAP4L
10
RESET
CIDLWDTE---CPS1CPS0ECF
CCAP4H (FEH) CCAP4L (EEH)
16-BIT COMPARATOR
CH (F9H)CL (E9H)
PCA TIMER/COUNTER
-ECOMnCAPPnCAPNnMATnTOGnPWMnECCFn
MODULE 4
MATCH
0
01X 0X
CMOD
(D9H)
INTERNAL
RESET
CCAPM4
(DEH)
Figure 58: PCA Watchdog Timer (Module 4 only)
In order to hold off the reset, the user has three options:
1. periodically change the compare value so it will never match the PCA timer,
2. periodically change the PCA timer value so it will never match the compare values, or
3. disable the watchdog by clearing the WDTE bit before a match occurs and then re-enable it.
The first two options are more re liable be cause the watchdog ti mer is ne ver disab led as in opt ion #3. If the progra m counter ever
goes astray, a matc h will ev entually occur and cause an i nternal res et. The s econd opt ion is al so not rec ommended if othe r PCA
modules are bein g u sed. R em em be r, th e PCA timer is the time base for
all
modules; changing t he time base for other modules
would not be a good idea. Thus, in most applications the first solution is the best option.
The following shows the code for initializing the watchdog timer:
INIT_WATCHDOG:
MOVCCAPM4,#04Ch;Module 4 in compare mode
MOVCCAP4L,#0FFh;Write to low byte first
MOVCCAP4H,#0FFh;Before PCA counts up to FFFFh, these compare values must be cha nge d
ORLCMOD,#040h;Set the WDTE bit to enable the watchdog timer without changing the
;other bits in CMOD
;CALL the following WATCHDOG subroutine periodically.
CLREA;Hold off interrupts
MOVCCAP4L,#00;Next compare value is within 255 counts of current PCA timer value
MOVCCAP4H,CH
SETBEA;Re-enable interrupts
RET
74Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Module 4 can be configured in either compare mode, and the WDTE bit in CMOD must also be set. The user’s software then
must periodically chang e (CCAP4 H,CCAP4L ) to kee p a m atch fr om oc curring with th e PCA t imer (CH, CL). Th is co de is give n in
the WATCHDOG routine shown above.
This routine shoul d no t be p art of an in terru pt s erv ic e rou tin e, because if the program coun ter goes astray and gets stuc k in an
infinite loop, interrupts will still be serviced and the watchdog will keep getting reset. Thus, the purpose of the watchdog would
be defeated. Instead, call this subroutine from the main program within 2
16
count of the PCA timer.
75Preliminary 2002 June 28
Philips SemiconductorsP87C51Mx2 User Manual
P87C51Mx2Extended Address Range Micr ocontroller
Disclaimers
Life support —
can reasonably be expected to result in personal injury. Philips Semiconductors customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify Philips Semiconductors for any damages resulting from such application.
Right to make changes —
dardcells, and/or software, described or contained herein in order to improve design and/or performance. Philips Semiconductors assumes no
responsibility or liability for the use of any of these products, conveys no license or title under any patent, copyright, or mask work right to these
products, and makes no representations or warranties that these products are free from patent, copyright, or mask work right infringement ,
unless otherwise specified.
Philips Semiconductors
811 East Arques Avenue
P.O. Box 3409
Sunnyvale, California 94088–3409
Telephone 800-234-7381
Copyright Philips Electronics North America Corporation 2002
All rights reserved. Printed in U.S.A.
Date of preliminary release: 06-02
These products are not designed for use in life support appliances, devices or systems where malfunction of these products
Philips Semiconductors reserves the right to make changes, without notice, in the products, including circuits, stan-
76Preliminary 2002 June 28
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.