V9821 Datasheet V0.1
V9821 Datasheet V0.1
V9821 Datasheet V0.1
Version: 0.1
Release Date: January 08, 2016
Revision History
Date Version Description
General Description
V9821 is a single-phase energy metering SoC chip, featuring very low-power consumption and high
performance. It integrates the analog front end, energy metering architecture, enhanced 8052 MCU core,
RTC (Real-time Clock), WDT (Watchdog Timer), Flash memory, RAM, and LCD driver. It can be used for the
single-phase multi-functional energy meter applications.
Features
Wide supply voltage range: 3.3 V to 5 V current/voltage RMS
calculation over dynamic range
Reference voltage: 1.185 V (Typical drift
of 1000:1
10 ppm/°C)
Various measurements:
Low power operation with power-saving
modes Raw waveform and DC
component of current and
Full operation: 5.5 mA
voltage signals
Sleep mode: 12 μA
Line frequency, temperature,
48-TQFP package and battery voltage
measurements
Operating temperature range:
-40 ~ +85°C CF pulse output and interrupt with
configurable pulse width
Energy metering features:
Programmable threshold for no-load
4 independent oversampling Σ/Δ
detection
ADCs:
Digital phase compensation
One voltage channel, two
current channels, and one MCU and peripherals:
multifunctional channel for
8052 MCU core, up to 26 MHz/6.5
various signal measurements
MIPS
High metering accuracy:
64-KB Flash, 4-KB RAM
Exceeds IEC 62053/ANSI
Crystal anti-failure supported
C12.20 Standards
Integrated Real-Time Clock (RTC)
Less than 0.1% error on active
and temperature sensor
energy metering over dynamic
range of 5000:1 Up to 3 UART serial interfaces, one
supporting IR communication
Less than 0.1% error on
reactive energy metering over 1 GPSI (General-Purpose Serial
dynamic range of 3000:1 Interface), I2C compliant
Table of Contents
Features ................................................................................................................................. 2
5. Reset ........................................................................................................................... 46
5.1. Level 3 ................................................................................................................. 48
5.2. Level 2 ................................................................................................................. 48
5.2.1. Power Supply Restoration ................................................................................ 48
5.2.2. IO Wakeup Input ............................................................................................ 48
5.2.3. RTC Wakeup .................................................................................................. 49
5.2.4. CF Pulse Wakeup Event ................................................................................... 49
5.3. Level 1 ................................................................................................................. 49
5.3.1. RSTn Pin Input (RSTn Pin Reset) ...................................................................... 50
5.3.2. Power-On Reset (POR) and Brown-Out Reset (BOR)............................................ 50
5.3.3. WDT Overflow ................................................................................................ 51
5.4. Registers .............................................................................................................. 51
6. Clock ........................................................................................................................... 55
6.1. RC Clock ............................................................................................................... 56
6.2. OSC Clock............................................................................................................. 56
9. Comparator ................................................................................................................. 80
Figure List
Figure 1-1 Timing Diagram ........................................................................................................................................ 23
Figure 6-2 Enabling PLL Circuit and Clock Source Switchover to PLL in Quick Operation ......... 61
Figure 6-3 Clock Source Switchover to OSC, Disabling PLL Circuit, Disabling CLK1 in Quick
Operation .................................................................................................................................................................... 61
Figure 7-1 Go to Sleeping State (Normal Method, Disable PLL Clock) ................................................ 72
Figure 7-2 Go to Sleeping State (Normal Method, PLL Clock Holds on) ............................................. 73
Figure 8-4 Relationship between VDCIN Input Signal and States of Flag Bits PWRUP and
PWRDN ......................................................................................................................................................................... 79
Figure 10-9 Signal Processing for Active Power Calculation and Calibration .................................. 96
Figure 10-10 Signal Processing for Reactive Power Calculation and Calibration .......................... 97
Figure 10-12 Signal Processing for Line Frequency Measurement ..................................................... 101
Figure 12-10 Timer2, 16-bit Timer/ Counter in Capture Mode ............................................................. 139
Figure 14-2 LCD Drive Waveform When LCD Panel of 1/4 Duty and 1/3 Bias Applied............. 163
Figure 14-3 LCD Drive Waveform When LCD Panel of 1/6 Duty and 1/3 Bias Applied............. 164
Figure 14-4 LCD Drive Waveform When LCD Panel of 1/8 Duty and 1/3 Bias Applied............. 165
Figure 14-5 LCD Drive Waveform When LCD Panel of 1/8 Duty and 1/4 Bias Applied............. 166
Table List
Table 1-1 Absolut Maximum Ratings .................................................................................................................... 18
Table 5-4 IO Wakeup Edge Control Register (IOEDG, SFR 0xC7) .......................................................... 52
Table 5-7 RTC Seconds Wake-up Interval Configuration Register (SECINT, SFR 0xDF) ............ 54
Table 6-2 Clock Switchover Control Register (SysCtrl, SFR 0x80) ........................................................ 62
Table 6-7 PLL Clock State Register (PLLLCK, SFR 0xA3) ............................................................................ 65
Table 6-8 Register 1 to Adjust Clock Frequency of Specific Functional Blocks ............................... 66
Table 6-9 Register 2 to Adjust Clock Frequency of Specific Functional Blocks ............................... 67
Table 10-3 Analog PGA Gain Configuration for Current and Voltage Analog Input ...................... 87
Table 10-6 fsmpl Determines Phase Compensation Resolution and Correction Range .................. 91
Table 10-13 Configurations for Energy Pulse Generation Rate and CF Pulse Output .................. 99
Table 11-9 Extended Interrupt Flag (Request) Register (ExInt2IFG, 0x2840) ............................ 113
Table 11-10 Extended Interrupt Input Type Register (ExInt2IN, 0x2841) .................................... 114
Table 11-11 Extended Interrupt Output Type Register (ExInt2OUT, 0x2842) ............................. 114
Table 11-12 Extended Interrupt Enable Register (ExInt2IE, 0x2843) ............................................. 114
Table 11-13 Extended Interrupt Pending Register (ExInt2OV, 0x2844) ......................................... 114
Table 11-15 Extended Interrupt Flag (Request) Register (ExInt3IFG, 0x2848) ......................... 115
Table 11-17 Extended Interrupt Output Type Register (ExInt3OUT, 0x284A) ............................. 115
Table 11-18 Extended Interrupt Enable Register (ExInt3IE, 0x284B) ............................................. 116
Table 11-19 Extended Interrupt Pending Register (ExInt3OV, 0x284C) ......................................... 116
Table 11-21 Extended Interrupt Flag (Request) Register (ExInt4IFG, 0x2850) ......................... 117
Table 11-22 Extended Interrupt Input Type Register (ExInt4IN, 0x2851) .................................... 117
Table 11-23 Extended Interrupt Output Type Register (ExInt4OUT, 0x2852) ............................. 117
Table 11-24 Extended Interrupt Enable Register (ExInt4IE, 0x2853) ............................................. 118
Table 11-25 Extended Interrupt Pending Register (ExInt4OV, 0x2854) ......................................... 118
Table 11-27 Extended Interrupt Flag (Request) Register (ExInt5IFG, 0x28A2) ......................... 119
Table 11-28 Extended Interrupt Input Type Register (ExInt5IN, 0x28A3) ................................... 119
Table 11-29 Extended Interrupt Output Type Register (ExInt5OUT, 0x28A4) ............................. 119
Table 11-30 Extended Interrupt Enable Register (ExInt5IE, 0x28A5) ............................................. 119
Table 11-31 Extended Interrupt Pending Register (ExInt5OV, 0x28A6) ......................................... 120
Table 12-6 Timer0/1 Mode Control Special Function Register (TMOD, SFR 0x89) ..................... 132
Table 12-7 Timer0/1 Control Special Function Register (TCON, SFR 0x88)................................... 133
Table 12-8 Timer2 Control Special Function Register (T2CON, SFR 0xC8) ..................................... 138
Table 12-10 UART1 Control Special Function Register (SCON1, SFR 0xC0) ................................... 141
Table 12-13 UARTx Timers Mode Control Register (TMOD2/TMOD4/TMOD5) ............................. 143
Table 13-4 GPSI Timer Divider Registers (SITHH/SITHL, 0x2F03/0x2F02) ................................. 156
Table 13-6 GPSI Communication Flag Register (SIFLG, 0x2F05) ........................................................ 156
Table 14-2 RAM Byte Allocation for Segments of LCD Panel of 1/4 Duty ........................................ 159
Table 14-3 RAM Byte Allocation for Segments of LCD Panel of 1/6Duty When 6COMTYPE=0
....................................................................................................................................................................................... 159
Table 14-4 RAM Byte Allocation for Segments of LCD Panel of 1/6 Duty When 6COMTYPE=1
....................................................................................................................................................................................... 160
Table 14-5 RAM Byte Allocation for Segments of LCD Panel of 1/8 Duty ........................................ 161
Table 15-9 P1.1 Special Function Register (P11FS, 0x28C5, R/W) .................................................... 174
Table 15-10 P1.2 Special Function Register (P12FS, 0x28C6, R/W) ................................................. 174
Table 15-12 P1.4 Special Function Register (P14FS, 0x28C8) .............................................................. 175
Table 15-17 P2.0 Special Function Register (P20FS, 0x28C9, R/W) ................................................. 176
Table 15-18 P2.1 Special Function Register (P21FS, 0x28CA, R/W) ................................................. 177
Table 15-19 P2.4 Special Function Register (P24FS, 0x28CD, R/W) ................................................. 177
Table 15-20 P2.5 Special Function Register (P25FS, 0x28CE, R/W) ................................................. 177
Table 15-45 P9 Output Enable Register (P9OE, SFR 0xA4) .................................................................... 187
Table 15-46 P9 Input Enable Register (P9IE, SFR 0xA5) ........................................................................ 187
Table 15-47 P9 Output Data Register (P9OD, SFR 0xA6) ........................................................................ 187
Table 15-48 P9 Input Data Register (P9ID, SFR 0xA7) ............................................................................ 188
Table 15-49 P9 Special Function Register (P9FS, SFR 0xAD) ................................................................ 188
Table 17-1 RTC Password Enable Register (RTCPEN, SFR 0x90) ......................................................... 195
Table 17-2 RTC Password Register (RTCPWD, SFR 0x97) ....................................................................... 195
Table 17-3 RTC Wakeup Interval Register (INTRTC, SFR 0x96) .......................................................... 195
Table 17-4 RTC Seconds Wake-up Interval Configuration Register (SECINT, SFR 0xDF) ....... 196
Table 17-6 RTC Calibration Registers (RTCCH/RTCCL, SFR 0x94/0x95) ......................................... 196
Table 17-7 RTC Data Reading Enable Register (RDRTC, SFR 0xDA) ................................................... 197
Table 17-9 PLL Counter State Register (PLLCNT, SFR 0xDE) ................................................................. 197
Table 18-3 Battery Discharge Control Register (CtrlBAT, 0x285C) .................................................... 200
Table 18-4 LCD Driver Voltage Control Register (CtrlLCDV, 0x285E) ................................................ 201
Table 18-13 Analog Circuits State Register (ANState, 0x286B) ........................................................... 205
Table 18-17 Phase Compensation Control Register 1 (PHCCtrl1, 0x287B) ..................................... 208
Table 18-18 Phase Compensation Control Register 2 (PHCCtrl2, 0x287C) ..................................... 208
Table 18-20 CF Pulse Output Control Register (CFCtrl, 0x287E) ......................................................... 210
Table 18-21 No-Load Detection Indication Register (CRPST, 0x287F) ............................................. 211
Table 18-22 Current Detection Control Register (IDET, 0x2886) ........................................................ 211
Table 18-25 Energy Accumulators and Energy Pulse Counters (R/W) ............................................. 214
Table 18-29 Registers for Power Offset Calibration (R/W) .................................................................... 216
Table 18-30 Band-pass Filter Coefficient Register (0x10EF, R/W) ..................................................... 217
Table 18-31 Energy Threshold Registers and Constant Power Register (R/W) ........................... 217
Table 18-32 Threshold Register for Current Detection (R/W) .............................................................. 218
1.Electrical Characteristics
CF Pulse Output
LDO3.3 Output
VVDD5 ≥ 4.0 V
Voltage 2.8 3.3 3.5 V IL33 = 16 mA
Programmable
Analog Inputs
ADC Performance
DC Offset 15 mV
Analog Comparator, CB
VDD5
Input Voltage 0 V
-0.8
Output High Voltage, VOH 2.4 V The 12-mA current will not cause any
ISOURCE 10 12 mA damage to the chip in a short period of
time. But, the current of more than
Output Low Voltage, VOL 0.4 V 10 mA for a long duration may cause the
Flash Memory
RAM
DVCC output
Data Retention Voltage 1.62 V
voltage
tHD;STA START condition hold time (Then, the first SCL pulse is generated.) 1.875 μs
tBUF Bus free time between STOP condition and START condition N/A
SDA
SCL
tHD;STA tHD;DAT tHIGH tSU:STA tSU;STO
S Sr P S
2.Pin Descriptions
P5.1/SEG9/COM7
P5.0/SEG8/COM6
P4.1/SEG1/COM5
P7.2/SEG26
P7.1/SEG25
P7.0/SEG24
P6.3/SEG19
P6.2/SEG18
P6.1/SEG17
P6.0/SEG16
LDO33
DVCC
36
35
34
33
32
31
30
29
28
27
26
25
P7.3/SEG27 37 24 P4.0/SEG0/COM4
P7.4/SEG28 38 23 P3.3/COM3
P7.5/SEG29 39 22 P3.2/COM2
P8.2/SEG34 40 21 P3.1/COM1
41 20 P3.0/COM0
P9.0/TA0/SEG35
M2/SEG39 42 19 P9.6/CF
P2.5/TXD2 43 18 P1.3/RXD5/INT0/CFx/SPX/WAKEUP2
P2.4/RXD2 17 P1.4/TXD5/INT1/SPI/WAKEUP1
V9821
44
P2.1/TXD4/T0 45 16 P0.3/WAKEUP4/TCK
P2.0/RXD4/T2/OSC 46 15 P0.2/WAKEUP3/TMS
RSTn 47 14 P0.1/TDI
CTI 48 13 P0.0/TDO
10
11
12
1
9
VDD5
UN
CTO
VDCIN
IAP
IAN
IBN
IBP
MODE1
UP
REF
AVSS
When the input voltage on this pin is higher than 1.1 V, the chip will be
2 VDCIN I powered by 5.0-V main power. When the input voltage on this pin is
lower than 1.0 V, the chip will be powered by batteries. Or the power
supply will be switched from 5.0-V main power to batteries.
P0.3 When the bit “IOP0” (bit1 of IOWK, SFR 0xC9) is set to ‘1’, this pin will
be used for the IO wakeup input, active on either transition
16 WAKEUP4 I/O
(Configurable).
TCK
When “logic 0” is input to the pin “MODE1”, this pin will be used as a
JTAG port for the test clock input (TCK).
Besides, this pin can be used to wake up the system from the sleeping
state, active on either transition (Configurable).
Besides, this pin can be used to wake up the system from the sleeping
state, active on either transition (Configurable).
The functions of this pin can be configured by the register “P9FS (SFR
P9.6 0xAD)”:
19 I/O
CF - General-Purpose Input/Output (GPIO) port (Fast IO)
P3.0
20
COM0 These pins are used as General-Purpose Input/Output (GPIO) ports by
I/O
P3.1 default. And they also can be used as backplanes of the LCD driver.
21
COM1
P3.2
22
COM2
P3.3
23
COM3
P4.0
24 SEG0
This pin is used as General-Purpose Input/Output (GPIO) port by
COM4 default, as SEG output for the LCD driver when bits “LCDTYPE”
I/O
P4.1 (bit[5:4] of LCDCtrl, 0x2C1E) are cleared, or as backplanes of the LCD
driver when bits “LCDTYPE” are set to ‘1’, ‘2’, or ‘3’.
25 SEG1
COM5
P5.0
26 SEG8
This pin is used as General-Purpose Input/Output (GPIO) port by
COM6 default, as SEG output for the LCD driver when bits “LCDTYPE”
I/O
P5.1 (bit[5:4] of LCDCtrl, 0x2C1E) are cleared or set to ‘1’; or as
backplanes of the LCD driver when bits “LCDTYPE” are set to ‘2’ or ‘3’.
27 SEG9
COM7
P6.0
30 These pins are used as General-Purpose Input/Output (GPIO) ports by
SEG16 I/O default; or SEG output for the LCD driver when the corresponding bits
in SEG control registers are set to 1 s.
31 P6.1
SEG17
P6.2
32
SEG18
P6.3
33
SEG19
P7.0
34
SEG24
P7.1
35
SEG25
P7.2
36
SEG26
P7.3
37
SEG27
P7.5
39
SEG29
P8.2
40
SEG34
The functions of this pin can be configured by the register “P9FS (SFR
0xAD)”:
P9.0
- General-Purpose Input/Output (GPIO) port (Fast IO)
41 TA0 I/O
- TimerA port 0, to input/output the signals for TimerA
SEG35 Compare/Capture Module 0
Besides, this pin can be used for SEG output for the LCD driver.
These pins are used for SEG output for the LCD driver, for analog input
for various measurements in Channel M, or for analog input to the
SEG39 analog comparator CB for comparison. The input voltage signal into
42 I/O this pin to be measured must be in the range of -200 mV ~ 3.4 V.
M2
When these pins are used for analog input to Channel M or the analog
comparator CB, the SEG output on these pins must be disabled.
The functions of this pin can be configured by the p2.1 register “P21FS
P2.1 (0x28CA)”:
COMx
SEGx
CFx
V9811A
CTI CLK_RC
OSC PLL CLK_OSC phase
CTO compensation CLK_OSC
CLK_MCU 4COM× 24SEG
RMS 6COM× 22SEG
OSC CLK_MEA
monitor
RC calculation 8COM× 20SEG
M1 ADC
- JTAG P0
Vango Metering
M2 enhanced
Architecture
_int
-
_ref
_int
RSTN
DVCC
VDD5
LDO33
VDCIN
* “1.2V REF_LP” is the low-power-consumption reference voltage module inside the chip and cannot be disabled. SP
This module provides the reference voltage to 3.3V LDO and digital power circuit. It can be configured as the inverted
signal input of analog comparator, CB.
COMx
SEGx
CFx
V9821
CTI CLK_RC
OSC PLL CLK_OSC phase
CTO compensation CLK_OSC
CLK_MCU 4COM× 17SEG
RMS 6COM× 15SEG
OSC CLK_MEA
monitor
RC calculation 8COM× 13SEG
M1 ADC
- JTAG P0
Vango Metering
M2 enhanced
Architecture
_int
8052 MCU core
(VMA) Px
GPIO/Fast IO
temp.
_int
1.185V
+ REF 8-bit data bus
CB _int
_ref
-
_ref
_int
RSTN
DVCC
VDD5
LDO33
VDCIN
SP
* “1.2V REF_LP” is the low-power-consumption reference voltage module inside the chip and cannot be disabled. This module provides
the reference voltage to 3.3V LDO and digital power circuit. It can be configured as the inverted signal input of analog comparator, CB.
- Internal SRAM (IRAM) with 256 bytes in size, sharing the upper 128 bytes of its addresses with
Special Function Registers (SFRs)
- Internal extended RAM (XRAM) with 4 KB in size and the memory of peripherals sharing the data
memory area at addresses 0000h ~ FFFFh
- On-chip Flash memory with 64 KB in size mapping the program memory area at addresses 0000h ~
FFFFh
The lower 128-byte internal RAM contains three distinct blocks: Register Bank 0 ~ 3 (00h ~ 1Fh), Bit
Address Area (20h ~ 2Fh) and General RAM Area (30h ~ 7Fh). All the lower 128-byte internal RAM can be
accessed by direct or indirect addressing.
- Register Bank 0 ~ 3, 32 bytes from 00h to 1Fh, each is composed of 8 registers, R0 ~ R7. Users can
configure bit4 (RS1) and bit3 (RS0) of the register “PSW” (SFR 0xD0, Program Status Word SFR) to
select the register bank to be used. By default Register Bank 0 is used.
Program Status Word 00: Register Bank 0, located at addresses 00h ~ 07h
bit[4:3]
PSW 0 01: Register Bank 1, located at addresses 08h ~ 0Fh
RS1/RS0
SFR 0xD0 10: Register Bank 2, located at addresses 10h ~ 17h
- Bit Address Area (20h ~ 2Fh), each with bit addresses from 00h to 7Fh, is bit addressable.
7Fh
Accessible by indirect
General RAM addressing ONLY
30h
Upper 128 bytes SFR
2Fh
Register Bank
Selection via Bit Address Area
Bit 4 and bit3 80h 80h
of PSW SFR Bit Addressable
7Fh
Addr. Register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
80h SysCtrl MEAFRQ FWC FSC PMG LCDG SLEEP1 SLEEP0 MCUFRQ
81h SP - - - - - - - -
82h DPL0 - - - - - - - -
83h DPH0 - - - - - - - -
84h DPL1 - - - - - - - -
85h DPH1 - - - - - - - -
88h TCON TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
8Ah TL0 - - - - - - - -
8Bh TL1 - - - - - - - -
8Ch TH0 - - - - - - - -
8Dh TH1 - - - - - - - -
90h RTCPEN - - - - - - - -
92h Reserved - - - - - - - -
95h RTCCL C7 C6 C5 C4 C3 C2 C1 C0
97h RTCPWD - - - - - - WE
98h Reserved - - - - - - - -
99h Reserved - - - - - - - -
9Eh RTCWC - - - - W8 W4 W2 W1
A0h CBANK - - - - - - B1 B0
A2h Reserved - - - - - - - -
A6h P9OD - - - - - - - -
A7h P9ID - - - - - - - -
A9h Reserved - - - - - - - -
AAh Reserved - - - - - - - -
ABh Reserved - - - - - - - -
ACh Reserved - - - - - - - -
AEh Reserved - - - - - - - -
C0h SCON1 SM0_1 SM1_1 SM2_1 REN_1 TB8_1 RB8_1 TI_1 RI_1
C1h SBUF1 - - - - - - - -
C7h IOEDG P03EDG<1> P03EDG<0> P02EDG<1> P02EDG<0> P14EDG<1> P14EDG<0> P13EDG<1> P13EDG<0>
CAh RCAP2L - - - - - - - -
CBh RCAP2H - - - - - - - -
CCh TL2 - - - - - - - -
CDh TH2 - - - - - - - -
CEh WDTEN - - - - - - - -
CFh WDTCLR - - - - - - - -
D9h Reserved - - - - - - - -
DAh RDRTC - - - - - - - -
DBh DIVTHH DIV23 DIV22 DIV21 DIV20 DIV19 DIV18 DIV17 DIV16
DCh DIVTHM DIV15 DIV14 DIV13 DIV12 DIV11 DIV10 DIV9 DIV8
DDh DIVTHL DIV7 DIV6 DIV5 DIV4 DIV3 DIV2 DIV1 DIV0
E0h ACC - - - - - - - -
F0h B - - - - - - - -
XRAM is located at addresses 0000h ~ 0FFFh that can be accessed without limit. The content of XRAM
cannot be reset by any reset event, and it will hold the data until the output voltage of DVCC is lower than
1.62 V.
Data storage space, except for the contents of XRAM, all of the peripherals registers can be reset,
among them, the LCD, GPIO, Analog control and power metering related registers can only be reset to the
default value of the level 1, other registers will be reset to the default value of the grade 1/2/3. The
contents of the Info area will not be reset; however, after a level 1 reset event, the data needs to be within
the scope of the stable time of 2 ms, that is, after MCU start normal execution program in a Flash.
28FFh
…...
FFFFh
2F05h 28DCh
GPSI
... 2F01h
… GPIO (P0~P8)/
Peripheral control 2D01h
registers IR communication
2D00h
3400h …
33FFh 2C23h
LCD
Info(Read only) 2C00h …... 28A8h
28A6h
3000h Extended interrupts
2FFFh 28A2h
... …...
XRAMPWD 28A0h
2F05h … 289Fh
IR communication/ PWM
2898h
2800h
…...
287Eh
2900h Energy control metering registers
28FFh 2878h
… …...
2800h 2868h
2000h
1FFFh Analog control registers
…... 2858h
2854h
… Extended interrupts
2840h
Extended UART
10FFh
Metering data registers
1000h 2820h
0FFFh
XRAM,Accessible, no …...
limitation
0000h 2800h
Number
Starting Address Functional Description Endianness
of Byte
0x420 a 4 Little-endian
0x 424 b 4 Little-endian
0x 428 c 4 Little-endian
0x 42C d 4 Little-endian
0x 430 e 4 Little-endian
0x 438 a 4 Little-endian
0x 43C b 4 Little-endian
0x 440 c 4 Little-endian
0x 444 d 4 Little-endian
0x 448 e 4 Little-endian
0x 450 a 4 Little-endian
0x 454 b 4 Little-endian
0x 458 c 4 Little-endian
0x 45C d 4 Little-endian
0x 460 e 4 Little-endian
Backup 1 of temperature
0x 480 2 Big-endian
deviation
*Users can read of these bytes and obtain the recommended configuration of the analog control registers,
and then write them to the analog control registers.
***When users are using the crystals provided by Vango, they can read these addresses to obtain the
details of crystal frequency deviation Δ, parabolic coefficient B para, and turnover temperature of the crystal,
to calibrate RTC. See the corresponding application notes for details.
The third page of the Flash memory, at addresses 0400h ~ 05FFh, is pre-burned with the codes by the
manufacturer. Therefore, this area cannot be used for the user codes.
bit7 - - Set this bit to ‘1’ to activate the write operation of other bits
When the MCU clock frequency (fMCU) is 3.2768 MHz, clear this bit to
enable programming, page erase, and mass erase of Flash memory.
bit6 CKSL 0
When fMCU is 13.1072 MHz, set this bit to ‘1’ to enable the programming,
page erase, and mass erase of the Flash memory.
bit[5:0] Reserved 0 These bits must hold their default values for the proper operation.
01FFFFH
Bank3
018000H
017FFFH
Bank2
Bank3
010000H Bank2
00FFFFH FFFFH
Bank1 Bank1
008000H 10000H
007FFFH FFFFH
The 8052 MCU core of V9821 can address up to 64-KB program memory area, 0000h ~ FFFFh, but the
Flash memory can store up to 64-KB codes. In order to execute the program with more than 64-KB in size,
the code banking technique is used. By using this technique, the program can be divided into no more
than four parts with no more than 64-KB codes each, and is allocated at different parts of the Flash
memory:
- Common Area, at addresses 0000h ~ 7FFFh: To allocate the common codes, such as interrupt
vectors, reset vectors, bank switching routines, interrupt service routines, and so on. It is always
mapped to the program memory area at addresses 0000h ~ 7FFFh.
- Code Area, at addresses 8000h~1FFFFh: To allocate the application codes; Bank 1, at addresses
8000h ~ FFFFh; Bank2, at addresses 10000h ~ 17FFFh; Bank 3, at addresses 18000h ~ 1FFFFh.
Each bank can be mapped to the program memory area at addresses 8000h ~ FFFFh, and the
processor can access the register “CBANK” (SFR 0xA0) to switch the banks and execute the
codes.
bit[7:2] Reserved 0
10: Bank 2
11: Bank 3
In V9821, the on-chip Flash memory is divided into 256 pages with 512 bytes each. The codes in the
Flash memory can be read, erased, or programmed in pages or mass erased.
When the low logic level is input on the pin “MODE1”, the chip will be in the debugging mode. In this
mode, the 4 pins of Group P0 work as JTAG interfaces. Users can use the DLL codes and simulators
provided by Vango to download and debug the applications in Keil μVision IDE or IAR IDE via the JTAG
interfaces.
Notes:
In the debugging mode, the system cannot get to LPM1 state or LPM2 state, and the reset events,
POR/BOR and WDT overflow, are masked. In the sleeping state, a power supply restoration event will
occur immediately when the system goes to the debugging mode.
In the debugging mode, the TCK speed limit is 400 Kbps by default. The command “0x22” can increase it
to the current PLL clock frequency, and the command “0x23” can recover it.
No capacitors should be connected to the JTAG interfaces to avoid the download failure of codes.
There is an encryption bit (bit0 of byte located at address 0x0400) in the Flash memory. The
configuration of this bit has effects on the access to the Flash memory. When the logic high level is input
on the pin “MODE1”, the chip will be in the metering mode. In this mode, the on-chip Flash memory is
IAP-supportive, and the access to the Flash memory will not be affected by the encryption bit
configuration. When the logic high level is input on the pin “MODE1”, the chip will be in the metering mode.
In this mode, the on-chip Flash memory is IAP- supportive and ISP-supportive, and the encryption bit
configuration will affect the access to the Flash memory.
00000h ~ 17FFFh X X X
In debugging
√ √ √ √ √
mode
18000h ~ 1FFFFh X √ X
00000h ~ 003FFh X √ X X √ X
IAP in normal
X X
mode
00400h ~ 1FFFFh √ √ √ √ √ √
Note:
After ISP, input logic low to the pin “RSTn” or power on the chip again to activate the ISP read encryption.
5.Reset
In V9821, all circuits, except for the RTC calibration registers, RTC timing registers, IRAM, XRAM, and
Info area, can be reset to their default states by an event of a specific reset level. Three levels of events
are designed to reset different circuits of the system, including:
Level 3: The lowest level, debugging reset instruction. When the event of this level occurs, MCU,
interrupt management circuits, timers, UART interfaces, and GPSI interfaces will be reset to their
default states;
Level 2: The middle level, including power supply restoration (Power up), IO wakeup input, RTC
wakeup event, and CF pulse wakeup event. When an event of this level occurs, Clock Switchover
Control Register (SysCtrl, SFR 0x80), IO Wakeup Control Register (IOWK, SFR 0xC9), IO Wakeup
Edge Control Register (IOEDG, SFR 0xC7), Flash control registers, watch-dog timer, and all the
circuits that can be reset by events of Level 3 will be reset to their default states.
Level 1: The highest level, including the “RSTn” pin input signal (RSTn pin reset), Power-On Reset
(POR), Brown-Out Reset (BOR), and WDT overflow event. When an event of this level occurs, the LCD
driver, General-Purpose I/O (GPIO) ports, System State Register (Systate, SFR 0xA1), P0 IO Wakeup
Flag Register (IOWKDET, SFR 0xAF), analog control registers, the global energy metering architecture,
and all the circuits that can be reset by events of Level 2 will be reset to their default states.
In V9821, the reset management circuits are designed by following the rule: A reset event of higher
level can reset the circuits that can be reset by the lower level reset events, but not vice versa.
Level 1: Level 2:
All circuits except SFR 0x80/0xC7/
registers for RTC 0xC9, Flash control
calibration and registers, WDT, and
timing, and data circuits that can be
of IRAM and reset by events of
XRAM. Level 3.
RSTN
POR/BOR
WDT overflow
POR Level 3: CPU,
MODE1 Interrupts,
Timers, UART
and GPSI.
VDCIN
Power recovery (power up)
CF pulse output
generate
signal?
CFWKEN
reset
Flag bits:
To
To select active
edge for IO
WAKEUP4
Pins
IOP0
P02WK P03WK IOP14 IO
Debugging
Instruction
Reset by
Unit
Events of Level 1 Events of Level 2 Events of Level 3
MCU √ √ √
Interrupts √ √ √
Timers √ √ √
UART √ √ √
GPSI √ √ √
WDT √ √ X
LCD Driver √ X X
Calibration Registers X X X
Other Registers √ X X
IRAM X X X
XRAM X X X
5.1. Level 3
In V9821, only the debugging reset instruction is designed as the reset event of Level 3. It can reset
MCU, interrupt management circuits, timers, UART interfaces and GPSI interfaces.
When logic ‘0’ is input to the pin “MODE1”, the system will enter the debugging mode. In this mode,
when the debugging operation is enabled or the tab “Reset” in IDE is clicked, a debugging reset instruction
will be executed to reset MCU and its peripherals.
5.2. Level 2
In V9821, power supply restoration, IO wake-up input, RTC wake-up event, and CF pulse wakeup event
are designed as the reset events of Level 2.
By default any event of this level can wake up the system from LPM1 state or LPM2 state and reset the
system to the OSC state. But if the bit “IORSTN” (bit0 of IOWK, SFR 0xC9) is set to ‘1’, any event of this
level can wake up the system without reset. That is, the event can wake up the system from the sleeping
state but not reset the system to the OSC state. In this case, after the wakeup, MCU keeps on executing
programs; all circuits go back where the system enters the sleeping state, but bit[2:1] (SLEEP1 and
SLEEP0) and bit[6:5] (FWC and FSC) are cleared. When “IORSTN” (bit0 IOWK, SFR 0 xc9) is cleared, the
dormancy awakening events can be reset by level 3 reset circuit, reset events can reset the clock switch
control register (SysCtrl, SFR 0 x80), IO sleep wake up edge selection register (IOEDG, SFR 0 xc7), IO
dormancy awakening control register (IOWK, SFR 0 xc9), FLASH control registers, and WDT. Please refer
to Table 5-1 for the detailed information.
In V9821, when the voltage on the pin “VDCIN” rises from lower than 1.0 V to higher than 1.1 V, or when
the voltage on the pin “VDCIN” is higher than 1.1 V after any reset event of Level 1, a power supply
restoration event will occur. By default this event wakes up the chip and reset it to the OSC state, and the
reset signal holds 8 OSC clock cycles.
In V9821, 4 pins, “WAKEUP1 (P1.4), WAKEUP2 (P1.3), WAKEUP3 (P0.2), and WAKEUP4 (P0.3)”, can be
If the 4 I/O ports are set to “Input enabled” before the chip enters the LPM1 state or LPM2 state, a
transition (Either high-to-low or low-to-high, with more than 4 OSC clock cycles on both levels) on the pin
in the LPM1 state or LPM2 state can wake up the system. Users can configure the register “IOEDG” (SFR
0xC7) to determine the active edge for the IO wakeup event. Any IO wakeup event can set the bit “IO”
(bit3 of Systate, SFR 0xA1) to ‘1’. When the bit “IO” is set to ‘1’, users can read bits “IOP14, P02WK, and
P03WK” (bit[0:2] of IOWKDET, SFR 0xAF) to detect the transition on which pin wakes up the system.
By default a transition on any one of the 4 I/O ports can wake up the system and reset it to the OSC
state. To lower the power consumption, users can set the bit “IORSTN” (bit0 of IOWK, SFR 0xC9) to ‘1’ to
wake up the system without reset.
In V9821, the RTC can wake up the system from the LPM1 state at an interval set at registers “INTRTC
(SFR 0x96) and SECINT (SFR 0xDF)”. When the system is woken up by an RTC event, the bit “RTC/CF”
(bit2 of Systate, SFR 0xA1) will be set to ‘1’, but the bit “CFWK” (bit3 of IOWKDET, SFR 0xAF) will be
cleared. Please refer to Figure 5-1 for the detailed information.
By default the RTC wakeup event can wake up the system from the LPM1 state and reset it to the OSC
state. The reset signal holds 8 OSC clock cycles. To lower the power consumption, users can set the bit
“IORSTN” (bit0 of IOWK, SFR 0xC9) to ‘1’ to wake up the system without reset.
In V9821, the system may be woken up from the LPM1 state by the CF pulse output if the CF pulse
output is enabled (CFENR = 1 or CFEN = 1, bit[5:4] of PMCtrl4, 0x287D), and the CF pulse output is
enabled to be a wakeup event (CFWKEN = 1, bit2 of IOWK, SFR 0xC9) before the system enters the LPM1
state. When a CF pulse wakeup event occurs, both bits “RTC/CF” (bit2 of Systate, SFR 0xA1) and “CFWK”
(bit3 of IOWKDET, SFR 0xAF) are set to 1s.
By default the CF pulse wakeup event can wake up the system from the LPM1 state and reset it to the
OSC state. To lower the power consumption, users can set the bit “IORSTN” (bit0 of IOWK, SFR 0xC9) to
‘1’ to wake up the system without reset.
5.3. Level 1
In V9821, WDT overflow, RSTn pin input signal, power-on (POR), and brown out (BOR) are designed as
the reset events of Level 1. When any one of these reset events occurs, the bit “POR” (bit5 of Systate, SFR
0xA1) will be set to ‘1’.
Holding logic low on the pin “RSTn” for more than 5 ms can trigger an RSTn pin reset signal to reset the
system. After the logic is pulled high, the reset signal holds 4 more OSC clock cycles (About 122 μs) and
then is released.
To prevent from the static disturbance, the input signal on the pin “RSTn” will be filtered based on the
RC clock.
RSTn input
Internal reset
signal
5ms 122μs
In V9821, the output voltage of the digital power supply (Via pin “DVCC”) is monitored by the
power-on/brown-out reset circuit.
On power-up, a power-on reset signal will be generated to reset the system when the output voltage of
pin DVCC is lower than 1.4 V. The system will stay in the reset state for 4 more OSC clock cycles (About
122 μs) even when the voltage on the pin “DVCC” is higher than 1.4 V.
On power-down, when the output voltage on the pin “DVCC” is lower than 1.4 V, the brown-out reset
circuit will generate a reset signal to reset the system.
When logic “0” is input to the pin “MODE1”, this reset event will be masked.
1.4 V 1.4 V
DVCC
In V9821, when the WDT overflows, a reset signal is generated and resets the system. The system will
exit from the reset state in 8 RC clock cycles (About 250 μs).
When logic ‘0’ is input to the pin “MODE1”, this reset event will be masked.
5.4. Registers
Table 5-2 System State Register, Systate (SFR 0xA1)
bit[7:6] Reserved
bit5 When this bit is read out as ‘1’, it indicates the system is reset by an event of Level 1:
0 POR/BOR, RSTn pin reset, or WDT overflow event. This bit will be cleared when a
POR reset event of other levels occurs.
bit4 0 Reserved
bit3 When this bit is read out as ‘1’, it indicates the system is woken up from the LPM1
0
IO state or LPM2 state by an IO wakeup event.
When this bit is read out as ‘1’, but the bit “CFWK” (bit3 of IOWKDET, SFR 0xAF) is
cleared, it indicates the system is woken up from the LPM1 state by the RTC wakeup
bit2
0 event.
RTC/CF
If both this bit and bit “CFWK” are set to 1s, it indicates the system is woken up from
the LPM1 state by the CF pulse wakeup event.
When the input voltage on the pin “VDCIN” is lower than 1.0 V, this bit is read out as
‘1’, indicating that the system is powered down. If the power down interrupt is
bit1
0 enabled, an interrupt will be triggered when this bit is read out as ‘1’.
PWRDN
When the input voltage on the pin “VDCIN” is higher than 1.1 V, this bit holds its
default value, indicating there is no power-down event occurring.
When the input voltage on the pin “VDCIN” is higher than 1.1 V, this bit is read out as
bit0 ‘1’, indicating that the system is powered up by the AC power supply.
0
PWRUP When the input voltage on pin VDCIN is lower than 1.0 V, this bit holds its default
value, indicating the system is powered up by batteries.
bit[7:2] Reserved - -
If this bit is set to ‘1’ when the bit “RTC/CF” (bit2 of Systate, SFR
bit3 CFWK R 0 0xA1) is read out as ‘1’, it indicates the system is woken up from
the LPM1 state by the CF pulse wakeup event.
If this bit is set to ‘1’ when the bit “IO” (bit3 of Systate, SFR 0xA1)
is read out as ‘1’, it indicates the system is woken up from the
bit2 P03WK R 0
LPM1 state or LPM2 state by a transition on the pin “WAKEUP4”
(P0.3).
If this bit is set to ‘1’ when the bit “IO” (bit3 of Systate, SFR 0xA1)
is read out as ‘1’, it indicates the system is woken up from the
bit1 P02WK R 0
LPM1 state or LPM2 state by a transition on the pin “WAKEUP3”
(P0.2).
If this bit is set to ‘1’ when the bit “IO” (bit3 of Systate, SFR 0xA1)
is read out as ‘1’, it indicates the system is woken up from the
bit0 IOP14 R 0
LPM1 state or LPM2 state by a transition on the pin “WAKEUP1”
(P1.4).
When an event of reset Level 1 occurs, this register is reset to its default state.
bit[7:3] Reserved - -
1: IO event wakes up but not reset the system. After the wakeup,
MCU keeps on executing programs; all circuits go back where the
system enters the sleeping state, but bit[2:1] (SLEEP1 and
bit0 IORSTN R/W 0 SLEEP0) and bit[6:5] (FWC and FSC) are cleared.
0: IO event wakes up and reset the system. After the wakeup, the
system goes to OSC state.
000: 1 second
001: 1 minute
011: 1 day
100: 500 ms
101: 250 ms
110: 125 ms
111: 62.5 ms
Table 5-7 RTC Seconds Wake-up Interval Configuration Register (SECINT, SFR 0xDF)
SFR 0xDF, R/W, RTC Seconds Wake-up Interval Configuration Register, SECINT
It is mandatory to set the register “INTRTC” (SFR 0x96) to 0x07, and then set
bit6 R/W 0
this bit to ‘1’ to enable writing of bit[5:0] of this register.
To set interval in unit of second for RTC to wake up the system from LPM1
state. The actual wakeup interval is equal to (bit[5:0]+1) seconds, of which
bit[5:0] R/W 0 bit[5:0] can be set to 1 ~ 63 (Decimal).
Setting these bits to ‘0’ (Decimal) forces the interval to be 62.5 ms.
6.Clock
In V9821, there are three clock generation circuits:
- The RC oscillator circuit is used to generate an RC clock (RCCLK). This circuit will stop running only
when the chip is powered off.
- The crystal oscillator circuit is used to generate an OSC clock (OSCCLK). Generally, this circuit will
stop running only when the chip is powered off, but it also will stop running in some special
circumstances. This circuit is monitored by the OSC monitoring circuit sourced by RC clock. When this
oscillator circuit stops running, RC clock will replace OSC clock to source all circuits that are sourced
by the OSC clock, and the monitoring circuit will stimulate the crystal oscillator circuit until it runs
again.
- The phase-locked loop (PLL) circuit is used to generate a PLL clock (PLLCLK). The PLL locks onto a
multiple of the OSCCLK frequencies to provide a stable clock: PLLCLK. This circuit can be disabled.
The above three clocks can work as the clock sources for the functional units:
- Clock 1 (CLK1) provides clock pulses for MCU (Including MCU, RAM, Flash memory, interrupt circuits,
timers/UART serial interfaces, GPSI and IO ports). The OSC clock and PLL clock can be the optional
source for CLK1. This clock is enabled by default, and it can be disabled.
- Clock 2 (CLK2) provides clock pulses for the energy metering architecture. The OSC clock and PLL
clock can be the optional source for CLK2. This clock is enabled by default, but it can be disabled.
- Clock 3 (CLK3) provides clock pulses for the LCD driver. The OSC clock is the source of this clock, and
this clock is enabled by default, but it can be disabled only when PLL clock is selected as the source for
CLK1 and CLK2.
- Clock 4 (CLK4) provides clock pulses for WDT. The RC clock is the source of this clock. This clock is
disabled and enabled together with CLK1.
- Clock 5 (CLK5) provides clock pulses for RTC. The OSC clock is the source of this clock. This clock
cannot be disabled.
ADCLKSEL<1:0>
MCUCLKSEL<1:0>
MEACLKSEL<1:0>
PLLPDN MCUFRQ MEAFRQ
x1 819.2KHz
x2 1.6384MHz
x4 3.2768MHz
x8 6.5536MHz ON
CLK1: MCUCLK, clock
PLL MCUCLK
MCU_PLL source for MCU and its
1
OFF SLEEP1 – SFR 0x80.2 peripherals (including CPU,
SLEEP0 – SFR 0x80.1 RAM, Flash, interrupt
circuits, timers, UART,
0 GPSI and GPIO ports)
OSC x1 204.8KHz X4 x1 819.2KHz
x2 409.6KHz X8 x2 1.6384MHz
x4 819.2KHz x4 3.2768MHz
1 ON
Monitoring/
Stimulating MTCLK
Circuit
MT_PLL 1 CLK2: clock source for the
0 OFF PMG – SFR 0.80.4 energy metering
architecture (MTCLK).
RC 0
FWC,SFR 0x80.6
FSC,SFR 0x80.5
6.1. RC Clock
In V9821, there is an embedded RC oscillator circuit. It can generate an independent 32-kHz RC clock.
It is the clock source for Clock 4 (CLK4) that provides clock pulses for WDT. The RC oscillator circuit will not
stop running until the chip is powered off, but CLK4 can be enabled or disabled together with CLK1.
There is a circuit monitoring the crystal oscillation and stimulating the oscillator to run again when it
stops working. This circuit is sourced by the RC clock. When the crystal oscillator circuit stops running, the
RC clock will immediately replace it to be the clock source for all circuits that are sourced by OSC clock.
Users can read bit “OSC” (bit7 of ANState, 0x286B) to detect whether the crystal stops running and has
been replaced by RC clock to source all circuits.
Generally, this circuit will not stop running until the chip is powered off, but some factors may cause the
oscillator circuit to stop running. There is a circuit monitoring the crystal oscillation and stimulating it to
run again when it stops working. This circuit is sourced by the RC clock. When the crystal oscillator circuit
stops running, the RC clock will immediately replace it to be the clock source for all circuits that are
sourced by OSC clock. Users can read bit “OSC” (bit7 of ANState, 0x286B) to detect whether the crystal
stops running and has been replaced by RC clock to source all circuits.
Start MCU and then enable the PLL circuit. When the PLL circuit is disabled, it will output the 32768-Hz
OSC clock.
Users can enable the PLL circuit, and select the PLL clock as the source for CLK1 and CLK2. Please
follow the steps:
1. Access to the register “CtrlCLK” (0x2867) to enable the PLL circuit, and configure the frequency of
MCUCLK and MTCLK
2. Wait for the configuration till the PLL is locked. MCU can access to the register “PLLLCK” (SFR 0xA3)
and read the bit “PLLLCK” to detect the state of the PLL circuit.
3. When the PLL circuit is locked, set the bit “MCUFRQ” or “MEAFRQ” (bit0 or bit7 of SysCtrl, SFR 0x80)
to ‘1’ to select the PLL clock as the source for CLK1 or CLK2. This duration only spends one PLL clock
cycle.
Users must follow the steps to reconfigure the MTCLK frequency or MCUCLK frequency when PLL circuit is
enabled:
1. Access to the register “SysCtrl” (SFR 0x80) to select the OSC clock as the source for CLK1 or CLK2
2. Access to the register “CtrlCLK” (0x2867) to adjust the frequency of MTCLK or MCUCLK
3. Access to the register “SysCtrl” (SFR 0x80) to select the PLL clock as the source for CLK1 or CLK2
V9821 is 50/60Hz-power-line supportive. By default the chip is applied to 50Hz-power-line. Users can
set the bit “PLLSEL” (bit5 of CtrlPLL, 0x2868) to ‘1’ to configure the chip for the application in 60-Hz power
grid. The PLL clock frequency in 60-Hz power grid is 1.2 times of that in 50-Hz power grid. In 60-Hz power
grid, the parameters related to the clock frequency, such as the baud rate and timers, must be
reconfigured. If not specifically noted, all information related to clock frequency in this datasheet will only
be applied to 50-Hz power grid.
In the full-speed operation, the MCUCLK frequency is 13.1072 MHz, the MTCLK frequency is
3.2768 MHz, and ADCCLK frequency is 819.2 kHz which is a quarter of the MTCLK frequency. The typical
- Normal operation
In this mode, MCU needs to access some registers to select the clock source for CLK1 or CLK2, and/or
to disable/enable the clock.
- Quick operation
In this mode, only one register is needed by MCU to access to trigger the hardware to enable/disable
the PLL circuit, select the source for CLK1, and/or enable/disable CLK1. If this method is used to
disable CLK1, the system will enter LPM1 state, but not LPM2 state. If the chip is used for a low-power
application, this method will be recommended.
When the RSTn pin reset, POR/BOR, or WDT overflow reset occurs, the analog control registers and the
register “SysCtrl” (SFR 0x80) will be reset to their default states, which means that the PLL circuit will be
disabled and CLK1 will be enabled and sourced by OSC clock. After the reset, access the analog control
registers to enable the PLL circuit and configure the frequency of MCUCLK, and then set the bit “MCUFRQ”
(bit0 of SysCtrl, SFR 0x80) to ‘1’ to select PLL clock as the source for CLK1. Only one OSC clock cycle is
needed for all the above processes.
It is mandatory to enable the PLL circuit before writing ‘1’ to the bit “MCUFRQ” to select the source for
CLK1. When CLK1 is sourced by PLL clock, PLL clock frequency will automatically change to 32768 Hz if the
PLL circuit is anomaly disabled, but the bit “MCUFRQ” is still read out as ‘1’. In this condition, MCU must
read the bit “PLLLCK” (bit0 of PLLLCK, SFR 0xA3) to detect the state of the PLL circuit.
When CLK1 is sourced by PLL clock, clear the bit “MCUFRQ” (bit0 of SysCtrl, SFR 0x80) to select OSC
clock as the source for CLK1. This switchover needs no more than one OSC clock cycle. In this period, the
write operation on the analog control registers is invalid. MCU can keep on reading this bit once
immediately clearing it. If this bit is read out as ‘0’, it indicates the switchover is finished.
When CLK1 is sourced by OSC clock, and the bit “PWRUP” (bit0 of Systate, SFR 0xA1) is read out as ‘0’,
write ‘1’ to the bit “SLEEP0” or “SLEEP1” (bit1 or bit2 of SysCtrl, SFR 0x80) to disable CLK1 to force the
system to enter the LPM2 state or LPM1 state. When CLK1 is disabled, MCU, including MCU, RAM, Flash
memory, interrupt circuits, timers, UART interfaces, and GPIO ports, will stop working.
When the RSTn pin reset, POR/BOR, or WDT overflow reset occurs, the analog control registers and the
register “SysCtrl” (SFR 0x80) will be reset to their default states, which means the PLL circuit will be
disabled; CLK2 will be enabled and sourced by OSC clock. After the reset, access to the analog control
registers to enable the PLL circuit and configure the frequency of MTCLK, and then set the bit “MEAFRQ”
(bit7 of SysCtrl, SFR 0x80) to ‘1’ to select PLL clock as the source for CLK2. Only one OSC clock cycle is
needed for all the above processes.
It is mandatory to enable the PLL circuit and then write ‘1’ to the bit “MEAFRQ” to select the source for
CLK2. When CLK2 is sourced by PLL clock, PLL clock frequency will automatically change to 32768 Hz if the
PLL circuit is anomaly disabled, but the bit “MEAFRQ” is still read out as ‘1’. In this condition, MCU must
read the bit “PLLLCK” (bit0 of PLLLCK, SFR 0xA3) to detect the state of the PLL circuit.
When CLK2 is sourced by PLL clock, clear the bit “MEAFRQ” (bit7 of SysCtrl, SFR 0x80) to select OSC
clock as the source for CLK2. This switchover needs no more than one OSC clock cycle. In this period, the
write operation on the analog control registers is invalid. MCU can keep on reading this bit once
immediately clearing it. When this bit is read out as ‘0’, it indicates the switchover is finished.
When CLK2 is sourced by OSC clock, write ‘1’ to the bit “PMG” (bit4 of SysCtrl, SFR 0x80) to disable
CLK2. When CLK2 is disabled, the energy metering architecture will stop working.
This mode is applied to disable/enable the PLL circuit, select the source for CLK1, and enable/disable
CLK1. In this mode, only the register “SysCtrl” (SFR 0x80) needs to be accessed.
When the RSTn pin reset, POR/BOR, WDT overflow reset, power supply restoration event, or IO/RTC
wakeup event occurs, the bits “FWC and FSC” (bit6 and bit5 of SysCtrl, SFR 0x80) will be reset to 0s. Thus,
the program determines the state of the system, including the PLL circuit and the clock source for CLK1.
Clear the bit “FSC”, and then write ‘1’ to the bit “FWC”, to enable the PLL circuit and select the PLL clock
as the source for CLK1 automatically. In this condition, the PLL clock frequency is 3.2768 MHz. The source
for CLK1 will be switched to PLL clock immediately once ‘1’ is written to the bit “FWC”.
When the bit “PWRUP” (bit0 of Systate, SFR 0xA1) is read out as ‘0’, write ‘1’ to the bit “FSC” whatever
the bit “FWC” is, to select the OSC clock to be the source for CLK1, to disable the PLL circuit, to disable
CLK1, and to force the system to enter the LPM1 state.
When the RSTn pin reset, POR/BOR, WDT overflow reset, power supply restoration event, or IO/RTC
wakeup event occurs, the system will get into a temporary state in which the OSC clock is used as the
clock source for CLK1 and the energy accumulation unit can only accumulate a constant. In this state, the
system consumes some power that should be diminished for the low-power-consumption applications. In
the power-down state, the process of disabling the circuits consumes some power that should also be
In the normal operation, applications need to access analog control registers to get the system out of
the temporary state or to disable the circuits in the power-down state. But in the quick operation, only the
bits “FSC/FWC” need to be accessed. Thus, completing the above implementation in the quick operation
is preferred.
But, as stated above, the clock source switchover in the normal operation and quick operation may
affect each other:
- If the bits “FSC/FWC” are set to “0b01”, the configuration of the register “CtrlCLK” (0x2867) and
the bit “MCUFRQ” (bit0 of SysCtrl, SFR 0x80) cannot be activated, and the PLL clock frequency
holds 3.2768 MHz.
- If the bit “MCUFRQ” is read out as ‘1’, clearing the bits “FSC/FWC” cannot switch the clock source
for CLK1.
To prevent MCU from the mis-operation, MCU can combine both methods, the combination operation:
To enable the PLL circuit and switch the source for CLK1 in the quick operation to lower power
consumption; and then, to hold PLL clock frequency in normal operation.
FWC = 1; // Turn on PLL, and switch the clock source to PLL clock
In Table 6-1, the normal, quick and combination operations are compared.
Quick Combination
Operation Normal Operation
Operation Operation
MCUFRQ = 0
While(MCUFRQ == 1){;}
Switch source for CLK1 to OSC clock, MCUFRQ = 0
access the analog control FSC = 1
disable PLL circuit, and disable CLK1 FSC = 1
registers and disable PLL circuit
SLEEP0 = 1
The arrow in Figure 6-2 indicates the process from the IO wake-up event to completing the clock source
switchover of CLK1 to the 3.2768-MHz PLL clock, in the quick operation or combination operation, which
lasts 800 ~ 900 μs, including the time to reset, to execute the initial long jump instruction, and to write
‘1’ into FWC.
Figure 6-2 Enabling PLL Circuit and Clock Source Switchover to PLL in Quick Operation
The arrows in Figure 6-3 indicate the process from the clock source switchover of CLK1 to OSC clock to
disabling CLK1, in quick or combination operation, which lasts less than 30 μs.
Figure 6-3 Clock Source Switchover to OSC, Disabling PLL Circuit, Disabling CLK1 in Quick
Operation
6.5. Registers
Table 6-2 Clock Switchover Control Register (SysCtrl, SFR 0x80)
0: OSC clock
bit7
0 1: PLL clock
MEAFRQ
This bit is writable and readable. Configure this bit to switch the clock source for
CLK2, and read this bit to acquire the current clock source for CLK2.
Only when the bit FSC is cleared be the configuration of FWC activated.
When the bit “FSC” is cleared, write ‘1’ to this bit to enable the PLL circuit to start
bit6 running and output a 3.2768-MHz PLL clock, and to select this clock to be the clock
0 source for CLK1.
FWC
When the bit “FSC” is cleared, write ‘1’ to the bit “FWC”, the clock setting will be
locked. Writing ‘0’ to the bit “FWC” will unlock the clock setting without switching
the clock.
Write ‘1’ to this bit to select the OSC clock as the clock source for CLK1, to disable the
PLL clock, and to disable CLK1.
bit5
0 If the bit “PWRUP” is read out as ‘0’, setting this bit to ‘1’ will make the system enter
FSC
the LPM1 state, but not the LPM2 state. If the bit “PWRUP” is read out as ‘1’, setting
this bit to ‘1’ cannot force the system enter the LPM1 state.
bit4
0 Set this bit to ‘1’ to stop CLK2. By default this clock is running.
PMG
Set this bit to ‘1’ to stop CLK3. By default this clock is running.
bit3
0 Only when the PLL clock is selected as the clock source for CLK1 and CLK2, can CLK3
LCDG
be stopped.
bit2 When the bit “PWRUP” is read out as ‘0’, write ‘0’ to the bit “MCUFRQ”, and then:
SLEEP1 - Set “SLEEP1” and “SLEEP0” to “0b11” or “0b01” to stop CLK1 (Together with
0 CLK4) and force the system to enter the LPM1 state
bit1
- Set “SLEEP1” and “SLEEP0” to “0b10” to stop CLK1 (Together with CLK4) and
SLEEP0 force the system to enter the LPM2 state
0: OSC clock
bit0
0 1: PLL clock
MCUFRQ
This bit is writable and readable. Configure this bit to switch the clock source for
CLK1, and read this bit to acquire the current clock source for CLK1.
When the bit “IORSTN” (bit0 of IOWK, SFR 0xC9) is set to ‘1’, any wakeup event can wake up the system
from the sleeping state without resetting the system. After the wakeup, MCU keeps on executing
programs; all circuits hold their states where they are before sleeping; only bit[2:1] (SLEEP1 and SLEEP0)
and bit[6:5] (FWC and FSC) are cleared.
bit7 Reserved - 0 -
0: Disable
bit5 Reserved - 0 -
0: Enable
0: Enable
bit[2:1] Reserved - 0 -
0: Enable
0: Enable
0: Enable
bit5 Reserved - 0 -
0: Enable
0: Enable
0: Enable
0: Enable
0: Enable
bit[7:5] Reserved 0 These bits must hold their default values for proper operation.
The fixed capacitance in the crystal oscillator circuit is 12.5 pF. Set
bit4 CSEL 0
this bit to ‘1’ to decrease the capacitance by 2.35 pF.
bit3 Reserved 0 These bits must hold their default values for proper operation.
11: Increment by 64 kΩ
bit7 Reserved 0
This bit must hold its default value for proper operation. By
bit6 Reserved 0
default this function is disabled.
bit5 XRESETEN 0 Set this bit to ‘1’ to enable the oscillation monitor
bit4 Reserved 0
bit[1:0] Reserved 0 These bits must hold their default values for proper operation.
bit[7:1] Reserved 0
When this bit is read out as ‘1’, it indicates that the PLL has locked onto a
bit0 PLLLCK 0
certain frequency.
0: Disable
bit7 PLLPDN 0
1: Enable
Enable the BandGap circuit, and then enable the PLL circuit.
0: Disable
bit6 BGPPDN 0
1: Enable
Enable the BandGap circuit, and then enable the PLL circuit.
01: × 2
10: × 4
01: × 2
10: × 4
00: × 1
bit[1:0] MCUCLKSEL[1:0] 0
01: × 2
10: × 4
11: × 8
When the bit “MCU13M” is set to ‘1’, set this bit to ‘1’ to double the
bit7 MCU26M 0
MCUCLK frequency further.
bit5 PLLSEL 0 0: 50 Hz
1: 60 Hz
bit[4:0] Reserved 0 These bits must hold their default values for proper operation.
bit6 Reserved -
bit5 COMPB 0 1: The positive input is higher than the negative input.
bit[1:0] Reserved -
7.Operating Mode
V9821 has three system states according to the state of Clock 1:
OSC state: When a reset event of Level 1 or Level 2 occurs, the system will go to the OSC state, in
which Clock 1 runs and is sourced by OSC clock.
Working state: The PLL circuit is enabled, and the PLL clock is used as the source for Clock 1.
Sleeping state: When the bit “PWRUP” (bit0 of Systate, SFR 0xA1) is cleared, select OSC clock as the
source for Clock 1 and disable Clock 1, and then the system will enter the sleeping state. By default
the chip will be woken up with reset and forced to go back to OSC state. But when the bit “IORSTN”
(bit0 of IOWK, SFR 0xC9) is set to ‘1’, the chip will be woken up without reset, which means the chip
will be woken up and go back to where it enters the sleeping state except that bits “SLEEP1, SLEEP0,
FWC and FSC” (bits of SysCtrl, SFR 0x80) are cleared to 0s. The sleeping state is classified into 2
states: LPM1 state and LPM2 state. An IO/ RTC wakeup event, CF pulse output, or a power supply
restoration event can wake up the system from the LPM1 state. An IO wakeup event or a power
supply restoration event can wake up the system from the LPM2 state.
LDO33 On No No No
OSC On No No No
REF_LP On No No No
RTC On No No No
Power Supervisor On No No No
Temperature
Off Yes No No
Measurement Circuit
Battery Voltage
Off Yes No No
Measurement Circuit
When a reset event of Level 1 or Level 2 occurs, the system will be reset to the OSC state. In this state,
LDO33 is enabled, the OSC clock is used as the source for CLK1, and MCU runs.
LDO33 On No On
OSC On No On
MCU On Yes On
REF_LP On No On
RTC On No On
In the OSC state, enable the PLL circuit, select the PLL clock to work as the source for CLK1, and then
the system will enter the working state.
In the working state, users can configure the MCU clock (CLK1) frequency, and enable the required
ADCs, the energy metering architecture, the LCD driver, and MCU and its peripherals according to the
application.
When the bit “PWRUP” (bit0 of Systate, SFR 0xA1) is read out as ‘0’, switch the source for CLK1 to the
OSC clock and then disable CLK1, then the system will go to the sleeping state.
There are two types of sleeping state: LPM1 state and LPM2 state.
In the LPM1 state or LPM2 state, RTC holds on; the memories, MCU, and its peripherals stop working;
but the LCD driver and the energy metering architecture will not stop working until they are disabled. If
ADCs, PLL circuit, LCD driver, and energy metering architecture are disabled, and IOs are set to “Output,
disabled; input, masked” before entering the LPM1 state or LPM2 state, the system will consume the
lowest power.
In the LPM1 state, if IO/RTC wakeup event, CF pulse output, or power supply restoration event occurs,
the system will be woken up and go back to the OSC state by default. In the LPM2 state, only an IO
wakeup event or power supply restoration event can wake up the system and reset it to the OSC state by
default. When the bit “IORSTN” (bit0 of IOWK, SFR 0xC9) is set to ‘1’, any wakeup event can wake up the
system from the LPM1 state or LPM2 state only without resetting the system to the OSC state. In this
condition, the chip will go back where it enters the sleeping state, except that bit[6:5] (FWC and FSC) and
bit[2:1] (SLEEP1 and SLEEP0) will be cleared to 0s.
If the pin “WAKEUP1, WAKEUP2, WAKEUP3, or WAKEUP4” is set to “Input enabled” before the system
enters the LPM1 state or LPM2 state, a transition (Either high-to-low or low-to-high, with more than 4 OSC
clock cycles on both levels) on the pin in the LPM1 state or LPM2 state can wake up the system. By default
ports “P0.2 and P0.3” are not used for the wakeup event input. Users must configure the bit “IOP0” (bit1
of IOWK, SFR 0xC9) to ‘1’ to set both pins for the wakeup input. When the bit “IO” (bit3 of Systate, SFR
0xA1) is set to ‘1’, read states of bits “IOP14” (bit0 of IOWKDET, SFR 0xAF), “P02WK” (bit1 of IOWKDET,
SFR 0xAF), and “P03WK” (bit2 of IOWKDET, SFR 0xAF) to detect which IO wakeup event wakes up the
If both bits “RTC” (bit2 of Systate, SFR A1) and “CFWK” (bit3 of IOWKDET, SFR 0xAF) are set to 1s, it
indicates that the system will be woken up by the CF pulse output. If the bit “RTC” is set to ‘1’, but “CFWK”
is cleared, it indicates that an RTC wakeup event will occur.
7.1.3.1. Sleep/Wake-Up
In V9821, there are two methods to wake up the system from the sleeping state or make the system go
to the sleeping state: normal method and quick method.
1. Normal Method
The normal method for wakeup/sleep switchover is totally controlled by the program.
When the PLL clock is enabled and works as the source for the MCU clock (CLK1), users can follow the
steps illustrated in Figure 7-1 to force both MCU and energy metering architecture to go to the sleeping
state, or force MCU to go to the sleeping state only but leave the energy metering architecture to
accumulate a constant for energy metering.
PMG=1
(bit4, SFR 0x80)
(optional)
Notes:
Clear MCUFRQ
Take the value of MCUFRQ as the condition for the
(bit0, SFR 0x80)
while loop, and count the while loop cycles to detect
whether it is the time to terminate the loop. In this
≤1 OSCCLK period case, CLK1 is sourced by PLL clock, so users can
MCUFRQ=1
estimate a value based on MCUCLK frequency to
detect the counts. when MCUCLK frequency is
Read MCUFRQ 13.1072MHz, about 50 assembly instructions are
(bit0, SFR 0x80) needed to terminate the loop. If one while loop cycle
needs 5 instructions, the value to detect the counts
should be 10.
MCUFRQ=0
PLLPDN=0, BGPPDN=0
(bit7, bit6, 0x2867)
Write SLEEP1/SLEEP0
(bit2, bit1, SFR 0x80)
sleeping
Notes:
Clear MCUFRQ Take the value of MCUFRQ as the condition for the
(bit0, SFR 0x80) while loop, and count the while loop cycles to detect
whether it is the time to terminate the loop. In this
≤1 OSCCLK period case, CLK1 is sourced by PLL clock, so users can
MCUFRQ=1
estimate a value based on MCUCLK frequency to
detect the counts. when MCUCLK frequency is
13.1072MHz, about 50 assembly instructions are
Read MCUFRQ needed to terminate the loop. If one while loop cycle
(bit0, SFR 0x80) needs 5 instructions, the value to detect the counts
should be 10.
MCUFRQ=0
Write SLEEP1/SLEEP0
(bit2, bit1, SFR 0x80)
sleeping
Figure 7-2 Go to Sleeping State (Normal Method, PLL Clock Holds on)
0 1 LPM1 state
SysCtrl
1 1 LPM1 state
SFR 0x80
1 0 LPM2 state
In the LPM1 state or LPM2 state, when the IO/RTC wakeup event, CF pulse output, or power supply
restoration event occurs, the system will be woken up from the sleeping state. If the wakeup with reset
mode is applied, after the reset, users should use the normal operation to enable the PLL circuit and select
it as the source for CLK1 to make the system go to the working state.
2. Quick Method
In V9821, the quick method can force the system to go to the LPM1 state, but not the LPM2 state.
When the PLL clock is enabled and works as the source for the MCU clock (CLK1), users can follow the
steps illustrated in Figure 7-3 to force both MCU and energy metering architecture to go to the LPM1 state,
or force MCU to go to the LPM1 state only but leave the energy metering architecture to accumulate a
constant for energy metering. In this case, the PLL clock will be disabled definitely.
PREN=0(bit4, 0x2878)
EGYEN=0
(bit3, 0x287D)
(optional)
Notes:
Clear MEAFRQ Take the value of MEAFRQ as the condition for the
(bit7, SFR 0x80) while loop, and count the while loop cycles to detect
whether it is the time to terminate the loop. In this
≤1 OSCCLK period case, CLK1 is sourced by PLL clock, so users can
MEAFRQ=1
estimate a value based on MCUCLK frequency to
detect the counts. when MCUCLK frequency is
13.1072MHz, about 50 assembly instructions are
Read MEAFRQ
needed to terminate the loop. If one while loop cycle
(bit7, SFR 0x80)
needs 5 instructions, the value to detect the counts
should be 10.
MEAFRQ=0
PMG=1
(bit4, SFR 0x80)
(optional)
Notes:
Set FSC to 1 Setting FSC to 1 can force the hardware to complete
(bit5, SFR 0x80) the following steps automatically:
1. to switch the clock source for CLK1 from PLL clock
≤2 OSCCLK periods to OSC clock;
2. to disable PLL and BandGap circuits;
3. to clear bits MCUCLK, MEACLK and ADCLK;
Sleep 4. to force the system to go to Sleep.
7.2. Registers
Table 7-4 Register for Clock Control
0: OSC clock
bit7
0 1: PLL clock
MEAFRQ
This bit is writable and readable. Configure this bit to switch the clock source for
CLK2, and read this bit to acquire the current clock source for CLK2.
Only when the bit “FSC” is cleared, is the configuration of “FWC” activated.
When the bit “FSC” is cleared, write ‘1’ to the bit “FWC” to enable the PLL circuit to
bit6 start running and output a 3.2768-MHz PLL clock, and to source CLK1.
0
FWC When the bit “FSC” is cleared, write ‘1’ to the bit “FWC”, the clock setting will be
locked. Writing ‘0’ to the bit “FWC” will unlock the clock setting without switching
the clock.
Write ‘1’ to this bit to select the OSC clock as the clock source for CLK1, to disable the
PLL clock, and to disable CLK1.
bit5
0 If the bit “PWRUP” is read out as ‘0’, setting this bit to ‘1’ will make the system enter
FSC
the LPM1 state, but not LPM2 state. If the bit “PWRUP” is read out as ‘1’, setting this
bit to ‘1’ cannot force the system to enter the LPM1 state.
Set this bit to ‘1’ to stop CLK3. By default this clock is running.
bit3
0 Only when the PLL clock is selected as the clock source for CLK1 and CLK2, can CLK3
LCDG
be stopped.
bit2 When the bit “PWRUP” is read out as ‘0’, write ‘0’ to the bit “MCUFRQ”, and then:
SLEEP1 - Set “SLEEP1” and “SLEEP0” to “0b11” or “0b01” to stop CLK1 (Together with
0 CLK4) and force the system to enter the LPM1 state
bit1
- Set “SLEEP1” and “SLEEP0” to “0b10” to stop CLK1 (Together with CLK4) and
SLEEP0 force the system to enter the LPM2 state
0: OSC clock
bit0
0 1: PLL clock
MCUFRQ
This bit is writable and readable. Configure this bit to switch the clock source for
CLK1, and read this bit to acquire the current clock source for CLK1.
When the bit “IORSTN” (bit0 of IOWK, SFR 0xC9) is set to ‘1’, any wakeup event can wake up the system
from the sleeping state without resetting the system. After the wakeup, MCU keeps on executing
programs; all circuits hold their states where they are before sleeping; only bit[2:1] (SLEEP1 and SLEEP0)
and bit[6:5] (FWC and FSC) are cleared.
bit[7:6] Reserved
bit5 When this bit is read out as ‘1’, it indicates the system is reset by an event of Level 1:
0 POR/BOR, RSTn pin reset, or WDT overflow event. This bit will be cleared when a
POR reset event of other levels occurs.
bit4 0 Reserved
bit3 When this bit is read out as ‘1’, it indicates the system is woken up from the LPM1
0
IO state or LPM2 state by an IO wakeup event.
When this bit is read out as ‘1’, but bit “CFWK” (bit3 of IOWKDET, SFR 0xAF) is
cleared, it indicates the system is woken up from the LPM1 state by the RTC wakeup
bit2
0 event.
RTC/CF
If both this bit and bit “CFWK” are set to 1s, it indicates the system is woken up from
the LPM1 state by the CF pulse wakeup event.
When the input voltage on the pin “VDCIN” is lower than 1.0 V, this bit will be read out
as ‘1’, indicating that the system is powered down. If the power down interrupt is
bit1
0 enabled, an interrupt will be triggered when this bit is read out as ‘1’.
PWRDN
When the input voltage on the pin “VDCIN” is higher than 1.1 V, this bit will hold its
default value, indicating there is no power-down event occurring.
When the input voltage on the pin “VDCIN” is higher than 1.1 V, this bit is read out as
bit0 ‘1’, indicating that the system is powered up by the AC power supply.
0
PWRUP When the input voltage on the pin “VDCIN” is lower than 1.0 V, this bit will hold its
default value, indicating the system is powered up by batteries.
8.Power Supply
V9821 supports 5 V or 3.3 V power input on the pin “VDD5”. The power supply is supervised
continuously. The internal analog circuits and General-Purpose I/O (GPIO) ports are powered by the 3.3-V
regulator circuit (3.3V-LDO), and the LDO33 output voltage powers the peripheral circuits; the energy
metering architecture and PLL circuit are powered by the digital power supply circuit.
There is an internal power detection circuit in V9821. By default this circuit is enabled. When the chip is
3.3 V powered, users must set the bit “PDDET” (bit7 of CtrlLDO, 0x2866) to ‘1’ to disable this circuit to
protect the battery from current leakage when a battery is connected. When the chip is 5 V powered, this
bit must hold its default value.
BAT M Channel
Peripheral
3.3V-LDO LDO33
VDCIN circuits
4.7μF 0.1μF
* Digital circuits include CPU and its peripherals (UART interfaces, timers,
interrupts, RAM, Flash memory, and so on), RTC, energy metering
architecture (VMA), and so on.
** Analog circuits include ADC, voltage reference, temperature sensor,
LCD driver, POR/BOR, RC oscillator, crystal oscillator, power supply
supervisor, and so on.
Note: the V9821 internal have a power detection circuit.The circuit is opened by default.When the system is composed of 3.3 V power
supply, the user must Set PDDET bits (bit7 CtrlLDO, 0 x2866) 1, disable power detection circuit, or when a battery connection to the
battery leakage may occur.System consists of 5 v power supply must be cleard, at this time there will be no battery leakage risk
LDO33 has a driving capability of 30 mA. When the load current through the analog circuits and the
GPIO ports is less than 30 mA, the LDO33 output voltage holds 3.3 V; when the load current is higher than
30 mA, the higher the load current is, the lower voltage the LDO33 will output.
2
5 0
-2
0
-4
Voltage (%)
-5 -6
When the external voltage is When the load current through the
-8
higher than 3.3V, the LDO33 analog circuit and IOs is higher than
-10 -10
(%)
The digital power supply circuit has a driving capability of 35 mA. When the load current through the
circuits is less than 35 mA, the digital power supply will be stable; when the load current is higher than
35 mA, the higher the load current is, the lower the digital power supply will be.
This supply circuit will not stop working until the system is powered off.
It is recommended to decouple the pin DVCC externally with a ≥ 4.7-μF capacitor in parallel with a
0.1-μF capacitor.
When the input voltage on the pin “VDCIN” is lower than 1.0 V, a power-down event will occur, the bit
“PWRDN” (bit1 of Systate, SFR 0xA1) will be set to ‘1’, and a power-down interrupt will be generated to
MCU.
1.1V
1.0V
VDCIN
PWRUP
PWRDN
Figure 8-4 Relationship between VDCIN Input Signal and States of Flag Bits PWRUP and
PWRDN
When the chip is powered by the batteries, please note that the batteries will get passive when it is
reactive for a long time. So users should set the bit “BATDISC” (bit0 of CtrlBAT, 0x285C) to ‘1’ at an
interval to discharge the batteries to protect them from the passivation. During the batteries discharge,
the load current is 3 mA, and the period for batteries discharge should not be too long. After the discharge,
the bit “BATDISC” must be cleared.
9.Comparator
CMPPDNB
M1
M2 CMPSSELB<1:0>
+ CB Interrupt
-
1.2V REF_LP
Positive signal input on pin “M1” and negative signal input on pin “M2”
Positive signal input on pin “M1” and negative signal from internal low power reference circuit
(REF_LP)
Positive signal input on pin “M2” and negative signal from internal low power reference circuit
(REF_LP)
When the RSTn pin reset, POR/BOR, or WDT overflow reset occurs, or the system is in the LPM1 state
or LPM2 state, this comparator will stop running.
When IE6 = 1 (bit6 of 0x28A5), EIE.3 = 1 (bit3 of SFR 0xE8), and IE.7 = 1 (bit7 of SFR 0xA8), the
comparator interrupt will be enabled. In this state, the interrupt flag “IR6” (bit6 of 0x28A2) will be set to
‘1’ when the output of the comparator changes, and the comparator will generate an interrupt to MCU.
After the interrupt service, users can read the bit “COMPB” (bit5 of 0x286B) to detect the comparison
result of the input signals.
bit4 Reserved 0
Four independent oversampling Σ/Δ ADCs: One voltage channel, two current channels, and one
multifunctional channel for various signal measurement.
- Less than 0.1% error on active energy metering over dynamic range of 5000:1
- Less than 0.1% error on reactive energy metering over dynamic range of 3000:1
- Less than 0.5% error on current and voltage RMS calculation over dynamic range of 1000:1
Providing measurements:
- Line frequency
Two current inputs for active energy, or one current input for active and reactive energy
Zero-crossing interrupt
- Phase compensation supported, resolution 0.005°/lsb (Min.), over a range of ± 1.4° (Min.)
AVG CF1
E1 PWR/s
Constant
Energy Acc_P
PWR
M ADC Decimation DATADM
CNT
AVG DATAADM
PMCtrl4, 0x287D
Phase Compensation
GAIN E2 PWR
E2 path CF2
FREQUENCY CF2
MEASUREMENT AVG E2 PWR/s Sign Energy Acc_P
*ITG represents the digital integrator. It is
used to shift the phase of the current signal by CNT
90 degrees for reactive power calculation.
When the POR/BOR, RSTn pin reset, or WDT overflow reset event occurs, all buffer registers for the
write and read operations on the registers for the energy-metering architecture are reset to their default
states.
2. Read operation
MCU must read the registers for the energy-metering architecture. Please follow the steps as illustrated
below:
c. When the flag bit “ACK” is read out as ‘0’, or in no more than 24 MTCLK clock periods, the content
(DATA) of the target register will be loaded into the buffer registers in sequence as illustrated in
Table 10-1
3. Write operation
MCU must write the registers for the energy-metering architecture. Please follow the steps as illustrated
below:
b. Write the data (DATA) to the buffer registers in sequence as illustrated in Table 10-1
d. When the flag bit “ACK” is read out as ‘0’, or in no more than 24 MTCLK clock periods, the content
(DATA) in the buffer registers will be loaded into the target registers.
There is a specific bit (GT, bit7 of IDET, 0x2886) to disable the clock for the sampling circuits and
RMS/power calculation circuits. When this bit is set to ‘1’, the circuits will stop working, but the energy
accumulation unit will keep on running.
In the working state, the PLL clock is enabled, and it is selected as the source for CLK2. In this condition,
the metering clock frequency (fMTCLK) and sampling frequency of ADCs (fADC) are configurable, and fMTCLK
must be 4 times of fADC.
0: OSC clock
bit7
1: PLL clock
SysCtrl MEAFRQ
This bit is writable and readable. Configure this bit to switch the clock
SFR 0x80 source for CLK2, and read this bit to acquire the current clock source
for CLK2.
ADCLKSEL[1:0] 00: × 1
01: × 2
CtrlCLK 10: × 4
MEACLKSEL[1:0] 00: × 1
01: × 2
10: × 4
In a current channel, a current transformer (CT) or a shunt resistor can be used for the current
channels.
CT RF
IP +
R0 CF
R1 RF AGND
IN -
CF
P AGND
AGND
N L
Load R1
IP
C1
Resistor
Shunt
C2
IN
R2
N L
PT UP +
RF CF
AGND
UN -
RF CF
N L AGND AGND
Ra
RF UP +
CF
AGND
AGND UN -
CF
RF
AGND
AGND
AGND
N L
Resistor-Divider Network
Table 10-3 Analog PGA Gain Configuration for Current and Voltage Analog Input
To set analog PGA gain for voltage input to Voltage Channel (U)
ADC. It is mandatory to set this bit to its default value for proper
bit6 operation.
0
ADCGU 0: × 1
1: × 2
To set analog PGA gain for current input to Current Channel B (IB)
ADC
CtrlADC0
000: × 1
0x2858
001: × 4
bit[5:3]
0 010: × 8
ADCGB[2:0]
011: × 16
100/101/110/111: × 32
To set analog PGA gain for current input to Current Channel A (IA)
ADC
000: × 1
001: × 4
bit[2:0]
0 010: × 8
ADCGA[2:0]
011: × 16
100/101/110/111: × 32
Note: It is mandatory to clear the bit “DCENN” (bit7 of CtrlLCDV, 0x285E) to add 10-mV direct voltage
offset to the current input to current channel ADCs.
1: Enable
1: Enable
After the analog-to-digital conversion, the analog signals are converted to be the 1-bit code streams of
22-bit length with both “bit21” and “bit20” being the sign bits.
Phase
compensation
U U RMS
DPGA Calculation
Power
IA I1 I1 Calculation CF pulse
DPGA Energy output
Accumulation
IB I2 I2 Energy-Pulse
DPGA Conversion
SELI
0x2878 SELI 0: current IA is sent to Current I1 Channel for signal processing, and current IB is sent
to Current I2 Channel for signal processing.
PMCtrl1 bit5
1: current IA is sent to Current I2 Channel for signal processing, and current IB is sent
to Current I1 Channel for signal processing.
Then current (I1 and I2) and voltage signals must be input to a phase compensation circuit to correct
the phase angle error between the current and voltage signals introduced by the transformers.
Sinc3 Filter
U
ADC D D D …… D D D
PHCx7~PHCx0
I1/I2
ADC D D D …… D D D
Sinc3 Filter
By default the phase compensation is disabled. Users can enable this function via configuring the bit
“PHCEN” (bit6 of PMCtrl1, 0x2878). When the phase compensation is enabled, the phase angle error
between I1 and U, and I2 and U, are corrected respectively. Bit [7:0] of register PHCCtrl1 (0x287B)
together with bit[1:0] (IAPHC) of register CRPST (0x287F) or bit[7:0] of register PHCCtrl2 (0x287C)
together with bit[3:2] (IBPHC) of register CRPST (0x287F) are used to calibrate the phase angle error
between signal I1 or I2 and the voltage signal, see Table 10-7 for details.
In 50Hz power grid, when the sampling frequency of the phase compensation circuit (fsmpl) is
3.2768MHz, the calibration resolution is 0.0055°/lsb, and the maximum phase angle error to be corrected
is 1.4°. The value of fsmpl is determined by the configuration of bits MEACLKSEL<1:0> (bit[3:2] of CtrlCLK,
0x2867).
The value (N) to be set to the phase compensation control registers can be calculated via the following
equation:
1 𝑓𝑠𝑚𝑝𝑙
N = 𝑅𝑜𝑢𝑛𝑑( × × {±𝑎𝑟𝑐𝑐𝑜𝑠[𝑐𝑜𝑠𝜃 × (1 + 𝐸)] − 𝜃 }) Equation 10-1
𝜋 100
where
N is the value, signed, to be set to the registers, listed in Table 10-7, to correct the phase angle error.
A positive N indicates that the current signal must be delayed, so “0” must be set to the sign bit; a
negative N indicates that the voltage signal must be delayed, so “1” must be set to the sign bit;
θ is the phase angle between current and voltage signals, in radian format. A positive θ indicates a
phase lead in current signal; a negative θ indicates a phase lag in current signal;
E is the energy metering error displayed on LCD screen of the calibration equipment;
Table 10-6 fsmpl Determines Phase Compensation Resolution and Correction Range
PHCCtrl1(0x287B)/PHCCtrl2(0x287C) CRPST(0x287F)
x=A or B. PHCx7 is the sign bit, PHCx6 is not used, and the other 8 bits are used to set the absolute value
to correct the phase angle error.
Digital programmable gain amplifiers (DPGA) with possible gain selection via PMCtrl2 (0x2879) and
PMCtrl3 (0x287A) are applied to digital signals output from the high-pass filters to amplify their capability
of depressing truncation noise when a low signal was input. Please note the product of the analog input
and the total PGA gains, including APGA and DPGA, should not be over the measurement scales of the
ADCs.
Gain=2PGAUx
bit[2:0] When the bit “LPFEN” (bit5 of PMCtrl3, 0x287A) is set to ‘1’, the digital PGA
gain for U signal will be lowered to 1/4 of its configuration. When the bit
“LPFEN” is cleared, the digital PGA gain for U signal will be what it is
configured.
Equation 10-2 describe the digital signals processed by the digital programmable gain amplifiers:
Aua
Ua = PGAdua × PGAua × × sin ωt = DUa × sin ωt
1.185
Aia
Equation 10-2
Ia = PGAdia × PGAia × × sin(ωt + ψ) = DIa × sin(ωt + ψ)
1.185
Where, “PGAdua” and “PGAdia” are the DPGA gains; “PGAua” and “PGAia” are the APGA gains; “Aua” and
“Aia” are the amplitude of current and voltage inputs; and ‘1.185’ is the reference voltage.
The configuration of the bit “IDLEN” (bit[3:0] of IDET, 0x2886) and the current detection period have a
relationship as shown in Equation 10-3:
256 × ([𝐼𝐷𝐿𝐸𝑁] + 1)
𝑡𝐼𝐷𝑇 = × 1000 Equation 10-3
𝑓𝐴𝐷𝐶
Where, ‘256’ means that the decimation filter (CIC) has reduced the sampling frequency to 1/256 of fADC,
the sampling frequency of the oversampling ADC; [IDLEN] is the configuration of bits “IDLEN”; tIDT is the
current detection period, in unit of “ms”. To perform the current detection, it is mandatory to enable the
metering clock (MTCLK), and enable the power/RMS calculation.
Set this bit to ‘1’ to disable the sampling circuits and power/RMS calculation circuits.
IDET GT In this case, the energy accumulation circuit keeps on working. Thus, in an application
to accumulate a constant for the energy accumulation, it is recommended to set this
0x2886 bit7 bit to ‘1’ to lower the power consumption further. But please note that the threshold
for the energy-to-pulse conversion must be set before setting this bit to ‘1’.
To enable power and RMS calculation, and digital signal processing in M Channel. 0:
PMCtrl1 PREN
disable; 1: enable.
0x2878 bit4
By default this function is disabled.
0x287A Bit6 This filter can improve the RMS calculation accuracy, but will lead to harmonics loss.
When a low signal is input, this filter will introduce greater truncation noise and
prolong the period for the system to be settled.
To set the coefficient for the band-pass filter in the RMS calculation circuits.
PARABPF If MTCLK frequency is reduced to 819.2kHz, users must disable energy accumulation,
CF pulse output and no-load detection, and then configure this register to
0x10EF
0x911D3C9C. When MTCLK frequency is reinstated to 3.2768MHz, this register must
be set to its default value.
As illustrated in Figure 10-8, the current or voltage signal output from the high-pass filter is multiplied
with itself in the multiplier to get the product with the second harmonic which can be removed by the
low-pass filter, and then the signal processed output from the low-pass filter is sent to the circuit for
rooting processing that produces a 32-bit datum, the raw RMS value of current or voltage. The raw RMS
data will be gain calibrated and then stored in instantaneous RMS registers. Besides, the instantaneous
RMS data will be averaged to acquire the average RMS data that are stored in average RMS registers.
If the raw RMS value is represented as RMS’, the gain calibration value is represented as S, and the
instantaneous RMS is represented as RMS, then the above three values have the relationship:
In V9821, the average current and voltage RMS are multiplied to acquire the apparent power, as
described in the following equation:
where, S represents apparent power; Irms and Urms are the average current and voltage RMS.
The content of the apparent power registers are in the form of 32-bit 2’-complement. When POR/BOR,
RSTn pin reset or WDT overflow reset occurs, these registers are reset to their default states.
There are two paths for power calculation, energy accumulation and energy pulse generation: E1 path
and E2 path. E1 path is used for active power calculation and energy accumulation only; but, E2 path can
be configured for active or reactive power calculation and energy accumulation which is determined by bit
DBLEN (bit4 of PMCtrl3, 0x287A). By default E2 path is used for reactive power calculation based on
current I1.
0: For reactive power calculation and energy metering based on current I1. If positive
0x287A DBLEN current I1 is input to the path, the reactive power is negative, and it is accumulated to
PMCtrl3 bit4 the negative energy accumulators; if negative current I1 is input to the path, the
reactive power is positive, and it is accumulated to the positive energy accumulators.
1: For active power calculation and energy metering based on current I2.
For energy
accumulation
Gain P(t)
u(t) from HPF 32 Calibration
32 32 32 AVG 32 P
i(t) from HPF 32
Multiplier LPF
Offset
S Calibration
Figure 10-9 Signal Processing for Active Power Calculation and Calibration
In V9821, E1 path always calculates active power based on current I1. And when DBLEN is set to ‘1’, E2
path will also be used to calculate the active power based on current I2.
As illustrated in
For energy
accumulation
Gain P(t)
u(t) from HPF
Calibration
32
AVG P
32
32
32
32
Multiplier LPF
Offset
S Calibration
Figure 10-9, after being filtered by the high-pass filter (HPF), the current and voltage multiply each other.
Then, the product is input to the low-pass filter (LPF) to remove the harmonics and the ripples caused by
the noise, and the output of the LPF is the raw active power. This raw power is gain calibrated and then
offset calibrated to acquire the instantaneous active power that is stored in the registers DATAIP (0x10D1,
for active power calculated in E1 path) and DATAIQ (0x10D2, for active power calculated in E2 path). The
instantaneous active power will be averaged to get the average active power that is stored in the registers
DATAP (0x10D6, for active power in E1 path) and DATAQ (0x10D7, for active power in E2 path). The
content of all the registers are in the form of 32-bit 2’-complement, and they will be reset to their default
states when POR/BOR, RSTn pin reset or WDT overflow reset occurs.
Users can configure the registers SCP (0x10E8) and SCQ (0x10E9) for gain calibration over the range of
By default the V9821 supports calculating active and reactive power based on current I1.
For Energy
Accumulation
∫ Gain
32
Q(t)
i(t) from HPF Calibration
32 AVG Q
32
32
32
32
Figure 10-10 Signal Processing for Reactive Power Calculation and Calibration
As illustrated in the above figure, current I1, filtered by the high-pass filter (HPF), is input into a digital
integrator to shift the phase by 90° (the integrator introduces an extra gain of 1.568 that can be
eliminated via gain calibration). The filtered current signal is sent to the multiplier together with voltage
to multiply each other. Then, the product is input to the low-pass filter (LPF) to remove the harmonics and
the ripples caused by the noise, and the output of the LPF is the raw reactive power. This raw power is gain
calibrated and offset calibrated to acquire the instantaneous reactive power, which is stored in the register
DATAIQ (0x10D2, for reactive power calculated in E2 path). The instantaneous reactive power will be
averaged to get the average reactive power, which is stored in the register DATAQ (0x10D7, for reactive
power in E2 path). The content of the registers are in the form of 32-bit 2’-complement, and they will be
reset to their default states when POR/BOR, RSTn pin reset or WDT overflow reset occurs.
Users can configure register SCQ (0x10E9) for gain calibration over the range of -∞~+49.9%, and
register PARAQC (0x10EE) for offset calibration over the range of -50%~+50%. Both registers are in the
form of 32-bit 2’-complement. When POR/BOR, RSTn pin reset or WDT overflow reset occurs, both
registers are reset to their default states.
32
32
SIGN
32
P(t)/Q(t) Threshold CF
1
32
32
32
ENERGY_ACC CNT
32
32
Figure 10-11 Energy Accumulation and CF Pulse Output
In E1 path, positive and negative active powers are accumulated into the energy accumulators
according to their signs; for example, positive active power is accumulated into PPCNT (0x10F0), and
negative active power is accumulated into NPCNT (0x10F1). Besides, other data, such as I1 current RMS
or a constant (preset in the register DATACP, 0x10FC), also can be selected to be accumulated into PPCNT
via configuring bits PSEL1~PSEL0 (bit[1:0] of PMCtrl4, 0x287D) when the chip is used for low power
applications.
In E2 path, positive and negative active/reactive powers are accumulated into the energy accumulators
according to their signs; for example, positive power is accumulated into PQCNT (0x10F6), and negative
power is accumulated into NQCNT (0x10F7).
When MTCLK frequency is 3.2768MHz, 1.6384MHz or 819.2kHz, the energy accumulation frequency is
12.8kHz. When MTCLK frequency is 32768Hz, the energy accumulation frequency is 2979Hz.
The energy accumulators are of actual 42-bit length. But only the higher 32 bits are readable; and only
the higher 32 bits are valid for write operation and the 10 least significant bits are padded with 0s in write
operation. When POR/BOR, RSTn pin reset or WDT overflow reset occurs, all the energy accumulators are
reset to default values, 0s.
When energy accumulation and energy-to-pulse conversion is enabled, the energy will be accumulated
When a low signal is input, users can reduce the energy threshold to increase the pulse generation rate
to speed up energy calibration via configuring bits CFQR1~CFQR0 and CFQ1~CFQ0 (bit[7:4] of CFCtrl,
0x287E).
When CF pulse output is enabled, one CF pulse will be output every 2 counts of the pulse counter. When
MTCLK frequency is 3.2768MHz, the maximum CF pulse output frequency is 6.4kHz, and the pulse width
is configurable via bits CFWD (bit[5:4] of CRPST, 0x287F) and by default the width is 80ms.
In the V9821, three pins, P9.5/CF2, P9.6/CF1 and P1.3/CFx, are used for CF pulse output:
- When bit5 and bit6 of the register P9FS (SFR 0xAD) are set to 1s, the ports P9.5 and P9.6 are used
for CF pulse output of E1 and E2 paths respectively;
- When the register P13FS (0x28C7) is set to 0x01, the port P1.3 is used for CF pulse output of E2 path;
when the register is set to 0x04, the port P1.3 is used for CF pulse output of E1 path.
When bit CFWKEN (bit2 of IOWK, SFR 0xC9) is set to 1, CF pulse output can wake up the system from
LPM1 state. By default CF pulse output can wake up and reset the system to OSC state. But when bit
IORSTN (bit0 of IOWK, SFR 0xC9) is set to 1, this event can wake the system only but not reset the
system. In this condition, after wakeup, the MCU keeps on executing the codes, and all circuits goes back
where they were before sleeping, except that bits of SysCtrl (SFR 0x80), SLEEP1, SLEEP0, FWC and FSC,
are cleared. When bits RTC/CF (bit2 of Systate, SFR 0xA1) and CFWK (bit3 of IOWKDET, SFR 0xAF) are
read out as 1s, it indicates the system was woken up by CF pulse output.
Table 10-13 Configurations for Energy Pulse Generation Rate and CF Pulse Output
0x287F CFWD 00: 80ms; 01: 40ms; 10: 20ms; 11: 10ms.
There is an anti-creeping accumulator in the no-load detection circuit. When no-load detection is
enabled, 1s are accumulated in this register constantly. When MTCLK frequency is 3.2768MHz,
1.6384MHz or 819.2kHz, the accumulation frequency is 12800Hz; and when MTCLK frequency is 32768Hz,
the accumulation frequency is 2979Hz.
When no-load detection is enabled, constant 1s are accumulated into the embedded anti-creeping
accumulator, and the energy accumulator in E1 or E2 path accumulates active or reactive power or a
power constant. Preset a threshold for no-load detection in register GATECP (0x10F5) or GATECQ
(0x10FB), and a threshold for energy-to-pulse conversion in register GATEP (0x10F4) or GATEQ (0x10FA).
Compare the accumulation rate. If the energy accumulator overflows sooner, the anti-creeping
accumulator is cleared, and E1 or E2 path starts to meter energy. Otherwise, E1 or E2 path enters
creeping state. Users can read bit CRPST or CRPSTR (bit7 or bit6 of CRPST, 0x287F) to detect the state of
the path.
When POR/BOR, RSTN pin reset or WDT overflow reset occurs, the mentioned threshold registers are
reset to their default values, 0s.
The energy accumulators are of actual 42-bit length, but the threshold registers for energy-to-pulse
conversion are of 32-bit length. So, the threshold registers will be padded with a string of 10 0s on the
right to work as 42-bit registers.
PMCtrl4 CRPENR, Bit7 To enable no-load detection of E2 path. 0: disable (default); 1: enable.
0x287D CRPEN, Bit6 To enable no-load detection of E1 path. 0: disable (default); 1: enable.
CRPST CRPST, Bit7 To indicate the state of E1 path. 0: metering energy; 1: creeping.
0x287F CRPSTR, Bit6 To indicate the state of E2 path. 0: metering energy; 1: creeping.
BPF
u(t) From HPF ZERO
0x10FD
CROSSING
32
16
32
DATAFREQ
DETECTION
f
f = ADC Equation 10-6
FRQ
where, f is the line frequency to be measured; FRQ is the content of register DATAFREQ (0x10FD) in the
form of decimal.
The line frequency register is a 16-bit, unsigned register. When POR/BOR, RSTn pin reset or WDT
overflow reset occurs, this register is reset to its default state. The measurement resolution is 0.05Hz/lsb,
and the measurement range is over 35~75Hz. When MTCLK frequency is 3.2768MHz, this register is
updated in 320ms, and is settled in 500ms.
Note: When MTCLK frequency is lowered to 819.2kHz, the sampling frequency of the enabled band-pass
filter in the RMS calculation circuit is changed to 800Hz and the center frequency is changed to 12.5Hz,
which has a greater attenuation on 50Hz signals and will reduce the accuracy of the RMS calculation and
line frequency measurement. So, if MTCLK frequency is reduced to 819.2kHz, users must disable energy
accumulation, CF pulse output and no-load detection, and then configure this register to 0x911D3C9C.
The M Channel can be used to measure the ground, temperature, battery voltage and external voltage
signals. As illustrated in the following figure, there is only one ADC in M Channel, so users must configure
registers to use this channel to measure one signal at a time.
MEAS[2:0]
Resistive
Voltage Divider
Temp.
AVSS
V
BAT
RESDIV_N
MUX
M1 R1
Vm M Channel
M2
RESDIV ADC
R2
RESDIV
R1+R2=30kΩ
ONM Instantaneous DC
component
0 0
Average DC
component
Raw waveform
In 50Hz power grid, when MTCLK frequency is 3.2768MHz, DATAOM is updated in 0.3ms and settled in
10ms; DATADM is updated in 20ms and settled in 70ms; DATAADM is updated in 1.28s and settled in 3s.
If MTCLK frequency is divided by a coefficient K, the update and settle time is K times of that for
3.2768MHz MTCLK frequency.
11. Interrupt
When POR/BOR, RSTn pin reset, WDT overflow event, power supply restoration event, IO/RTC wakeup
event or debugging event occurs, the interrupt control module is reset to its default state.
CLK1 provides clock pulses for the interrupt control module, so when the system enters LPM1 state or
LPM2 state, the interrupt control module stops running to save power. Each extended interrupt can be
gate controlled independently via configuring register PRCtrl1 (0x2D01).
- 1 zero-crossing interrupt;
- 1 power-down interrupt;
- 1 comparator interrupt;
In the V9821 the interrupts triggered by peripheral events are called Extended Interrupt. They are
named after the polling sequence; for example, Interrupt 8 is named because the polling sequence of the
extended interrupt handler located at 43h is 8. Additionally, an extended interrupt may be triggered by
more than one event (interrupt sources); for example, both transmitter data output interrupt and receiver
data input interrupt of UART2 can trigger the program execution to service the interrupt handler located
at 43h (Interrupt 8).
Take Interrupt 8 as an example to introduce how to trigger an interrupt, service and clear the interrupt
flag, and detect the event that triggers an extended interrupt. Only when the global enable bit IE.7 and
the enable bit for Interrupt 8 (EIE.0) is set to 1, will Interrupt 8 be triggered if any one enabled peripheral
event occurs and the flag bits of Interrupt 8 and the interrupt event is set bit. The program has to detect
the interrupt source depending on the flags and enable bits of the peripheral event when the program
enters to the interrupt subroutine located at address 43h. The processor can respond to the interrupt
event by polling or interrupt handling. When an extended interrupt is responded, the program must clear
In the V9821, there are two tiers of interrupts: Interrupt Priority 1 and Interrupt Priority 0. Registers IP
(SFR 0xB8) and EIP (SFR 0xF8) can configure the priority of the interrupts. Interrupt Priority 1 takes
precedence over Interrupt Priority 0. In addition to an assigned priority level (1 or 0), each interrupt has
a polling sequence. An interrupt with a small polling sequence number means that it must be serviced
firstly when two interrupts of the same tier occur simultaneously. If two interrupts of different priority
occur, the one of Interrupt Priority 1 is serviced firstly. Only an interrupt of higher priority level can break
the service routine of the interrupt currently being serviced; when the new interrupt is serviced, the
program will go back where it was interrupted and serve the last interrupt.
Enable
Polling Vector Interrupt Enable bit of Flag of Flag of peripheral
Description bit of
sequence address No. 1
peripheral event interrupt event
interrupt
5 23h 4 Reserved.
1
When Keil IDE is applied, users must use Interrupt No. to check the interrupts.
Reserved.
Reserved.
Reserved.
Reserved.
X0EN (bit7 of
Zero-crossing interrupt. 0x287A) ExInt4IFG.5
ExInt4IE.5
Reserved.
Reserved.
Reserved.
IO interrupt 0 1
IE0
IT0
Respond to the interrupt to clear the flag
bit.
Timer0 TF0
Respond to the interrupt to clear the flag
bit.
1 1
IE1
IT1
Timer1 TF1
Respond to the interrupt to clear the flag
bit.
TF2
Timer2
EXF2
RI1
UART1
TI1
Polling Sequence
RI
UART2/
UART4 TI
Interrupt 8
TF0 EXIF.4
CF1 IR7
RI
UART5 TI
Interrupt 9 TF0
EXIF.5
RTC IR6
CF2 IR7
RTC IR0
IO interrupt INT2
2
REF leakage
IR4
interrupt
Zero-crossing IR5
interrupt
IR0
IR1
TimerA
IR2
IR3 EXIF.7
Interrupt 11
IR4
GPSI
IR5
Comparator IR6
Interrupt 12 EICON.3
Enable
Enable bit Enable bit
bit Global enable
bit (EA)
Bit Description
1: indicating that each interrupt is enabled or disabled by its individual enable bit.
1: to enable transmitter data output interrupt of UART1 triggered by the flag TI1 or receiver
IE.6 ES1
data interrupt of UART1 triggered by the flag RI1.
Bit Description
Bit Description
Interrupt 11 flag. When this bit is set to 1, it indicates that Interrupt 11 was
EXIF.7 IE5 triggered. IE5 must be cleared by software. When Interrupt 11 was enabled, setting
IE5 by software can trigger an interrupt.
Interrupt 10 flag. When this bit is set to 1, it indicates that Interrupt 10 was
EXIF.6 IE4 triggered. IE4 must be cleared by software. When Interrupt 10 was enabled, setting
IE4 by software can trigger an interrupt.
Interrupt 9 flag. When this bit is set to 1, it indicates that Interrupt 9 was triggered.
EXIF.5 IE3 IE3 must be cleared by software. When Interrupt 9 was enabled, setting IE3 by
software can trigger an interrupt.
Interrupt 8 flag. When this bit is set to 1, it indicates that Interrupt 8 was triggered.
EXIF.4 IE2 IE3 must be cleared by software. When Interrupt 8 was enabled, setting IE2 by
software can trigger an interrupt.
Bit Description
UART1 baud rate double enable bit. Set this bit to 1 to double the baud rate for
EICON.7 SMOD1
UART1 serial interface.
EICON.5 Reserved.
EICON.4 Reserved.
Power-down Interrupt (Interrupt 12) flag. When this bit is set to 1, it indicates
that a power-down interrupt was triggered. This flag must be cleared by
EICON.3 PFI software before exiting the interrupt service routine. Otherwise, the interrupt
will occur again. When Interrupt 12 was enabled, setting this flag by software
can trigger a power-down interrupt.
Bit Description
Set this bit to 1 to configure UART1 transmit or receive interrupt (RI1 or TI1) to
IP.6 PS1
Interrupt Priority 1. Clear this bit to configure it to Interrupt Priority 0.
Set this bit to 1 to configure Timer2 interrupt (TF2 or EXF2) to Interrupt Priority 1. Clear
IP.5 PT2
this bit to configure it to Interrupt Priority 0.
Set this bit to 1 to configure Timer1 interrupt (TF1) to Interrupt Priority 1. Clear this bit
IP.3 PT1
to configure it to Interrupt Priority 0.
Set this bit to 1 to configure IO Interrupt 1 to Interrupt Priority 1. Clear this bit to
IP.2 PX1
configure it to Interrupt Priority 0.
Set this bit to 1 to configure Timer0 interrupt (TF0) to Interrupt Priority 1. Clear this bit
IP.1 PT0
to configure it to Interrupt Priority 0.
Set this bit to 1 to configure IO Interrupt 0 to Interrupt Priority 1. Clear this bit to
IP.0 PX0
configure it to Interrupt Priority 0.
Bit Description
Set this bit to 1 to configure Interrupt 12 (Power-down interrupt) Interrupt Priority 1. Clear this
EIP.4
bit to configure it to Interrupt Priority 0.
Set this bit to 1 to configure Interrupt 11 Interrupt Priority 1. Clear this bit to configure it to
EIP.3
Interrupt Priority 0.
Set this bit to 1 to configure Interrupt 10 Interrupt Priority 1. Clear this bit to configure it to
EIP.2
Interrupt Priority 0.
Set this bit to 1 to configure Interrupt 9 Interrupt Priority 1. Clear this bit to configure it to
EIP.1
Interrupt Priority 0.
Set this bit to 1 to configure Interrupt 8 Interrupt Priority 1. Clear this bit to configure it to
EIP.0
Interrupt Priority 0.
Main Program
Interrupt
ISR ISR ISR
Priority 1
RETI
Interrupt
ISR ISR ISR ISR ISR ISR
Priority 0
A B C D Polling sequence:
low to high
- The program jumps to the interrupt vector address to execute the interrupt service routine (ISR) of
the interrupt. An ISR being executed can only be interrupted by one of the interrupt with higher
priority. Each ISR ends with an RETI (return from interrupt) instruction, as shown as A in the
preceding figure.
- After executing the RETI, the program returns to the place where it was interrupted, as if it did not
leave off, to execute the next instruction that would have been executed if the interrupt had not
occurred. The program always completes an instruction in progress before servicing an interrupt. If
an instruction executed in progress is RETI, or a write operation to registers including IP SFR, IE SFR,
EIP SFR, and EIE SFR, the program will complete one additional instruction before servicing the ISR.
- In the V9821, Interrupt Priority 1 has higher priority than Interrupt Priority 0. So, the ISR of Interrupt
Priority 0 only can be interrupted by the ISR of Interrupt Priority 1, as shown as B and C in the
preceding figure.
- An ISR of Interrupt Priority 0 can be intruded by one of Interrupt Priority 1. When the latter one is
executed, the program will return to the place at the vector address of the former one where it was
interrupted to execute the ISR, and then, execute the instruction RETI to finish the ISR, as shown as
B in the preceding figure.
- When two interrupts of the same tier (Interrupt Priority 1 or Interrupt Priority 0) occur simultaneously,
the polling sequence of them is observed, as shown as D in the preceding figure.
11.4.1. Interrupt 8
Interrupt 8 can be triggered by 7 interrupt events which are listed in the following table. Bit ExInt2 (bit0
of PRCtrl1, 0x2D01) gate controls Interrupt 8.
Interrupt 8
Interrupt Event Enable bit Flag (R/W)
Vector Address Enable Bit Flag (R/W)
Default 0 X 0 0 0 0 0 0
A flag bit can be set to 1 only when the corresponding interrupt was enabled. When an interrupt was
enabled, writing 1 to the corresponding flag bit can trigger the interrupt. Otherwise, however, cannot.
Default 1 X 1 1 1 1 1 1
These bits must be set to their default values for proper operation.
- - - - - - - EDGO
Default - - - - - - - 1
These bits must be set to their default values for proper operation.
Default 0 X 0 0 0 0 0 0
Default 0 X 0 0 0 0 0 0
If an interrupt is triggered again when the corresponding flag in the register ExInt2IFG has not been
cleared yet, the corresponding pending bit of this register will be set to 1. The pending bit is just an
indication flag, nothing to do with the interrupt. It must be cleared by the program.
11.4.2. Interrupt 9
Interrupt 9 can be triggered by 5 interrupt events which are listed in the following table. Bit ExInt3 (bit1
of PRCtrl1, 0x2D01) gate controls Interrupt 9.
Interrupt 9
Interrupt Event Enable Bit Flag (R/W)
Vector Address Enable Bit Flag (R/W)
Default 0 0 0 X 0 0 X X
A flag bit can be set to 1 only when the corresponding interrupt was enabled. When an interrupt was
enabled, writing 1 to the corresponding flag bit can trigger the interrupt. Otherwise, however, cannot.
Default 1 1 1 X 1 1 X X
These bits must be set to their default values for proper operation.
- - - - - - - EDGO
Default - - - - - - - 1
These bits must be set to their default values for proper operation.
Default 0 0 0 X 0 0 X X
Default 0 0 0 X 0 0 X X
If an interrupt occurs again when the corresponding flag in the register ExInt3IFG has not been cleared
yet, the corresponding pending bit of this register will be set to 1. The pending bit is just an indication flag,
nothing to do with the interrupt. It must be cleared by the program.
11.4.3. Interrupt 10
Interrupt 10 can be triggered by 5 interrupt events which are listed in the following table. Bit ExInt4
(bit2 of PRCtrl1, 0x2D01) gate controls Interrupt 10.
Interrupt 10
Default X X 0 0 0 0 X 0
A flag bit can be set to 1 only when the corresponding interrupt was enabled. When an interrupt was
enabled, writing 1 to the corresponding flag bit can trigger the interrupt. Otherwise, however, cannot.
Default X X 1 1 1 1 X 1
These bits must be set to their default values for proper operation.
- - - - - - - EDGO
Default - - - - - - - 1
These bits must be set to their default values for proper operation.
Default X X 0 0 0 0 X 0
Default 0 X 0 IPND4 0 0 X 0
If an interrupt occurs again when the corresponding flag in the register ExInt4IFG has not been cleared
yet, the corresponding pending bit of this register will be set to 1. The pending bit is just an indication flag,
nothing to do with the interrupt. It must be cleared by the program.
11.4.4. Interrupt 11
Interrupt 11 can be triggered by 7 interrupt events which are listed in the following table. Bit ExInt5
(bit3 of PRCtrl1, 0x2D01) gate controls Interrupt 11.
Interrupt 11
Interrupt Event Enable Bit Flag (R/W)
Vector Address Enable Bit Flag (R/W)
*When bit GPSI (bit6 of PRCtrl0, 0x2D00) is set to 1, GPSI (general-purpose serial interface) is enabled.
Writing of illegal data or transmit completion will trigger interrupt to MCU.
Default X 0 0 0 0 0 0 0
A flag bit can be set to 1 only when the corresponding interrupt was enabled. When an interrupt was
enabled, writing 1 to the corresponding flag bit can trigger the interrupt. Otherwise, however, cannot.
Default X 1 1 1 1 1 1 1
These bits must be set to their default values for proper operation.
- - - - - - - EDGO
Default - - - - - - - 1
These bits must be set to their default values for proper operation.
Default X 0 0 0 0 0 0 0
Default X 0 0 0 0 0 0 0
If an interrupt occurs again when the corresponding flag in the register ExInt5IFG has not been cleared
yet, the corresponding pending bit of this register will be set to 1. The pending bit is just an indication flag,
nothing to do with the interrupt. It must be cleared by the program.
12. UART/Timers
When power-on or brown out reset (POR/BOR), RSTn pin reset, WDT overflow, power supply restoration
event, IO/RTC wakeup event or debugging reset occurs, all the timers and the UART serial interfaces are
reset to their default states. In LPM1 state or LPM2 state, they stop working. Each extended UART serial
interface and TimerA can be gate controlled independently via configuring register PRCtrl0 (0x2D00) and
PRCtrl1 (0x2D01).
12.1. Timers/Counters
The V9821 can provide users with timers listed as follows:
Timer0, Timer1 and Timer2 of 8052 microcontroller. They work as general timers; furthermore,
Timer1 can work as the baud rate generator of UART1;
The general timer and specific baud rate generator of each extended UART serial interface
(UART2/UART4/UART5). Each interface can be gate controlled independently. The general timer has
the same function with Timer0, an overflow event of which will set a flag bit to 1, which will be cleared
by executing interrupt service routine (ISR) or by polling interrupt sources, and generate an interrupt
to the MCU. The specific baud rate generator has the same function with Timer1: it can be used as a
general timer, an overflow event of which can set the flag bit to 1 but cannot generate an interrupt to
the MCU.
In this section, only TimerA, Timer0, Timer1 and Timer2 are introduced. The general timers in extended
UART serial interfaces are introduced in “UART”.
12.1.1. TimerA
TimerA is a 16-bit timer/counter, and has 4 operation modes. It has 3 compare/capture modules, and 3
configurable output units with 8 output modes. Bit TimerA (bit0 of PRCtrl0, 0x2D00) gate controls TimerA.
TAIFG
CLR
TACCR0
TACCR1
TACCR2
Comparator2
CMx
COV
16-bit TACCR2
capture
TA2 15 0 EQU2
mode
0
CCI CCIFG
1
SCCI Latch
CAP
OUT
Output
Unit 2
EQU0
Logic OUT2 Signal
OUTMODx
Address Description
0x2903 Bit[7:0] The registers give the value of TimerA (TAR), of which the low byte is in the
register located at address 0x2902, and the high byte is in 0x2903. It is
0
read-only, and can be reset by software. When TimerA overflows, an
0x2902 Bit[7:0]
interrupt is generated to the MCU.
These bits are used to select the divider for the input clock.
Bit7 ID1
ID1 ID0 Description
Bit3 TSEL - To select the clock source for the timer. 0: fMCU /128; 1: fMCU.
Set the bit CLR to 1 to clear the register TAR, meanwhile, [ID1, ID0]=00; if the
Bit2 CLR 0 timer works in Up/Down mode, the timer rolls over to 0000h, and back up to the
value of TACCR0.
When the bit EX3 (EIE.3) is set to 1, set this bit to 1 to enable TimerA overflow
Bit1 TAIE 0
interrupt. When this bit is cleared, the interrupt is disabled.
In the Up Mode, when the timer rolls over to 0000h from the value of TACCR0,
TAIFG is set bit.
Bit0 TAIFG 0 In the Continuous Mode, when the timer rolls over to 0000h from FFFFh, TAIFG is
set bit.
In the Up/Down Mode, when the timer counts down to 0000h from 0001h, TAIFG
is set bit.
FFFFh
Continuous Mode
Stop Mode Up to FFFFh, rolls over to 0000,
Timer is halted. back up to FFFFh, etc.
FFFFh FFFFh
TACCR0 TACCR0
In Up Mode, when the value of the register TACCR0 is changed while the timer is running,
- if the new value is not less than the former value or current counts, the timer will count up to the
new TACCR0 value, and then rolls over to 0000h;
- if the new value is less than current counts, the timer will count to the former value firstly, rolls
over to 0000h, and then counts to the new TACCR0 value.
In Up/Down Mode,
- when the value of the register TACCR0 is changed while the timer is counting in the down direction,
the timer continues its direction until it counts down to 0000h, and then it counts up to the new
- when the value of the register TACCR0 is changed while the timer is counting in the up direction:
if the new value is not less than the former value or current counts, the timer counts up to the
new TACCR0 value before counting down;
if the new value is less than current counts, the timer will count to the former value firstly,
counts back to 0000h, and then counts up to the new TACCR0 value.
In Continuous Mode, the output frequency is configurable, as illustrated in the following figure. This
operation mode can be used to generate independent output frequencies.
TACCR0b
FFFFh
TACCR1b TACCR0c
TACCR1a TACCR1e
TACCR1d TACCR0d
TACCR0a TACCR1c
TACCR1f
t0 t0 t0
t1 t1 t1 t1 t1
Bit9 Reserved 0 Read-only. This bit is read out as 0 all the time.
Bit8 CAP 0 To select capture or compare mode. 0: Compare Mode; 1: Capture Mode.
Low byte To select the output mode, see Figure 12-4 for description of the pulse output.
0x2904 0 0 0 Output To output the value of the bit OUT on the pin TAx.
†
x can be equal to 0/1/2 to represent the TimerA Capture/Compare Module 0/1/2 control register.
0 1 0 Toggle When TAR= TACCRx (x=1~2), the output on the corresponding pin
And this mode is not for the output on the pin TA0.
Bit5 OUTMOD0 When TAR= TACCRx (x=0~2), the output on the corresponding pin
1 0 1 Reset
TAx is reset. It remains reset until another output mode is selected.
Bit4 CCIE 0 Interrupt enable bit, to enable TimerA compare/capture interrupt. 0: disable; 1: enable.
Bit3 CCI 0 To read the captured input signal (via configuring the bits CCIS1/CCIS0).
When the bits OUTMOD2, OUTMOD1 and OUTMOD0 are cleared, the value of this is output on the pins TAx
Bit2 OUT 0
(x=0~2).
In capture mode, when COV is read out as 0, the capture signal is reset, and the capture event cannot set
this bit to 1.
Bit1 COV 0
In capture mode, when COV is read out as 1, if a capture event occurs when the value of the last capture
has not been read out, COV is set bit.
This bit must be reset by program. Reading the captured signal cannot reset this bit.
In capture mode: when the value of the register TAR is captured into the registers TACCR0/1/2, this flag
bit will be set bit.
In compare mode: when the value of the register TAR is equal to that of the registers TACCR0/1/2 (EQUx
signal), this flag bit will be set bit.
Bit0 CCIFG 0
In Compare/Capture Module 0, when the interrupt request is responded, this flag bit will be reset
automatically.
In Compare/Capture Module 1/2, when the interrupt request is responded, the CCIFG flag is reset; if the
corresponding enable bit is cleared, this flag bit still will be set bit, which must be cleared by program, but
no interrupt will be generated.
FFFFh
TACCR0
TACCR1
0h
OUTMODx=1, Set
OUTMODx=2, Toggle/Reset
OUTMODx=3, Set/Reset
OUTMODx=4, Toggle
OUTMODx=5, Reset
OUTMODx=6, Toggle/Set
OUTMODx=7, Reset/Set
TAIFG
CCIFG
TAR=TACCR0 (EQU0)
CCIFG
TAR=TACCR1 (EQU1)
FFFFh
TACCR0
TACCR1
0h
OUTMODx=1, Set
OUTMODx=2, Toggle/Reset
OUTMODx=3, Set/Reset
OUTMODx=4, Toggle
OUTMODx=5, Reset
OUTMODx=6, Toggle/Set
OUTMODx=7, Reset/Set
TAIFG
CCIFG
TAR=TACCR0 (EQU0)
CCIFG
TAR=TACCR1 (EQU1)
FFFFh
TACCR0
TACCR1
0h
OUTMODx=1, Set
OUTMODx=2, Toggle/Reset
OUTMODx=3, Set/Reset
OUTMODx=4, Toggle
OUTMODx=5, Reset
OUTMODx=6, Toggle/Set
OUTMODx=7, Reset/Set
TAIFG
CCIFG
TAR=TACCR0 (EQU0)
CCIFG
TAR=TACCR1 (EQU1)
12.1.2. Timer0/Timer1/Timer2
When the bits in CKCON (SFR 0x8E), CKCON.5, CKCON.4 and CKCON.3, are set bit, the associated
timers increment by ones every clock cycle (clk). When they are cleared, the associated timers increment
by ones every 12 clock cycles (clk/12). The timers are independent of each other. By default the above
three bits are cleared.
Bit Description
12.1.2.2. Timer0/Timer1
Timer0 and Timer1 are two of three embedded timers of 8052 microcontroller. Both timers can act as a
timer to count the MCU clock frequency, or act as a counter to count the input signals. Furthermore,
Timer1 also can act as a baud rate generator of UART1 for serial communication.
There are 4 operation modes for Timer0 and Timer1. They are determined by TMOD (SFR 0x89) and
TCON (SFR 0x88). The four modes are:
- TL0 (SFR 0x8A) and TH0 (SFR 0x8C), the lower byte and higher byte of Timer0.
- TL1 (SFR 0x8B) and TH1 (SFR 0x8D), the lower byte and higher byte of Timer1.
Table 12-6 Timer0/1 Mode Control Special Function Register (TMOD, SFR 0x89)
Bit Description
Bit7 Timer1 gate control bit. If the bit TR1 (TCON.6) is set bit and the signal on the pin INT1
GATE is high, Timer1 runs when this bit is set to 1. If this bit is cleared, Timer1 runs when TR1
TMOD.7 is set to 1, regardless of the state of the pin INT1.
When this bit is cleared, Timer1 acts as a timer to count the clock pulse (clk or clk/12,
Bit6 depending on the bit T1M, CKCON.4). When this bit is set bit, Timer1 acts as a counter
C/T
TMOD.6 driven by the input signal on the pin T1 and counts the 1-0 transitions of the input
signal.
Bit3 Timer0 gate control bit. If the bit TR0 (TCON.4) is set bit and the signal on the pin INT0
GATE is high, Timer0 runs when this bit is set bit. If this bit is cleared, Timer0 runs when TR0
TMOD.3 is set bit, regardless of the state of the pin INT0.
Timer or counter select bit. When this bit is cleared, Timer0 acts as a timer to count the
Bit2 clock pulse (clk or clk/12, depending on the bit T0M, CKCON.3). When this bit is set bit,
C/T
TMOD.2 Timer0 acts as a counter driven by the input signal on the pin T0 and counts the 1-0
transitions of the input signal.
Bit1 M1 M0 Mode
M1
TMOD.1 0 0 Mode 0: 13-bit timer/counter.
Table 12-7 Timer0/1 Control Special Function Register (TCON, SFR 0x88)
Bit Description
Bit7 Timer 1 overflow flag. It is set bit when Timer1 overflows. It is cleared when the processor
TF1 vectors to execute interrupt service routine located at program address 0x001B
TCON.7 (“Interrupt Resources”).
Bit5 Timer0 overflow flag. It is set bit when Timer0 overflows. It is cleared when the processor
TF0 vectors to execute interrupt service routine located at program address 0x000B
TCON.5 (“Interrupt Resources”).
Bit2 IO Interrupt 1 signal type control bit. When IT1 is set bit, IO Interrupt 1 is triggered when
IT1 a 1-to-0 transition of the input signal is detected on the pin INT1. When IT1 is cleared, IO
TCON.2 Interrupt 1 is triggered when a low level input signal is detected on the pin INT1.
Bit0 IO Interrupt 0 signal type control bit. When IT0 is set bit, IO Interrupt 0 is triggered when
IT0 a 1-to-0 transition of the input signal is detected on the pin INT0. When IT0 is cleared, IO
TCON.0 Interrupt 0 is triggered when a low level input signal is detected on the pin INT0.
In Mode 0, Timer0 and Timer1 act as a 13-bit timer/counter. In this mode, the lower byte of
Timer0/Timer1 (TLx, SFR 0x8A or SFR 0x8B) counts from 0 to 31. When it increments from 31, TLx SFR
(x=0~1) is cleared, and the higher byte of the timer (THx, SFR 0x8C or SFR 0x8D) increments by 1. In
this mode, only 13 bits of Timer0/Timer1, Bit0~Bit4 of TLx SFR and all 8 bits of THx SFR, are active. The
upper three bits of TLx SFR are indeterminate in Mode 0 and must be masked when the software evaluates
the register.
Users can configure the bit (TR0 or TR1, Bit4 or Bit6 of TCON SFR) to run Timer0 or Timer1. In the
V9821, according to the value of the bit C/T (Bit6 or Bit2 of TMOD SFR), Timer0 or Timer1 can act as a
timer or a counter.
When the bit GATE (Bit7 or Bit3 of TMOD SFR) is cleared or set bit, and the input signal on the pin INT0
or INT1 is active, Timer0 or Timer1 runs when TRx (x=0~1, TCON.4 or TCON.6) is set bit.
When the 13-bit timer increments from 0x1FFF, it rolls over to all zeros, and then the bit TF0 (TCON.5)
In Mode 1, Timer0 and Timer1 act as 16-bit timers/counters. In this mode, all eight bits of the lower
byte of the timers, TL0 (SFR 0x8A) or TL1 (SFR 0x8B), are active, so, TLx SFR increments from 0 to 255.
When the TLx SFR increments from 255, it is cleared, and the higher byte of the timer, THx SFR (TH0 SFR
or TH1 SFR), increments by 1. The timer will roll over to all zeros when the timer/counter increments from
0xFFFF.
MODE1
TR0 (or TR1)
0 TH0 (or TH1) 7
GATE
INT0
(or INT1)
INT
TF0 (or TF1)
In Mode 2, only the lower byte of Timer0/Timer1 (TLx SFR, x=0~1) acts as an 8-bit timer/counter, while
the higher byte of it (THx SFR, x=0~1) holds a value that will be loaded into TLx SFR every time TLx SFR
overflows. When the value is loaded into the TLx SFR, the timer will increment from the loaded value.
For example, TH1 SFR is set to 200, and when TL1 SFR increments from 255, it rolls to 200, and
recounts from 200 to 255, and then to 200, and repeats.
GATE
INT
TF0 (or TF1)
In Mode 3, Timer0 becomes two completely separate 8-bit timers/counters. When Timer0 is set to work
in this mode, TR0 (TCON.4) and TF0 (TCON.5) are used by TL0 SFR, but TR1 (TCON.6) and TF1 (TCON.7)
are used by TH0 SFR, so Timer1 stops running as a general timer but still can be used as a baud rate
generator.
When Timer0 works in Mode3, Timer1 still can be enabled via configuring its operation mode to Mode
0/1/2, but no interrupt will be generated by it, because the flag TF1 is used by Timer0. When Timer1 is
configured to work in Mode 3, it stops running, but holds its counts.
clk 0
C/T TL0
0 7
1 0 clk
clk
1
T0
TF0 INT
TR0
GATE
INT0
INT1 TF1 INT
TR1
0 TH0 7
12.1.2.3. Timer2
Besides Timer0 and Timer1, there is a third timer, Timer2, in 8052 microcontroller, a 16-bit timer, has
a number of new functions. The modes for Timer2 are:
- 16-bit timer/counter.
- RCAP2L (SFR 0xCA) – To capture the value of TL2 SFR when Timer 2 is configured in capture mode,
or, to hold the lower byte of the loaded value when Timer 2 is configured in auto-reload mode.
- RCAP2H (SFR 0xCB) –To capture the value of TH2 SFR when Timer 2 is configured in capture
mode, or, to hold the higher byte of the loaded value when Timer 2 is configured in auto-reload
mode.
Bit Description
Bit6 When EXEN2 is set bit, EXF2 will be set bit when a 1-to-0 transition of the input signal
EXF2 on the pin T2EX is detected, which can trigger an auto-reload or capture event. EXF2
T2CON.6
must be cleared by the program. Writing 1 to EXF2 can force the Timer 2 external
interrupt if it is enabled.
Bit5 Reserved.
RCLK
T2CON.5 By default it is 0.
Bit4 Reserved.
TCLK
T2CON.4 By default it is 0.
Timer or counter select bit. When C/T2 is cleared, Timer2 acts as a timer to count the
Bit1 clock pulses (clk or clk/12, depending on the bit T2M, CKCON.5). When C/T2 is set
C/T2
T2CON.1 bit, Timer2 acts as a counter driven by the input signal on the pin T2 and counts the
1-to-0 transitions of the input signals.
Capture/reload flag.
When CP/RL2 and EXEN2 are set bit, the current counts will be captured into the
Bit0 registers RCAP2L SFR and RCAP2H SFR when a 1-to-0 transition of the input signal
CP/RL2 on the pin T2EX is detected. When CP/RL2 is cleared, but EXEN2 is set bit, an
T2CON.0
auto-reload event will occur when a 1-to-0 transition of the input signal on the pin
T2EX is detected. If either RCLK or TCLK is set bit, CP/RL2 cannot work, and Timer2
can operate in auto-reload mode on overflow.
1 X X 1 Reserved.
X 1 X 1 Reserved.
X X X 0 Stop working
In this mode, users can configure the register T2CON SFR to enable Timer2 to act as a 16-bit timer or
a 16-bit counter (C/T2, T2CON.1), and to enable Timer2 to run (TR2, T2CON.2). In this mode, Timer2
increments from 0000h to FFFFh, and then rolls over to all zeros, setting the flag TF2 (T2CON.7) to 1,
which generate an interrupt to MCU.
When CP/RL2 (T2CON.0) and EXEN2 (T2CON.3) are set bit, the values of TH2 SFR and TL2 SFR are
captured and loaded into the registers RCAP2L SFR and RCAP2H SFR when a 1-to-0 transition of the input
signal on the pin T2EX is detected. At the same time, the flag EXF2 (T2CON.6) is set bit, which will
generate an interrupt to the processor if it is enabled.
T2M
clk/12
clk 0
C/T2
0 7 8 15
1 0
clk
clk TL2 TH2
1
T2
TR2
INT
When CP/RL2 (T2CON.0) is cleared, Timer2 acts as a 16-bit counter/timer in auto-reload mode.
In this mode, the MCU must write the reload value to the registers RCAP2L (SFR 0xCA) and RCAP2H
(SFR 0xCB). When the timer increments from FFFFh, the value stored in RCAP2L will be reloaded into the
register TL2 (SFR 0xCC), and the value stored in RCAP2H will be reloaded into the register TH2 (SFR
0xCD), at the same time, TF2 is set bit, which will generate an interrupt to the processor if it is enabled.
When CP/RL2 is cleared, but EXEN2 (T2CON.3) is set bit, an auto-reload event occurs when a 1-to-0
transition of the input signal on the pin T2EX is detected, at the same time, the flag EXF2 (T2CON.6) is set
bit, which will generate an external interrupt to the processor if it is enabled.
T2M
clk/12
clk 0
C/T2
0 7 8 15
1 0 clk
clk TL2 TH2
1
T2
TR2
INT
12.2. UART
In V9821, there are 4 active UART serial interfaces on the chip, including UART1 of 8052 microcontroller
and the extended UART2, UART4 and UART5 serial interfaces. Bits UART2, UART4 and UART5 (bit4, bit6
and bit7 of PRCtrl1, 0x2D01) gate controls the corresponding UART serial interfaces.
The UART serial interfaces can work in 4 modes. In Mode 0, the serial interface can only receive data on
the RXD port and output shifting clock on the TXD port. In other modes, the extended UART serial
interfaces can work like UART1 serial interfaces of 8052 microcontroller.
12.2.1. UART1
UART1 uses Timer1 to generate baud rate, and the bit SMOD1 (EICON.7) controls doubling the baud
rate of UART1.
Table 12-10 UART1 Control Special Function Register (SCON1, SFR 0xC0)
Bit Description
Multiprocessor communication enable bit. In Mode2 and Mode3, SM2_1 enables the
multiprocessor communication. In Mode2 and Mode3, when SM2_1 is set bit, RI_1
Bit5 cannot be set bit in case that the received 9th bit is 0. In Mode1, when SM2_1 is set
SM2_1
SCON1.5 bit, RI_1 will be set bit only if a valid stop bit is received. In Mode0, SM2_1 establishes
the baud rate: when SM2_1 is cleared, the baud rate is clk/12; when SM2_1 is set to
1, the baud rate is clk.
Bit3
TB8_1 To define the 9th bit to be transmitted in Mode2 or Mode3.
SCON1.3
Bit2 In Mode2 and Mode3, RB8_1 is to store the received 9th bit. In Mode1, the stop bit is
RB8_1
SCON1.2 stored as the RB8_1. In Mode0, RB8_1 is not used.
Transmit interrupt flag. If this bit is set bit, it indicates that the transmit data has been
Bit1 shifted out. In Mode0, TI_1 is set bit at the end of the 8 th bit. In other modes, TI_1 is
TI_1
SCON1.1 set bit when the stop bit is placed on the pin TXD1. TI_1 must be cleared by the
program.
Receive interrupt flag. If this bit is set bit, it indicates that a serial data has been
Bit0 received. In Mode 0, RI_1 is set bit at the end of the 8 th data bit. In Mode1, according
RI_1 to the state of SM2_1, RI_1 is set bit after the last sample of the incoming stop bit. In
SCON1.0 Mode2 and Mode3, RI_1 is set bit at the end of the last sample of the 9 th bit. RI_1
must be cleared by the program.
All the extended UART serial interfaces have the same architecture, but only UART2 has an optional 38
kHz carrier wave modulator.
In each extended UART serial interface, there are a general timer (compatible with Timer0) and a baud
rate generator (compatible with Timer1). The overflow of general timer can set a flag bit which will be
cleared by executing interrupt service routine (ISR) or by polling interrupt sources, and generate an
interrupt to the MCU. When the baud rate generator is used as a general timer, it can set the related
overflow flag to 1, but cannot generate an overflow interrupt. As an extended peripheral, there is a specific
control/status register for each UART interface, which can control the baud rate, select the clock sources
for the timers, disable or enable the timers, and show the overflow state of the timers.
12.2.2.1. Registers
Bit7 SMOD 0 When this bit is set to 1, the baud rate of UARTx is doubled.
Bit6 Reserved
Bit5 T1M 0 To select the clock source for the baud rate generator. 0: clk/12; 1: clk.
Bit4 T0M 0 To select the clock source for the general timer. 0: clk/12; 1: clk.
Bit1 TR1 0 Baud rate generator run control bit. 1: to run; 0: to stop.
Bit Description
Bit7 This bit must be cleared for proper operation. In this case, the baud rate generator
GATE1
TMOD2.7 runs when TR1 (Bit1 of TCONx) is set bit.
Bit6 This bit must be cleared for proper operation. In this case, the clock source for the
C/T1
TMOD2.6 baud rate generator is determined by the bit T1M (bit5 of TCONx).
Bit3 This bit must be cleared for proper operation. In this case, the general timer runs
GATE0
TMOD2.3 when TR0 (Bit0 of TCONx) is set bit.
Bit2 This bit must be cleared for proper operation. In this case, the clock source for the
C/T0
TMOD2.2 baud rate generator is determined by the bit T0M (bit4 of TCONx).
Bit Description
0 1 Mode1: 8-bit UART; baud rate, determined by the baud rate generator.
Bit6
SM1
1 0 Mode2: 9-bit UART; baud rate =clk/32 or clk/64.
SCON2.6
1 1 Mode3: 9-bit UART; baud rate, determined by the baud rate generator.
Multiprocessor communication enable bit. In Mode2 and Mode3, SM2 enables the
Bit5 multiprocessor communication. In Mode2 or Mode3, when SM2 is set bit, RI cannot be
SM2 set bit in case that the received 9 th bit is 0. In Mode1, when SM2 is set bit, RI will be set
SCON2.5 bit only if a valid stop bit is received. In Mode0, SM2 determines the baud rate: when
SM2 is cleared, the baud rate is clk/12; when SM2 is set bit, the baud rate is clk.
Bit3
TB8 To define the 9th bit transmitted in Mode2 and Mode3.
SCON2.3
Bit2 In Mode2 and Mode3, RB8 stores the received 9 th bit. In Mode 1, RB8 stores the received
RB8
SCON2.2 stop bit. In Mode0, RB8 is not used.
Bit1 Transmit interrupt flag. If this flag is set bit, it indicates that the transmit data has been
TI shifted out. In Mode0, TI is set bit at the end of the 8th bit. In other modes, TI is set bit
SCON2.1 when the stop bit is placed on the pin TXD2. TI must be cleared by the program.
Receive interrupt flag. If this flag is set bit, it indicates that a serial data has been
Bit0 received. In Mode0, RI is set bit at the end of the 8 th bit. In Mode1, according to the
RI state of SM2, RI is set bit after the last sample of the incoming stop bit. In Mode2 and
SCON2.0 Mode3, RI is set bit at the end of the last sample of the 9th bit. RI must be cleared by the
program.
UART2 has a 38 kHz carrier wave modulator controlled by TXD2 Type Register (Txd2FS). When bit
TXD2CARRY (bit0 of Txd2FS, 0x28CF) is cleared, pin TXD2 will output modulated signals. Users can write
of the carrier wave generation registers to configure the carrier wave frequency and its duty cycle:
𝐶𝐴𝑅𝑅𝐻
𝐷𝑢𝑡𝑦𝐶𝐴𝑅𝑅 = Equation 12-2
𝐶𝐴𝑅𝑅𝐿
where, fCARR is the carrier wave frequency; fMCU is MCU clock frequency; DutyCARR is the duty cycle of the
carrier wave; CARRH is the value of registers CARRHH and CARRHL; CARRL is the value of registers
CARRLH and CARRLL.
When the level on the pin TXD2 is low, the modulated signal is output.
Bit[7:1] Reserved X
Bit0 TXD2CARRY 0 0: with 38 kHz carrier wave; 1: without 38 kHz carrier wave.
The UART serial interfaces can work in 4 modes via configuring the mode select bits, for example, SM1
and SM2 of the register SCON2 (0x2826).
Sync. Or
Mode Baud rate Data Start or Stop Bit The 9th Bit
Async.
8-bit shift
0 Sync. clk or clk/12 8-bit None None
register
2 9-bit UART Async. clk/32 or clk/64 9-bit 1 start, 1 stop Parity bit
All the UART serial interfaces have the same architecture and functions except that:
So take UART2 for an example to introduce the work modes for UART serial interfaces.
12.2.2.3.1. Mode0
In Mode0, UART2 receives data on the pin RXD2, and outputs shift clock on the pin TXD2. Data can be
received as soon as the bit REN (bit4 of SCON2, 0x2826) is set bit and the bit RI (bit0 of SCON2, 0x2826)
is cleared. The shift clock is activated and the UART shifts data in on each rising edge of the shift clock until
eight bits have been received. The 8th bit was shifted in, and one machine cycle later, the bit RI is set bit
and the reception stops until the bit RI is cleared by the program.
12.2.2.3.2. Mode1
Mode1 provides standard asynchronous and full-duplex communication. In this mode, a data frame
contains ten bits: one start bit, eight bits of data, and one stop bit. When a data frame is received, the stop
bit is stored in the bit RB8 (bit2 of SCON2, 0x2826). On receive and transmit operation, start with the LSB.
In Mode1, the baud rate is determined by the baud rate generator overflow frequency. UART2 uses a
dedicated baud rate generator, which is compatible with Timer 1. When the baud rate generator overflows,
it generates a clock which is then divided by 16 to generate the baud rate.
2 SMODx
BaudRate= × Overflow Equation 12-3
32
Where,
Overflow is the baud rate generator overflow frequency. As for UART1, Timer1 is the baud rate generator;
as for the extended UART serial interfaces, the specific baud rate generator is used. SMODx, the value of
the bit SMOD0/1, determines to double the baud rate or not.
Generally, the baud rate generator works in the mode of 8-bit timer with auto-reload. The reload value
is stored in the register TH21 (0x2823), which makes the above equation for baud rate (clk/12 is used as
the clock source):
where, clk is the MCU clock, and TH21 is the reload value of the register TH21 (0x2823).
The bit T1M (TCON2.5) determines the clock source for the baud rate generator of UART2. When T1M is
set bit, clk is used as the clock source:
2SMODx clk
BaudRate = × Equation 12-5
32 (256 - TH21)
2SMODx × clk
TH21 = 256 - Equation 12-6
32 × BaudRate
When T1M is cleared, and the baud rate is known, users can obtain the value of TH21 via the following
equation:
2SMODx × clk
TH21 = 256 - Equation 12-7
384 × BaudRate
In Mode1, UART2 begins to transmit data after the program writing data into the register SBUF2
(0x2827). UART2 transmits data on the pin TXD2 in the following order: start bit, eight data bits (LSB
first), stop bit. The bit TI (bit1 of SCON2, 0x2826) will be set bit two clock cycles after the stop bit is
transmitted.
In Mode1, UART2 starts to receive data at the falling edge of a start bit received on the pin RXD2, when
REN (bit4 of SCON2, 0x2826) is set bit. To achieve this, every bit on the pin RXD2 should be sampled
sixteen times at any baud rate. When a falling edge of a start bit is detected, the timer used to generate
the receive clock is reset to synchronize with the received bits. To reject noise, the serial port detects the
values of the three consecutive samples in the middle of each bit. Only more than two same values can
decide the received data bit to be valid. This is especially true for the start bit. If the falling edge on the
pin RXD2 is not verified by a majority decision of three consecutive samples, then the serial port stops
receiving data and waits for another falling edge on RXD2.
When RI (bit0 of SCON2, 0x2826) is cleared, SM2 (bit5 of SCON2, 0x2826) is set bit, and the stop bit
is 1 (if SM2 is cleared, the state of stop bit does not matter), the serial port will write the received byte to
the register SBUF2 (0x2827), load the stop bit into RB8 (bit2 of SCON2, 0x2826), and set the bit RI to 1.
Otherwise, the received data lose; they cannot load data into the register SBUF2 and the bit RB8; and the
bit RI cannot be set bit.
12.2.2.3.3. Mode2
Mode2 provides asynchronous and full-duplex communication. In this mode, the data frame contains
eleven bits: one start bit, eight data bits, one programmable 9th bit, and one stop bit.
When data bits are received or transmitted, start with LSB. As to the transmitting operation, the 9 th bit
is determined by the value of the bit TB8 (bit3 of SCON2, 0x2826). If the 9th bit is used as a parity bit, the
value of the P bit (Bit 0 of PSW SFR) should be moved to TB8.
2 SMODx × clk
BaudRate= Equation 12-8
64
In Mode2, UART2 starts transmitting data after the software writing data into the register SBUF2
(0x2827). UART2 transmits data on the pin TXD2 in the following order: the start bit, eight data bits (LSB
first), the 9th bit, then the stop bit. The bit TI (bit1 of SCON2, 0x2826) is set bit when the stop bit has been
transmitted.
In Mode2, receiving data begins at the falling edge of a start bit received on the pin RXD2, when the bit
REN=1 (bit4 of SCON2, 0x2826). To achieve it, every bit on the pin RXD2 should be sampled sixteen times
at any baud rate. When a falling edge of a start bit is detected, the timer used to generate the receive
clock is reset to synchronize with the received bits. To reject noise, the serial port detects the values of the
three consecutive samples in the middle of every bit. Only more than two same values can decide the
received data bit to be valid. This is especially true for the start bit. If the falling edge on the pin RXD2 is
not verified by a majority decision of three consecutive samples, then the serial port stops receiving data
and waits for another falling edge on RXD2.
When RI (bit0 of SCON2) is cleared, SM2 (bit5 of SCON2) is set bit, and the stop bit is 1 (if SM2 is
cleared, the state of stop bit does not matter), the serial port will write the received byte to the register
SBUF2 (0x2827), load the stop bit into RB8 (bit2 of SCON2), and set the bit RI. Otherwise, the received
data lose; they cannot load data into the register SBUF2 and the bit RB8; and the bit RI cannot be set bit.
12.2.2.3.4. Mode3
Mode3 provides asynchronous and full-duplex communication. In this mode, the data frame contains
eleven bits: one start bit, eight data bits, one programmable 9th bit, and one stop bit. When data bits are
received and transmitted, start with LSB.
In Mode3, the data is transmitted or received in the same way that in Mode2. In Mode3, the baud rate
generation is identical to that in Mode1. That is, Mode3 is a combination of the communication protocol in
Mode2 and the baud rate generation in Mode1.
The multiprocessor communication is enabled in Mode2 and Mode3 when the bit SM2 (bit5 of SCON2,
0x2826) is set bit. In the multiprocessor communication mode, the received 9 th bit is stored in the bit RB8
(bit2 of SCON2, 0x2826), and, after the stop bit has been received, UART2 receive interrupt is activated
if RB8 is set bit.
The multiprocessor communication is used to send a block of data from a master to one slave. The
master first transmits an address byte that identifies the target slave. When transmitting an address byte,
the master sets the 9th bit to 1; when transmitting data bytes, the master clears the 9th bit.
When SM2 is set bit, no slave can generate an interrupt when a data byte has been received. However,
SCL
//
START
STOP or
SDA D0 D1 D2 D3 D4 D5 D6 D7 ACK ACK
RESTART
- 1-bit START: a falling edge on SDA when SCL holds HIGH sets up a START condition. This bit must be
sent by Master.
- 8-bit DATA byte: 1 bit DATA transferred on 1 SCL clock. A DATA bit is prepared on falling edge of each
SCL clock, and sampled on rising edge of each SCL clock. The endian of byte transfer is defined by bit
Endian (bit4 of SICFG, 0x2F01). 8-bit DATA byte must be followed by 1-bit ACK.
- 1-bit ACK: the ACK bit is prepared on falling edge of an SCL clock, and sampled on rising edge of an
SCL clock. Only the ACK bit transferred by the receiver is valid. HIGH indicates not acknowledged;
LOW indicates acknowledged. 1-bit ACK must be preceded by 8-bit DATA.
- 1-bit STOP or RESTART: to set up a STOP or RESTART condition, it is mandatory to generate a falling
edge of the SCL clock, and then ensure a low level on SDA when SCL holds HIGH to set up a STOP
condition, or a high level on SDA when SCL holds HIGH to set up a RESTART condition. Either bit must
be sent by Master device.
Bit[3:0] of register SICFG (0x2F01) defines the structure of the frame to be transmitted or received.
0 ○ ○ ○ Not valid.
2 ○ X ○ Not valid.
7 X X X Not valid.
fMCU
fSCL = Equation 13-1
4 × (TH + 1)
where fMCU is the clock frequency for MCU operation; TH is the threshold preset in registers SITHH (0x2F03)
and SITHL (0x2F02); fSCL is the serial clock (SCL) frequency.
Interrupt service
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
SCL
ACK=0 ACK=0
by slave by master
bit bit bit bit bit bit bit bit bit bit bit bit bit bit bit
SDA 1
1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
R /W
START bit 8-bit target DATA 8-bit target DATA
by master by master by slave
Data Output bit bit bit bit bit bit bit bit
0xFF
by Master 0 1 2 3 4 5 6 7
Data Output bit bit bit bit bit bit bit bit
by Slave 0 1 2 3 4 5 6 7
The data on the wire SDA is in the format of Wire-AND, which means the data is the data from receiver
and transmitter in “AND” logic, but not the state of either. The MCU can read the register SIDAT (0x2F04)
and bit ACK (bit0 of SIFLG, 0x2F05) to acquire the data of the SDA. When GPSI is idle (BUSY, bit1 of SIFLG,
0x2F05, is cleared), writing of register SIDAT (0x2F04) triggers data receive and transmit.
When bit BUSY (bit1 of SIFLG, 0x2F05) is cleared, writing 0xFF or a specific data byte to be transmitted
to register SIDAT (0x2F04) triggers data receive and transmit. Then bit BUSY is set to 1. After data
transmit and receive, bit BUSY is cleared again, and read register SIDAT and bit ACK (bit0 of SIFLG,
0x2F05) to acquire the data from SDA.
When IE5=1 (bit5 of ExInt5IE, 0x28A5), EIE.3=1 (SFR 0xE8) and IE.7=1 (SFR 0xA8), writing of
registers located at addresses 0x2F01~0x2F04 when bit BUSY (bit1 of SIACK, 0x2F05) is set to 1, an
illegal data interrupt will be triggered and the write operation is invalid.
bit bit bit bit bit bit bit bit bit bit bit bit bit bit bit bit //
SDA 1
1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0
//
R /W
START bit 8-bit address byte of slave 8-bit target DATA STOP or RESTART
by master by master by slave by master
Data Output bit bit bit bit bit bit bit bit
0xFF 0xFF
by Master 0 1 2 3 4 5 6 7
Data Output bit bit bit bit bit bit bit bit bit //
by Slave 0 1 2 3 4 5 6 7 0
//
Data Output
by Slave
2. Write of register SICFG (0x2F01) to enable transmitting START, and clear bit Endian to 0;
3. Write anything to register SIDAT (0x2F04) to trigger to transmit START. During transmission, bit BUSY
is set to 1;
4. When BUSY is cleared, write of register SICFG (0x2F01) to enable transmitting DATA and ACK; write
0x01 to register SIACK (0x2F05); and then write target slave address to bit[7:1] of register SIDAT
(0x2F04) and write 1 (to read) or 0 (to write) to bit0 to trigger transmitting the slave address frame.
During transmission, bit BUSY is set to 1;
5. When BUSY is cleared, read of register SIACK (0x2F05). If it is read out as 0, the target slave device
is selected;
6. Write of register SICFG (0x2F01) to enable transmitting DATA and ACK; write of 0x01 to register
SIACK (0x2F05); and then write the content to be transmitted to register SIDAT (0x2F04) to trigger
9. Write anything to register SIDAT (0x2F04) to trigger transmitting bit STOP or RESTART.
13.6. Registers
Table 13-2 Register to Disable or Enable GPSI
Bit3 TXS R/W 0 Set this bit to 1 to enable receiving or transmitting START bit.
Bit1 TXP R/W 0 Set this bit to 1 to enable receiving or transmitting STOP bit.
Bit0 TXRS R/W 0 Set this bit to 1 to enable receiving or transmitting RESTART bit.
0x2F03 SITHH Bit[7:0] TH[15:8] R/W 0 Set a threshold for serial clock (SCL)
generation.
Endian=0 D0 D1 D2 D3 D4 D5 D6 D7
Endian=1 D7 D6 D5 D4 D3 D2 D1 D0
The content of this register is the 8-bit DATA byte received or to be transmitted. Writing of this register
triggers receiving or transmitting data.
When Master works as the receiver, writing of this bit and transmit
it to acknowledge the transmitter or not.
When POR/BOR, RSTn pin reset, or WDT overflow reset occurs, the LCD driver is reset to its default
state.
ON/OFF
R COM2
COM/SEG Driver
COM3
3/4 VLCD
R COM4/SEG0
VLCD
COM5/SEG1
2/3 VLCD
IO
COM6/SEG8
R Or
2/4 VLCD COM7/SEG9
SEG2
1/3 VLCD
R Or
1/4 VLCD
...
AVSS SEG39
Frame Display
LCD SEG control
OSC CLK CLK3 Frequency
fLCD timing registers
buffer
Config. registers
When some bits of Table 14-11 are set to 1s, the corresponding pins are used for SEG output. In this
condition, it is mandatory to configure the GPIO ports as “input disabled” and “output disabled” in
corresponding input and output enable registers.
When the pins work as GPIO or analog input of M Channel or comparator CB, the corresponding bits of
Table 14-11 must be cleared to disable SEG output.
The CLK3 frequency is divided to generate frame frequency for the waveform. The MCU can configure
bit[1:0] of LCDCtrl (0x2C1E) to select the appropriate frame frequency. By default it is 64Hz.
Where,
Users can adjust the resistance value of each resistor in the resistor ladder of the bias voltage
generation circuits via bits DRV1/DRV0 (bit[3:2] of LCDCtrl, 0x2C1E) to adjust the current through the
circuits to change the lightness of the display panel. By default the resistance value is 300 kΩ.
The LCD driver supports LCD panel of 1/4 duty, 1/6 duty or 1/8 duty. When bits LCDTYPE (bit[5:4] of
LCDCtrl, 0x2C1E) are cleared, an LCD panel of 1/4 Duty should be used. In this application, each byte of
display RAM stores content of 2 LCD segments: lower 4 bits for Seg (n), and higher 4 bits for Seg (n+1).
Table 14-2 RAM Byte Allocation for Segments of LCD Panel of 1/4 Duty
D7 D6 D5 D4 D3 D2 D1 D0
Register Segment
COM3 COM2 COM1 COM0 COM3 COM2 COM1 COM0
When bits LCDTYPE (bit[5:4] of LCDCtrl, 0x2C1E) are set to 1, an LCD panel of 1/6 Duty should be used.
In this application, by default every 3 bytes of display RAM store content of 4 LCD segments. But when bit
6COMTYPE (bit6 of LCDCtrl, 0x2C1E) is set to 1, each byte of display RAM stores content of one LCD
segment.
Table 14-3 RAM Byte Allocation for Segments of LCD Panel of 1/6Duty When 6COMTYPE=0
Register SEG D7 D6 D5 D4 D3 D2 D1 D0
Table 14-4 RAM Byte Allocation for Segments of LCD Panel of 1/6 Duty When 6COMTYPE=1
Register D7 D6 D5 D4 D3 D2 D1 D0
When bits LCDTYPE (bit[5:4] of LCDCtrl, 0x2C1E) are set to 2 or 3, an LCD panel of 1/8 Duty should be
used. In this application, each byte of display RAM stores content of one LCD segment.
Table 14-5 RAM Byte Allocation for Segments of LCD Panel of 1/8 Duty
Register D7 D6 D5 D4 D3 D2 D1 D0
When an LCD panel of 1/4 or 1/6 duty is applied, only 1/3 bias mode can be used.
When an LCD panel of 1/8 duty is applied, users can configure bit LCDBMOD (bit3 of CtrlBAT, 0x285C)
to disable or enable one resistor in the bias voltage generation circuit to enable the LCD driver to work in
1/3 bias mode or 1/4 bias mode.
When an LCD panel of 1/4 duty is applied, the LCD drive waveform is depicted in the following figure.
VLCD-
2/3 VLCD-
COM0
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM1
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM2
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM3
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
SEGn
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
SEGn+1
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
1/3 VLCD-
COM0_SEGn
GND-
-1/3 VLCD-
-2/3 VLCD-
-VLCD-
VLCD-
2/3 VLCD-
1/3 VLCD-
COM0_SEGn+1
GND-
-1/3 VLCD-
-2/3 VLCD-
-VLCD-
Figure 14-2 LCD Drive Waveform When LCD Panel of 1/4 Duty and 1/3 Bias Applied
When an LCD panel of 1/6 duty is applied, the LCD drive waveform is depicted in the following figure.
VLCD-
2/3 VLCD-
COM0
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM1
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM2
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM3
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM4
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM5
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
SEGn
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
SEGn+1
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
1/3 VLCD-
COM0_SEGn
GND-
-1/3 VLCD-
-2/3 VLCD-
-VLCD-
VLCD-
2/3 VLCD-
1/3 VLCD-
COM0_SEGn+1
GND-
-1/3 VLCD-
-2/3 VLCD-
-VLCD-
Figure 14-3 LCD Drive Waveform When LCD Panel of 1/6 Duty and 1/3 Bias Applied
When an LCD panel of 1/8 duty is applied, the LCD drive waveform is depicted in the following figures.
VLCD-
2/3 VLCD-
COM1
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM2
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM3
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM4
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM5
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM6
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
COM7
1/3 VLCD-
GND-
VLCD-
SEGn 2/3 VLCD-
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
SEGn+1
1/3 VLCD-
GND-
VLCD-
2/3 VLCD-
1/3 VLCD-
COM0_SEGn
GND-
-1/3 VLCD-
-2/3 VLCD-
-VLCD-
VLCD-
2/3 VLCD-
1/3 VLCD-
COM0_SEGn+1
GND-
-1/3 VLCD-
-2/3 VLCD-
-VLCD-
Figure 14-4 LCD Drive Waveform When LCD Panel of 1/8 Duty and 1/3 Bias Applied
VLCD-
3/4 VLCD-
COM1
1/4 VLCD-
GND-
VLCD-
3/4 VLCD-
COM2
1/4 VLCD-
GND-
VLCD-
3/4 VLCD-
COM3
1/4 VLCD-
GND-
VLCD-
3/4 VLCD-
COM4
1/4 VLCD-
GND-
VLCD-
3/4 VLCD-
COM5
1/4 VLCD-
GND-
VLCD-
3/4 VLCD-
COM6
1/4 VLCD-
GND-
VLCD-
3/4 VLCD-
COM7
1/4 VLCD-
GND-
VLCD-
GND-
VLCD-
GND-
VLCD-
3/4 VLCD-
1/2 VLCD-
1/4 VLCD-
GND-
COM0_SEGn -1/4 VLCD-
-1/2 VLCD-
-3/4 VLCD-
-VLCD-
VLCD-
3/4 VLCD-
1/2 VLCD-
1/4 VLCD-
COM0_SEGn+1 GND-
-1/4 VLCD-
-1/2 VLCD-
-3/4 VLCD-
-VLCD-
Figure 14-5 LCD Drive Waveform When LCD Panel of 1/8 Duty and 1/4 Bias Applied
14.6. Registers
Table 14-6 LCD Control Register (LCDCtrl, 0x2C1E)
When 1/6 Duty is applied, set this bit to 1 to enable each byte of display
Bit6 6COMTYPE 0 RAM to store content of one LCD segment. By default, every 6 bits of
display RAM store content of 1 LCD segments in 1/6 Duty mode.
Bit3 DRV1 0 To set the resistance value of each resistor in the internal resistor ladder
for bias voltage generation.
Bit2 DRV0 0 00: 300kΩ; 01: 600kΩ; 10: 150kΩ; 11: 200kΩ.
Bit0 FRQ0 0 11: 512Hz; 10: 256Hz; 01: 128Hz; 00: 64Hz.
bit[7:4] Reserved 0 These bits must hold their default values for proper operation.
When the LCD driver works in 1/8 duty mode, set this bit to select the
bias ratio.
When the LCD driver works in 1/4 or 1/6 duty mode, 1/3 Bias ratio is
used whatever this bit is set.
To adjust the bias current of the amplifier of the voltage channel ADC.
bit[2:1] IITU<1:0> 0
00: 0%; 01: -33%; 11:+33%; 10: 100%.
Bit[6:3] Reserved 0 These bits must hold their default values for proper operation.
bit[1:0] Reserved 0 These bits must hold their default values for proper operation.
When the chip is 3.3V powered, users must set this bit to 1 to
Bit7 PDDET 0
disable the power detection circuit, to prevent current leakage of
the battery when a battery is connected to the device.
When the chip is 5V powered, this bit must hold its default value.
Bit6 LDO3IT 0 Set this bit to 1 to increase bias current of LDO33 by 100%.
0x2C20 SegCtrl1 SEGON15 SEGON14 SEGON13 SEGON12 SEGON11 SEGON10 SEGON9 SEGON8
Default 0 0 0 0 0 0 0 0
In the V9821, the pins for SEG output are multiplexed by GPIO and analog input of M Channel. When these
pins are configured for SEG output, they must be set to “input and output are disabled” for GPIO purpose.
When the pins work as GPIO ports or for analog input of M Channel, they must be set to “disable SEG
signal output” in these registers.
When bits LCDTYPE (bit[5:4] of LCDCtrl, 0x2C1E) are cleared, bit[1:0] of SegCtrl0 and SegCtrl1 are valid.
When bits LCDTYPE is set to 1, bit[1:0] of SegCtrl1 is valid, but bit[1:0] of SegCtrl0 is invalid.
When bits LCDTYPE is set to 2 or 3, bit[1:0] of SegCtrl1 and SegCtrl0 are invalid.
15. GPIO
In the V9821 there are 10 groups, P0~P9, 43 general-purpose input/output ports (GPIO) in total, of
which:
Ports of Group P0 are multiplexed by general input/output and JTAG interfaces. When the chip
operates in metering mode, besides for general input/output, both P0.2 and P0.3 can be used to wake
up the system from sleeping state. When the chip operates in debugging mode, these ports work as
JTAG interfaces;
Ports of Group P1 and P2 are multiplexed by general input/output and special functions. Both P1.3 and
P1.4 can be used to wake up the system from sleeping state;
Ports of Group P3 are multiplexed by general input/output and backplanes of the LCD driver;
Ports of Group P4 and P5 are multiplexed by general input/output and COM or SEG output of the LCD
driver;
Ports of Group P6~P8 are multiplexed by general input/output and SEG output of the LCD driver;
Ports of Group 9 are General-Purpose Input/Output (GPIO) ports, which are named Fast IO in this
datasheet. These ports are multiplexed by general input/output and special functions.
Ports of Group P0~P8 can be gate controlled simultaneously; Ports of Group P9 can be gate controlled
independently;
When POR/BOR, RSTn pin reset or WDT overflow event occurs, all ports will be reset to their default
states: both input and output are disabled;
15.1. P0
In Group P0 there are 4 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and JTAG
interfaces.
When the level on the pin MODE1 is driven low, all ports of this group will work as JTAG interfaces. In this
state, Port P0.0 is used for test data output (TDO); Port P0.1 is used for test data input (TDI); Port P0.2
is used for test mode select (TMS); Port P0.3 is used for test clock input (TCK).
When the level on the pin MODE1 is pulled high, all ports of this group will work as General-Purpose
Input/Output (GPIO) ports, and the input and output enable registers determine the state of each port.
Set bit P0P8 (bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power
consumption when these ports are not used. Besides, bit IOP0 (bit1 of IOWK, SFR 0xC9) determines both
P0.2 and P0.3 to be used for IO wakeup inputs. See “IO wakeup inputs” for details.
0 0 1
1 P0 input enable 1 P0 input enable
P0 input data 1
P0 input data
0 0
0
TCK, TMS or TDI
P0.0 P0 output enable P0.1/P0.2/P0.3 1
0 1 P0 output enable
0 1
0 TDO
P0 output data
1 P0 output data
Default X X X X 1 1 1 1
Default X X X X 0 0 0 0
Default X X X X 1 1 1 1
X: do not care.
Default X X X X 0 0 0 0
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
15.2. P1
In Group P1 there are 4 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and
special functions.
The function of each port can be configured via the dedicated special function register. When a port
works as a General-Purpose Input/Output (GPIO) port, the input and output enable registers determine
its state. Set bit P0P8 (bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power
consumption when these ports are not used. However, setting this bit to 1 after configuring these ports to
work for special functions has no effect on its functions.
P1 input enable
P1 input data
0
Special function
1 (input)
P1 special function
configuration
P1 output data
Special function
(output)
P1 output enable
Default X X X 1 1 1 1 X
Default X X X 0 0 0 0 X
Default X X X 1 1 1 1 X
X: do not care.
Default X X X 0 0 0 0 X
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
Bit[7:3] Reserved. 0
Bit[7:3] Reserved. 0
Bit[7:3] Reserved. 0
110: PLLDIV, pulse output proportional to the divided PLL clock frequency,
can be configured to output pulses of 1s width from the PLL counter.
Bit[7:2] Reserved. 0
001: PLLDIV, pulse output proportional to the divided PLL clock frequency,
P14FNC1
Bit[1:0] 0 can be configured to output pulses of 1s width from the PLL counter;
P14FNC0
010: TXD5, transmitter data output of UART5;
15.3. P2
In Group P2 there are 4 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and
special functions.
The function of each port can be configured via the dedicated special function register. When a port
works as a General-Purpose Input/Output (GPIO) port, the input and output enable registers determine
its state. Set bit P0P8 (bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power
consumption when these ports are not used. However, setting this bit to 1 after configuring these ports to
work for special functions has no effect on its functions.
P2 input enable
P2 input data
0
Special function
1 (input)
P2 special function
P2 output data
Special function
(output)
P2 output enable
Default X X 1 1 X X 1 1
Default X X 0 0 X X 0 0
Default X X 1 1 X X 1 1
X: do not care.
Default X X 0 0 X X 0 0
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
Bit[7:2] Reserved. 0
Bit[7:2] Reserved. 0
Bit[7:2] Reserved 0
Bit[7:2] Reserved 0
15.4. P3
In Group P3 there are 4 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and
backplanes of the LCD driver.
When a port works as backplanes of the LCD driver, in input and output enable registers, P3OE (0x28B4)
and P3IE (0x28B5), the corresponding bit must be configured “input disabled, output disabled”.
When a port works as a General-Purpose Input/Output (GPIO) port, the SEG/COM driver in the LCD
driver must be disabled (bit7 of LCDCtrl, 0x2C1E), and input and output enable registers determine its
state. Set bit P0P8 (bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power
consumption when these ports are not used.
P3 input enable
LCDON
P3 input data
P3 output data
P3 output enable
Default X X X X 1 1 1 1
Default X X X X 0 0 0 0
Default X X X X 1 1 1 1
X: do not care.
Default X X X X 0 0 0 0
X: do not care.
15.5. P4
In Group P4 there are 2 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and
signal output of the LCD driver.
Ports P4.0 and P4.1 can be configured to be multiplexed by SEG output when a display panel of 1/4 duty
is applied, or two extra backplanes when a display panel of 1/6 or 1/8 duty is applied, and
General-Purpose Input/Output (GPIO).
When a port works as backplanes or SEG output of the LCD driver, in input and output enable registers,
P4OE (0x28B8) and P4IE (0x28B9), the corresponding bit must be configured “input disabled, output
disabled”.
When a port works as a General-Purpose Input/Output (GPIO) port, the SEG output on the
corresponding port must be disabled and input and output enable registers determine its state. Set bit
P0P8 (bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power consumption
when these ports are not used.
SEGx COMx
LCDON LCDTYPE
P4 input enable
P4 output data
P4 output enable
P41OEN P40OEN
Default X X X X X X 1 1
P41INEN P40INEN
Default X X X X X X 0 0
Default X X X X X X 1 1
X: do not care.
Default X X X X X X 0 0
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
15.6. P5
In Group P5 there are 8 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and
signal output of the LCD driver.
Ports P5.0 and P5.1 can be configured to be multiplexed by SEG output when a display panel of 1/4 or
1/6 duty is applied, or two extra backplanes when a display panel of 1/8 duty is applied, and
General-Purpose Input/Output (GPIO); and ports P5.2-P5.7 are multiplexed by SEG output and
General-Purpose Input/Output (GPIO).
When a port works as backplanes or SEG output of the LCD driver, in input and output enable registers,
P5OE (0x28BC) and P5IE (0x28BD), the corresponding bit must be configured “input disabled, output
disabled”.
When a port works as a General-Purpose Input/Output (GPIO) port, SEG output on the corresponding
port must be disabled, and input and output enable registers determine its state. Set bit P0P8 (bit3 of
SEGx
P5 output data
P5 output enable
Default 1 1 1 1 1 1 1 1
Default 0 0 0 0 0 0 0 0
Default 1 1 1 1 1 1 1 1
Default 0 0 0 0 0 0 0 0
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
15.7. P6
In Group P6 there are 6 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and SEG
output of the LCD driver.
When a port works as SEG output of the LCD driver, in input and output enable registers, P6OE (0x28C0)
and P6IE (0x28C1), the corresponding bit must be configured “input disabled, output disabled”.
When a port works as a General-Purpose Input/Output (GPIO) port, SEG output on the corresponding
port must be disabled, and input and output enable registers determine its state. Set bit P0P8 (bit3 of
PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power consumption when these ports
are not used.
SEGx
P6 output data
P6 output enable
Default 1 1 1 1 1 1 X X
Default 0 0 0 0 0 0 X X
Default 1 1 1 1 1 1 X X
X: do not care.
Default 0 0 0 0 0 0 X X
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
15.8. P7
In Group P7 there are 2 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and SEG
output of the LCD driver.
When a port works as SEG output of the LCD driver, in input and output enable registers, P7OE (0x28D5)
and P7IE (0x28D6), the corresponding bit must be configured “input disabled, output disabled”.
When a port works as a General-Purpose Input/Output (GPIO) port, the SEG output on the
corresponding ports must be disabled and input and output enable registers determine its state. Set bit
P0P8 (bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power consumption
when these ports are not used.
P7 output data
P7 output enable
P77OEN P76OEN - - - - - -
Default 1 1 X X X X X X
P77INEN P76INEN - - - - - -
Default 0 0 X X X X X X
Default 1 1 X X X X X X
X: do not care.
Default 0 0 X X X X X X
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
15.9. P8
In Group P8 there are 3 ports, which are multiplexed by General-Purpose Input/Output (GPIO) and SEG
output of the LCD driver.
When a port works as SEG output of the LCD driver, in input and output enable registers, P8OE (0x28D9)
and P8IE (0x28DA), the corresponding bit must be configured “input disabled, output disabled”.
When a port works as a General-Purpose Input/Output (GPIO) port, the SEG output on the
corresponding port must be disabled, and input/output enable registers determine its state. Set bit P0P8
(bit3 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P0~P8 to lower power consumption when
these ports are not used.
SEGx
P8 output data
P8 output enable
Default X X X X X 1 1 1
Default X X X X X 0 0 0
Default X X X X X 1 1 1
X: do not care.
Default X X X X X 0 0 0
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
15.10. P9
In Group P9 there are 6 ports, which are multiplexed by General-Purpose Input/Output (GPIO), special
functions and SEG output of the LCD driver.
When the ports work as General-Purpose Input/Output (GPIO) ports, the ports of Group P9 are different
from those of the above groups. They are accessed in a fast mode. But when a reference pulse of exact
one second width is input to the port P9.1, the input of this port is enabled automatically.
The function of each port can be configured via the register P9FS (SFR 0xAD).
When bit GPSI (bit6 of PRCtrl0, 0x2D00) is set to 1, port P9.1 and P9.2 are used for serial data and clock
delivery for general-purpose serial interface (GPSI). In this condition, P9.1 must be set to “input enabled”;
and P9.2 is set to “output enabled” automatically.
The port P9.0 can be used for SEG output of the LCD driver. When the port works as SEG output of the
LCD driver, in input and output enable registers, P9OE (SFR 0xA4) and P9IE (SFR 0xA5), the
corresponding bit must be configured “input disabled, output disabled”.
Set bit P9 (bit4 of PRCtrl0, 0x2D00) to 1 to gate control ports of Group P9 to lower power consumption
when these ports are not used. However, setting this bit to 1 after configuring these ports to work for
special functions has no effect on its functions.
Default X 1 1 X 1 1 1 1
Default X 0 0 X 0 0 0 0
X: do not care.
Default X 0 0 X 0 0 0 0
X: do not care.
When input is enabled, users can read the state of each I/O port via this register all the time, which is not
affected by the special function of the port. But the state change of an I/O port will lead to value variation
of this register, which consumes more power. So to lower power consumption, it is recommended to
disable data input if no need to read the input data.
Bit Description
Bit7 Reserved
Bit4 Reserved
1: PLLDIV, pulse output proportional to the divided PLL clock frequency, can be
Bit3 P93FNC
configured to output pulses of 1s width from the PLL counter;
Bit2 P92FNC 1: TA2, to input/output the signals for Timer A Compare/Capture Module 2;
Bit Description
Bit1 P91FNC 1: TA1, to input/output the signals for Timer A Compare/Capture Module 1;
Bit0 P90FNC 1: TA0, to input/output the signals for Timer A Compare/Capture Module 0;
Bit2 When the bit PWRUP is read out as 0, write 0 to the bit MCUFRQ, and then:
SLEEP1 - set SLEEP1 and SLEEP0 to 0b11 or 0b01 to stop CLK1 (together with CLK4) and
0 force the system entering the LPM1 state.
Bit1
- set SLEEP1 and SLEEP0 to 0b10 to stop CLK1 (together with CLK4) and force the
SLEEP0 system entering the LPM2 state.
Users can write a program to clear the WDT counts to prevent the WDT from resetting the system when
its counts overflow: write 0xA5 to the register WDTEN (SFR 0xCE) and then 0x5A to the register WDTCLR
(SFR 0xCF) continuously to clear the WDT counts. Immediately the WDT is cleared, it will restart counting
pulses from zero.
When the WDT overflow reset occurs, the flag bit POR (bit5 of Systate, SFR 0xA1) is set to 1. When other
reset events, not POR/BOR or RSTn pin reset, occurs, this bit will be cleared. In debugging mode, this
reset event is masked.
A WDT overflow event can reset all circuits except the RTC calibration registers, RTC timing registers,
IRAM and XRAM.
WDT counts
3 × 214
Feed dog
0 t
-214
8/fRC
WDT
overflow
reset pulse
providing real-time clock and calendar, and adjusting the date for leap year automatically.
In the RTC, the registers for calibration and timing cannot be reset by any reset event; and the other
registers will be reset to their default states when POR/BOR, RSTn pin reset or WDT overflow event occurs.
In LPM1 state, the RTC keeps running and can be configured to wake up the system at an programmable
interval of 1 day, 1 hour, 1 minute, 1~64 seconds, 500ms, 250ms, 125ms or 62.5ms. The wakeup signal
will hold 8 OSC clock periods.
32.768kHz
Month
Load, configure
Bus
In the V9821, the registers INTRTC (SFR 0x96), RTC calibration registers and RTC timing registers are
protected from writing.
The MCU must write of these registers following exact steps as:
1. writing 0x96 to the register RTCPEN to enable writing of the register RTCPWD;
2. writing 0x57 to the register RTCPWD to enable writing of INTRTC (SFR 0x96), RTC calibration registers
and RTC timing registers;
3. configuring the registers INTRTC (SFR 0x96), RTC calibration registers and RTC timing registers;
4. writing 0x96 to the register RTCPEN to enable writing of the register RTCPWD;
5. writing 0x56 to the register RTCPWD to disable writing of the registers INTRTC (SFR 0x96), RTC
calibration registers and RTC timing registers. 5 OSC clock cycles later, the contents of the registers
are activated. A second write operation can be done to these registers only when the last
configuration is completed.
To read the timing registers, the MCU must read the register RDRTC (SFR 0xDA) firstly, waits no less
than 5 OSC clock cycles till the contents of the RTC timing registers are latched, and then read the timing
registers for the time information.
17.2. Timing
When the chip is powered on, the RTC starts to run, and it keeps on running until the system is powered
off.
If the timing registers are not configured, the RTC runs from a random time; otherwise, the RTC runs
from the preset time.
When the RTC illegal data interrupt is enabled (EA=1, EIE.2=1 and ExInt4IE.0=1), an illegal data
interrupt will be triggered when:
The MCU writes of the registers INTRTC (SFR 0x96), RTC calibration registers and RTC timing registers
when they are still being protected from writing;
The MCU writes the contents in an illegal format into the registers INTRTC (SFR 0x96), RTC calibration
registers and RTC timing registers when the writing operation is enabled;
The contents of the timing registers are in binary-coded decimal (BCD) format, so 0xF is not considered
as an illegal data.
In both circumstances, the RTC timing registers will hold the contents.
Data error caused by the system error occurs during the operation. In this circumstance, the MCU
must configure all RTC timing registers consecutively immediately the writing operation is enabled,
and then disable the writing operation to activate the correction.
When EA=1, EIE.1=1 and ExInt3IE.6=1, the pulse output interrupt per second is enabled, and the RTC
will output pulses of 1 second width to the MCU to trigger interrupts.
When the register PLLCNT (SFR 0xDE) is set to 0x00, the PLL counter works as a divider. In this mode,
the PLL counter counts from 0 and increments by 1 every OSC clock cycle. When it counts to the pre-set
value of the PLL clock divider registers, this counter will be cleared, output pulses at a frequency
proportional to the divided PLL clock frequency from Pin22/Pin21/Pin27, and then the counter will start
recounting. The frequency of the pulse can be calculated as follows:
fMCU
fDIV = Equation 17-1
2 × (TH + 1)
Where,
fMCU, the MCU clock frequency (Hz), which has a relationship with the OSC clock frequency (f OSC)as
follows:
Where, K is a coefficient, equal to 100/200/400; when the theoretical fMCU is 13.1072MHz, K is 400.
TH, the preset value of the PLL divider registers (DIVTHH/DIVTHM/DIVTHL). In the default state, the
value of TH is 0, so the MCU clock frequency is divided by 2. The MCU clock frequency can be divided
When the register PLLCNT (SFR 0xDE) is configured to 0x01, the PLL counter works as a counter. When
the first low-to-high transition of a reference pulse of exact 1 second width input on Pin57 (SDSP) is
detected, which will configure the register to 0x02 automatically, the counter starts counting from zero.
And then, when the second low-to-high transition of the reference pulse input is detected, the register
PLLCNT (SFR 0xDE) is configured to 0x03 automatically, the PLL counter stops running, and the current
counts is transferred to the PLL clock divider registers to calculate the actual frequency of the pulse.
17.5. Registers
In the RTC, the registers for calibration and timing cannot be reset by any reset event; and the other
registers will be reset when POR/BOR, RSTn pin reset or WDT overflow event occurs.
bit[7:0] 0 W Only when this register is configured to 0x96 can the register RTCPWD
(SFR 0x97) be configured validly. The write operation of both registers
must be consecutive without interruption.
bit[7:3] 0 R/W
Configure this register for the interval at which the RTC will wake up the system from LPM1 state. The
wakeup signal holds 8 OSC clock periods.
Table 17-4 RTC Seconds Wake-up Interval Configuration Register (SECINT, SFR 0xDF)
SFR 0xDF, R/W, RTC Seconds Wake-up Interval Configuration Register, SECINT
It is mandatory to set register INTRTC (SFR 0x96) to 0x07, and then set this bit
Bit6 R/W 0
to 1 to enable writing of bit[5:0] of this register.
To set interval in unit of second for RTC to wake up the system from LPM1 state.
The actual wakeup interval is equal to (bit[5:0]+1) seconds, of which bit[5:0]
Bit[5:0] R/W 0 can be set to 1~63 (decimal).
When this bit is read out as 1, but bit CFWK (bit3 of IOWKDET, SFR 0xAF) is cleared, it
Bit2 indicates the system was woken up from LPM1 state by RTC wakeup event.
0
RTC/CF If both this bit and bit CFWK are set to 1s, it indicates the system was woken up from
LPM1 state by CF pulse wakeup event.
The MCU must read this register to enable read operation on the RTC timing
bit[7:0] 0 R
registers. This register is read out as 0x00.
SFR 0xDB, DIVTHH bit[7:0] DIV<23:16> 0 R/W High byte of the PLL clock divider.
SFR 0xDC, DIVTHM bit[7:0] DIV<15:8> 0 R/W Middle byte of the PLL clock divider.
SFR 0xDD, DIVTHL bit[7:0] DIV<7:0> 0 R/W Low byte of the PLL clock divider.
bit[7:2] 0 R/W When this register is cleared to 0x00, the PLL counter works as a divider.
When the PLL counter increments from 0 to the value of the PLL clock divider
registers, this counter is cleared, outputs a pulse at a frequency proportional
to the divided PLL clock frequency, and then starts recounting.
When this register is set to 0x01, the PLL counter works as a counter. When
bit[1:0] the first low-to-high transition of the reference pulse of exact 1 second width
0 R/W input on Pin57(SDSP) is detected, which will set this register to 0x02
STT<1:0> automatically, the counter starts counting from zero. And then, when the
second low-to-high transition of the reference pulse input is detected, the
register is configured to 0x03 automatically, the PLL counter stops running,
and the current counts is transferred to the PLL clock divider registers to
calculate the actual frequency of the pulse per second.
The time and calendar information is obtained by reading the appropriate register bytes. The contents
of the timing registers, except the register for day of week configuration, are in binary-coded decimal
(BCD) format, of which bit7~bit4 represents the tens digit of the time and calendar, and bit3~bit0
represents the units digit of the time and calendar; for example, 0b1000011 in the register RTCSC
represents 43 seconds. The RTC can provide second, hour, day, week, month and year information. As
such, both RTCSC (seconds) and RTCMiC (minutes) range 0~59, RTCHC (hour) ranges 00~24, RTCDC
(day) ranges 1~31, RTCMoC (month) ranges 1~12 and RTCYC (year) ranges 0~99.
Default X X X X X X X X
Users must set the day of week information for one date; for example, set the date 1st Jan. 2010 to be
Friday, and the RTC will determine the date 2nd, Jan., 2010 to be Saturday automatically. 0b0000:
Sunday; 0b0001: Monday; 0b0010: Tuesday; 0b0011: Wednesday; 0b0100: Thursday; 0b0101: Friday;
0b0110: Saturday.
For the year information, only the tens and units digits of the year need to be configured in the register
RTCYC; for example, 0b00010000 represents the year 2010.
18. Registers
The register located at address 0x285F must be configured to its default values for proper operation.
Users can read of bytes located at addresses 0x300C~0x3059 to obtain the recommended configuration
of the analog registers, and write them to the analog registers.
Bit7 Reserved 0 This bit must hold its default value for proper operation.
To set analog PGA gain for voltage input to Voltage Channel (U) ADC.
Bit6 ADCGU 0 This bit must hold its default value for proper operation.
0: × 1; 1: × 2.
To set analog PGA gain for current input to Current Channel B (IB)
ADC.
To match the output signal from the sensor to the measurement scale
of the ADC, the default value should not be used.
To set analog PGA gain for current input to Current Channel A (IA)
ADC.
To match the output signal from the sensor to the measurement scale
of the ADC, the default value should not be used.
bit[7:5] Reserved 0 These bits must hold their default values for proper operation.
bit4 Reserved 0
bit[7:4] Reserved 0 These bits must hold their default values for proper operation.
When the LCD driver works in 1/8 duty mode, set this bit to select the
bias ratio.
When the LCD driver works in 1/4 or 1/6 duty mode, 1/3 Bias ratio is
used whatever this bit is set.
bit[2:1] Reserved 0
Bit[6:3] Reserved 0 These bits must hold their default values for proper operation.
bit[1:0] Reserved 0 These bits must hold their default values for proper operation.
Bit[7:5] Reserved 0 These bits must hold their default values for proper operation.
The fixed capacitance in the crystal oscillator circuit is 12.5pF. Set this
Bit4 CSEL 0
bit to 1 to decrease the capacitance by 2.35pF.
Bit3 Reserved 0 These bits must hold their default values for proper operation.
Bit7 Reserved 0
This bit must hold its default value for proper operation. By default
Bit6 Reserved 0
this function is disabled.
Bit4 Reserved 0
Bit[1:0] Reserved 0 These bits must hold their default values for proper operation.
Bit[7:6] Reserved 0 These bits must hold their default values for proper operation.
0: × 1; 1: × 1/4.
Bit3 Reserved 0 This bit must hold its default value for proper operation.
000: ground;
001: temperature;
Bit[2:0] MEAS<2:0> 0 010: battery voltage or other external DC voltage via pin BAT.
011/100/101: reserved;
Note: When the pins M1 and M2 are used for analog input for Channel M, bit7 and bit 6 of the register
SegCtrl4 (0x2C23) must be cleared to disable the SEG output on the pins.
bit[7:6] Reserved 0 These bits must hold their default values for proper operation.
bit4 Reserved 0 This bit must hold its default value for proper operation.
bit[7:1] Reserved 0 These bits must hold their default values for proper operation.
By default the ADC offset of the input signal into the M Channel will be
removed. When M Channel is used to measure temperature, it is
bit0 MADCHOPN 0
recommended to set this bit to 1 to disable this function to improve the
measurement accuracy.
When the chip is 3.3V powered, users must set this bit to 1 to
Bit7 PDDET 0
disable the power detection circuit, to prevent current leakage of
the battery when a battery is connected to the device.
When the chip is 5V powered, this bit must hold its default value.
Bit6 Reserved 0
When the bit MCU13M is set to 1, set this bit to 1 to double MCUCLK
bit7 MCU26M 0
frequency further.
bit5 PLLSEL 0 To apply the chip to 50Hz or 60Hz power grid. 0: 50Hz; 1: 60Hz.
bit[4:0] Reserved 0 These bits must hold their default values for proper operation.
Bit6 Reserved -
bit5 COMPB 0 1: the positive input is higher than the negative input;
bit[1:0] Reserved -
All the default values in this section are in decimal form if not specifically noted.
bit7 Reserved 0
To set the digital PGA gain for I1 signal. Gain=2PGACx. PGACx is in the
bit[6:4] PGAC2~PGAC0 0
range of 0~5.
bit3 PGAUS 0 To set sign of the digital PGA for U signal. 0: positive; 1: negative.
To set the digital PGA gain for U signal. Gain=2PGAUx. PGAUx is in the
range of 0~5.
bit[2:0] PGAU2~PGAU0 0 When bit LPFEN (bit5 of PMCtrl3, 0x287A) is set to 1, the digital PGA
gain for U signal is lowered to 1/4 of its configuration. When bit
LPFEN is cleared, the digital PGA gain for U signal is what it is
configured.
bit6 BPFEN 0 This filter can improve the RMS calculation accuracy, but it will lead
to harmonics loss. When a low signal is input, this filter will introduce
greater truncation noise and prolong the period for the system to be
settled.
When this bit is set to 1, the digital PGA gain for U signal is lowered
bit5 LPFEN 0 to 1/4 of its configuration. When this bit is cleared, the digital PGA
gain for U signal is what it is configured.
To set the digital PGA gain for I2 signal. Gain=2PGANx. PGANx is in the
bit[2:0] PGAN2~PGAN0 0
range of 0~5.
Together with bit IAPHC (bit[1:0] of CRPST, 0x287F) as the right 2 bits,
these 8 bits are to set the time to be delayed. When the sampling
Bit[5:0] PHCA<5:0> 0 frequency of phase compensation circuit (fsmpl) is 3.2768MHz, the
resolution of the phase compensation is 0.0055°/lsb, and 1.4° in total
of the phase angle error can be calibrated.
Together with bit IBPHC (bit[3:2] of CRPST, 0x287F) as the right 2 bits,
these 8 bits are to set the time to be delayed. When the sampling
Bit[5:0] PHCB<5:0> 0 frequency of phase compensation circuit (fsmpl) is 3.2768MHz, the
resolution of the phase compensation is 0.0055°/lsb, and 1.4° in total
of the phase angle error can be calibrated.
bit2 CFXCG 0 0: CF1 pin for E1 path, CF2 pin for E2 path;
When current signal is detected, this bit is set to 1 and holds until bit
Bit6 CST R 0
CLR is set to 1 or DETON is cleared.
After a cycle of current detection, set this bit to 1 and then clear it to
Bit5 CLR R/W 0
clear bit CST.
All metering data registers are readable and writable (R/W). But users must not write of these registers
to avoid unexpected results.
All the default values in this section are in decimal form if not specifically noted. All the time for updating
and settling listed in the tables is appropriate for 50Hz power grid and fMTCLK=3.2768MHz. When the
frequency for metering architecture (fMTCLK) is divided by K, the time for updating and settling must be K
times of that for 3.2768MHz. In 60Hz power grid, the time for updating and settling is 1.2 times of that for
50Hz power grid.
Update Settle
Address Register R/W Default Format
in in
32-bit 2’
0x1005 DATAOIU Raw waveform of voltage. R/W 0 0.3ms 10ms
complement
32-bit 2’
0x100A DATAOII1 Raw waveform of Current I1. R/W 0 0.3ms 10ms
complement
32-bit 2’
0x100F DATAOII2 Raw waveform of Current I2. R/W 0 0.3ms 10ms
complement
Instantaneous
32-bit 2’
0x10D2 DATAIQ active/reactive power in R/W 0 80ms 250ms
complement
E2 path.
32-bit 2’
0x10D8 RMSU Average voltage RMS. R/W 0 1.28s 3s
complement
32-bit 2’
0x10D9 RMSI1 Average current I1 RMS. R/W 0 1.28s 3s
complement
32-bit 2’
0x10DA RMSI2 Average current I2 RMS. R/W 0 1.28s 3s
complement
32-bit,
0x10F0 PPCNT Positive active energy accumulator in E1 path. R/W 0
unsigned
32-bit,
0x10F1 NPCNT Negative active energy accumulator in E1 path. R/W 0
unsigned
32-bit,
0x10F2 PPCFCNT Positive active energy pulse counter in E1 path. R/W 0
unsigned
32-bit,
0x10F3 NPCFCNT Negative active energy pulse counter in E1 path. R/W 0
unsigned
The energy accumulators are of actual 42-bit length. But only the higher 32 bits are readable; and only
the higher 32 bits are valid for write operation and the 10 least significant bits are padded with 0s in write
operation.
When MTCLK frequency is 3.2768MHz, 1.6384MHz or 819.2kHz, the energy accumulation frequency is
12800Hz; when MTCLK frequency is 32768Hz, the energy accumulation frequency is 2979Hz.
When CF pulse output is enabled, the overflow frequency of the energy accumulators is twice of CF pulse
output frequency. The reading of the energy pulse counter is twice of the number of the output CF pulses.
Default 0x0000 0 0 0 0 0 0
When MTCLK frequency is 3.2768MHz, the content is updated in 320ms and settled in 500ms. The
frequency measurement resolution is up to 0.05Hz/lsb, and the measurement scale is over the range of
35~75Hz.
Update Settle
Address Register R/W Default Format
in in
32-bit 2’
0x10CE DATAOM Raw waveform of Channel M. R/W 0 0.3ms 10ms
complement
All the default values in this section are in decimal form if not specifically noted.
To set a value to
32-bit 2’
0x10ED PARAPC offset calibrate active R/W 0
complement
power in E1 path.
The gain calibration range is
To set a value to from -50% to +50%.
offset calibrate 32-bit 2’
0x10EE PARAQC R/W 0
active/reactive complement
power in E2 path.
When MTCLK frequency is lowered to 819.2kHz, the sampling frequency of the enabled band-pass filter in
the RMS calculation circuit is changed to 800Hz and the center frequency is changed to 12.5Hz, which has
a greater attenuation on 50Hz signals and will reduce the accuracy of the RMS calculation and line
frequency measurement. So, if MTCLK frequency is reduced to 819.2kHz, users must disable energy
accumulation, CF pulse output and no-load detection, and then configure this register to 0x911D3C9C.
When MTCLK frequency is reinstated to 3.2768MHz, this register must be set to its default value.
Table 18-31 Energy Threshold Registers and Constant Power Register (R/W)
32-bit,
0x10F5 GATECP To set a threshold for no-load detection in E1 path. R/W 0
unsigned
32-bit,
0x10FB GATECQ To set a threshold for no-load detection in E2 path. R/W 0
unsigned
The energy accumulators are of actual 42-bit length, but the threshold registers for energy-to-pulse
conversion are of 32-bit length. So, the threshold registers will be padded with a string of 10 0s on the
right to work as 42-bit registers for computation.
There is an anti-creeping accumulator in the no-load detection circuit. When no-load detection is enabled,
1s are accumulated in this register constantly. When MTCLK frequency is 3.2768MHz, 1.6384MHz or
819.2kHz, the accumulation frequency is 12800Hz; and when MTCLK frequency is 32768Hz, the
accumulation frequency is 2979Hz.
When no-load detection is enabled, the circuit compares the rate at which the anti-creeping accumulator
increments by 1s to that at which the energy accumulators accumulate E1/E2 power or the preset
constant. If the energy accumulator overflows sooner, the anti-creeping accumulator is cleared, and E1 or
E2 path starts to metering energy. Otherwise, the energy accumulator in E1 or E2 path is cleared, and the
path enters creeping state. Users can read bit7 or bit6 of register CRPST (0x287F) to detect the state of
the path.