MPC89L (E) 51-515 Application Note A1.5
MPC89L (E) 51-515 Application Note A1.5
MPC89L (E) 51-515 Application Note A1.5
MPC89E51/52/53/54/58/515
Application Note
Contents
0. Features
1. Pin Assignment
2. Special Function Registers
3. Extended General Purpose I/O Port, P4 New Feature
4. On-chip eXpanded RAM (XRAM) New Feature
5. Second DPTR New Feature
6. Up/Down Counting of Timer 2 New Feature
7. Programmable Clock-Out New Feature
8. Enhanced UART New Feature
9. Eight Interrupt Sources and Four-Priority-Level Nested Structure New Feature
10. Wake-up from Power-down by External Interrupt New Feature
11. One-time Enabled Watchdog Timer (WDT) New Feature
12. Reduced EMI Mode New Feature
13. 12T Mode and 6T Mode New Feature
14. In-System-Programming (ISP) New Feature
15. Non-volatile Data Application using In-Application-Programming New Feature
16. Power-ON Flag New Feature
17. Option Registers
18. Flash Memory Configuration
19. XTAL Oscillating Requirement and ALE Output Frequency
20. Power Consumption
21. How to Reduce EMI
22. UART Baudrate Setting
23. Notes on Using External Interrupt
This document contains information on a new product under development by MEGAWIN. MEGAWIN reserves the right to change or discontinue
this product without notice.
MEGAWIN Technology Co., Ltd. 2003 All rights reserved. 2005/02 version A1.5
MEGAWIN
Revision History
Version Revision
(1) Add “ISP Mode Select Table” and remove attached “ISP Technical Support” in Section 14.
1.5 (2) Revise test Ipwdn to be < 1.0 uA, in Section 20
(3) Add a new section, Section 23.
• Including All the 8052 Features, and New Powerful Features Are Added:
- Extended General Purpose I/O Port, P4
- On-chip eXpanded RAM (XRAM)
- Second DPTR
- Up/Down Counting of Timer 2
- Programmable Clock-Out
- Enhanced UART
- Eight Interrupt Sources
- Four-Priority-Level Nested Interrupt Structure
- Wake-up from Power-down by External Interrupt
- One-time Enabled Watchdog Timer (WDT)
- Reduced EMI Mode
- Non-volatile Data Application using In-Application-Programming
- Power-ON Flag
T2/P1.0 1 40 VDD
T2EX/P1.1 2 39 P0.0/AD0
P1.2 3 38 P0.1/AD1
P1.3 4 37 P0.2/AD2
40-pin
P1.4 5 36 P0.3/AD3
P1.5 6 DIP 35 P0.4/AD4
P1.6 7 34 P0.5/AD5
P1.7 8 33 P0.6/AD6
RST 9 32 P0.7/AD7
RXD/P3.0 10 31 -EA
TXD/P3.1 11 30 ALE
-INT0/P3.2 12 29 -PSEN
-INT1/P3.3 13 28 P2.7/A15
T0/P3.4 14 27 P2.6/A14
T1/P3.5 15 26 P2.5/A13
-WR/P3.6 16 25 P2.4/A12
-RD/P3.7 17 24 P2.3/A11
XTAL2 18 23 P2.2/A10
XTAL1 19 22 P2.1/A9
VSS 20 21 P2.0/A8
MPC89L51/52/53/54/58/515AE
MPC89E51/52/53/54/58/515AE
P1.1/T2EX
P1.1/T2EX
P4.2/-INT3
P4.2/-INT3
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P1.0/T2
P1.0/T2
VDD
VDD
P1.4
P1.3
P1.2
P1.4
P1.3
P1.2
VSS
- WR/P3.6
P4.0
- WR/P3.6
- RD/P3.7
XTAL2
- RD/P3.7
A8/P2.0
A9/P2.1
A10/P2.2
A11/P2.3
A12/P2.4
XTAL1
A8/P2.0
A9/P2.1
A10/P2.2
A11/P2.3
A12/P2.4
XTAL2
XTAL1
MPC89L51/52/53/54/58/515AP MPC89L51/52/53/54/58/515AF
MPC89E51/52/53/54/58/515AP MPC89E51/52/53/54/58/515AF
Notes:
*: bit addressable
+
: modified from the 8052 SFRs
-: reserved bit
Set EXTRAM bit will disable XRAM accessing (but leave XRAM unchanged), and both “MOVX @Ri” and
“MOVX @DPTR” will access the external data memory as the traditional 8051 does.
For KEIL-C51 compiler, to assign the variables to be located at XRAM, the “pdata” or “xdata” definition should
be used. After being compiled, the variables declared by “pdata” and “xdata” will become the memories
accessed by “MOVX @Ri” and “MOVX @DPTR”, respectively. Thus the MPC89L(E)51/../515 H/W can access
them correctly. See the following descriptions, which is obtained from “Keil Software — Cx51 Compiler User’s
Guide”.
(83h) (82h)
DPS=0
DPTR0 DPH DPL
DPTR Instructions
The six instructions that refer to DPTR currently selected using the DPS bit are as follows:
The reset value of DCEN bit is 0, which makes Timer 2 function as the standard 8052 (always count up). If
DCEN=1, Timer 2 can count up or count down according to the logic level of the T2EX pin.
The external flag EXF2 (T2CON.6) toggles when Timer 2 overflows or underflows. It can be used as the 17th bit
of resolution if needed. The EXF2 flag does not cause an interrupt while DCEN=1.
TF2: Timer 2 overflow flag set by a Timer 2 overflow and must be cleared by software. TF2 will not be set when
either RCLK=1 or TCLK=1.
EXF2: Timer 2 external flag set when either a capture or reload is caused by a negative transition on T2EX pin
and EXEN2=1. When Timer 2 interrupt is enabled, EXF2=1 will cause the CPU to vector to the Timer 2 interrupt
routine. EXF2 must be cleared by software. EXF2 does not cause an interrupt in up/down mode (DCEN = 1).
RCLK: Receive clock flag. When set, causes the serial port to use Timer 2 overflow pulses for its receive clock
in modes 1 and 3. RCLK=0 causes Timer 1 overflow to be used for the receive clock.
TCLK: Transmit clock flag. When set, causes the serial port to use Timer 2 overflow pulses for its transmit clock
in modes 1 and 3. TCLK=0 causes Timer 1 overflows to be used for the transmit clock.
EXEN2: Timer 2 external enable flag. When set, allows a capture or reload to occur as a result of a negative
transition on T2EX pin if Timer 2 is not being used to clock the serial port. EXEN2=0 causes Timer 2 to ignore
events at T2EX pin.
C/T2: Timer or counter select. When cleared, select internal timer, when set, select external event counter
(falling edge triggered).
CP/RL2: Capture/Reload flag. When set, captures will occur on negative transitions at T2EX pin if EXEN2=1.
When cleared, auto-reloads will occur either with Timer 2 overflows or negative transitions at T2EX pin 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.
To configure the Timer/Counter2 as a clock generator, bit C/T2 (T2CON.1) must be cleared and bit T2OE (in
T2MOD, bit 1) must be set. Of course, 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:
Operating Frequency
n x (65536-[RCAP2H,RCAP2L])
where,
n=4 for 12T mode
n=2 for 6T mode
In the Clock-Out mode, Timer 2 roll-overs will not generate an interrupt. This is similar to when it is used 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 baud-rate, however, and the clock-out frequency will be the same.
While the SMOD0 bit (in PCON, bit 6) is set, the hardware will set the FE bit (SCON.7) when an invalid stop bit
is detected. The FE bit is not cleared by valid frames but should be cleared by software.
SM0/FE:
SM0: Serial Port Mode bit0 (while SMOD0=0).
FE: Frame Error bit (while SMOD0=1).
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 which passes by the serial port. This
feature is enabled by setting the SM2 bit in 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. Automatic address recognition is shown in the following figure.
The 8 bit mode is called Mode 1. In this mode the RI flag will be set if SM2 is enabled and the information
received has a valid stop bit following the 8 address bits and the information is either a Given or Broadcast
address.
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
SADEN = 1111 1101
Given = 1100 00X0
Slave 1
SADDR = 1100 0000
SADEN = 1111 1110
Given = 1100 000X
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 bit 1. Slave 1 requires a 0 in bit 1 and bit 0 is ignored. A unique
address for Slave 0 would be 1100 0010 since slave 1 requires a 0 in bit 1. A unique address for slave 1 would
be 1100 0001 since a 1 in bit 0 will exclude slave 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:
Slave 0
SADDR = 1100 0000
SADEN = 1111 1001
Given = 1100 0XX0
Slave 1
SADDR = 1110 0000
SADEN = 1111 1010
Given = 1110 0X0X
Slave 2
SADDR = 1110 0000
SADEN = 1111 1100
Given = 1110 00XX
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 addressed by 1110 0110. Slave 1 requires that bit 1 = 0 and it can be uniquely
addressed by 1110 0101. 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 trended as don’t-cares. In most cases, interpreting the don’t-cares as ones, the broadcast address will
be FF hexadecimal.
Upon reset SADDR (SFR address 0A9H) and SADEN (SFR address 0B9H) are leaded with 0s. This produces a
given address of all “don’t cares” as well as a Broadcast address of all “don’t cares”. This effectively disables the
Automatic Addressing mode and allows the micro-controller to use standard 80C51 type UART drivers which do
not make use of this feature.
PX3: defines the priority level of /INT3 interrupt. If PX3=1, the /INT3 interrupt has the higher priority level.
EX3: enables or disables the /INT3 interrupt. If EX3=1, the /INT3 interrupt is enabled.
IE3: /INT3 interrupt edge flag. Set by hardware when external interrupt edge detected. Cleared when
interrupt processed.
IT3: /INT3 type control bit. Set/cleared by software to specified falling-edge/low-level triggered.
PX2: defines the priority level of /INT2 interrupt. If PX2=1, the /INT2 interrupt has the higher priority level.
EX2: enables or disables the /INT2 interrupt. If EX2=1, the /INT2 interrupt is enabled.
IE2: /INT2 interrupt edge flag. Set by hardware when external interrupt edge detected. Cleared when
interrupt processed.
IT2: /INT2 type control bit. Set/cleared by software to specified falling-edge/low-level triggered.
For example, if (PT1H,PT1)=(1,0), then priority level of Timer 1 interrupt is 2, which is higher than level 1 with
(PT1H,PT1)=(0,1) and level 0 with (PT1H,PT1)=(0,0).
Either hardware reset or external interrupt (/INT0, /INT1, /INT2 or /INT3) can be used to exit from power-down
mode. Hardware reset initializes all the SFRs but does not change the on-chip RAM/XRAM, while external
interrupt allows both the SFRs and the on-chip RAM/XRAM to retain their values. To properly exit from power-
down mode, the external interrupt which is selected for waking up CPU must be enabled before power-down.
After power-down, trigger the selected external interrupt to wake up the CPU. Once the interrupt is serviced, the
next instruction (after RETI) to be executed will be the one following the instruction that invoked the power-down
mode. Note, this instruction must be a “NOP”.
CSEG AT 0000h
JMP start
;
CSEG AT 0003h ;INT0 interrupt vector, address=0003h
JMP IE0_isr
IE0_isr:
CLR EX0
;... do something
;...
RETI
;
start:
;...
;...
wake_up:
;If INT0(P3.2) is triggered by a falling-edge,
; the MCU will wake up, and enter "IE0_isr",
;then return here to run continuously !
;...
;...
;
When WDT is enabled, the user needs to service it by writing 1 to the CLRW bit to avoid WDT overflow. When
the 15-bit counter overflows, the chip reset signal will reset the MCU.
ENW: Set to enable WDT. This bit can only be cleared by any kind of reset. Software can not clear it.
CLRW: Write 1 to this bit to clear WDT. After WDT cleared, it is automatically cleared by H/W.
WIDL: Set this bit (!! Clear this bit for MPC89L516(556)X2) to let WDT keep counting while the MCU is in the Idle mode.
PS2~PS1: Used to determine the prescaler value.
Clock source:
Fosc/12, or Fosc/6 PS2,PS1,PS0
Prescaler
Chip reset
ENW 15-bit counter when overflow
2
4 clear
1: in Idle mode 8
0: otherwise
WIDL 16
CLRW
32
64
128
256
The following table shows the WDT overflow period for MCU running at 12MHz. The period is the maximum
interval for user to clear the WDT to prevent from chip reset.
main_loop:
ORL WDTCR_buf,#10h ;clear WDT
MOV WDTCR,WDTCR_buf ;
;...
;...
JMP main_loop
Timing Calculation
While the MCU runs at 6T-mode and at Fosc, the user may regard it as 12T-mode and at Fosc x 2. So, all
MCU’s timing (including internal and external) calculation can be based on Fosc x 2.
For example,
Suppose that the MCU runs at 6T-mode and Fosc=18MHz, we can regard it as a standard 8051 running at
36MHz. So, we will get
(1) One machine cycle has 1 / 36MHz x 12 = 0.33us
(2) ALE output frequency = 36MHz / 6 = 6MHz
(3) External program/data accessing timing, I/O timing and internal Timer/counter timing are calculated on the
base of 36MHz.
This MCU’s program memory is made of Flash memory, which has In-System-Programming (ISP) capability. In-
System-Programming allows the MCU to alter its program memory, in the actual end product, under software
control. This feature opens up a range of applications that need the ability to field update the application
firmware.
As shown in Figure 14a, the ISP-memory is allocated. To run the “ISP code”, the CPU should boot from the ISP-
memory. Two methods are used to boot from the ISP-memory. Figure 14b and Figure 14c demonstrate them.
0000h
AP-memory
Only 4KB for 51
Only 8KB for 52
15KB-ISPsize for 53
Application
code Only 16KB for 54
Only 32KB for 58
63KB-ISPsize for 515
ISP_start_address
ISP code
ISP-memory
3BFFh for 51/52/53 0KB, 1KB, 2KB or 4KB
FBFFh for 54/58/515
Notes:
(a) “ISP_start_address” is determined by OR0 (Option Register 0).
(b) Use the WRITER to program the “ISP code” into the ISP-memory beginning with “ISP_start_address”.
Start
Now,
CPU will boot from AP-memory,
and run "Application code".
YES
Now,
CPU will re-boot from ISP-memory,
and run "ISP code".
End
Start
Now,
CPU will boot from ISP-memory,
and run "ISP code".
YES
Now,
CPU will re-boot from AP-memory,
End and run "Application code" normally.
As mentioned in Section 14-1, to run “ISP code” via booting from ISP-memory by hardware method, the HWBS
bit in OR1 should be programmed to 0 by the Writer. Once HWBS becomes 0 (and ISP-memory exists), the
CPU will always boot from ISP-memory each time it starts from power-on, H/W reset or WDT reset. So, user
must distinguish normal operation from ISP programming. The new red dash line in the following chart (from
Figure 14c) shows the flow for normal operation (not do ISP).
Start
Now,
CPU will boot from ISP-memory,
and run "ISP code".
YES
Now,
CPU will re-boot from AP-memory,
End and run "Application code" normally.
Once the ISP condition is satisfied, the ISP operation is executed from label “do_ISP”, otherwise go to label
“not_do_ISP”. The following code shows this example.
Start:
.
.
do_ISP:
.
.
.
not_do_ISP:
.
.
.
delay_1ms:
.
.
RET
Figure 14f~14h show the flow chart for the various ISP modes used in the “ISP code”.
Start
Page_address=0
NO
Check
end of Page?
YES
End
Start
Byte_address=0
NO
Check
end of address?
YES
End
Start
Byte_address=0
YES
NO
Check end of
address?
YES
;=============================================================================
; 1. Page Erase Mode (512 bytes per page)
;=============================================================================
;=============================================================================
; 2. Byte Program Mode
;=============================================================================
;=============================================================================
; 3. Read Mode
;=============================================================================
ICK2-0: Set programming time of ISP. See the following table for their setting in several Fosc ranges.
SWBS: Software boot select. Set/Cleared to select ISP-memory/AP-memory to boot from after reset.
SWRST: Write 1 to trigger S/W reset.
Note:
1. The value 1 in the column ISP-memory means ISP-memory exists (not zero byte), while 0 means not exists
(zero byte).
2. For the ISPCR register, the bits ISPEN and SWBS will be initialized to its reset value only by power-on
reset. The other resets won’t initialize these two bits. So, for example, if ISP-memory exists (not zero byte)
and SWBS is set to 1 by firmware before H/W reset, S/W reset or WDT reset come, then the MCU will re-
boot from ISP-memory after these resets.
Any Flash page (with 512 bytes) in the IAP-memory can be erased, programmed and read by using the
ISP, as described in Section 14-4. This useful feature can be applied to the application where data must be
kept after power off. Thus, there is no need to use an external EEPROM for saving non-volatile data.
To update the non-volatile data, user should take the following steps:
Step1) Save the whole non-volatile data page (512 bytes) to a buffer (with size of 512 bytes).
Step2) Update some specific bytes in the buffer.
Step3) Erase this non-volatile data page.
Step4) Program the updated data out of the buffer to this page.
Usually, for MPC89L(E)51/52, there is not enough internal RAM for this buffer except using external RAM. So,
we recommend users use the on-chip 256 bytes of XRAM as the buffer. Of course, there should be no user
data saved there. So, one 512-byte Flash page can save only 256 bytes of non-volatile data due to the
limitation of XRAM’s size. If more non-volatile data are needed, use another Flash page to save one more 256
bytes.
For MPC89L(E)54/58, there is enough internal RAM for this buffer while the on-chip 1024 bytes of XRAM are
used (only 512 bytes are needed). Of course, there should be no user data saved there. So, one 512-byte
Flash page can save 512 bytes of non-volatile data. If more non-volatile data are needed, use another Flash
page to save one more 512 bytes.
MOVCL:
0: MOVC instruction executed from external program memory is disabled for security.
1: MOVC is always available.
SB:
0: Code dumped on a Writer is scrambled for security.
1: Code dumped on a Writer is not scrambled.
LOCK:
0: Code dumped on a Writer is locked to 0xFF for security.
1: Code dumped on a Writer is not locked.
FZWDTCR:
0: The WDTCR register will be initialized to its reset value only by power-on reset.
1: The WDTCR register will be initialized to its reset value by all reset (including power-on, H/W, S/W and WDT reset).
OSCDN:
0: Used under 25MHz for EMI reduction. (The gain of oscillating amplifier is reduced.)
1: The gain of crystal oscillator is enough for higher Fosc oscillating.
HWBS:
0: When power-on, H/W will set SWBS and CPU will boot from ISP-memory if ISP-memory exists.
1: (No action)
EN6T:
0: MCU runs at 6T mode (each machine-cycle has 6 clocks).
1: MCU runs at 12T mode (each machine-cycle has 12 clocks).
AP-memory
4KB
0x0FFF AP-memory
8KB
0x1FFF AP-memory
15KB
(for IAP)
AP-memory
16KB
0x3FFF AP-memory
32KB
AP-memory
0x7FFF 63KB
(for IAP)
While OSCDN=1
X1 2~19MHz 20~25MHz 26~30MHz 31~35MHz 36~39MHz 40~43MHz 44~48MHz
While OSCDN=0
X1 2~19MHz 20~25MHz 26~30MHz 31~35MHz 36~39MHz 40~43MHz 44~48MHz
Note:
(1) ‘-’ means no need.
(2) C1 and C2 include the parasitic capacitance in the PCB.
Oscillating Circuit
MPC89L(E)51~515
XTAL2
X1
XTAL1
R1
C1 C2
At 12T-mode, if the XTAL oscillating is successful and correct, the ALE output frequency will be Fosc / 6 (as that
of the standard 8051). While at 6T-mode, it will be Fosc*2 / 6.
For example,
If Fosc=24MHz, the ALE output frequency is 4MHz and 8MHz for 12T-mode and 6T-mode, respectively.
MPC89L(E)51~515
R2
XTAL2
X1 R3
XTAL1
R1
C1 C2
R1 - - - - -
The popular XTAL frequency used for UART application is 11.0592MHz, 18.432MHz, 22.1184MHz and
36.864MHz. The following tables show the TH1 and [RCAP2H, RCAP2L] values for a variety of the standard
baudrate.
Fosc=18.432MHz
Timer1 ( TH1 ) Timer2 ( [RCAP2H, RCAP2L] )
Baudrate 12T-mode 6T-mode
12T-mode 6T-mode
SMOD=0 SMOD=1 SMOD=0 SMOD=1
300 96 - - - 63616 61696
600 176 96 96 - 64576 63616
1200 216 176 176 96 65056 64576
1800 - - - - 65216 64896
2400 236 216 216 176 65296 65056
4800 246 236 236 216 65416 65296
7200 - - - - 65456 65376
9600 251 246 246 236 65476 65416
14400 - - - - 65496 65456
19200 - 251 251 246 65506 65476
38400 - - - 251 65521 65506
57600 - - - - 65526 65516
115200 - - - - 65531 65526
Fosc=36.864MHz
Timer1 ( TH1 ) Timer2 ( [RCAP2H, RCAP2L] )
Baudrate 12T-mode 6T-mode
12T-mode 6T-mode
SMOD=0 SMOD=1 SMOD=0 SMOD=1
300 - - - - 61696 57856
600 96 - - - 63616 61696
1200 176 96 96 - 64576 63616
1800 - - - - 64896 64256
2400 216 176 176 96 65056 64576
4800 236 216 216 176 65296 65056
7200 - - - - 65376 65216
9600 246 236 236 216 65416 65296
14400 - - - - 65456 65376
19200 251 246 246 236 65476 65416
38400 - 251 251 246 65506 65476
57600 - - - - 65516 65496
115200 - - - - 65526 65516
To safely use external interrupts, please refer to the following example, which includes some useful suggestion.
An Example:
ORG 0000h
JMP main
;--------------------------------------------------------------
main:
CLR IT0 ;IT0=0, select /INT0 as low-level-triggered
;
check_alarm:
;(Suppose: while “check_alarm” is being executed, it must not be interrupted by /INT0.)
CLR EX0 ;!!! Note: /INT0 interrupt may happen at this time
POP IE ;restore IE
RET
;
;--------------------------------------------------------------
INT0_isr:
;…
;…
SETB EX0 ;!!! delete this instruction if have,
; to prevent from /INT0 being enabled again while main program’s
; "CLR EX0" is being executed
;…
;…
RETI
;