NuMicro Family MS51 Series Technical Reference Manual
NuMicro Family MS51 Series Technical Reference Manual
NuMicro Family MS51 Series Technical Reference Manual
1T 8051
8-bit Microcontroller
NuMicro® Family
MS51 Series
MS51FB9AE
MS51XB9AE
MS51XB9BE
Technical Reference Manual
Nuvoton is providing this document only for reference purposes of NuMicro microcontroller based
system design. Nuvoton assumes no responsibility for errors or omissions.
All data and specifications are subject to change without notice.
TABLE OF CONTENTS
1 GENERAL DESCRIPTION .............................................................................. 8
2 FEATURES ...................................................................................................... 9
3 PARTS INFORMATION ................................................................................. 12
3.1 Package Type .............................................................................................................. 12
3.2 MS51 Series Selection Guide.................................................................................... 12
3.3 MS51 Series Selection Code ..................................................................................... 13
4 PIN CONFIGURATION .................................................................................. 14
4.1 MS51 16KB Series Multi Function Pin Diagram ..................................................... 14
4.1.1 TSSOP 20-pin Package Pin Diagram ........................................................................ 14
4.1.2 QFN 20-pin Package Pin Diagram ............................................................................. 15
4.2 MS51 16KB Series Pin Description .......................................................................... 17
5 BLOCK DIAGRAM......................................................................................... 19
5.1 MS51 16KB Series Block Diagram ........................................................................... 20
6 FUNCTION DESCRIPTION ........................................................................... 21
6.1 Memory Organization.................................................................................................. 21
6.1.1 Program Memory ............................................................................................................ 21
6.1.2 Data Flash ....................................................................................................................... 23
MS51 SERIES TECHNICAL REFERENCE MANUAL
2
6.10.5 I C Interrupt ................................................................................................................... 275
6.10.6 Control Registers .......................................................................................................... 275
6.10.7 Typical Structure of I2C Interrupt Service Routine ................................................... 279
6.11 Pulse Width Modulated (PWM) ......................................................................... 283
6.11.1 PWM Generator ............................................................................................................ 283
6.11.2 PWM Types ................................................................................................................... 286
6.11.3 Operation Modes .......................................................................................................... 287
6.11.4 Mask Output Control .................................................................................................... 288
6.11.5 Fault Brake .................................................................................................................... 288
6.11.6 Polarity Control ............................................................................................................. 288
6.11.7 PWM Interrupt ............................................................................................................... 289
6.11.8 Control Regsiter ............................................................................................................ 289
6.12 12-Bit Analog-To-Digital Converter (ADC) ....................................................... 297
6.12.1 ADC Operation.............................................................................................................. 298
6.12.2 ADC Conversion Triggered by External Source ...................................................... 298
6.12.3 ADC Conversion Result Comparator ........................................................................ 299
6.12.4 Internal Band-gap ......................................................................................................... 299
6.12.5 Control Registers .......................................................................................................... 300
6.13 Auxiliary Features ................................................................................................ 305
6.13.1 Dual DPTRs .................................................................................................................. 305
7 PACKAGE DIMENSIONS ............................................................................ 307
MS51 SERIES TECHNICAL REFERENCE MANUAL
LIST OF FIGURES
Figure 4.1-1 Pin Assignment of TSSOP-20 Package .................................................................... 14
Figure 4.1-2 Pin Assignment of QFN-20 Package ......................................................................... 15
Figure 4.1-3 Pin Assignment of QFN-20 Package ......................................................................... 16
Figure 5.1-1 Functional Block Diagram .......................................................................................... 20
Figure 6.1-1 MS51 Program Memory Map and Boot Select .......................................................... 22
Figure 6.1-2 SPROM Memory Mapping And SPROM Security Mode ........................................... 23
Figure 6.1-3 CONFIG0 Any Reset Reloading ................................................................................ 24
Figure 6.1-4 CONFIG2 Power-On Reset Reloading ...................................................................... 26
Figure 6.1-5 Data Memory Map ..................................................................................................... 28
Figure 6.1-6 Internal 256 Bytes RAM Addressing.......................................................................... 29
Figure 6.2-1 Clock System Block Diagram .................................................................................. 153
Figure 6.2-2 Boot Selecting Diagram ........................................................................................... 164
Figure 6.4-1 Quasi-Bidirectional Mode Structure ......................................................................... 194
Figure 6.4-2 Push-Pull Mode Structure ........................................................................................ 194
Figure 6.4-3 Input-Only Mode Structure ...................................................................................... 194
Figure 6.4-4 Open-Drain Mode Structure .................................................................................... 195
Figure 6.4-5 Pin Interface Block Diagram .................................................................................... 200
Figure 6.5-1 Timer/Counters 0 and 1 in Mode 0 .......................................................................... 205
Figure 6.9-6 SPI Clock and Data Format with CPHA = 1 ............................................................ 259
Figure 6.9-7 SPI Overrun Waveform............................................................................................ 261
Figure 6.9-8 SPI Interrupt Request .............................................................................................. 261
2
Figure 6.10-1 I C Bus Interconnection ......................................................................................... 265
2
Figure 6.10-2 I C Bus Protocol .................................................................................................... 266
Figure 6.10-3 START, Repeated START, and STOP Conditions ............................................... 266
Figure 6.10-4 Master Transmits Data to Slave by 7-bit ............................................................... 267
Figure 6.10-5 Master Reads Data from Slave by 7-bit................................................................. 267
2
Figure 6.10-6 Data Format of One I C Transfer........................................................................... 267
Figure 6.10-7 Acknowledge Bit .................................................................................................... 268
Figure 6.10-8 Arbitration Procedure of Two Masters ................................................................... 268
Figure 6.10-9 Control I2C Bus according to the Current I2C Status ............................................. 269
Figure 6.10-10 Flow and Status of Master Transmitter Mode ..................................................... 270
Figure 6.10-11 Flow and Status of Master Receiver Mode ......................................................... 271
Figure 6.10-12 Flow and Status of Slave Receiver Mode............................................................ 272
Figure 6.10-13 Flow and Status of General Call Mode ................................................................ 273
Figure 6.10-14 I2C Time-Out Counter .......................................................................................... 275
Figure 6.10-15 Hold Time extend enable ..................................................................................... 276
Figure 6.11-1 PWM Block Diagram.............................................................................................. 284
MS51 SERIES TECHNICAL REFERENCE MANUAL
Figure 6.11-2 PWM and Fault Brake Output Control Block Diagram .......................................... 285
Figure 6.11-3 PWM Edge-aligned Type Waveform ..................................................................... 286
Figure 6.11-4 PWM Center-aligned Type Waveform ................................................................... 287
Figure 6.11-5 PWM Complementary Mode with Dead-time Insertion ......................................... 288
Figure 6.11-6 Fault Brake Function Block Diagram ..................................................................... 288
Figure 6.11-7 PWM Interrupt Type............................................................................................... 289
Figure 6.12-112-bit ADC Block Diagram ..................................................................................... 297
Figure 6.12-2 External Triggering ADC Circuit ............................................................................ 299
Figure 6.12-3 ADC Result Comparator ........................................................................................ 299
Figure 7.1-1 TSSOP-20 Package Dimension .............................................................................. 307
Figure 7.2-1 QFN-20 Package Dimension for MS51XB9AE ....................................................... 309
Figure 7.3-1 QFN-20 Package Dimension for MS51XB9BE ....................................................... 310
List of Tables
Table 6.1-1 Special Function Register Memory Map ..................................................................... 34
Table 6.1-2 SFR Definitions and Reset Values ............................................................................. 38
Table 6.2-1 Interrupt Vectors ....................................................................................................... 166
Table 6.2-2 Interrupt Priority Level Setting .................................................................................. 167
Table 6.2-3 Characteristics of Each Interrupt Source .................................................................. 168
Table 6.3-1 IAP Modes and Command Codes ............................................................................ 181
Table 6.4-1 Configuration for Different I/O Modes ....................................................................... 193
Table 6.6-1 Watchdog Timer-out Interval Under Different Pre-scalars........................................ 228
Table 6.8-1 Serial Port UART0 Mode / baudrate Description ...................................................... 238
Table 6.8-2 Serial Port UART1 Mode / baudrate Description ...................................................... 239
Table 6.9-1 Slave Select Pin Configurations ............................................................................... 257
Table 8.1-1 Instructions That Affect Flag Settings ....................................................................... 311
Table 8.2-1 Instruction Set ........................................................................................................... 314
1 GENERAL DESCRIPTION
The MS51 16KB series are embedded flash type, 8-bit high performance 1T 8051-based
microcontroller. The instruction set is fully compatible with the standard 80C51 and performance
enhanced.
The MS51 16KB series contains a up of main Flash called APROM, in which the contents of User
Code resides. The MS51 Flash supports In-Application-Programming (IAP) function, which enables
on-chip firmware updates. IAP also makes it possible to configure any block of User Code array to be
used as non-volatile data storage, which is written by IAP and read by IAP or MOVC instruction, this
function means whole 16K Bytes area all can be use as Data Flash through IAP command. MS51
support an function of configurationable Flash from APROM called LDROM, in which the Boot Code
normally resides for carrying out In-System-Programming (ISP). The LDROM size is configurable with
a maximum of 4K Bytes by CONFIG define. There is an additional include special 128 bytes security
protection memory (SPROM) to enhance the security and protection of customer application. To
facilitate programming and verification, the Flash allows to be programmed and read electronically by
parallel Writer or In-Circuit-Programming (ICP). Once the code is confirmed, user can lock the code for
security.
The MS51 16KB series provides rich peripherals including 256 Bytes of SRAM, 1K Bytes of auxiliary
RAM (XRAM), Up to 18 general purpose I/O, two 16-bit Timers/Counters 0/1, one 16-bit Timer2 with
three-channel input capture module, one Watchdog Timer (WDT), one Self Wake-up Timer (WKT),
one 16-bit auto-reload Timer3 for general purpose or baud rate generator, two UARTs with frame error
2
detection and automatic address recognition, one SPI, one I C, five enhanced PWM output channels,
eight-channel shared pin interrupt for all I/O, and one 12-bit ADC. The peripherals are equipped with
18 sources with 4-level-priority interrupts capability.
The MS51 16KB series is equipped with three clock sources and supports switching on-the-fly via
software. The three clock sources include external clock input, 10 kHz internal oscillator, and one 16
MHz internal precise oscillator that is factory trimmed to ±1% at room temperature. The MS51
MS51 SERIES TECHNICAL REFERENCE MANUAL
provides additional power monitoring detection such as power-on reset and 4-level brown-out
detection, which stabilizes the power-on/off sequence for a high reliability system design.
The MS51 16KB series microcontroller operation consumes a very low power with two economic
power modes to reduce power consumption - Idle and Power-down mode, which are software
selectable. Idle mode turns off the CPU clock but allows continuing peripheral operation. Power-down
mode stops the whole system clock for minimum power consumption. The system clock of the MS51
can also be slowed down by software clock divider, which allows for a flexibility between execution
performance and power consumption.
With high performance CPU core and rich well-designed peripherals, the MS51 benefits to meet a
general purpose, home appliances, or motor control system accomplishment.
2 FEATURES
Brown-out Detector (BOD) 4-level selection, with brown-out interrupt and reset option.
(4.4V / 3.7V / 2.7V / 2.2V)
Low Voltage Reset (LVR) LVR with 2.0V threshold voltage level
Memories
Clocks
Timers
Analog Interfaces
Communication Interfaces
3 PARTS INFORMATION
ADC(12-Bit)
Part Number
SRAM (KB)
[2]
Flash (KB)
ISO-7816
Package
Timer/
UART
PWM
SPI
IC
I/O
2
MS51BA9AE 8 1 4 8 4 5 - 2 - 1 5-ch MSOP10
Note:
1. ISP ROM programmable 1K/2K/3K/4KB Flash for user program loader (LDROM) share from ARPOM.
2. ISO-7816 configurable as UART2.
3. Detailed package information please refer to Chapter 7
4. This TRM only for 16KB flash size part number product
4 PIN CONFIGURATION
Users can find pin configuaration informations by using NuTool - PinConfigure. The NuTool -
PinConfigure contains all Nuvoton NuMicro® Family chip series with all part number, and helps users
configure GPIO multi-function correctly and handily.
[ ] alternate function remapping , if the same alternate function is shown twice, it indicates an exclusive choice not a duplication of the function.
1 2 3 4 5
VDD
[ ] alternate function remapping , if the same alternate function is shown twice, it indicates an exclusive choice not a duplication of the function.
1 2 3 4 5
INT0 / OSCIN / ADC_CH1 / P3.0
[ ] alternate function remapping , if the same alternate function is shown twice, it indicates an exclusive choice not a duplication of the function.
Pin Number
[1]
Symbol Multi-Function Description
MS51FB9AE MS51XB9AE MS51XB9BE
Pin Number
[1]
Symbol Multi-Function Description
MS51FB9AE MS51XB9AE MS51XB9BE
Pin Number
[1]
Symbol Multi-Function Description
MS51FB9AE MS51XB9AE MS51XB9BE
OSCIN If the ECLK mode is enabled, Xin is the external clock input pin.
Note:
1. All I/O pins can be configured as a interrupt pin. This feature is not listed in multi-function description.
2. UART0_TXD and UART0_RXD pins are software exchangeable by UART0PX (AUXR1.2).
3. [I2C] alternate function remapping option. I2C pins is software switched by I2CPX (I2CON.0).
4. [STADC] alternate function remapping option. STADC pin is software switched by STADCPX(ADCCON1.6).
5. PIOx register decides which pins are PWM or GPIO.
5 BLOCK DIAGRAM
16KB T0 (P0.5)
Memory APROM Flash
Timer 0/1
T1 (P0.0)
Access
Max. 4KB Timer 2 8
LDROM Flash with IC0~IC7
Input Capture
Max. Bytes
Data Flash
(page: 128B) Timer 3
Digital
128 Bytes Peripheral
Self Wake-up
SPROM
Timer
256 Bytes
Internal RAM Watchdog Timer
6 PWM0_CH0
1K Bytes ~
XRAM PWM PWM0_CH5
(Auxiliary RAM) FB (P1.4)
MS51 SERIES TECHNICAL REFERENCE MANUAL
XIN
16 MHz/ 24MHz Clock Divider
10 kHz
Internal RC Oscillator
System Clock
Internal RC Oscillator
(HIRC)
(LIRC) Source
6 FUNCTION DESCRIPTION
CONFIG1
7 6 5 4 3 2 1 0
- - - - - LDSIZE[2:0]
- - - - - R/W
FFFFH
SPROM
FF80H
SPROM
3FFFH
3C00H[1] 0FFFH[1]
3800H[1] 0BFFH[1]
3400H[1] 07FFH[1]
3000H[1] 03FFH[1]
MS51 SERIES TECHNICAL REFERENCE MANUAL
LDROM
APROM 0000H
16K bytes CHPCON[1] BS = 1
0000H
CHPCON[1] BS = 0
[1] The logic boundary addresses of APROM and LDROM are defined by CONFIG1[2:0].
FFFFH
SPROM FFFFH
FF80H 0xFF Others
FFFEH
SPROM SPROM
3FFFH Non-security mode Security mode
FF80H
3C00H[1]
3800H[1]
3400H[1]
3000H[1]
APROM
(1) SPROM non-secured mode (the last byte is 0xFF). The access behavior of SPROM is the same
with APROM and LDROM. All area can be read by CPU or ISP command, and can be erased and
programmed by ISP command.
(2) SPROM secured mode (the last byte is not 0xFF). In order to conceal SPROM code in secured
mode, CPU only can perform instruction fetch and get data from SPROM when CPU is run at SPROM
area. Otherwise, CPU will get all 00H for data access. In order to protect SPROM, the CPU instruction
fetch will also get zero value when ICE (OCD) port is connected in secured code. At this mode,
SPROM doesn’t support ISP program, read or erase.
CONFIG0
7 6 5 4 3 2 1 0
Writer or ICP programmer will be all blank (FFH). Programming to Flash Memory is invalid.
Note that CONFIG bytes are always unlocked and can be read. Hence, once the chip is
locked, the CONFIG bytes cannot be erased or programmed individually. The only way to
disable chip lock is execute “whole chip erase”. However, all data within the Flash Memory
and CONFIG bits will be erased when this procedure is executed.
If the chip is locked, it does not alter the IAP function.
CONFIG0 7 6 5 4 3 2 1 0
CBS - OCDPWM OCDEN - RPD LOCK -
CHPCON 7 6 5 4 3 2 1 0
SWRST IAPFF - - - - BS IAPEN
CONFIG1
7 6 5 4 3 2 1 0
- - - - - LDSIZE[2:0]
- - - - - R/W
CONFIG2
7 6 5 4 3 2 1 0
CONFIG2 7 6 5 4 3 2 1 0
CBODEN CBOV[2:0] BOIAP CBORST - -
MS51 SERIES TECHNICAL REFERENCE MANUAL
BODCON0 7 6 5 4 3 2 1 0
BODEN BOV[2:0] BOF BORST BORF BOS
CONFIG4
7 6 5 4 3 2 1 0
WDTEN[3:0] - - - -
R/W - - - -
3:0 - Reserved
FFH
Upper 128 Bytes 0FFFH
SFR 07FFH
internal RAM 03FFH
(direct addressing)
(indirect addressing)
80H
7FH Lower 128 Bytes
internal RAM 1KByte XRAM
(direct or indirect (MOVX addressing)
00H addressing)
0000H
Figure 6.1-5 Data Memory Map shows the internal Data Memory spaces available on MS51. Internal
Data Memory occupies a separate address space from Program Memory. The internal Data Memory
can be divided into three blocks. They are the lower 128 bytes of RAM, the upper 128 bytes of RAM,
and the 128 bytes of SFR space. Internal Data Memory addresses are always 8-bit wide, which
implies an address space of only 256 bytes. Direct addressing higher than 7FH will access the special
function registers (SFR) space and indirect addressing higher than 7FH will access the upper 128
MS51 SERIES TECHNICAL REFERENCE MANUAL
bytes of RAM. Although the SFR space and the upper 128 bytes of RAM share the same logic
address, 80H through FFH, actually they are physically separate entities. Direct addressing to
distinguish with the higher 128 bytes of RAM can only access these SFR. Sixteen addresses in SFR
space are either byte-addressable or bit-addressable. The bit-addressable SFR are those whose
addresses end in 0H or 8H.
The lower 128 bytes of internal RAM are present in all 80C51 devices. The lowest 32 bytes as general
purpose registers are grouped into 4 banks of 8 registers. Program instructions call these registers as
R0 to R7. Two bits RS0 and RS1 in the Program Status Word (PSW[3:4]) select which Register Bank
is used. It benefits more efficiency of code space, since register instructions are shorter than
instructions that use direct addressing. The next 16 bytes above the general purpose registers (byte-
address 20H through 2FH) form a block of bit-addressable memory space (bit-address 00H through
7FH). The 80C51 instruction set includes a wide selection of single-bit instructions, and the 128 bits in
this area can be directly addressed by these instructions. The bit addresses in this area are 00H
through 7FH.
Either direct or indirect addressing can access the lower 128 bytes space. However, the upper 128
bytes can only be accessed by indirect addressing.
Another application implemented with the whole block of internal 256 bytes RAM is used for the stack.
This area is selected by the Stack Pointer (SP), which stores the address of the top of the stack.
Whenever a JMP, CALL or interrupt is invoked, the return address is placed on the stack. There is no
restriction as to where the stack can begin in the RAM. By default however, the Stack Pointer contains
07H at reset. User can then change this to any value desired. The SP will point to the last used value.
Therefore, the SP will be incremented and then address saved onto the stack. Conversely, while
popping from the stack the contents will be read first, and then the SP is decreased.
FFH FFH
The SFR reside in the register locations 80 to FFH and are accessed by direct addressing only. SFR
those end their addresses as 0H or 8H are bit-addressable. It is very useful in cases where user would
like to modify a particular bit directly without changing other bits via bit-field instructions. All other SFR
are byte-addressable only. The MS51 contains all the SFR presenting in the standard 8051. However
some additional SFR are built in. Therefore, some of unused bytes in the original 8051 have been
given new functions. The SFR are listed below.
7 6 5 4 3 2 1 0
- - - - - - - SFRPAGE
- - - - - - - R/W
TA – Timed Access
7 6 5 4 3 2 1 0
TA[7:0]
In timed access method, the bits, which are protected, have a timed write enable window. A write is
successful only if this window is active, otherwise the write will be discarded. When the software writes
AAH to TA, a counter is started. This counter waits for 3 clock cycles looking for a write of 55H to TA.
If the second write of 55H occurs within 3 clock cycles of the first write of AAH, then the timed access
window is opened. It remains open for 4 clock cycles during which user may write to the protected bits.
After 4 clock cycles, this window automatically closes. Once the window closes, the procedure should
be repeated to write another protected bits. Not that the TA protected SFR are required timed access
for writing but reading is not protected. User may read TA protected SFR without giving AAH and 55H
to TA register. The suggestion code for opening the timed access window is shown below.
(CLR EA) ;if any interrupt is enabled, disable temporally
MOV TA,#0AAH
MOV TA,#55H
C0 I2CON I2ADDR TA
1 - - PWM4H PWM5H PIOCON1
0
B8 IP SADEN SADEN_1 SADDR_1 I2DAT I2STAT I2CLK I2TOC
1
0 P0M1 P0M2 P1M1 P1M2 IPH
B0 P3 P2S -
1 P0S P0SR P1S P1SR PWMINTC
0 P3M1 P3M2
A8 IE SADDR WDCON BODCON1 IAPFD IAPCN
1 P3S P3SR
0
A0 P2 - AUXR1 BODCON0 IAPTRG IAPUEN IAPAL IAPAH
1
0
98 SCON SBUF SBUF_1 EIE EIE1 - - CHPCON
1
0
90 P1 SFRS CAPCON0 CAPCON1 CAPCON2 CKDIV CKSWT CKEN
1
0
88 TCON TMOD TL0 TL1 TH0 TH1 CKCON WKCON
1
0
80 P0 SP DPL DPH RCTRIM0 RCTRIM1 RWK PCON
1
Note: Unoccupied addresses in the SFR space marked in “-“ are reserved for future use. Accessing
these areas will have an indeterminate effect and should be avoided.
Table 6.1-1 Special Function Register Memory Map
Extensive interrupt
EIPH F7H PT2H PSPIH PFBH PWDTH PPWMH PCAPH PPIH PI2CH 0000 0000b
priority high
ADC channel digital
AINDIDS F6H P11DIDS P03DIDS P04DIDS P05DIDS P06DIDS P07DIDS P30DIDS P17DIDS 0000 0000b
input disable
F5H
SPDR SPI data SPDR[7:0] 0000 0000b
(0)
SPSR SPI status F4H SPIF WCOL SPIOVF MODF DISMODF TXBUF - - 0000 0000b
F3H
SPCR SPI control SSOE SPIEN LSBFE MSTR CPOL CPHA SPR[1:0] 0000 0000b
(0)
F3H
SPCR2 SPI control 2 - - - - - - SPIS[1:0] 0000 0000b
(1)
Input capture control
CAPCON4 F2H - - - - CAP23 CAP22 CAP21 CAP20 0000 0000b
4
Input capture control
CAPCON3 F1H CAP13 CAP12 CAP11 CAP10 CAP03 CAP02 CAP01 CAP00 0000 0000b
3
B B register F0H B.7 B.6 B.5 B.4 B.3 B.2 B.1 B.0 0000 0000b
Extensive interrupt
EIP EFH PT2 PSPI PFB PWDT PPWM PCAP PPI PI2C 0000 0000b
priority
Input capture 2 high
C2H EEH C2H[7:0] 0000 0000b
byte
Input capture 2 low
C2L EDH C2L[7:0] 0000 0000b
byte
PIF Pin interrupt flag ECH PIF7 PIF6 PIF5 PIF4 PIF3 PIF2 PIF1 PIF0 0000 0000b
PWM negative
PNP D6H - - PNP5 PNP4 PNP3 PNP2 PNP1 PNP0 0000 0000b
polarity
PWM0 channel 3
PWM3H D5H PWM3[15:8] 0000 0000b
duty high byte
PWM0 channel 2
PWM2H D4H PWM2[15:8] 0000 0000b
duty high byte
PWM0 channel 1
PWM1H D3H PWM1[15:8] 0000 0000b
duty high byte
PWM0 channel 0
PWM0H D2H PWM0[15:8] 0000 0000b
duty high byte
PWM period high
PWMPH D1H PWMP[15:8] 0000 0000b
byte
PSW Program status word D0H CY AC F0 RS1 RS0 OV - P 0000 0000b
ADC compare high CFH
ADCMPH ADCMP[11:4] 0000 0000b
byte (0)
ADC compare low
ADCMPL CEH - - - - ADCMP[3:0] 0000 0000b
byte
PWM0 channel 5 CDH
PWM5L PWM5 [7:0] 0000 0000b
duty low byte (1)
CDH
TH2 Timer 2 high byte TH2[7:0] 0000 0000b
(0)
PWM0 channel 4 CCH
PWM4L PWM4[7:0] 0000 0000b
duty low byte (1)
CCH
TL2 Timer 2 low byte TL2[7:0] 0000 0000b
(0)
Timer 2 compare
RCMP2H CBH RCMP2H[7:0] 0000 0000b
high byte
Timer 2 compare low CAH
RCMP2L RCMP2L[7:0] 0000 0000b
byte (0)
T2MOD Timer 2 mode C9H LDEN T2DIV[2:0] CAPCR CMPCR LDTS[1:0] 0000 0000b
T2CON Timer 2 control C8H TF2 - - - - TR2 - ̅̅̅̅̅̅ 0000 0000b
CM/RL2
Timed access
TA C7H TA[7:0] 0000 0000b
protection
C6H
PIOCON1 PWM I/O switch 1 - - PIO15 - PIO13 PIO12 PIO11 - 0000 0000b
(1)
Timer 3 reload high C6H
RH3 RH3[7:0] 0000 0000b
byte (0)
PWM0 channel 5 C5H
PWM5H PWM5 [15:8] 0000 0000b
MS51 SERIES TECHNICAL REFERENCE MANUAL
B2H
P0SR P0 slew rate P0SR.7 P0SR.6 P0SR.5 P0SR.4 P0SR.3 P0SR.2 P0SR.1 P0SR.0 0000 0000b
(1)
B2H
P0M2 P0 mode select 2 P0M2.7 P0M2.6 P0M2.5 P0M2.4 P0M2.3 P0M2.2 P0M2.1 P0M2.0 0000 0000b
(0)
P0 Schmitt trigger B1H
P0S P0S.7 P0S.6 P0S.5 P0S.4 P0S.3 P0S.2 P0S.1 P0S.0 0000 0000b
input (1)
B1H
P0M1 P0 mode select 1 P0M1.7 P0M1.6 P0M1.5 P0M1.4 P0M1.3 P0M1.2 P0M1.1 P0M1.0 1111 1111b
(0)
Output latch,
0000 0001b
P3 Port 3 B0H 0 0 0 0 0 0 0 P3.0
Input
0000 000Xb[3]
IAPCN IAP control AFH IAPA[17:16] FOEN FCEN FCTRL[3:0] 0011 0000b
IAPFD IAP flash data AEH IAPFD[7:0] 0000 0000b
ADH
P3SR P3 slew rate - - - - - - - P3SR.0 0000 0000b
(1)
ADH
P3M2 P3 mode select 2 - - - - - - - P3M2.0 0000 0000b
(0)
P3 Schmitt trigger ACH
P3S - - - - - - - P3S.0 0000 0000b
input (1)
ACH
P3M1 P3 mode select 1 - - - - - - - P3M1.0 0000 0001b
(0)
POR,
BODCON1 Brown-out detection 0000 0001b
[4] ABH - - - - - LPBOD[1:0] BODFLT
Others,
control 1
0000 0UUUb
POR,
0000 0111b
Watchdog Timer WDT,
WDCON[4] AAH WDTR WDCLR WDTF WIDPD WDTRF WDPS[2:0]
0000 1UUUb
control
Others,
0000 UUUUb
SADDR Slave 0 address A9H SADDR[7:0] 0000 0000b
IE Interrupt enable A8H EA EADC EBOD ES ET1 EX1 ET0 EX0 0000 0000b
IAP address high
IAPAH A7H IAPA[15:8] 0000 0000b
byte
IAPAL IAP address low byte A6H IAPA[7:0] 0000 0000b
IAPUEN[4] IAP update enable A5H - - - - - CFUEN LDUEN APUEN 0000 0000b
IAPTRG[4] IAP trigger A4H - - - - - - - IAPGO 0000 0000b
POR,
CCCC XC0Xb
Extensive interrupt
EIE1 9CH - - - - - EWKT ET3 ES_1 0000 0000b
enable 1
Extensive interrupt
EIE 9BH ET2 ESPI EFB EWDT EPWM ECAP EPI EI2C 0000 0000b
enable
Serial port 1 data
SBUF_1 9AH SBUF_1[7:0] 0000 0000b
buffer
Serial port 0 data
SBUF 99H SBUF[7:0] 0000 0000b
buffer
SCON Serial port 0 control 98H SM0/FE SM1 SM2 REN TB8 RB8 TI RI 0000 0000b
CKEN[4] Clock enable 97H EXTEN[1:0] HIRCEN - - - - CKSWTF 0011 0000b
CKSWT[4] Clock switch 96H - - HIRCST - ECLKST OSC[1:0] - 0011 0000b
CKDIV Clock divider 95H CKDIV[7:0] 0000 0000b
Input capture control
CAPCON2 94H - ENF2 ENF1 ENF0 - - - - 0000 0000b
2
Input capture control
CAPCON1 93H - - CAP2LS[1:0] CAP1LS[1:0] CAP0LS[1:0] 0000 0000b
1
Input capture control
CAPCON0 92H - CAPEN2 CAPEN1 CAPEN0 - CAPF2 CAPF1 CAPF0 0000 0000b
0
SFRS[4] SFR page selection 91H - - - - - - - SFRPSEL 0000 0000b
Output latch,
1111 1111b
P1 Port 1 90H P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0
Input
XXXX XXXXb [3]
Self Wake-up Timer
WKCON 8FH - - - WKTF WKTR WKPS[2:0] 0000 0000b
control
CKCON Clock control 8EH - PWMCKS - T1M T0M - CLOEN - 0000 0000b
TH1 Timer 1 high byte 8DH TH1[7:0] 0000 0000b
TH0 Timer 0 high byte 8CH TH0[7:0] 0000 0000b
TL1 Timer 1 low byte 8BH TL1[7:0] 0000 0000b
TL0 Timer 0 low byte 8AH TL0[7:0] 0000 0000b
TMOD Timer 0 and 1 mode 89H GATE ̅
C/T M1 M0 GATE ̅
C/T M1 M0 0000 0000b
TCON Timer 0 and 1control 88H TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 0000 0000b
POR,
0001 0000b
PCON Power control 87H SMOD SMOD0 - POF GF1 GF0 PD IDL
Others,
000U 0000b
Self Wake-up Timer
RWK 86H RWK[7:0] 0000 0000b
reload byte
Internal RC trim HIRCTRIM[
RCTRIM1 85H - - - HIRC24 - - -
0]
0000 0000b
value low byte
Internal RC trim value
RCTRIM0 84H HIRCTRIM[8:1] 0000 0000b
high byte
Data pointer high
DPH 83H DPTR[15:8] 0000 0000b
byte
DPL Data pointer low byte 82H DPTR[7:0] 0000 0000b
SP Stack pointer 81H SP[7:0] 0000 0111b
Output latch,
1111 1111b
P0 Port 0 80H (P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
Input,
XXXX XXXXb [3]
Note:
1. ( ) item means the bit address in bit-addressable SFRs.
2. Reset value symbol description. 0: logic 0; 1: logic 1; U: unchanged; C: see [5]; X: see [3], [6], and [7].
3. All I/O pins are default input-only mode (floating) after reset. Reading back P2.0 is always 0 if RPD (CONFIG0.2) remains un-programmed 1.
After reset OCDDA and OCDCK pin will keep quasi mode with pull high resister 600 LIRC clock before change to input mode.
4. These SFRs have TA protected writing.
5. These SFRs have bits those are initialized according to CONFIG values after specified resets.
6. BOF reset value depends on different setting of CONFIG2 and VDD voltage level. Please check
7. BOS is a read-only flag decided by VDD level while brown-out detection is enabled.
MS51 SERIES TECHNICAL REFERENCE MANUAL
Pn – Port n (Bit-addressable)
Regiser Address Reset Value
7 6 5 4 3 2 1 0
P0 / P1
Bit Name Description
P2
Bit Name Description
P3
Bit Name Description
SP – Stack Pointer
Regiser Address Reset Value
7 6 5 4 3 2 1 0
SP[7:0]
R/W
7 6 5 4 3 2 1 0
DPL[7:0]
R/W
7 6 5 4 3 2 1 0
DPH[7:0]
R/W
7 6 5 4 3 2 1 0
HIRCTRIM[8:1]
R/W
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
- - - HIRC24 - - - HIRCTRIM.0
- - - R/W - - - R/W
7 6 5 4 3 2 1 0
RWK[7:0]
R/W
POR, 0001_0000b
PCON 87H, all pages
Others,000U_0000b
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
R (level) R (level)
R/W R/W R/W R/W R/W R/W
R/W (edge) R/W (edge)
3 IE1
If IT1 = 1 (falling edge trigger), this flag will be set by hardware when a falling edge is detected. It
remain set until cleared via software or cleared by hardware in the beginning of its interrupt service
routine.
̅̅̅̅̅̅̅ input signal’s logic level.
If IT1 = 0 (low level trigger), this flag follows the inverse of the INT1
Software cannot control it.
7 6 5 4 3 2 1 0
GATE ̅
C/T M1 M0 GATE ̅
C/T M1 M0
7 6 5 4 3 2 1 0
TL0[7:0]
R/W
7 6 5 4 3 2 1 0
TL1[7:0]
R/W
7 6 5 4 3 2 1 0
TH0[7:0]
R/W
7 6 5 4 3 2 1 0
TH1[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
- - - - - - - SFRPAGE
- - - - - - - R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
CKDIV[7:0]
R/W
FSYS = FOSC
, while CKDIV = 00H, and
FOSC
FSYS =
2 × CKDIV , while CKDIV = 01H to FFH.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
- - R R R W -
7 6 5 4 3 2 1 0
R/W R/W - - - - R
4:1 - Reserved
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
SBUF[7:0]
R/W
7 6 5 4 3 2 1 0
SBUF_1[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
POR, 0001_0000b
BOD, 000U_0100
RSR 9DH, all pages Software, 000U_0U01
nReset pin, 0U0U_
Others 000U_0U0U
7 6 5 4 3 2 1 0
Software: 0000_00U0b
CHPCON 9FH, all pages,TA protected
Others 0000_00C0b
7 6 5 4 3 2 1 0
1 BS Boot select
This bit defines from which block that MCU re-boots after all resets.
POR 0000_0000b,
Software 1U00_0000b
AUXR1 A2H, all pages
nRESET pin U100_0000b
Others UUU0_0000b
7 6 5 4 3 2 1 0
1 0 Reserved
This bit is always read as 0.
POR,CCCC_XC0Xb
BODCON0 A3H, all pages,TA protected BOD, UUUU_XU1Xb
Others,UUUU_XUUXb
7 6 5 4 3 2 1 0
[1] [1] [2] [1]
BODEN BOV[1:0] BOF BORST BORF BOS
7 6 5 4 3 2 1 0
- - - - - - - IAPGO
- - - - - - - W
0 IAPGO IAP go
IAP begins by setting this bit as logic 1. After this instruction, the CPU holds the Program Counter
(PC) and the IAP hardware automation takes over to control the progress. After IAP action
completed, the Program Counter continues to run the following instruction. The IAPGO bit will be
automatically cleared and always read as logic 0.
Before triggering an IAP action, interrupts (if enabled) should be temporary disabled for hardware
limitation.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
IAPA[7:0]
R/W
7 6 5 4 3 2 1 0
IAPA[15:8]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
SADDR[7:0]
R/W
POR 0000_0111b
WDCON AAH, all pages, TA protected WDT 0000_1UUUb
Others 0000_UUUUb
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
- - - - - LPBOD[1:0] BODFLT
- - - - - R/W R/W
7 6 5 4 3 2 1 0
IAPFD[7:0]
R/W
7 6 5 4 3 2 1 0
4 FCEN
3:0 FCTRL[3:0]
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
IP – Interrupt Priority
Regiser Address Reset Value
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
SADEN[7:0]
R/W
7 6 5 4 3 2 1 0
SADEN_1[7:0]
R/W
7 6 5 4 3 2 1 0
SADDR_1[7:0]
R/W
2
I2DAT – I C Data
Regiser Address Reset Value
7 6 5 4 3 2 1 0
I2DAT[7:0]
R/W
2
I2STAT – I C Status
Regiser Address Reset Value
7 6 5 4 3 2 1 0
I2STAT[7:3] 0 0 0
R R R R
2
I2CLK – I C Clock
Regiser Address Reset Value
7 6 5 4 3 2 1 0
I2CLK[7:0]
R/W
2
I2TOC – I C Time-out Counter
Regiser Address Reset Value
7 6 5 4 3 2 1 0
2
I2CON – I C Control
Regiser Address Reset Value
7 6 5 4 3 2 1 0
2
The STO flag setting is also used to recover the I C device from the bus error state (I2STAT as
2
00H). In this case, no STOP condition is transmitted to the I C bus.
2
If the STA and STO bits are both set and the device is original in the master mode, the I C bus will
generate a STOP condition and immediately follow a START condition. If the device is in slave
2
mode, STA and STO simultaneous setting should be avoid from issuing illegal I C frames.
2
3 SI I C interrupt flag
2
SI flag is set by hardware when one of 26 possible I C status (besides F8H status) is entered. After
SI is set, the software should read I2STAT register to determine which step has been passed and
take actions for next step.
SI is cleared by software. Before the SI is cleared, the low period of I2C0_SCL line is stretched. The
transaction is suspended. It is useful for the slave device to deal with previous data bytes until ready
for receiving the next byte.
2
The serial transaction is suspended until SI is cleared by software. After SI is cleared, I C bus will
continue to generate START or repeated START condition, STOP condition, 8-bit data, or so on
depending on the software configuration of controlling byte or bits. Therefore, user should take care
of it by preparing suitable setting of registers before SI is software cleared.
2
I2ADDR – I C Own Slave Address
Regiser Address Reset Value
7 6 5 4 3 2 1 0
I2ADDR[7:1] GC
R/W R/W
7 6 5 4 3 2 1 0
- - - - ADCR[3:0]
- - - - R
7 6 5 4 3 2 1 0
ADCR[11:4]
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
RL3[7:0]
R/W
7 6 5 4 3 2 1 0
RH3[7:0]
R/W
7 6 5 4 3 2 1 0
TA – Timed Access
Regiser Address Reset Value
7 6 5 4 3 2 1 0
TA[7:0]
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
RCMP2L[7:0]
R/W
7 6 5 4 3 2 1 0
RCMP2H[7:0]
R/W
7 6 5 4 3 2 1 0
TL2[7:0]
R/W
7 6 5 4 3 2 1 0
TH2[7:0]
R/W
7 6 5 4 3 2 1 0
- - - - ADCMP[3:0]
- - - - W/R
7 6 5 4 3 2 1 0
ADCMP[11:4]
W/R
7 6 5 4 3 2 1 0
CY AC F0 RS1 RS0 OV F1 P
7 CY Carry flag
For a adding or subtracting operation, CY will be set when the previous operation resulted in a
carry-out from or a borrow-in to the Most Significant bit, otherwise cleared.
If the previous operation is MUL or DIV, CY is always 0.
CY is affected by DA A instruction, which indicates that if the original BCD sum is greater than 100.
For a CJNE branch, CY will be set if the first unsigned integer value is less than the second one.
Otherwise, CY will be cleared.
6 C Auxiliary carry
th
Set when the previous operation resulted in a carry-out from or a borrow-in to the 4 bit of the low
order nibble, otherwise cleared.
5 0 User flag 0
The general purpose flag that can be set or cleared by user.
0 1 1 08H to 0FH
1 0 2 10H to 17H
1 1 3 18H to 1FH
2 V Overflow flag
OV is used for a signed character operands. For a ADD or ADDC instruction, OV will be set if there
is a carry out of bit 6 but not out of bit 7, or a carry out of bit 7 but not bit 6. Otherwise, OV is
cleared. OV indicates a negative number produced as the sum of two positive operands or a
positive sum from two negative operands. For a SUBB, OV is set if a borrow is needed into bit6 but
not into bit 7, or into bit7 but not bit 6. Otherwise, OV is cleared. OV indicates a negative number
produced when a negative value is subtracted from a positive value, or a positive result when a
positive number is subtracted from a negative number.
For a MUL, if the product is greater than 255 (00FFH), OV will be set. Otherwise, it is cleared.
For a DIV, it is normally 0. However, if B had originally contained 00H, the values returned in A and
B will be undefined. Meanwhile, the OV will be set.
1 1 User flag 1
The general purpose flag that can be set or cleared by user via software.
0 P Parity flag
Set to 1 to indicate an odd number of ones in the accumulator. Cleared for an even number of ones.
It performs even parity check.
7 6 5 4 3 2 1 0
PWMP[15:8]
R/W
7 6 5 4 3 2 1 0
PWM0[15:8]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
PWMP[7:0]
R/W
7 6 5 4 3 2 1 0
PWM0[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
A or ACC – Accumulator
Regiser Address Reset Value
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Note: After this bit is enabled and ADC start is triggered, the ADC keeps converting. The register
ADCRH and ADCRL value will change based on the result of ADC setting and can also be read
out from the register. This process only stops after ADCF is set to 1
7 6 5 4 3 2 1 0
ADCDLY[7:0]
R/W
7 6 5 4 3 2 1 0
C0L[7:0]
R/W
7 6 5 4 3 2 1 0
C0H[7:0]
R/W
7 6 5 4 3 2 1 0
01 = PWM2.
10 = PWM4
11 = STADC pin.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Note: EIP is used in combination with the EIPH to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
B – B Register
Regiser Address Reset Value
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
- - - - - - SPIS1 SPIS0
- - - - - - R/W R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
SPDR[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Note: EIPH is used in combination with the EIP to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
4 Receiving enable
REN_1
0 = Serial port 1 reception Disabled.
1 = Serial port 1 reception Enabled in Mode 1,2, or 3. In Mode 0, reception is initiated by the
condition REN_1 = 1 and RI_1 = 0.
th
3 9 transmitted bit
TB8_1 th
This bit defines the state of the 9 transmission bit in serial port 1 Mode 2 or 3. It is not used in
Mode 0 or 1.
th
2 9 received bit
RB8_1 th
The bit identifies the logic level of the 9 received bit in serial port 1 Mode 2 or 3. In Mode 1,
RB8_1 is the logic level of the received stop bit. SM2_1 bit as logic 1 has restriction for
exception. RB8_1 is not used in Mode 0.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
PDTCNT[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
PORDIS[7:0]
7 6 5 4 3 2 1 0
Note: EIP1 is used in combination with the EIPH1 to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
7 6 5 4 3 2 1 0
Note: EIPH1 is used in combination with the EIP1 to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
MS51 SERIES TECHNICAL REFERENCE MANUAL
FECLK Flash
XIN
Memory
10
HIRCTRIM[8:1]
R/W
- - - HIRC24 - - - HIRCTRIM.0
- - - R/W - - - R/W
source switching. User can enable the target clock source by writing proper value into CKEN register,
wait for the clock source stable by polling its status bit in CKSWT register, and switch to the target
clock source by changing OSC[1:0] (CKSWT[2:1]). After these step, the clock source switching is
successful and then user can also disable the original clock source if power consumption is
concerned. Note that if not following the steps above, the hardware will take certain actions to deal
with such illegal operations as follows.
1. If user tries to disable the current clock source by changing CKEN value, the device will ignore this
action. The system clock will remain the original one and CKEN will remain the original value.
2. If user tries to switch the system clock source to a disabled one by changing OSC[1:0] value,
OSC[1:0] value will be updated right away. But the system clock will remain the original one and
CKSWTF flag will be set by hardware.
3. Once user switches the system clock source to an enabled but still instable one, the hardware will
wait for stabilization of the target clock source and then switch to it in the background. During this
waiting period, the device will continue executing the program with the original clock source and
CKSWTF will be set as 1. After the stable flag of the target clock source (see CKSWT[7:3]) is set and
the clock source switches successfully, CKSWTF will be cleared as 0 automatically by hardware.
7 6 5 4 3 2 1 0
- - R - R W -
7 6 5 4 3 2 1 0
R/W R/W - - - - R
4:1 - Reserved
7 6 5 4 3 2 1 0
CKDIV[7:0]
R/W
7 6 5 4 3 2 1 0
The MS51 has several features that help user to control the power consumption of the device. The
power reduced feature has two option modes: Idle mode and Power-down mode, to save the power
consumption. For a stable current consumption, the state and mode of each pin should be taken care
of. The minimum power consumption can be attained by giving the pin state just the same as the
external pulls for example output 1 if pull-high is used or output 0 if pull-low. If the I/O pin is floating,
user is recommended to leave it as quasi-bidirectional mode. If P2.0 is configured as a input-only pin,
it should have an external pull-up or pull-low, or enable its internal pull-up by setting P20UP (P2S.7).
POR, 0001_0000b
PCON 87H, all pages
7 6 5 4 3 2 1 0
1 PD Power-down mode
Setting this bit puts CPU into Power-down mode. Under this mode, both CPU and peripheral clocks
stop and Program Counter (PC) suspends. It provides the lowest power consumption. After CPU is
woken up from Power-down, this bit will be automatically cleared via hardware and the program
continue executing the interrupt service routine (ISR) of the very interrupt source that woke the
system up before. After return from the ISR, the device continues execution at the instruction, which
follows the instruction that put the system into Power-down mode.
Note that If IDL bit and PD bit are set simultaneously, CPU will enter Power-down mode. Then it
does not go to Idle mode after exiting Power-down.
POR, 0001_0000b
PCON 87H, all pages
Others,000U_0000b
7 6 5 4 3 2 1 0
POR,CCCC_XC0Xb
BODCON0 A3H, all pages,TA protected BOD, UUUU_XU1Xb
Others,UUUU_XUUXb
7 6 5 4 3 2 1 0
POR 0000_0000b,
Software 1U00_0000b
AUXR1 A2H, all pages
nRESET pin U100_0000b
Others UUU0_0000b
7 6 5 4 3 2 1 0
source. User can clear the WDT at any time, causing it to restart the counter. When the selected time-
out occurs but no software response taking place for a while, the WDT will reset the system directly
and CPU will begin execution from 0000H.
Once a reset due to WDT occurs, the WDT reset flag WDTRF (WDCON.3) will be set. This bit keeps
unchanged after any reset other than a power-on reset or WDT reset itself. User can clear WDTRF via
software.
POR 0000_0111b
WDCON AAH, all pages, TA protected WDT 0000_1UUUb
Others 0000_UUUUb
7 6 5 4 3 2 1 0
Software: 0000_00U0b
CHPCON 9FH, all pages,TA protected
Others 0000_00C0b
7 6 5 4 3 2 1 0
POR 0000_0000b,
Software 1U00_0000b
AUXR1 A2H, all pages
nRESET pin U100_0000b
Others UUU0_0000b
7 6 5 4 3 2 1 0
MS51 SERIES TECHNICAL REFERENCE MANUAL
CONFIG0.7 CHPCON.1
CBS BS
Load
Power-on reset
Low voltage reset
Reset and boot from APROM
Watchdog timer reset BS = 0
Brown-out reset
Hard fault reset BS = 1
RST pin reset Reset and boot from LDROM
Software reset
The MS51 provides user a flexible boot selection for variant application. The SFR bit BS in
CHPCON.1 determines MCU booting from APROM or LDROM after any source of reset. If reset
occurs and BS is 0, MCU will reboot from address 0000H of APROM. Else, the CPU will reboot from
address 0000H of LDROM. Note that BS is loaded from the inverted value of CBS bit in CONFIG0.7
after all resets except software reset.
Note: After the MCU is released from reset state, the hardware will always check the BS bit instead of
the CBS bit to determine from which block that the device reboots.
CONFIG0
7 6 5 4 3 2 1 0
Software: 0000_00U0b
CHPCON 9FH, all pages,TA protected
Others 0000_00C0b
7 6 5 4 3 2 1 0
[1]
1 BS Boot select
This bit defines from which block that MCU re-boots after all resets.
0 = MCU will re-boot from APROM after all resets.
1 = MCU will re-boot from LDROM after all resets.
Note: BS is initialized by being loaded from the inverted value of CBS bit in CONFIG0.7 after resets except
software reset. It keeps unchanged after software reset.
The MS51 has a four-priority-level interrupt structure with 30 interrupt sources. Each of the interrupt
sources has an individual priority setting bits, interrupt vector and enable bit. In addition, the interrupts
can be globally enabled or disabled. When an interrupt occurs, the CPU is expected to service the
interrupt. This service is specified as an Interrupt Service Routine (ISR). The ISR resides at a
predetermined address as shown in Table 6.2-1 Interrupt Vectors. When the interrupt occurs if
enabled, the CPU will vector to the respective location depending on interrupt source, execute the
code at this location, stay in an interrupt service state until the ISR is done. Once an ISR has begun, it
can be interrupted only by a higher priority interrupt. The ISR should be terminated by a return from
interrupt instruction RETI. This instruction will force the CPU return to the instruction that would have
been next when the interrupt occurred.
Vector Vector Vector Vector
Source Source
Addess Number Address Number
Reset 0000H - SPI interrupt 004BH 9
External interrupt 0 0003H 0 WDT interrupt 0053H 10
Timer 0 overflow 000BH 1 ADC interrupt 005BH 11
External interrupt 1 0013H 2 Input capture interrupt 0063H 12
Timer 1 overflow 001BH 3 PWM interrupt 006BH 13
Serial port 0 interrupt 0023H 4 Fault Brake interrupt 0073H 14
Timer 2 event 002BH 5 Serial port 1 interrupt 007BH 15
2
I C status/timer-out interrupt 0033H 6 Timer 3 overflow 0083H 16
Note:
1. While the external interrupt pin is set as edge triggered (Itx = 1), its own flag Iex will be automatically cleared if
the interrupt service routine (ISR) is executed. While as level triggered (Itx = 0), Iex follows the inverse of
respective pin state. It is not controlled via software.
2. TF0, TF1, or TF3 is automatically cleared if the interrupt service routine (ISR) is executed. On the contrary,
be aware that TF2 is not.
3. If level triggered is selected for pin interrupt channel n, PIFn flag reflects the respective channel state. It is not
controlled via software.
completed. RET would leave the controller still thinking that the service routine is underway, making
future interrupts impossible.
IE – Interrupt Enable
Regiser Address Reset Value
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
IP – Interrupt Priority
Regiser Address Reset Value
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Note : EIPH is used in combination with the EIP to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
Note: EIP1 is used in combination with the EIPH1 to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
7 6 5 4 3 2 1 0
Note: EIPH1 is used in combination with the EIP1 to determine the priority of each interrupt source. See Table 6.2-2 Interrupt
Priority Level Setting for correct interrupt priority configuration.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
R (level) R (level)
R/W R/W R/W R/W R/W R/W
R/W (edge) R/W (edge)
IAPCN
IAPA[15:0]
IAP Mode IAPB FCTRL IAPFD[7:0]
FOEN FCEN {IAPAH, IAPAL}
[1:0] [3:0]
CONFIG byte-read 11 0 0 0000 CONFIG0: 0000H Data out
CONFIG1: 0001H
CONFIG2: 0002H
CONFIG4: 0004H
CONFIG6: 0005H
Note:
1. “X” means “don’t care”.
2. Each page is 128 bytes size. Therefore, the address should be the address pointed to the target page
CONFIG2
7 6 5 4 3 2 1 0
Software: 0000_00U0b
CHPCON 9FH, all pages,TA protected
Others 0000_00C0b
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
IAPA[15:8]
R/W
7 6 5 4 3 2 1 0
IAPA[7:0]
7 6 5 4 3 2 1 0
IAPFD[7:0]
R/W
7 6 5 4 3 2 1 0
- - - - - - - IAPGO
- - - - - - - W
7:1 - Reserved
0 IAPGO IAP go
IAP begins by setting this bit as logic 1. After this instruction, the CPU holds the Program Counter
(PC) and the IAP hardware automation takes over to control the progress. After IAP action
completed, the Program Counter continues to run the following instruction. The IAPGO bit will be
automatically cleared and always read as logic 0.
Before triggering an IAP action, interrupts (if enabled) should be temporary disabled for hardware
limitation.
The program process should follows below.
CLR EA
MOV TA,#0AAH
MOV TA,#55H
ORL IAPTRG,#01H
(SETB EA)
;******************************************************************************
; This code illustrates how to use IAP to make APROM 201h as a byte of
ORG 0000h
MOV TA,#0Aah
MOV TA,#55h
ANL CHPCON,#11111110b ;IAPEN = 0, disable IAP mode
MOV DPTR,#201h
CLR A
MOVC A,@A+DPTR ;Read content of address 201h
MOV P0,A
SJMP $
/*Data Flash, as part of APROM, is read by MOVC. Data Flash can be defined as
128-element array in “code” area from absolute address 0x0200 */
Main (void)
{
TA = 0Xaa; //CHPCON is TA protected
TA = 0x55;
CHPCON |= 0x01; //IAPEN = 1, enable IAP mode
TA = 0x55;
IAPUEN &= ~0x01; //APUEN = 0, disable APROM update
while(1);
}
user quite easy perform ISP through UART port. Please visit Nuvoton 8-bit Microcontroller website:
Nuvoton 80C51 Microcontroller Technical Support. A simple ISP demo code is given below.
Assembly demo code:
;**************************************************************************
; This code illustrates how to do APROM and CONFIG IAP from LDROM.
; APROM are re-programmed by the code to output P1 as 55h and P2 as aah.
; The CONFIG2 is also updated to disable BOD reset.
; User needs to configure CONFIG0 = 0x7F, CONFIG1 = 0Xfe, CONFIG2 = 0Xff.
;**************************************************************************
PAGE_ERASE_AP EQU 00100010b
BYTE_PROGRAM_AP EQU 00100001b
BYTE_READ_AP EQU 00000000b
ALL_ERASE_CONFIG EQU 11100010b
BYTE_PROGRAM_CONFIG EQU 11100001b
BYTE_READ_CONFIG EQU 11000000b
ORG 0000h
CALL Enable_AP_Update
CALL Erase_AP ;erase AP data
CALL Program_AP ;programming AP data
CALL Disable_AP_Update
CALL Program_AP_Verify ;verify Programmed AP data
CALL Disable_IAP
MOV TA,#0Aah ;TA protection
MOV TA,#55h ;
ANL CHPCON,#11111101b ;BS = 0, reset to APROM
MOV TA,#0Aah
MOV TA,#55h
ORL CHPCON,#80h ;software reset and reboot from APROM
SJMP $
;********************************************************************
; IAP Subroutine
;********************************************************************
Enable_IAP:
MOV TA,#0Aah ;CHPCON is TA protected
MOV TA,#55h
ORL CHPCON,#00000001b ;IAPEN = 1, enable IAP mode
RET
Disable_IAP:
MOV TA,#0Aah
MOV TA,#55h
ANL CHPCON,#11111110b ;IAPEN = 0, disable IAP mode
RET
Enable_AP_Update:
MOV TA,#0Aah ;IAPUEN is TA protected
MOV TA,#55h
ORL IAPUEN,#00000001b ;APUEN = 1, enable APROM update
RET
Disable_AP_Update:
MOV TA,#0Aah
MOV TA,#55h
ANL IAPUEN,#11111110b ;APUEN = 0, disable APROM update
RET
Enable_CONFIG_Update:
MOV TA,#0Aah
MOV TA,#55h
ORL IAPUEN,#00000100b ;CFUEN = 1, enable CONFIG update
RET
Disable_CONFIG_Update:
MOV TA,#0Aah
MOV TA,#55h
ANL IAPUEN,#11111011b ;CFUEN = 0, disable CONFIG update
RET
Trigger_IAP:
MOV TA,#0Aah ;IAPTRG is TA protected
MOV TA,#55h
ORL IAPTRG,#00000001b ;write ‘1’ to IAPGO to trigger IAP process
MS51 SERIES TECHNICAL REFERENCE MANUAL
RET
;********************************************************************
; IAP APROM Function
;********************************************************************
Erase_AP:
MOV IAPCN,#PAGE_ERASE_AP
MOV IAPFD,#0FFh
MOV R0,#00h
Erase_AP_Loop:
MOV IAPAH,R0
MOV IAPAL,#00h
CALL Trigger_IAP
MOV IAPAL,#80h
CALL Trigger_IAP
INC R0
CJNE R0,#44h,Erase_AP_Loop
RET
Program_AP:
MOV IAPCN,#BYTE_PROGRAM_AP
MOV IAPAH,#00h
MOV IAPAL,#00h
MOV DPTR,#AP_code
Program_AP_Loop:
CLR A
MOVC A,@A+DPTR
MOV IAPFD,A
CALL Trigger_IAP
INC DPTR
INC IAPAL
MOV A,IAPAL
CJNE A,#14,Program_AP_Loop
RET
Program_AP_Verify:
MOV IAPCN,#BYTE_READ_AP
MOV IAPAH,#00h
MOV IAPAL,#00h
MOV DPTR,#AP_code
Program_AP_Verify_Loop:
CALL Trigger_IAP
CLR A
MOVC A,@A+DPTR
MOV B,A
MOV A,IAPFD
CJNE A,B,Program_AP_Verify_Error
INC DPTR
INC IAPAL
MOV A,IAPAL
CJNE A,#14,Program_AP_Verify_Loop
RET
Program_AP_Verify_Error:
CALL Disable_IAP
MOV P0,#00h
SJMP $
Read_CONFIG:
MOV IAPCN,#BYTE_READ_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#02h
CALL Trigger_IAP
MOV R7,IAPFD
RET
Program_CONFIG:
MOV IAPCN,#BYTE_PROGRAM_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#02h
MOV A,R7
ANL A,#11111011b
MOV IAPFD,A ;disable BOD reset
MOV R6,A ;temp data
CALL Trigger_IAP
RET
Program_CONFIG_Verify:
MOV IAPCN,#BYTE_READ_CONFIG
MOV IAPAH,#00h
MOV IAPAL,#02h
CALL Trigger_IAP
MOV B,R6
MOV A,IAPFD
CJNE A,B,Program_CONFIG_Verify_Error
RET
Program_CONFIG_Verify_Error:
CALL Disable_IAP
MOV P0,#00h
SJMP $
;********************************************************************
; APROM code
;********************************************************************
AP_code:
DB 75h,0B1h, 00h ;OPCODEs of “MOV P0M1,#0”
DB 75h,0Ach, 00h ;OPCODEs of “MOV P3M1,#0”
DB 75h, 90h, 55h ;OPCODEs of “MOV P1,#55h”
DB 75h,0A0h,0Aah ;OPCODEs of “MOV P2,#0Aah”
DB 80h,0Feh ;OPCODEs of “SJMP $”
END
MS51 SERIES TECHNICAL REFERENCE MANUAL
programmed as 1, the OCD is activated. The OCD cannot operate if chip is locked. The OCD system
uses a two-wire serial interface, OCDDA and OCDCK, to establish communication between the target
device and the controlling debugger host. OCDDA is an input/output pin for debug data transfer and
OCDCK is an input pin for synchronization with OCDDA data. The ̅̅̅̅̅̅̅̅̅̅̅ pin is also necessary for
OCD mode entry and exit. The MS51 supports OCD with Flash Memory control path by ICP writer
mode, which shares the same three pins of OCD interface.
The MS51 uses OCDDA, OCDCK, and nRESET pins to interface with the OCD system. When
designing a system where OCD will be used, the following restrictions must be considered for correct
operation:
1. nRESET cannot be connected directly to VDD and any external capacitors connected must be
removed.
2. All external reset sources must be disconnected.
3. Any external component connected on OCDDA and OCDCK must be isolated.
CONFIG0
7 6 5 4 3 2 1 0
0 0 Quasi-bidirectional
0 1 Push-pull
1 0 Input-only (high-impedance)
1 1 Open-drain
All I/O pins can be selected as TTL level inputs or Schmitt triggered inputs by selecting corresponding
VDD
2-CPU-clock P P Very
delay Strong
Weak
Port Pin
N
Port Latch
Input
P Strong
Port Pin
N
Port Latch
Input
Port Pin
N
Port Latch
Input
Pn – Port n (Bit-addressable)
Regiser Address Reset Value
7 6 5 4 3 2 1 0
P0 / P1
Bit Name Description
P2
Bit Name Description
P3
Bit Name Description
0 0 Quasi-bidirectional
0 1 Push-pull
1 0 Input-only (high-impedance)
1 1 Open-drain
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
MS51 SERIES TECHNICAL REFERENCE MANUAL
PIPS[1:0]
(PICON[1:0])
00
P0.0
PIPEN0
Pin Interrupt Channel 0
00
P0.1
01 0
P1.1
Reserved
10 PIF1
11 PIT1 1
Reserved PINEN1
PIPEN1
Pin Interrupt Channel 1
Pin Interrupt
00
P0.7
01 0
P1.7
Reserved
10 PIF7
11 PIT67 1
Reserved PINEN7
PIPEN7
Pin Interrupt Channel 7
Pin interrupt is generally used to detect an edge transient from peripheral devices like keyboard or
keypad. During idle state, the system prefers to enter Power-down mode to minimize power
consumption and waits for event trigger. Pin interrupt can wake up the device from Power-down mode.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
6.5 Timer
TF0
0 7 Timer Interrupt
TR0 (TR1) (TF1)
TH0 (TH1)
GATE T0 (T1) pin
T0OE
INT0 (INT1) pin (T1OE)
TF0
0 7 Timer Interrupt
TR0 (TR1) (TF1)
TH0 (TH1)
GATE T0 (T1) pin
T0OE
INT0 (INT1) pin (T1OE)
enabled by setting the TR0 (TR1) bit as 1 and proper setting of GATE and INT0 ̅̅̅̅̅̅̅ (INT1
̅̅̅̅̅̅̅) pins. The
̅̅̅̅̅̅̅ ̅̅̅̅̅̅̅
functions of GATE and INT0 (INT1) pins are just the same as Mode 0 and 1.
T0M
(T1M)
1/12
0
FSYS C/T
1
0
1
TL0 (TL1)
T0 (T1) pin TF0
0 7 Timer Interrupt
(TF1)
T0 (T1) pin
T0OE
TR0 (TR1) (T1OE)
0 7
GATE TH0 (TH1)
INT0 (INT1) pin
flag TF1 and the enable bit TR1. However Timer 1 can still be used as a Timer/Counter and retains
̅̅̅̅̅̅̅ pin and T1M. It can be used as a baud rate generator for the serial port or
the use of GATE, INT1
other application not requiring an interrupt.
T0M
1/12
0
FSYS C/T
1
0
1
TL0
T0 pin
0 7 TF0 Timer 0 Interrupt
T0 pin
T0OE
TR0
GATE
T1 pin
T1OE
7 6 5 4 3 2 1 0
GATE ̅
C/T M1 M0 GATE ̅
C/T M1 M0
7 6 5 4 3 2 1 0
R (level) R (level)
R/W R/W R/W R/W R/W R/W
R/W (edge) R/W (edge)
remain set until cleared via software or cleared by hardware in the beginning of its interrupt service
routine.
̅̅̅̅̅̅̅ input signal’s logic level.
If IT1 = 0 (low level trigger), this flag follows the inverse of the INT1
Software cannot control it.
7 6 5 4 3 2 1 0
TL0[7:0]
R/W
7 6 5 4 3 2 1 0
TH0[7:0]
R/W
TL1[7:0]
R/W
7 6 5 4 3 2 1 0
TH0[7:0]
R/W
7 6 5 4 3 2 1 0
C0L C0H
CAPF0
CAPF1 CMPCR
CAPF2 Clear
Clear Timer 2 (T2MOD.2)
CAPCR[1] Counter
(T2MOD.3)
Clear Timer 2
00
CAPF0
CAPF1
01
10
=
CAPF2 11 LDEN[1]
LDTS[1:0] (T2MOD.7)
(T2MOD[1:0])
RCMP2L RCMP2H
[1] Once CAPCR and LDEN are both set, an input capture event only clears TH2 and TL2 without reloading RCMP2H and RCMP2L contents.
C0L C0H
CAPF0
CAPF1
CAPF2
CAPCR[1]
(T2MOD.3)
Clear Timer 2
FSYS Pre-scalar
TL2 TH2 TF2 Timer 2 Interrupt
T2DIV[2:0] TR2
(T2MOD[6:4]) (T2CON.2)
00
CAPF0 01
CAPF1 10
CAPF2 11 LDEN[1]
LDTS[1:0] (T2MOD.7)
(T2MOD[1:0])
RCMP2L RCMP2H
Timer 2 Module
[1] Once CAPCR and LDEN are both set, an input capture event only clears TH2 and TL2 without reloading RCMP2H and RCMP2L contents.
C0L C0H
CMPCR
(T2MOD.2)
Clear Timer 2
FSYS Pre-scalar
TL2 TH2
T2DIV[2:0] TR2
(T2MOD[6:4]) (T2CON.2)
= TF2 Timer 2 Interrupt
RCMP2L RCMP2H
Timer 2 Module
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
RCMP2L[7:0]
R/W
7 6 5 4 3 2 1 0
RCMP2H[7:0]
R/W
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
TL2[7:0]
R/W
7 6 5 4 3 2 1 0
TH2[7:0]
R/W
Note that the TH2 and TL2 are accessed separately. It is strongly recommended that user stops Timer
2 temporally by clearing TR2 bit before reading from or writing to TH2 and TL2. The free-running
reading or writing may cause unpredictable result.
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
C0L[7:0]
R/W
7 6 5 4 3 2 1 0
C0H[7:0]
R/W
7 6 5 4 3 2 1 0
0110 = P0.3/IC5
0111 = P0.5/IC6
1000 = P1.5/IC7
others = P1.2/IC0
7 6 5 4 3 2 1 0
6.5.3 Timer3
Timer 3 is implemented simply as a 16-bit auto-reload, up-counting timer. The user can select the pre-
scale with T3PS[2:0] (T3CON[2:0]) and fill the reload value into RH3 and RL3 registers to determine
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
RL3[7:0]
R/W
7 6 5 4 3 2 1 0
RH3[7:0]
R/W
CONFIG4
7 6 5 4 3 2 1 0
WDTEN[3:0] - - - -
R/W - - - -
The WDT is implemented with a set of divider that divides the low-speed internal oscillator clock
MS51 SERIES TECHNICAL REFERENCE MANUAL
nominal 10kHz. The divider output is selectable and determines the time-out interval. When the time-
out interval is fulfilled, it will wake the system up from Idle or Power-down mode and an interrupt event
will occur if WDT interrupt is enabled. If WDT is initialized as a time-out reset timer, a system reset will
occur after a period of delay if without any software action.
1
The Watchdog time-out interval is determined by the formula × 64 , where
FLIRC × clock dividerscalar
FLIRC is the frequency of internal 10 kHz oscillator. The following table shows an example of the
Watchdog time-out interval with different pre-scales.
[1]
WDPS.2 WDPS.1 WDPS.0 Clock Divider Scale WDT Time-Out Timing
0 0 0 1/1 6.40 ms
0 0 1 1/4 25.60 ms
0 1 0 1/8 51.20 ms
0 1 1 1/16 102.40 ms
1 0 0 1/32 204.80 ms
1 0 1 1/64 409.60 ms
1 1 0 1/128 819.20 ms
1 1 1 1/256 1.638 s
Since the limitation of the maxima vaule of WDT timer delay. To up MS51 from idle mode or power
down mode suggest use WKT function see Chapter 6.7 Self Wake-Up Timer (WKT).
10 kHz 512-clock
FLIRC Pre-scalar WDT counter overflow
Internal Delay
WDTRF WDT Reset
(1/1~1/256) (6-bit)
Oscillator clear
clear
WDPS[2:0] WDCLR
WDTF WDT Interrupt
After the device is powered and it starts to execute software code, the WDT starts counting
simultaneously. The time-out interval is selected by the three bits WDPS[2:0] (WDCON[2:0]). When
the selected time-out occurs, the WDT will set the interrupt flag WDTF (WDCON.5). If the WDT
interrupt enable bit EWDT (EIE0.4) and global interrupt enable EA are both set, the WDT interrupt
routine will be executed. Meanwhile, an additional 512 clocks of the low-speed internal oscillator
delays to expect a counter clearing by setting WDCLR to avoid the system reset by WDT if the device
operates normally. If no counter reset by writing 1 to WDCLR during this 512-clock period, a WDT
reset will happen. Setting WDCLR bit is used to clear the counter of the WDT. This bit is self-cleared
for user monitoring it. Once a reset due to WDT occurs, the WDT reset flag WDTRF (WDCON.3) will
10 kHz
FLIRC
Internal Pre-scalar WDT counter overflow
WDTF WDT Interrupt
Oscillator (1/1~1/256) (6-bit)
clear
IDL (PCON.0)
PD (PCON.1)
WDPS[2:0] WDCLR
WIDPD
WDTR
The WDT starts running by setting WDTR as 1 and halts by clearing WDTR as 0. The WDTF flag will
Dec. 17, 2019 Page 229 of 316 Rev 1.01
MS51
be set while the WDT completes the selected time interval. The software polls the WDTF flag to detect
a time-out. An interrupt will occur if the individual interrupt EWDT (EIE0.4) and global interrupt enable
EA is set. WDT will continue counting. User should clear WDTF and wait for the next overflow by
polling WDTF flag or waiting for the interrupt occurrence.
In some application of low power consumption, the CPU usually stays in Idle mode when nothing
needs to be served to save power consumption. After a while the CPU will be woken up to check if
anything needs to be served at an interval of programmed period implemented by Timer 0~3.
However, the current consumption of Idle mode still keeps at a “mA” level. To further reducing the
current consumption to “uA” level, the CPU should stay in Power-down mode when nothing needs to
be served, and has the ability of waking up at a programmable interval. The MS51 is equipped with
this useful function by WDT waking up. It provides a very low power internal oscillator 10 kHz as the
clock source of the WDT. It is also able to count under Power-down mode and wake CPU up. The
demo code to accomplish this feature is shown below.
MS51 SERIES TECHNICAL REFERENCE MANUAL
POR 0000_0111b
WDCON AAH, all pages, TA protected WDT 0000_1UUUb
Others 0000_UUUUb
7 6 5 4 3 2 1 0
Note:
1. WDTRF will be cleared after power-on reset, be set after WDT reset, and remains unchanged after any other
resets.
2. WDPS[2:0] are all set after power-on reset and keep unchanged after any reset other than power-on reset.
WKTCK
(WKCON.5) WKPS[2:0]
WKTR (WKCON[2:0]) 0 7
(WKCON.3) RWK
7 6 5 4 3 2 1 0
7:5 - Reserved
7 6 5 4 3 2 1 0
RWK[7:0]
R/W
6.8.1.1 Mode 0
Mode 0 provides synchronous communication with external devices. Serial data centers and exits
through RXD pin. TXD outputs the shift clocks. 8-bit frame of data are transmitted or received. Mode 0
therefore provides half-duplex communication because the transmitting or receiving data is via the
same data line RXD. The baud rate is enhanced to be selected as FSYS/12 if SM2 (SCON.5) is 0 or as
FSYS/2 if SM2 is 1. Note that whenever transmitting or receiving, the serial clock is always generated
by the MCU. Thus any device on the serial port in Mode 0 should accept the MCU as the master.
Figure 6.8-1 shows the associated timing of the serial port in Mode 0.
As shown there is one bi-directional data line (RXD) and one shift clock line (TXD). The shift clocks
are used to shift data in or out of the serial port controller bit by bit for a serial communication. Data
bits enter or emit LSB first. The band rate is equal to the shift clock frequency.
Transmission is initiated by any instruction writes to SBUF. The control block will then shift out the
clocks and begin to transfer data until all 8 bits are complete. Then the transmitted flag TI (SCON.1)
will be set 1 to indicate one byte transmitting complete.
Reception is initiated by the condition REN (SCON.4) = 1 and RI (SCON.0) = 0. This condition tells the
serial port controller that there is data to be shifted in. This process will continue until 8 bits have been
received. Then the received flag RI will be set as 1. User can clear RI to triggering the next byte
reception.
6.8.1.2 Mode 1
Mode 1 supports asynchronous, full duplex serial communication. The asynchronous mode is
commonly used for communication with PCs, modems or other similar interfaces. In Mode 1, 10 bits
are transmitted through TXD or received through RXD including a start bit (logic 0), 8 data bits (LSB
first) and a stop bit (logic 1). The baud rate is determined by the Timer 1. SMOD (PCON.7) setting 1
makes the baud rate double. Figure 6.8-2 shows the associated timings of the serial port in Mode 1 for
transmitting and receiving.
Transmission is initiated by any writing instructions to SBUF. Transmission takes place on TXD pin.
First the start bit comes out, the 8-bit data follows to be shifted out and then ends with a stop bit. After
the stop bit appears, TI (SCON.1) will be set to indicate one byte transmission complete. All bits are
MS51 SERIES TECHNICAL REFERENCE MANUAL
shifted out depending on the rate determined by the baud rate generator.
Once the baud rate generator is activated and REN (SCON.4) is 1, the reception can begin at any
time. Reception is initiated by a detected 1-to-0 transition at RXD. Data will be sampled and shifted in
at the selected baud rate. In the midst of the stop bit, certain conditions should be met to load SBUF
with the received data:
1. RI (SCON.0) = 0, and
2. Either SM2 (SCON.5) = 0, or the received stop bit = 1 while SM2 = 1 and the received data
matches “Given” or “Broadcast” address. (For enhancement function, see Section 6.8.4
“Multiprocessor Communication” and Section 6.8.5 “Automatic Address Recognition”.)
If these conditions are met, then the SBUF will be loaded with the received data, the RB8 (SCON.2)
with stop bit, and RI will be set. If these conditions fail, there will be no data loaded and RI will remain
0. After above receiving progress, the serial control will look forward another 1-to-0 transition on RXD
pin to start next data reception.
6.8.1.3 Mode 2
Mode 2 supports asynchronous, full duplex serial communication. Different from Mode1, there are 11
bits to be transmitted or received. They are a start bit (logic 0), 8 data bits (LSB first), a programmable
9th bit TB8 or RB8 bit and a stop bit (logic 1). The most common use of 9th bit is to put the parity bit in it
or to label address or data frame for multiprocessor communication. The baud rate is fixed as 1/32 or
1/64 the system clock frequency depending on SMOD (PCON.7) bit. Figure 6.8-3 shows the
associated timings of the serial port in Mode 2 for transmitting and receiving.
Transmission is initiated by any writing instructions to SBUF. Transmission takes place on TXD pin.
First the start bit comes out, the 8-bit data and bit TB8 (SCON.3) follows to be shifted out and then
ends with a stop bit. After the stop bit appears, TI will be set to indicate the transmission complete.
While REN is set, the reception is allowed at any time. A falling edge of a start bit on RXD will initiate
the reception progress. Data will be sampled and shifted in at the selected baud rate. In the midst of
the stop bit, certain conditions should be met to load SBUF with the received data:
1. RI (SCON.0) = 0, and
6.8.1.4 Mode 3
Mode 3 has the same operation as Mode 2, except its baud rate clock source uses Timer 1 overflows
as its baud rate clocks. See Figure 6.8-3 for timing diagram of Mode 3. It has no difference from Mode
2.
0 FSYS divided by 12
0 8 00 -
1 FSYS divided by 2
Time1 1 FSYS
TM1 CKCON[3] = 0 32 12 256 - TH1
Time1 1 FSYS
32 256 - TH1
0
TM1 CKCON[3] = 1
1 FSYS
32 Pre- scale 65536 - (256 RH 3 RL 3)
Timer 3
1 10 01 -
Time1 1 FSYS
TM1 CKCON[3] = 0 16 12 256 - TH1
Time1 1 FSYS
16 256 - TH1
1
TM1 CKCON[3] = 1
1 FSYS
16 Pre - scale 65536 - (256 RH3 RL3)
Timer 3
0 FSYS divided by 64
2 11 10 -
1 FSYS divided by 32
Time 1
[1] 1 FSYS
TM1 CKCON[3] = 0 32 12 256-TH1
MS51 SERIES TECHNICAL REFERENCE MANUAL
Time 1
[1] 1 FSYS
0
TM1 CKCON[3] = 1 32 256-TH1
1 FSYS
32 Pre - scale65536 -(256 RH3RL3)
Timer 3
3 11 11 -
Time1
[1] 1 FSYS
TM1 CKCON[3] = 0 16 12 256-TH1
Time1
[1] 1 FSYS
1
TM1 CKCON[3] = 1 16 256-TH1
1 FSYS
16 Pre- scale 65536 - (256 RH 3 RL 3)
Timer 3
0 8 00 - FSYS divided by 12
1 FSYS
32 Pre-scale 65536-(256RH3RL3)
0 Timer 3
1 10 01
1 FSYS
16 Pre-scale 65536-(256RH3RL3)
1 Timer 3
0 FSYS divided by 64
2 11 10
1 FSYS divided by 32
1 FSYS
32 Pre-scale 65536-(256RH3RL3)
0 Timer 3
3 11 11
1 FSYS
16 Pre-scale 65536-(256RH3RL3)
1 Timer 3
Sample code: we list the most popular UART setting Mode 1 initial step as following:
Fsys Value Baud Rate TH1 Value (Hex) RH3,RL3 Value (Hex) Baudrate Deviation
64
4800 FEC8 0.160256%
(SMOD=0)
9600 64 FF64 0.160256%
The FE bit will be set 1 via hardware while a framing error occurs. FE can be checked in UART
interrupt service routine if necessary. Note that SMOD0 should be 1 while reading or writing to FE. If
FE is set, any following frames received without frame error will not clear the FE flag. The clearing has
to be done via software.
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.
Example 1, slave 0:
SADDR = 11000000b
SADEN = 11111101b
Given = 110000X0b
Example 2, slave 1:
SADDR = 11000000b
SADEN = 11111110b
Given = 1100000Xb
In the above example SADDR is the same and the SADEN data is used to differentiate between the
two slaves. Slave 0 requires 0 in bit 0 and it ignores bit 1. Slave 1 requires 0 in bit 1 and bit 0 is
ignored. A unique address for Slave 0 would be 1100 0010 since slave 1 requires 0 in bit 1. A unique
address for slave 1 would be 11000001b since 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 11000000b as their “Broadcast” address.
In a more complex system the following could be used to select slaves 1 and 2 while excluding slave
MS51 SERIES TECHNICAL REFERENCE MANUAL
0:
Example 1, slave 0:
SADDR = 11000000b
SADEN = 11111001b
Given = 11000XX0b
Example 2, slave 1:
SADDR = 11100000b
SADEN = 11111010b
Given = 11100X0Xb
Example 3, slave 2:
SADDR = 11000000b
SADEN = 11111100b
Given = 110000XXb
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 11100110b. Slave 1 requires that bit 1 = 0
and it can be uniquely addressed by 11100101b. Slave 2 requires that bit 2 = 0 and its unique address
is 11100011b. To select Slaves 0 and 1 and exclude Slave 2 use address 11100100b, since it is
Dec. 17, 2019 Page 242 of 316 Rev 1.01
MS51
The use of don’t-care bits provides flexibility in defining the Broadcast address, however in most
applications, interpreting the “don’t-cares” as all ones, the broadcast address will be FFH.
On reset, SADDR and SADEN are initialized to 00H. This produces a “Given” address of all “don’t
cares” as well as a “Broadcast” address of all XXXXXXXXb (all “don’t care” bits). This ensures that the
serial port will reply to any address, and so that it is backwards compatible with the standard 80C51
microcontrollers that do not support automatic address recognition.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
POR, 0001_0000b
PCON 87H, all pages
Others,000U_0000b
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
for details.
7 6 5 4 3 2 1 0
SBUF[7:0]
R/W
7 6 5 4 3 2 1 0
SBUF1[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
SADDR[7:0]
R/W
7 6 5 4 3 2 1 0
SADEN[7:0]
R/W
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
SADDR1[7:0]
R/W
7 6 5 4 3 2 1 0
SADEN1[7:0]
R/W
POR 0000_0000b,
Software 1U00_0000b
AUXR1 A2H, all pages
nRESET pin U100_0000b
Others UUU0_0000b
7 6 5 4 3 2 1 0
CLOCK
SPR1
SPR0
SS
DISMODF
SSOE
SPIEN
MSTR
MSTR
MODF
SPIF
LSBFE
SPIEN
MSTR
SSOE
CPHA
CPOL
SPR1
SPR0
Internal
SPI Interrupt Data Bus
Figure15.1 SPI Block Diagram shows SPI block diagram. It provides an overview of SPI architecture in
this device. The main blocks of SPI are the SPI control register logic, SPI status logic, clock rate
control logic, and pin control logic. For a serial data transfer or receiving, The SPI block exists a write
data buffer, a shift out register and a read data buffer. It is double buffered in the receiving and
transmit directions. Transmit data can be written to the shifter until when the previous transfer is not
complete. Receiving logic consists of parallel read data buffer so the shift register is free to accept a
second data, as the first received data will be transferred to the read data buffer.
The four pins of SPI interface are Master-In/Slave-Out (MISO), Master-Out/Slave-In (MOSI), Shift
̅̅̅̅). The MOSI pin is used to transfer a 8-bit data in series from the
Clock (SPCLK), and Slave Select (SS
Master to the Slave. Therefore, MOSI is an output pin for Master device and an input for Slave.
Respectively, the MISO is used to receive a serial data from the Slave to the Master.
The SPCLK pin is the clock output in Master mode, but is the clock input in Slave mode. The shift
clock is used to synchronize the data movement both in and out of the devices through their MOSI and
MISO pins. The shift clock is driven by the Master mode device for eight clock cycles. Eight clocks
exchange one byte data on the serial lines. For the shift clock is always produced out of the Master
device, the system should never exist more than one device in Master mode for avoiding device
conflict.
Each Slave peripheral is selected by one Slave Select pin (SS ̅̅̅̅). The signal should stay low for any
̅̅̅̅
Slave access. When SS is driven high, the Slave device will be inactivated. If the system is multi-
slave, there should be only one Slave device selected at the same time. In the Master mode MCU, the
̅̅̅̅
SS pin does not function and it can be configured as a general purpose I/O. However, ̅̅̅̅
SS can be used
as Master Mode Fault detection (see chapter 6.9.4 Mode Fault Detection) via software setting if multi-
master environment exists. The MS51 also provides auto-activating function to toggle ̅̅̅̅ SS between
each byte-transfer.
Master/Slave Master/Slave
MCU1 MCU2
MISO MISO
MOSI MOSI
SPCLK SPCLK
SS SS
0 0
I/O 1 1 I/O
PORT 2 2 PORT
3 3
SO
SCK
SO
SO
SCK
SCK
SS
SS
SS
SI
SI
SI
MS51 SERIES TECHNICAL REFERENCE MANUAL
Figure 6.9-2 shows a typical interconnection of SPI devices. The bus generally connects devices
together through three signal wires, MOSI to MOSI, MISO to MISO, and SPCLK to SPCLK. The
Master devices select the individual Slave devices by using four pins of a parallel port to control the
four ̅̅̅̅
SS pins. MCU1 and MCU2 play either Master or Slave mode. The ̅̅̅̅ SS should be configured as
Master Mode Fault detection to avoid multi-master conflict.
MOSI MOSI
SPI clock
generator SS SS
*
Master MCU GND Slave MCU
* SS configuration follows DISMODF and SSOE bits.
Figure 6.9-3 shows the simplest SPI system interconnection, single-master and signal-slave. During a
transfer, the Master shifts data out to the Slave via MOSI line. While simultaneously, the Master shifts
Dec. 17, 2019 Page 256 of 316 Rev 1.01
MS51
data in from the Slave via MISO line. The two shift registers in the Master MCU and the Slave MCU
can be considered as one 16-bit circular shift register. Therefore, while a transfer data pushed from
Master into Slave, the data in Slave will also be pulled in Master device respectively. The transfer
effectively exchanges the data, which was in the SPI shift registers of the two MCUs.
By default, SPI data is transferred MSB first. If the LSBFE (SPCR.5) is set, SPI data shifts LSB first.
This bit does not affect the position of the MSB and LSB in the data register. Note that all the following
description and figures are under the condition of LSBFE logic 0. MSB is transmitted and received
first.
There are three SPI registers to support its operations, including SPI control register (SPCR), SPI
status register (SPSR), and SPI data register (SPDR). These registers provide control, status, data
storage functions, and clock rate selection. The following registers relate to SPI function.
1 1 ̅̅̅̅ output
Automatic SS
that CPOL and CPHA compose four different clock formats. The CPOL bit denotes the SPCLK line
level in its idle state. The CPHA bit defines the edge on which the MOSI and MISO lines are sampled.
The CPOL and CPHA should be identical for the Master and Slave devices on the same system. To
Communicate in different data formats with one another will result undetermined result.
CPOL = 0
Clock Polarity (CPOH)
sample sample
CPOL = 1
sample sample
In SPI, a Master device always initiates the transfer. If SPI is selected as Master mode (MSTR = 1)
and enabled (SPIEN = 1), writing to the SPI data register (SPInDR) by the Master device starts the
SPI clock and data transfer. After shifting one byte out and receiving one byte in, the SPI clock stops
and SPIF (SPInSR.7) is set in both Master and Slave. If SPI interrupt enable bit is set 1 and global
interrupt is enabled (EA = 1), the interrupt service routine (ISR) of SPI will be executed.
Concerning the Slave mode, the ̅̅̅̅̅
SS signal needs to be taken care. As shown in Figure 6.9-4 SPI
MS51 SERIES TECHNICAL REFERENCE MANUAL
Clock Formats, when CPHA = 0, the first SPCLK edge is the sampling strobe of MSB (for an example
of LSBFE = 0, MSB first). Therefore, the Slave should shift its MSB data before the first SPCLK edge.
The falling edge of ̅̅̅̅̅
SS is used for preparing the MSB on MISO line. The ̅̅̅̅̅ SS pin therefore should
toggle high and then low between each successive serial byte. Furthermore, if the slave writes data to
the SPI data register (SPInDR) while ̅̅̅̅̅
SS is low, a write collision error occurs.
When CPHA = 1, the sampling edge thus locates on the second edge of SPCLK clock. The Slave
̅̅̅̅̅ falling edge. Therefore, the SS
uses the first SPCLK clock to shift MSB out rather than the SS ̅̅̅̅̅ line can
remain low between successive transfers. This format may be preferred in systems having single fixed
Master and single fixed Slave. The ̅̅̅̅̅
SS line of the unique Slave device can be tied to GND as long as
only CPHA = 1 clock mode is used.
Note: The SPI should be configured before it is enabled (SPIEN = 1), or a change of LSBFE, MSTR,
CPOL, CPHA and SPR[1:0] will abort a transmission in progress and force the SPI system into idle
state. Prior to any configuration bit changed, SPIEN must be disabled first.
SPCLK Cycles
SPCLK Cycles 1 2 3 4 5 6 7 8
SPCLK (CPOL=0)
SPCLK (CPOL=1)
Transfer Progress[1]
(internal signal)
Input to Slave SS
SS output of Master[2]
SPIF (Master)
SPIF (Slave)
SPCLK Cycles
1 2 3 4 5 6 7 8
SPCLK (CPOL=0)
SPCLK (CPOL=1)
Transfer Progress[1]
(internal signal)
Input to Slave SS
SS output of Master[2]
SPIF (Master)
SPIF (Slave)
written directly into the SPI shift register. Once a write collision error is generated, WCOL (SPInSR.6)
will be set as 1 via hardware to indicate a write collision. In this case, the current transferring data
continues its transmission. However the new data that caused the collision will be lost. Although the
SPI logic can detect write collisions in both Master and Slave modes, a write collision is normally a
Slave error because a Slave has no indicator when a Master initiates a transfer. During the receiving
of Slave, a write to SPInDR causes a write collision in Slave mode. WCOL flag needs to be cleared via
software.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
- - - - - - SPIS1 SPIS0
- - - - - - R/W R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
SPDR[7:0]
R/W
2
6.10 Inter-Integrated Circuit (I C)
2
The MS51 provides two Inter-Integrated Circuit (I C) bus to serves as an serial interface between the
2
microcontrollers and the I C devices such as EEPROM, LCD module, temperature sensor, and so on.
2
The I C bus used two wires design (a serial data line I2C0_SDA and a serial clock line I2C0_SCL) to
transfer information between devices.
2
The I C bus uses bi-directional data transfer between masters and slaves. There is no central master
and the multi-master system is allowed by arbitration between simultaneously transmitting masters.
The serial clock synchronization allows devices with different bit rates to communicate via one serial
2
bus. The I C bus supports four transfer modes including master transmitter, master receiver, slave
2
receiver, and slave transmitter. The I C interface only supports 7-bit addressing mode. A special mode
2
General Call is also available. The I C can meet both standard (up to 100kbps) and fast (up to 400k
bps) speeds.
RUP RUP
2
Figure 6.10-1 I C Bus Interconnection
2
The I C is considered free when both lines are high. Meanwhile, any device, which can operate as a
master can occupy the bus and generate one transfer after generating a START condition. The bus
now is considered busy before the transfer ends by sending a STOP condition. The master generates
all of the serial clock pulses and the START and STOP condition. However if there is no START
condition on the bus, all devices serve as not addressed slave. The hardware looks for its own slave
address or a General Call address. (The General Call address detection may be enabled or disabled
by GC (I2CnADDRx.0).) If the matched address is received, an interrupt is requested.
2
Every transaction on the I C bus is 9 bits long, consisting of 8 data bits (MSB first) and a single
acknowledge bit. The number of bytes per transfer (defined as the time between a valid START and
STOP condition) is unrestricted but each byte has to be followed by an acknowledge bit. The master
device generates 8 clock pulse to send the 8-bit data. After the 8th falling edge of the I2C0_SCL line,
the device outputting data on the I2C0_SDA changes that pin to an input and reads in an
acknowledge value on the 9th clock pulse. After 9th clock pulse, the data receiving device can hold
I2C0_SCL line stretched low if next receiving is not prepared ready. It forces the next byte transaction
suspended. The data transaction continues when the receiver releases the I2C0_SCL line.
SDA
MSB LSB ACK
SCL
1 2 8 9
START STOP
condition condition
2
Figure 6.10-2 I C Bus Protocol
SDA
MS51 SERIES TECHNICAL REFERENCE MANUAL
SCL
Repeated
START STOP START STOP
START
data transfer
‘0’ : write (n bytes + acknowlegde)
Figure 6.10-5 shows a master read data from slave by 7-bit. A master addresses a slave with a 7-bit
address and 1-bit read index to denote that the master wants to read data from the slave. The slave
will start transmitting data after the slave returns acknowledge to the master.
data transfer
‘1’ : read (n bytes + acknowlegde)
There is an exception called “General Call” address, which can address all devices by giving the first
byte of data all 0. A General Call is used when a master wishes to transmit the same message to
several slaves in the system. When this address is used, other devices may respond with an
acknowledge or ignore it according to individual software configuration. If a device response the
General Call, it operates as like in the slave-receiver mode. Note that the address 0x00 is reserved for
2
General Call and cannot be used as a slave address, therefore, in theory, a 7-bit addressing I C bus
SDA
SCL
1-7 8 9 1-7 8 9 1-7 8 9
2
Figure 6.10-6 Data Format of One I C Transfer
During the data transaction period, the data on the I2C0_SDA line should be stable during the high
period of the clock, and the data line can only change when I2C0_SCL is low.
6.10.1.3 Acknowledge
The 9th I2C0_SCL pulse for any transferred byte is dedicated as an Acknowledge (ACK). It allows
receiving devices (which can be the master or slave) to respond back to the transmitter (which also
can be the master or slave) by pulling the I2C0_SDA line low. The acknowledge-related clock pulse is
generated by the master. The transmitter should release control of I2C0_SDA line during the
acknowledge clock pulse. The ACK is an active-low signal, pulling the I2C0_SDA line low during the
clock pulse high duty, indicates to the transmitter that the device has received the transmitted data.
Commonly, a receiver, which has been addressed is requested to generate an ACK after each byte
has been received. When a slave receiver does not acknowledge (NACK) the slave address, the
I2C0_SDA line should be left high by the slave so that the mater can generate a STOP or a repeated
START condition.
If a slave-receiver does acknowledge the slave address, it switches itself to not addressed slave mode
and cannot receive any more data bytes. This slave leaves the I2C0_SDA line high. The master
should generate a STOP or a repeated START condition.
If a master-receiver is involved in a transfer, because the master controls the number of bytes in the
transfer, it should signal the end of data to the slave-transmitter by not generating an acknowledge on
the last byte. The slave-transmitter then switches to not addressed mode and releases the I2C0_SDA
line to allow the master to generate a STOP or a repeated START condition.
SDA output by transmitter
6.10.1.4 Arbitration
A master may start a transfer only if the bus is free. It is possible for two or more masters to generate
a START condition. In these situations, an arbitration scheme takes place on the I2C0_SDA line, while
I2C0_SCL is high. During arbitration, the first of the competing master devices to place‘a’’1’ (high) on
I2C0_SDA while another master transmits‘a’’0’ (low) switches off its data output stage because the
level on the bus does not match its own level. The arbitration lost master switches to the not
MS51 SERIES TECHNICAL REFERENCE MANUAL
addressed slave immediately to detect its own slave address in the same serial transfer whether it is
being addressed by the winning master. It also releases I2C0_SDA line to high level for not affecting
the data transfer continued by the winning master. However, the arbitration lost master continues
generating clock pulses on I2C0_SCL line until the end of the byte in which it loses the arbitration.
Arbitration is carried out by all masters continuously monitoring the I2C0_SDA line after outputting
data. If the value read from the I2C0_SDA line does not match the value that the master has to output,
it has lost the arbitration. Note that a master can only lose arbitration when it outputs a high I2C0_SDA
value while another master outputs a low value. Arbitration will continue until only one master remains,
and this may take many bits. Its first stage is a comparison of address bits, and if both masters are
trying to address the same device, arbitration continues on to the comparison of data bits or
acknowledge bit.
DATA 1 from master 1
Master 1 loses arbitration for DATA 1 ≠ SDA
It immediately switches to not addressed slave
and outputs high level
DATA 2 from master 2
SDA line
SCL line
START
condition
2
Since control of the I C bus is decided solely on the address or master code and data sent by
competing masters, there is no central master, nor any order of priority on the bus. Slaves are not
involved in the arbitration procedure.
The on-chip I2C ports support three operation modes, Master, Slave, and General Call Mode.
In a given application, I2C port may operate as a master or as a slave. In Slave mode, the I2C port
hardware looks for its own slave address and the general call address. If one of these addresses is
detected, and if the slave is willing to receive or transmit data from/to master(by setting the AA bit),
acknowledge pulse will be transmitted out on the 9th clock, hence an interrupt is requested on both
master and slave devices if interrupt is enabled. When the microcontroller wishes to become the bus
master, hardware waits until the bus is free before entering Master mode so that a possible slave
action is not be interrupted. If bus arbitration is lost in Master mode, I2C port switches to Slave mode
immediately and can detect its own slave address in the same serial transfer.
To control the I2C bus transfer in each mode, user needs to set I2C_CTL0, I2C_DAT registers
according to current status code of I2C_STATUS0 register. In other words, for each I2C bus action,
user needs to check current status by I2C_STATUS0 register, and then set I2C_CTL0, I2C_DAT
registers to take bus action. Finally, check the response status by I2C_STATUS0.
The bits, STA, STO and AA in I2C_CTL0 register are used to control the next state of the I2C
hardware after SI flag of I2C_CTL0 [3] register is cleared. Upon completion of the new action, a new
status code will be updated in I2C_STATUS0 register and the SI flag of I2C_CTL0 register will be set.
But the SI flag will not be set when I2C STOP. If the I2C interrupt control bit INTEN (I2C_CTL0 [7]) is
set, appropriate action or software branch of the new status code can be performed in the Interrupt
service routine.
Figure 6.10-9 Control I2C Bus according to the Current I2C Status shows the current I2C status code
is 0x08, and then set I2C_DATA=SLA+W and (STA,STO,SI,AA) = (0,0,1,x) to send the address to I2C
I2C_DAT
S ACK
(SLA+W)
Register Control
Master to Slave I2C_DAT=SLA+W
(STA,STO,SI,AA)=(0,0,1,x)
Slave to Master
Figure 6.10-9 Control I2C Bus according to the Current I2C Status
MT ACK STATUS=0x18
STATUS=0x08 ACK STATUS=0x28
NAK STATUS=0x20 NAK STATUS=0x30
I2CnDAT ACK/
(Data) NAK
I2C_DAT=Data
(STA,STO,SI,AA)=(0,0,1,x)
STATUS=0x10
Sr
(STA,STO,SI,AA)=(1,0,1,x) STATUS=0xF8
(STA,STO,SI,AA)=(0,1,1,x)
STATUS=0x08
P S MT
(STA,STO,SI,AA)=(1,1,1,x)
MR
MR
STATUS=0x08 STATUS=0x40 STATUS=0x50
I2CnDAT I2CnDAT
S ACK ACK
(SLA+R) (Data)
(STA,STO,SI,AA)=(1,0,1,x) I2CnDAT=SLA+R (STA,STO,SI,AA)=(0,0,1,1)
(STA,STO,SI,AA)=(0,0,1,x) (Arbitration Lost) ACK
STATUS=0x38
I2CnDAT
ACK
(Data)
(STA,STO,SI,AA)=(0,0,1,0)
STATUS=0x58
I2CnDAT
NAK
(Data)
(STA,STO,SI,AA)=(0,0,1,0)
STATUS=0x48 STATUS=0x08
NAK P S
(STA,STO,SI,AA)=(1,1,1,x)
(Arbitration Lost)
STATUS=0x38
STATUS=0xF8
I2CnDAT ACK/
(SLA+R) NAK
P
I2CnDAT=SLA+R
(STA,STO,SI,AA)=(0,0,1,X)
(STA,STO,SI,AA)=(0,1,1,x)
To corresponding states in
slave mode MR
(STA,STO,SI,AA)=(1,0,1,X)
until it is addressed by its own address with the data direction bit “read” (SLA+R). The slave
transmitter mode may also be entered if arbitration is lost.
After the slave is addressed by SLA+R, it should clear its SI flag to transmit the data to the master
receiver. Normally the master receiver will return an acknowledge after every bytes of data is
transmitted by the slave. If the acknowledge is not received, it will transmit all “1” data if it continues
the transaction. It becomes a not addressed slave. If the AA flag is cleared during a transaction, the
slave transmits the last byte of data. The next transmitting data will be all “1” and the slave becomes
not addressed.
I2CnDAT I2CnDAT
... S ACK ACK
(SLA+W) (Data)
(STA,STO,SI,AA)=(0,0,1,1) STATUS=0x88
(STA,STO,SI,AA)=(0,0,1,1) (Arbitration Lost)
STATUS=0x68
I2CnDAT
I2CnDAT NAK
ACK (Data)
(SLA+W)
(STA,STO,SI,AA)=(0,0,1,0)
STATUS=0xA8
STATUS=0xA0
I2CnDAT
ACK
(SLA+R) P
I2CnDAT
ACK Sr ... Sr
(SLA+R)
(STA,STO,SI,AA)=(0,0,1,X) (STA,STO,SI,AA)=(0,0,1,1)
STATUS=0xB8
Switch to not addressed mode
Own SLA will be recognized
I2CnDAT
ACK Send START when bus free
(Data) Become I2C
I2CnDAT=Data
... S ...
Master
(STA,STO,SI,AA)=(0,0,1,1)
MS51 SERIES TECHNICAL REFERENCE MANUAL
STATUS=0xC8
(STA,STO,SI,AA)=(1,0,1,1)
I2CnDAT
ACK Switch to not addressed mode
(Data) Own SLA will not be recognized
I2CnDAT=Data Send START when bus free
(STA,STO,SI,AA)=(0,0,1,0)
STATUS=0xC0
Become I2C
... S ...
Master
I2CnDAT
NAK (STA,STO,SI,AA)=(1,0,1,0)
(Data)
I2CnDAT=Data Switch to not addressed mode
(STA,STO,SI,AA)=(0,0,1,0) Own SLA will be recognized
STATUS=0xA0
Become I2C
...
P Slave
Sr ... Sr Bus
...
Free
I2C_DAT=Data
(STA,STO,SI,AA)=(0,0,1,X) (STA,STO,SI,AA)=(0,0,1,1)
(STA,STO,SI,AA)=(0,0,1,0)
I2CnDAT I2CnDAT
... S ACK ACK
(SLA+W=0x00) (Data)
(STA,STO,SI,AA)=(0,0,1,1)
GC=1 (STA,STO,SI,AA)=(0,0,1,1)
(Arbitration Lost)
STATUS=0x78 STATUS=0x98
I2CnDAT I2CnDAT
ACK NAK
(SLA+W=0x00) (Data)
(STA,STO,SI,AA)=(0,0,1,0)
STATUS=0xA0
(STA,STO,SI,AA)=(0,0,1,X)
STATUS=0xA0
Sr ... Sr
(STA,STO,SI,AA)=(0,0,1,X) (STA,STO,SI,AA)=(0,0,1,1)
(STA,STO,SI,AA)=(1,0,1,1)
(STA,STO,SI,AA)=(1,0,1,0)
(STA,STO,SI,AA)=(0,0,1,1)
Switch to not addressed mode
Master to Slave Own SLA will not be recognized
Slave to Master
... Bus Free
Arbitraion Lost
(STA,STO,SI,AA)=(0,0,1,0)
There are two I2CnSTAT status codes that do not correspond to the 25 defined states, The first status
code F8H indicates that no relevant information is available during each transaction. Meanwhile, the
2
SI flag is 0 and no I C interrupt is required. The other status code 00H means a bus error has
occurred during a transaction. A bus error is caused by a START or STOP condition appearing
temporally at an illegal position such as the second through eighth bits of an address or a data byte,
and the acknowledge bit. When a bus error occurs, the SI flag is set immediately. When a bus error is
2
detected on the I C bus, the operating device immediately switches to the not addressed salve mode,
releases I2C0_SDA and I2C0_SCL lines, sets the SI flag, and loads I2CnSTAT as 00H. To recover
from a bus error, the STO bit should be set and then SI should be cleared. After that, STO is cleared
2 2
by hardware and release the I C bus without issuing a real STOP condition waveform on I C bus.
There is a special case if a START or a repeated START condition is not successfully generated for
2
I C bus is obstructed by a low level on I2C0_SDA line e.g. a slave device out of bit synchronization,
2
the problem can be solved by transmitting additional clock pulses on the I2C0_SCL line. The I C
hardware transmits additional clock pulses when the STA bit is set, but no START condition can be
generated because the I2C0_SDA line is pulled low. When the I2C0_SDA line is eventually released,
a normal START condition is transmitted, state 08H is entered, and the serial transaction continues. If
2
a repeated START condition is transmitted while I2C0_SDA is obstructed low, the I C hardware also
performs the same action as above. In this case, state 08H is entered instead of 10H after a
successful START condition is transmitted. Note that the software is not involved in solving these bus
problems.
The following table is show the status display in I2STAT register of I2C number and description:
0x18 Master Transmit Address ACK 0xB0 Slave Transmit Arbitration Lost
0x20 Master Transmit Address NACK 0xB8 Slave Transmit Data ACK
0x28 Master Transmit Data ACK 0xC0 Slave Transmit Data NACK
0x30 Master Transmit Data NACK 0xC8 Slave Transmit Last Data ACK
0x40 Master Receive Address ACK 0x68 Slave Receive Arbitration Lost
0x48 Master Receive Address NACK 0x80 Slave Receive Data ACK
0x50 Master Receive Data ACK 0x88 Slave Receive Data NACK
2
There is a 14-bit time-out counter, which can be used to deal with the I C bus hang-up. If the time-out
counter is enabled, the counter starts up counting until it overflows. Meanwhile I2TOF will be set by
2
hardware and requests I C interrupt. When time-out counter is enabled, setting flag SI to high will
2
reset counter and restart counting up after SI is cleared. If the I C bus hangs up, it causes the SI flag
not set for a period. The 14-bit time-out counter will overflow and require the interrupt service.
FSYS 0
14-bit I2C Time-out Counter I2TOF
1/4 1
Clear Counter
DIV
I2CEN
I2TOCEN
SI
7 6 5 4 3 2 1 0
If the AA flag is cleared, a NACK (high level on I2C0_SDA) will be returned during the acknowledge
2
clock pulse of the I2C0_SCL line while the I C device is a receiver or an own-address-matching slave.
A device with its own AA flag cleared will ignore its own salve address and the General Call.
Consequently, SI will note be asserted and no interrupt is requested.
Note that if an addressed slave does not return an ACK under slave receiver mode or not receive an
ACK under slave transmitter mode, the slave device will become a not addressed slave. It cannot
receive any data until its AA flag is set and a master addresses it again.
There is a special case of I2STAT value C8H occurs under slave transmitter mode. Before the slave
device transmit the last data byte to the master, AA flag can be cleared as 0. Then after the last data
byte transmitted, the slave device will actively switch to not addressed slave mode of disconnecting
with the master. The further reading by the master will be all FFH.
1 - Reserved
SCL
SDA
2
I2STAT – I C Status
Regiser Address Reset Value
7 6 5 4 3 2 1 0
I2STAT[7:3] 0 0 0
R R R R
2:0 0 Reserved
The least significant three bits of I2STAT are always read as 0.
2
I2DAT – I C Data
Regiser Address Reset Value
I2DAT[7:0]
R/W
shifting direction
2
I2ADDR – I C Own Slave Address
7 6 5 4 3 2 1 0
I2ADDR[7:1] GC
R/W R/W
2
I2CLK – I C Clock
MS51 SERIES TECHNICAL REFERENCE MANUAL
7 6 5 4 3 2 1 0
I2CLK[7:0]
R/W
2
I2TOC – I C Time-out Counter
Regiser Address Reset Value
7 6 5 4 3 2 1 0
STO = 1;
AA = 1;
break;
case 0x50: /*50H, DATA received, ACK transmitted*/
DATA_RECEIVED1 = I2DAT; //store received DATA
if (To_RX_Last_Data1) //if last DATA will be received
AA = 0; //not ACK next received DATA
else //if continuing receiving DATA
AA = 1;
break;
case 0x58: /*58H, DATA received, NACK transmitted*/
DATA_RECEIVED_LAST1 = I2DAT;
STO = 1;
AA = 1;
break;
//====================================
//Slave Receiver and General Call Mode
//====================================
case 0x60: /*60H, own SLA+W received, ACK returned*/
AA = 1;
break;
case 0x68: /*68H, arbitration lost in SLA+W/R
own SLA+W received, ACK returned */
AA = 0; //not ACK next received DATA after
//arbitration lost
STA = 1; //retry to transmit START if bus free
break;
break;
case 0Xb8: /*B8H, previous own SLA+R, DATA transmitted,
ACK received*/
I2DAT = NEXT_SEND_DATA4;
if (To_TX_Last_Data) //if last DATA will be transmitted
AA = 0;
else
AA = 1;
break;
case 0Xc0: /*C0H, previous own SLA+R, DATA transmitted,
NACK received, not addressed SLAVE mode
entered*/
AA = 1;
break;
case 0Xc8: /*C8H, previous own SLA+R, last DATA trans-
mitted, ACK received, not addressed SLAVE
AA = 1; mode entered*/
break;
}//end of switch (I2STAT)
LOAD (PWMnCON0.6)
PWMRUN
(PWMnCON0.7) 16-bit clear counter
up/down CLRPWM
Interrupt INTSEL[1:0], INTTYP[1:0]
FSYS 0 FPWM counter (PWMnCON0.4) select/type (PWMnCON0[3:0])
Pre-scalar edge/center
Timer 1 overflow 1
PWMCKS PWMDIV0[2:0]
PWMTYP PG0
(CKCON.6) (PWMnCON1[2:0])
(PWMnCON1.4) = PWMn_CH0
PWM0 buffer
(PWMnCH0H,
PWMnCH0L) PWM0 Register
PG1
= PWMn_CH1
PWM1 buffer
(PWMnCH1H,
PWMnCH1L) PWM1 Register
= 0 PG2 PWMn_CH2
1
PWM2 buffer
PWM and
Fault Brake
output
(PWMnCH2H, control
PWMnCH2L) PWM2 Register
MS51 SERIES TECHNICAL REFERENCE MANUAL
= 0 PG3 PWMn_CH3
1
PWM3 buffer
(PWMnCH3H,
PWMnCH3L) PWM3 Register
= 0 PG4 PWMn_CH4
1
PWM4 buffer
(PWMnCH4H,
PWMnCH4L) PWM4 Register
= 0 PG5 PWMn_CH5
1
PWM5 buffer
GP
[PWMnCON1.5] Brake event
(PWMnCH5H, (PWM_BRAKEn)
PWMnCH5L) PWM5 Register
The PWM counter generates six PWM signals called PG0, PG1, PG2, PG3, PG4, and PG5. These
signals will go through the PWM and Fault Brake output control circuit. It generates real PWM outputs
on I/O pins. The output control circuit determines the PWM mode, dead-time insertion, mask output,
Fault Brake control, and PWM polarity. The last stage is a multiplexer of PWM output or I/O function.
PMEN2
PG2_DT
PNP2
PG2 0
0
PMD2 0
1
FBD2
PWM2/3
PWM2/3 1 PWMn_CH2
dead 1
mode
time
PG3 PG3_DT
0
PMD3 0
1 0
FBD3
PMEN3 1 PWMn_CH3
1
PNP3
PMEN4
PNP4
PG4_DT
PG4 0 0
0
PMD4 FBD4
PWM4/5
1 1 PWMn_CH4
1
PWM4/5
dead
mode
time
PG5 PG5_DT
PWMnMOD[1:0] FBINEN
PWMnDTEN, PWMnMEN, PWMnFBD (PWMnCON1.3) PWMnPNP
(PWMnCON1[7:6]) PWMnDTCNT PWMnMD
Brake event
(FBn)
Figure 6.11-2 PWM and Fault Brake Output Control Block Diagram
User should follow the initialization steps below to start generating the PWM signal output. In the first
step by setting CLRPWM (PWMnCON0.4), it ensures the 16-bit up counter reset for the accuracy of
the first duration. After initialization and setting {PWMnPH, PWMnPL} and all {PWMnH, PWMnL}
registers, PWMRUN (PWMnCON0.7) can be set as logic 1 to trigger the 16-bit counter running. PWM
starts to generate waveform on its output pins. The hardware for all period and duty control registers
are double buffered designed. Therefore, {PWMnPH, PWMnPL} and all {PWMnH, PWMnL} registers
can be written to at any time, but the period and duty cycle of PWM will not be updated immediately
until the LOAD (PWMnCON0.6) is set and previous period is complete. This prevents glitches when
updating the PWM period or duty.
NOTE: A loading of new period and duty by setting LOAD should be ensured complete by monitoring
it and waiting for a hardware automatic clearing LOAD bit. Any updating of PWM control registers
during LOAD bit as logic 1 will cause unpredictable output.
The PWM generator provides two PWM types: edge-aligned or center-aligned. PWM type is selected
by PWMTYP (PWMnCON1.4).
6.11.2.1 Edge-Aligned Type
In edge-aligned mode, the 16-bit counter uses single slop operation by counting up from 0000H to
{PWMnPH, PWMnPL} and then starting from 0000H. The PWM generator signal (PGn before PWM
and Fault Brake output control) is cleared on the compare match of 16-bit counter and the duty
register {PWMnH, PWMnL} and set at the 16-bit counter is 0000H. The result PWM output waveform
is left-edge aligned.
PWMnP (2nd)
PWMnP (1st)
12-bit counter
PWMnCH01
(2nd)
PWMnCH01
(1st)
PWMnCH01
(2nd)
duty valid
PG01 output
PWMnCH01
PWMnP (2nd)
(2nd)
The output frequency and duty cycle for edge-aligned PWM are given by following equations:
FPWM
PWM frequency = (FPWM is the PWM clock source frequency divided by
{PWMnPH , PWMnPL} 1
PWMDIV).
{PWMnCHxH , PWMnCHxL}
PWM high level duty = .
{PWMnPH , PWMnPL} 1
6.11.2.2 Center-Aligned Type
In center-aligned mode, the 16-bit counter use dual slop operation by counting up from 0000H to
{PWMnPH, PWMnPL} and then counting down from {PWMnPH, PWMnPL} to 0000H. The PGn signal
is cleared on the up-count compare match of 16-bit counter and the duty register {PWMnH, PWMnL}
and set on the down-count compare match. Center-aligned PWM may be used to generate non-
overlapping waveforms.
PWMP (2nd)
PWMP (1st)
12-bit counter
PWM01 (2nd)
PWM01 (1st)
PWM01 (2nd)
duty valid
PG01 output
The output frequency and duty cycle for center-aligned PWM are given by following equations:
FPWM
PWM frequency = (FPWM is the PWM clock source frequency divided by
2 {PWMnPH , PWMnPL}
PWMDIV).
{PWMnCHxH , PWMnCHxL}
PWM high level duty = .
{PWMnPH , PWMnPL}
PG0
PG1
PG0_DT
PG1_DT
Synchronous mode is enabled when PWMMOD[1:0] = [1:0]. In this mode, PG0/2/4 output PWM
signals the same as the independent mode. PG1/3/5 output just the same in-phase PWM signals of
PG02/4 correspondingly.
0
FBn De-bounce
1
FBINLS
FBINEN
Fault Brake event
ADC comparator FBF Fault Brake interrupt
ADC compare event
Each PWM output channel has its independent polarity control bit, PNP0~PNP5. The default is high
Dec. 17, 2019 Page 288 of 316 Rev 1.01
MS51
active level on all control fields implemented with positive logic. It means the power switch is ON when
PWM outputs high level and OFF when low level. User can easily configure all setting with positive
logic and then set PWMnNP bit to make PWM actually outputs according to the negative logic.
Fault Brake event requests another interrupt, Fault Brake interrupt. It has different interrupt vector from
PWM interrupt. When either Fault Brake pin input event or ADC compare event occurs, FBF
(PWMnFBD.7) will be set by hardware. It generates Fault Brake interrupt if enabled. The Fault Brake
interrupt enable bit is EFB0 (EIE0.5). FBF Is cleared via software.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
PWMP[7:0]
R/W
7 6 5 4 3 2 1 0
PWMP[15:8]
R/W
PWM0H D2H, all pages PWM Channel 0 Duty High Byte 0000_0000 b
PWM1H D3H, all pages PWM Channel 1 Duty High Byte 0000_0000 b
PWM2H D4H, all pages PWM Channel 2 Duty High Byte 0000_0000 b
PWM3H D5H, all pages PWM Channel 3 Duty High Byte 0000_0000 b
7 6 5 4 3 2 1 0
R/W
PWM0L DAH, all pages PWM Channel 0 Duty Low Byte 0000_0000 b
PWM1L DBH, all pages PWM Channel 1 Duty Low Byte 0000_0000 b
PWM2L DCH, all pages PWM Channel 2 Duty Low Byte 0000_0000 b
PWM3L DDH, all pages PWM Channel 3 Duty Low Byte 0000_0000 b
7 6 5 4 3 2 1 0
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
PDTCNT[7:0]
R/W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
VDD
ADC_CH0
VREF
0000
ADC_CH1 0001
ADC_CH2 0010
ADC_CH3 0011 ADCF ADC interrupt
ADC_CH4 0100 12-bit SAR
ADC_CH5 0101
ADC_CH6
ADC 12
0110
ADC_CH7 0111
Internal band-gap 1000
A/D convertion start
ADCEN
ADC result
ADCHS[3:0] comparator
ADCS
ADC Clock
FSYS Divider FADC
ADCDIV[2:0]
External Trigger
[00]
PWM0_CH0 00
[01]
PWM0_CH2 01
0 ADCDLY
P0.4 PWM0_CH4 10
11
[10] ADCEX
P1.3 1
STADC
[11]
STADCPX ETGSEL[1:0]
(ADCCON0[5:4])
ETGTYP[1:0]
(ADCCON1[3:2])
By the way, digital circuitry inside and outside the device generates noise which might affect the
accuracy of ADC measurements. If conversion accuracy is critical, the noise level can be reduced by
applying the following techniques:
1. Keep analog signal paths as short as possible. Make sure to run analog signals tracks well away
from high-speed digital tracks.
2. Place the device in Idle mode during a conversion.
MS51 SERIES TECHNICAL REFERENCE MANUAL
3. If any ADC_CHn pins are used as digital outputs, it is essential that these do not switch while a
conversion is in progress.
[00]
PWM0_CH0 00
[01]
PWM0_CH2 01 External
10
ADCDLY
PWM0_CH4 Trigger
[10]
STADC 11
[11]
PTRGSEL[1:0]
(ADCCON0[5:4])
PTRGTYP[1:0]
(ADCCON1[3:2])
ADCMPO
ADCR[11:0] + 0 (ADCCON2.4)
ADCF ADC interrupt
ADCMP[11:0] - 1 ADFBEN
(ADCCON2.7)
ADCMPOP
ADCMPEN (ADCCON2.6)
(ADCCON2.5)
Formula as following
For example:
Read the 2 bytes value after the UID address, wherein the first byte value is 0x64, and the second
byte value is 0x0E, merged as 0x64E = 1614. The conversion result is as follows:
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
3:1 ADCAQT
This 3-bit field decides the acquisition time for ADC sampling, following by equation below:
ADC acquisition time = 4 * ADCAQT 6 .
FADC
The default and minimum acquisition time is 6 ADC clock cycles. Note that this field should not
be changed when ADC is in converting.
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
ADCDLY[7:0]
R/W
Note that this field is valid only when ADCEX (ADCCON1.1) is set. User should not modify
ADCDLY during PWM run time if selecting PWM output as the external ADC trigger source.
ADCR[11:4]
7 6 5 4 3 2 1 0
- - - - ADCR[3:0]
- - - - R
7 6 5 4 3 2 1 0
ADCMP[11:4]
W/R
7 6 5 4 3 2 1 0
- - - - ADCMP[3:0]
- - - - W/R
MS51 SERIES TECHNICAL REFERENCE MANUAL
POR 0000_0000b,
Software 1U00_0000b
AUXR1 A2H, all pages
nRESET pin U100_0000b
Others UUU0_0000b
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
DPL[7:0]
R/W
7 6 5 4 3 2 1 0
DPH[7:0]
R/W
POR 0000_0000b,
Software 1U00_0000b
AUXR1 A2H, all pages
nRESET pin U100_0000b
Others UUU0_0000b
7 6 5 4 3 2 1 0
3 GF2
The general purpose flag that can be set or cleared by the user via software.
7 PACKAGE DIMENSIONS
8 INSTRUCTION SET
Instruction CY OV AC Instruction CY OV AC
[1]
ADD X X X CLR C 0
ADDC X X X CPL C X
SUBB X X X ANL C, bit X
MUL 0 X ANL C, /bit X
DIV 0 X ORL C, bit X
DA A X ORL C, /bit X
RRC A X MOV C, bit X
Table 8.2-1 Instruction Set lists all instructions for details. The note of the instruction set and
addressing modes are shown below.
Rn (N = 0~7) Register R0 To R7 Of The Currently Selected Register Bank.
Direct 8-bit internal data location’s address. It could be an internal data RAM location (00H to 7FH) or an
SFR (80H to FFH).
@RI (I = 0, 1) 8-bit internal data RAM location (00H to FFH) addressed indirectly through register R0 or R1.
MUL AB A4 1 4 12
DIV AB 84 1 4 12
DA A D4 1 1 12
ANL A, Rn 58~5F 1 2 6
ANL A, direct 55 2 3 4
ANL A, @Ri 56, 57 1 4 3
ANL A, #data 54 2 2 6
ANL direct, A 52 2 4 3
ANL direct, #data 53 3 4 6
ORL A, Rn 48~4F 1 2 6
ORL A, direct 45 2 3 4
ORL A, @Ri 46, 47 1 4 3
ORL A, #data 44 2 2 6
ORL direct, A 42 2 4 3
ORL direct, #data 43 3 4 6
XRL A, Rn 68~6F 1 2 6
XRL A, direct 65 2 3 4
XRL A, @Ri 66, 67 1 4 3
XRL A, #data 64 2 2 6
XRL direct, A 62 2 4 3
XRL direct, #data 63 3 4 6
CLR A E4 1 1 12
CPL A F4 1 1 12
RL A 23 1 1 12
9 REVISION HISTORY
Date Revision Description
Important Notice
Nuvoton Products are neither intended nor warranted for usage in systems or equipment, any
malfunction or failure of which may cause loss of human life, bodily injury or severe property
damage. Such applications are deemed, “Insecure Usage”.
Insecure usage includes, but is not limited to: equipment for surgical implementation, atomic
energy control instruments, airplane or spaceship instruments, the control or operation of
dynamic, brake or safety systems designed for vehicular use, traffic signal instruments, all
types of safety devices, and other applications intended to support or sustain life.
All Insecure Usage shall be made at customer’s risk, and in the event that third parties lay
claims to Nuvoton as a result of customer’s Insecure Usage, customer shall indemnify the
damages and liabilities thus incurred by Nuvoton.