CMS80F261x Reference Manual - V1.04
CMS80F261x Reference Manual - V1.04
CMS80F261x series
Reference Manual
Enhanced flash memory 8-bit 1T 8051 microcontroller
Rev. 1.04
*Cmsemicron Limited(denoted as ‘our company’ for later use) has already applied for relative patents and entitled legal rights. Any patents
related to CMS’s MCU or other producrts is not authorized to use. Any individual, organization or company which infringes s our company’s
interlectual property rights will be forbidden and stopped by our company through any legal actions, and our company will claim the lost and
required for compensation of any damage to the company.
* The name of Cmsemicron Limited and logo are both trademarks of our company.
*Our company preserve the rights to further elaborate on the improvements about products’ function, reliability and design in this manual.
However, our company is not responsible for any usage about this munal. The applications and their purposes in this manual are just for
clarification,our company does not guarantee that these applications are feasible without further improvements and changes,and our
company does not recommend any usage of the products in areas where people’s safety is endangered during accident. Our company’s
products are not authorzed to be used for life-saving or life support devices and systems.our company has the right to change or improve the
product without any notification,for latest news, please visit our website: www.mcu.com.cn
Table of content
1. Central processing unit(CPU) .................................................................................... 12
1.1 Reset vector(0000H) ............................................................................................................................................ 12
1.2 Accumulator(ACC) ................................................................................................................................................ 12
1.3 B register(B) ......................................................................................................................................................... 12
1.4 Stack pointer register(SP)..................................................................................................................................... 13
1.5 Data pointer register(DPTR0/DPTR1) .................................................................................................................. 13
1.6 Data pointer selection register(DPS) .................................................................................................................... 13
1.7 Program status register(PSW) .............................................................................................................................. 14
1.8 Program counter(PC) ........................................................................................................................................... 14
1.9 Timing access register(TA) ................................................................................................................................... 15
3. Reset ................................................................................................................................. 32
3.1 Power-on reset .......................................................................................................................................................... 32
3.2 External reset ............................................................................................................................................................ 34
3.3 LVR Low voltage reset............................................................................................................................................... 34
3.4 Watchdog reset ......................................................................................................................................................... 35
3.5 Software reset ........................................................................................................................................................... 35
3.6 CONFIG state protection reset .................................................................................................................................. 36
3.7 Power-on configuration monitoring reset ................................................................................................................... 36
6. Interrupt ............................................................................................................................ 44
6.1 Overview ................................................................................................................................................................... 44
6.2 External interrupt ....................................................................................................................................................... 45
6.2.1 INT0/INT1 interrupt ............................................................................................................................................... 45
20.3.22 SEG port P20-P23 drive current control register LEDSDRP2L ........................................................................... 170
20.3.23 SEG port P24-P27 drive current control register LEDSDRP2H ........................................................................... 171
20.3.24 SEG port P30-P33 drive current control register LEDSDRP3L ........................................................................... 171
20.3.25 COM port sink current selection register P3DR................................................................................................... 172
20.4 The output waveform ............................................................................................................................................... 173
1.2 Accumulator(ACC)
ALU is an 8Bit wide arithmetic logic unit, and all the mathematics and logic operations of the MCU are completed through
it. It can add, subtract, shift and logic operations on data; ALU also controls the status bit (in the PSW status register) to indicate
the status of the operation result.
The ACC register is an 8Bit register, the result of the ALU operation can be stored here.
1.3 B register(B)
The B register is used when using multiplication and division instructions. If you don’t use multiplication and division
instructions, it can also be used as a general-purpose register.
0000H
APROM
FLASH: 64KB
BOOT
FFFFH
After the chip is reset, the CPU starts to execute from 0000H. Each interrupt is assigned a fixed address in the program
memory, and the interrupt causes the CPU to jump to this address and start executing the service program.
For example, external interrupt 1 is assigned the address 0013H. If External Interrupt 1 is used, its service program must
start at 0013H. If the interrupt is not used, its service address is used as the storage address of the ordinary program.
03FFH
Data FLASH
1KB
0000H
Data FLASH memory read, write, and erase operations are realized through the FLASH control interface.
FFH FFH
80H 80H
7FH
Internal RAM
128Bytes lower
(Indirect or direct addressing)
00H
The high 128 bytes and SFR shown in the figure above occupy the same area (80H~FFH), but they are independent.
Directly address the storage space (SFR) higher than 7FH and indirectly address the storage space higher than 7FH (high 128
bytes) into different storage spaces. SFR is divided into two pages, BANK0 and BANK1, each page is 128Bytes, occupying the
same address area, and entering different storage spaces through the paging register selection.
The lower 128 bytes space register allocation shown in the figure above is shown in the figure below. The lowest 32 bytes
(00H~1FH) constitute 4 register groups, each group of 8 storage units, with R0~R7 as the unit number, used to store operands
and intermediate results. After reset, group 0 is selected by default. If another register group is selected, it needs to be
determined by changing the program state. The 16Bytes (20H~2FH) behind the register group constitute a bit-addressable
storage space. The RAM unit in this area can be operated either by byte or directly on each bit in the unit. The remaining 80
storage units (30H~7FH), the user can set the stack area and store intermediate data.
7FH
7F 7E 7D 7C 7B 7A 79 78
77 76 75 74 73 72 71 70
6F 6E 6D 6C 6B 6A 69 68
80Bytes General Purpose Register
67 66 65 64 63 62 61 60
5F 5E 5D 5C 5B 5A 59 58
57 76 55 54 53 52 51 50
4F 4E 4D 4C 4B 4A 49 48
30H
47 46 45 44 43 42 41 40
2FH
3F 3E 3D 3C 3B 3A 39 38
37 36 35 34 33 32 31 30
16Bytes
Bit Addressable
(128Bits) 2F 2E 2D 2C 2B 2A 29 28
27 26 25 24 23 22 21 20
1F 1E 1D 1C 1B 1A 19 18
20H
1FH 17 16 15 14 13 12 11 10
Register Bank3 0F 0E 0D 0C 0B 0A 09 08
8Bytes
(8Bytes)
18H 07 06 05 04 03 02 01 00
17H
00H R2
R1
R0
0FFFH
XRAM
4 KB
(Indirect addressing)
0000H
XRAM/XSFR space access is operated by the DPTR data pointer. DPTR includes two sets of pointers: DPTR0, DPTR1,
which are selected by the DPS register. For example, through MOVX indirect addressing operation, the assembly code is as
follows:
MOV R0,#01H
MOV A,#5AH
; Write the data in A into XRAM address 01H, the upper 8-bit address is
MOVX @R0,A
determined by DPH0/1
After setting Target-->Memory Model to Large in Keil51, the C compiler will use XRAM as the variable address. Generally
use DPTR for XRAM/XSFR operations.
FFFFH
XSFR: 4K
F000H
EFFFH
reserved space
1000H
0FFFH
XRAM: 4K
0000H
3. Reset
The reset time (Reset Time) refers to the time from the chip reset to the chip starting to execute instructions, and its default
design value is about 16ms. This time includes the oscillator start-up time and configuration time. Whether the chip is power-on
reset or reset caused by other reasons, there will be this reset time. In addition, when the oscillator is selected as an external
low-speed crystal oscillation (32.768KHz), the reset time (including the start-up time) is about 1.5s by default (external capacitor
10pF~22pF).
When any of the above resets occurs, all system registers will return to the default state, the program will stop running, and
Program counterPC will be cleared at the same time. After the reset, the program will start to run from the reset vector 0000H.
Any reset situation requires a certain response time, and the system provides a complete reset process to ensure the
smooth progress of the reset action.
VLVR = 1.8 V
VDD
(Internal Signal)
Oscillation
~
(CLK)
Whether the system is power-on reset can be judged by PORF (WDCON.6) flag bit. The reset types that can set the PORF
flag to 1 are: Power-on reset, LVR reset, External reset, CONFIG protection reset.
0x97 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
WDCON SWRST PORF -- -- WDTIF WDTRF WDTRE WDTCLR
R/W R/W R/W R R R/W R/W R/W R/W
reset value 0 1 0 0 0 0 0 0
LSI
(125KHz)
VDD 3 raise sample
~
Release
VLVR VLVR
Internal
RESETB
The chip reconfiguration process within the Stabilization Time is the same as the Power-on reset configuration process.
The clock source of the WDT is provided by the system clock, and the basic time period of the WDT counter is Tsys. Reset
the CPU and all registers after the WDT overflows, and the program will start executing from 0000H immediately after 1 Tsys.
WDT reset will not re-configure Power-on reset. The overflow time of the watchdog can be set by the program, and the overflow
time can be selected in the two bits WDS2-WTS0 of the CKCON register. The watchdog overflow time is shown in the table
below:
WTS[2:0] Watchdog Interval Number of clocks OVT@Fsys=16MHz OVT@Fsys=48MHz
000 217 131072 8.192ms 2.731ms
001 218 262144 16.384ms 5.461ms
010 219 524288 32.768ms 10.923ms
011 220 1048576 65.536ms 21.845ms
100 221 2097152 131.072ms 43.691ms
101 222 4194304 262.144ms 87.381ms
110 224 16777216 1.048s 349.525ms
111 226 67108864 4.194s 1.398s
WDT can also be set to not reset the system and can generate interrupts.
4. Clock structure
The clock source of the system clock has 4 types, and the clock source and clock division can be selected through the
system configuration register settings. The system clock source is as follows;
◆ Internal high-speed oscillation HSI (48MHz).
◆ External high-speed oscillator HSE (8MHz/16MHz).
◆ External low-speed oscillator LSE (32.768KHz).
◆ Internal low-speed oscillation LSI (125KHz).
The default clock source of the chip is HSI, and the system clock will run in HSI after the chip reset is completed. If you
need to change the system clock source, you can set it through the system configuration register (you need to cooperate with
the burning tool and the upper computer software to operate). When the external high-speed oscillator is used as the system
clock source, select which group of ports as the crystal oscillator ports through the system configuration register.
CPU
BUZZ
CONFIG
configuration PWM
/1
HSI
oscillator /2 HSI_FS IIC
48MHz /3 MUX
/6 MUX UART0
SPI
WDT
TIMER0/1
LSI
oscillator LSI MUX UART1
125KHz CONFIG TIMER2
CONFIG
configuration
configuration
/1
Register TIMER3/4
/2 Fsys
Fosc Fsys_pre
/4 MUX CLKDIV
HSE MUX
/8 BRT
CONFIG UART2
MUX
configuration
OSCIN1
BRT1
HSE1
OSCOUT1 MUX
GATE
ADC
LSI WUT
OPA UART3
MUX
ACMP
OSCIN2
LSE LSE LSE
HSE2/LSE GATE
Timer CRC
OSCOUT2
MDU
LCD
LSE
MUX
LSI LED
Modify the instruction sequence required by CLKDIV (no other instructions can be inserted in the middle):
MOV TA,#0AAH
MOV TA,#055H
MOV CLKDIV,#02H
5. Power management
low power consumption modes are divided into two categories:
◆ IDLE: idle mode
◆ STOP: sleep mode When
users use C language for program development, it is strongly recommended to use the IDLE and STOP macro instructions
to control the system mode, and do not directly set the IDLE and STOP bits. The macro is as follows:
enter idle mode: IDLE();
enter sleep mode: STOP();
Example: When using timing wake-up, enter sleep processing program (assembler)
SLEEP_MODE:
MOV WUTCRL,#31h
MOV WUTCRH,#80h
MOV P0TRIS,#0FFh
MOV P0,#0FFh
MOV P1TRIS,#0FFh
MOV P1,#0FFh
MOV P2TRIS ,#0FFh
MOV P2,#0FFh
MOV P3TRIS,#0FFh
MOV P3,#0FFh
Operation instructions to turn
off other functions
MOV PCON,#06H; Perform functional wake-up sleep operation,
NOP
NOP
NOP
NOP
NOP
; The instruction to execute the sleep operation must be followed
NOP
by other operation instructions after the wake-up of 6 NOP
www.mcu.com.cn 43 / 261 Rev. 1.04
CMS80F261x Reference Manual
6. Interrupt
6.1 Overview
chips having 25 interrupt sources and vector:
interrupt source Interrupt described interrupt vector sibling priority sequence
INT0 external 0-0x0003interrupt 0 1
Timer0 timer 0 interrupt 1 -0x000B 2
INT1 external interrupt 1 2-0x0013 3
Timer1 timer 1 interrupt 3-0x001B 4
UART0 TI0 or RI0 4-0x0023 5
Timer2 timer 2 interrupt 5-0x002B 6
UART1 TI1 or RI1 6-0x0033 7
P0EXTIF<7:0 > P0 external interrupt 7-0x003B 8
P1EXTIF<7:0> P1 external interrupt 8-0x0043 9
P2EXTIF<7:0> P2 external interrupt 9-0x004B 10
P3EXTIF<7:0> P3 external interrupt 10-0x0053 11
P4EXTIF<7:0> Port 4 external interrupt 11-0x005B 12
P5EXTIF<7:0> Port 5 external interrupt 12-0x0063 13
- - 13-0x006B 14
ACMP comparator interrupt 14-0x0073 15
Timer3 timer 3 interrupt 15-0x007B 16
Timer4 Timer 4 Interrupt 16-0x0083 17
- - 17-0x008B 18
PWM PWM Interrupt 18-0x0093 19
ADC ADC Interrupt 19-0x009B 20
WDT WDT Interrupt 20-0x00A3 21
I2 C I2C Interrupt 21 -0x00AB 22
SPI SPI interrupt 22-0x00B3 23
UART2 TI2 or RI2 23-0x00BB 24
UART3 TI3 or RI3 24-0x00C3 25
LSE_Timer LSE timer interrupt 25-0x00CB 26
L VD LVD power-down interrupt 26-0x00D3 27
- - 27-0x00DB 28
The chip stipulates two interrupt priority levels, which can realize two-level interrupt nesting. When an interrupt has been
responded, if a high-level interrupt sends a request, the latter can interrupt the former to achieve interrupt nesting.
If the interrupt of Timer2 is enabled, the total interrupt enable bit of Timer2 ET2=1 (IE.5=1)
Bit7 SPISIF: SPI transmission complete interrupt flag bit, read only;
1= SPI transmission is complete (read SPSR first, then clear after reading/writing SPDR);
0= The SPI transmission is not complete.
Bit6 WCOL: SPI write conflict interrupt flag bit, read only;
1= Write SPDR operation conflict occurs when SPI transmission is not completed (read SPSR
first, then clear after reading/writing SPDR);
0= No write conflicts.
Bit5~Bit1 -- Reserved, all must be 0.
Bit0 SSCEN: SPI master mode NSS output control bit.
1= When SPI is in idle state, NSS outputs high level;
0= NSS outputs the contents of register SSCR.
Note: I2C master mode interrupts and slave mode interrupts share the same interrupt vector (00ABH).
The software clearing operation requires attention: when multiple interrupt flags are in the same register and the moments
when these flags are generated are not related to each other, it is not recommended to use read-modify-write operations. For
example, the PWMUIF interrupt flag bit register contains the upward comparison interrupts of the PG0-PG5 channels. These
interrupt flag bits are not related to each other. When PG0 generates an upward comparison interrupt, the value of PWMUIF is
0x01. After entering the interrupt service routine, perform a read-modify-write operation to clear the bit
PWMUIF &= 0xFE;
This operation is specifically implemented by first reading the value of PWMUIF back to the CPU, and then perform
calculations again, and finally send back to PWMUIF. If the interrupt flag bit PWMUIF[1] of PG1 is set to 1 after the CPU is
read, and PWMUIF[1] is 0 when it is read, it will be sent back to PWMUIF[1] after the calculation is also 0, and PG1 will be
cleared at this time The up interrupt flag that has been generated is PWMUIF[1].
To clear the above type of interrupt flag bit, it is recommended to write 0 directly, and write 1 to other irrelevant flag bits:
PWMUIF = 0xFE. This operation has no actual effect on writing 1 to the irrelevant interrupt flag.
Example: The transmission completion flag bit SPISIF in the SPI interrupt flag register in debug mode
... //Set port and interrupt enable
SPDR = 0x56; //Send SPDR data
delay();
...
When the breakpoint is running, after stopping at breakpoint 1, the SPI completes the transmission operation, and the
transmission completion interrupt has been generated, so SPSR.7=1, at this time the emulator has completed the operation of
reading all registers (including reading SPSR).
Execute breakpoint operation again and stop at breakpoint 2. At this time, the emulator once again completes the
operation of reading all registers (including SPDR), so SPSR.7=0 at this time. The above situation will also occur when single
stepping twice, so you need to pay attention to it in debug mode.
7. I/O port
7.1 GPIO function
Chip has six groups of I/O ports: PORT0, PORT1, PORT2, PORT3, PORT4, PORT5.
PORTx is a bidirectional port. Its corresponding data direction register is PxTRIS. Set a bit of PxTRIS to 1 (=1) to configure
the corresponding pin as an output. Clear a bit of PxTRIS (= 0) to configure the corresponding PORTx pin as an input.
When PORTx is used as an output port, writing to the Px register will write to the port latch, and all writing operations are
read-modify-write operations. Therefore, writing a port means first reading the pin level of the port, then modifying the read
value, and finally writing the modified value to the port data latch.
When PORTx is used as an output port, reading the Px register is related to the setting of the PxDS register. A bit of PxDS
is 1 (=1), the corresponding bit of Px read is the status of the pin, a bit of PxDS is cleared (=0), the corresponding bit of Px read
is the state of the port data latch; PORTx is When the input port is used, the status of the pin is read by reading the Px register,
which has nothing to do with the setting of the PxDS register.
When using the PORTx pin as an analog input, the user must ensure that the bits in the PxTRIS register remain set to 0.
I/O pins configured as analog inputs always read 0.
The registers related to PORTx include Px, PxTRIS, PxOD, PxUP, PxRD, PxDS, etc.
Note:
1) After the port is set as an output port, the data read from the port is the value of the output register.
2) After the port is set as an input port, the <read-modify-write> type of instruction for the port is actually an operation on the output
register.
Note: The control of the pull-down resistor has nothing to do with the configuration of GPIO and the multiplexing function, and
is controlled separately by the PxRD register.
Note: If you need to read the pin status when the port is a multiplex function input structure, you need to set the port direction
control to input mode.
Each port has a function configuration register PxnCFG, through which each port can be set to the corresponding digital
function. For example, to set P20 as BEEP buzzer function, configure P20CFG=0x06;
The port direction register PxTRIS does not need to be configured when the port is used as a multiplexing function.
- SCL and SDA pull-up resistance registers can be configured to force open drain output.
- RXD0 and RXD1 synchronization modes force pull-up.
Other multiplexing functions are forced to close the pull-up resistance and open drain output by hardware, that is, set the
pull-up resistance PxUP or open drain output PxOD by software to be invalid.
When the port is multiplexed into SCL and SDA functions, the hardware forces the port to be open-drain output, and the
pull-up resistance PxUP can be set through software.
PS_CAP3 F0CBH CAP3 Timer2 input capture channel 3 port allocation register
PS_ADET F0CCH ADET ADC external trigger input Port allocation register
PS_XX input function port allocation register PS_XX (as described in the above table)
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PS_XX -- PS_XX6 PS_XX5 PS_XX4 PS_XX3 PS_XX2 PS_XX1 PS_XX0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset
1 1 1 1 1 1 1 1
value
1) Each port can be configured For INT0, INT1 interrupt function (other input function port assignment is fixed). If multiple ports
are configured for the same digital function at the same time, the priority will decrease in the order of P00, P01,..., P54, P55.
If P03 and P20 are configured as T1 functions at the same time, the P03 configuration is valid and the P20 configuration is
invalid.
2) The input function assignment structure supports multiple input functions assigned to the same port. For example, INT0
and T0 can be allocated to port P02 at the same time, the configuration is as follows:
P02CFG = 0x00; //P00 port is configured as GPIO function
P0TRIS = 0x00; //P02 is used as GPIO input function
PS_INT0 = 0x02; //P02 port is configured as INT0 function
PS_T0 = 0x02; //P02 port is configured as T0 function.
3) The input function allocation structure is relatively independent and can support simultaneous use with other multiplexed
function ports. At this time, there is no need to configure the direction register of the corresponding port. For example, RXD0
and INT0 can be allocated to Port P20 is configured as follows:
P20CFG = 0x02; //P20 is multiplexed as RXD0 function of UART0
PS_INT0 = 0x20; //P20 port is configured as INT0 function.
4) The input function configuration structure can also be used simultaneously with the port external interrupt function. If you
can assign T1G and GPIO interrupt functions to port P00 at the same time, the configuration is as follows:
P00CFG = 0x00; //P00 port is configured as GPIO function
P0TRIS = 0x00; //P00 is used as GPIO input function
PS_T1G = 0x00; //P00 port is configured as T1G function
P00EICFG = 0x01; //P00 port is configured as rising edge trigger interrupt
P0EXTIE = 0x01; //Enable P00 port external interrupt
Communication input function port distribution register PS_XX (as described in the above table)
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PS_XX -- PS_XX6 PS_XX5 PS_XX4 PS_XX3 PS_XX2 PS_XX1 PS_XX0
R/W W W W W W W W W
Reset value 1 1 1 1 1 1 1 1
recommended to configure the port distribution register when SCLK is used as an output or input.
9) When the SCL of IIC is used as the clock input of the slave, it needs to be selected by the port allocation register. When
it is used as the clock output of the master, it is related to the port allocation register. It is recommended that the SCL
be configured with the port allocation register whether it is used as the output or input.
Modify the instruction sequence required by WDCON (no other instructions can be inserted in the middle):
MOV TA,#0AAH
MOV TA,#055H
ORL WDCON,#01H
9. Timer 0/1
Timer 0 is similar in type and structure to Timer 1, and is two 16-bit timers. Timer 1 has three working modes, and Timer 0
has four working modes. They provide basic timing and event counting operations.
In the "timer mode", the timer register is incremented every 12 or 4 system cycles when the timer clock is enabled.
In the "counter mode", the timing register will increase whenever it detects a falling edge on the corresponding input pin (T0
or T1).
9.1 Overview
Timer 0 and Timer 1 are fully compatible with standard 8051 timers.
Each timer consists of two 8-bit registers: {TH0 (0x8C): TL0 (0x8A)} and {TH1 (0x8D): TL1 (0x8B)}. Timers 0 and 1 work
in four identical modes. Timer0 and Timer1 modes are described below.
Register THx and TLx are special function registers, it has the function of storing the actual timer value. THx and TLx can
be cascaded into 13-bit or 16-bit registers through mode options. Each time an internal clock pulse is received or a state transition
occurs on the external timer pin, the value of the register is increased by one. The timer will start counting from the value loaded
in the preset register until the timer overflows, at which time an internal interrupt signal will be generated. If the automatic reload
mode of the timer is selected, the timer value will be reset to the initial value of the preload register and continue counting,
otherwise the timer value will be reset to zero. Note that in order to get the maximum calculation range of the timer/counter, the
preset register must be cleared first.
Bit7~ Bit0 TL0<7:0>: Timer 0 low bit data register (also used as counter low bit).
Bit7~Bit0 TH0<7:0>: Timer 0 high data register (also used as counter high).
Bit7~Bit0 TL1<7:0>: Timer 1 low bit data register (also used as counter low bit).
Bit7~Bit0 TH1<7:0>: Timer 1 high data register (also used as counter high bit).
The flag bit that generates an interrupt can be cleared by software, and the result is the same as cleared by hardware. In
other words, you can generate interrupts by software (it is not recommended to generate interrupts by writing flag bits) or
cancel pending interrupts.
The TF0 and TF1 flags can be cleared by writing 0 when the interrupt is not enabled.
:12-T0M=0
CLK TMOD.2=0
: 4-T0M=1
Interrupt request
TCON.4
TMOD.3
T0G
:12-T0M=0
CLK : 4-T0M=1 TMOD.2=0
Interrupt request
TCON.4
TMOD.3
T0G
:12-T0M=0
CLK TMOD.2=0
: 4-T0M=1
TL0 TCON.5
8Bit
T0 TMOD.2=1
Interrupt request
Reset
TCON.4
TMOD.3
TH0
8Bit
T0G
TH0 TCON.7
8Bit
Interrupt request
TCON.6
:12-T0M=0 TMOD.2=0
CLK
: 4-T0M=1
TL0 TCON.5
8Bit
T0 TMOD.2=1
Interrupt request
TCON.4
TMOD.3
T0G
:12-T1M=0
CLK TMOD.6=0
: 4-T1M=1
Interrupt request
TCON.6
TMOD.7
T1G
:12-T1M=0
CLK TMOD.6=0
: 4-T1M=1
Interrupt request
TCON.6
TMOD.7
T1G
:12-T1M=0
CLK : 4-T1M=1 TMOD.6=0
TL1 TCON.7
8Bit
T1 TMOD.6=1
Interrupt request
Reset
TCON.6
TMOD.7
TH1
8Bit
T1G
10. Timer 2
Timer 2 with additional compare/capture/reload functions is one of the core peripheral units. It can be used for various
digital signal generation and event capture, such as pulse generation, pulse width modulation, pulse width measurement, etc..
10.1 SUMMARY
The structure diagram of Timer 2 with additional compare/capture/reload register function is shown in the figure below
EXEN2
T2I[1:0]
T2 Sync
Reload
T2R[1:0]
0 TF2
CLK /12
1 T2OVIE
/2 Timer2
Interrupt
T2PS Request
TH2 TL2
Compare T2C3IF
T2C3IE
T2C2IF
Input/Output T2C1IF
Control
T2C1IE
T2C0IF
CAP0 CC0
CAP1 CC1
CAP2 CC2
CAP3 CC3
Bit7~Bit0 TL2<7:0>: Timer 2 low bit data register (also used as counter low bit).
Bit7~Bit0 TH2<7:0>: Timer 2 high data register (also used as counter low).
To set the Timer2 interrupt, you need to configure the global interrupt enable bit (EA=1), the Timer2 total interrupt enable
bit (ET2=1), and the corresponding interrupt type enable bit (T2IE) of Timer2. The 4 types of interrupts of Timer2 share an
interrupt vector. After entering the interrupt service routine, it is necessary to determine the relevant flag bit to determine which
type has generated the interrupt.
T2EX
Mode 2
Reload
Mode 1
RLDL RLDH TF2
Timer 2
Interrupt
T2EXIF Request
T2CxIF (x=0,1,2,3)
Compare Register
RLDH,RLDL
CCxH,CCxL/RLDH,RLDL
/ CCHx,CCLx
(x=1,2,3)
16-Bit
Set Register
Comparator
Compare Singnal
Reset Register
16-Bit
Q Q Q Q
TH2 TL2 Overflow
Timer2
TF2
the output structure block diagram of comparison mode 0 is shown in the following figure:
~
Timer Count = Reload Vaule
CCx(x=0,1,2,3)
T2CxIF(x=0,1,2,3)
Compare Register
RLDH,RLDL / CCHx,CCLx
(x=1,2,3)
Port
16-Bit Register
Circuit P1.3 P1.2 P1.1 P1.0
Comparator
Compare Singnal
Q Q Q Q
16-Bit
T2CON[6:5]
CCEN[7:0]
Capture
CAPx(x=0,1,2,3)
RLDL/CCLx RLDH/CCHx
(x=1,2,3) (x=1,2,3)
T2CxIF(x=0,1,2,3)
11.1 Overview
Timer 3 and Timer 4 are composed of two 8-bit registers {TH3, TL3} and {TH4, TL4}. Timers 3 and 4 work in the same
four modes. Timer3 and Timer4 modes are described as follows:
Bit7~Bit0 TL3<7:0>: Timer 3 low-bit data register (also used as timer low-bit).
Bit7~Bit0 TH3<7:0>: Timer 3 high data register (also used as timer high bit).
Bit7~Bit0 TL4<7:0>: Timer 4 low-bit data register (also used as timer low-bit).
Bit7~Bit0 TH4<7:0>: Timer 4 high data register (also used as timer high bit).
Interrupt request
T34MOD.3
Interrupt request
T34MOD.3
Interrupt request
Reset
TH3
T34MOD.3 8Bit
TH3 EIF2.1
8Bit
Interrupt request
T34MOD.7
:12-T3M=0
CLK : 4-T3M=1
TL3 EIF2.0
8Bit
Interrupt request
T34MOD.3
Interrupt request
T34MOD.7
Interrupt request
T34MOD.7
Interrupt request
Reset
TH4
T34MOD.7 8Bit
Bit7~Bit0 LSED<15:8>: The upper 8 bits of the LSE timing/wake-up time data.
When the count value of the LSE timer is equal to the timing value, the timer interrupt flag bit LSEIF is set to 1. If the
global interrupt is enabled (EA=1) and the LSE timer interrupt is enabled (LSEIE=1), the CPU will execute the interrupt service
routine.
To use LSE timer interrupt to wake up the sleep mode, you need to turn on LSEEN, LSECNT, LSEWIEN before sleep,
and set the time from sleep state to wakeup{𝐿𝑆𝐸𝐶𝑅𝐻[7: 0], 𝐿𝑆𝐸𝐶𝑅𝐿[7: 0]}. If the global interrupt enable and LSE interrupt
enable are turned on before the sleep, after the sleep wakes up, the interrupt service routine will be executed first, and the
next instruction of the sleep instruction will be executed after the interrupt returns.
1
LSE timing time = × ( { LSECRH[7:0], LSECRL[7:0]}+1) ms
32.768
If any bit of LSEEN, LSECNTEN, LSETA is 0, the count value of LSE will be cleared..
{WUTCRH[3:0] and WUTCRL[7:0]} form a 12-bit timing wake-up data register. After entering sleep mode, the WUT
counter starts timing. When the value of the WUT counter equals the value of the timing wake-up data register, the system
oscillator is started , Enter the wake-up waiting state.
Timing wake-up time:T=(WUTD[11:0]+1)×WUTPS×TLSI
14.2.5 BRT1 timer data load value lower 8-bit register BRT1DL
F5C5H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
BRT1DL BRT1DL7 BRT1DL6 BRT1DL5 BRT1DL4 BRT1DL3 BRT1DL2 BRT1DL1 BRT1DL0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
reset value 0 0 0 0 0 0 0 0
14.2.6 BRT1 timer data load value lower 8 bits register BRT1DH
F5C6H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
BRT1DH BRT1DH7 BRT1DH6 BRT1DH5 BRT1DH4 BRT1DH3 BRT1DH2 BRT1DH1 BRT1DH0
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset value 0 0 0 0 0 0 0 0
Bit7~Bit0 CRCD<15 :8> The high 8-bit data of CRC operation result
Write MD0 first Write MD5 or ARCON at the end First read MD0 Last read MD3 or MD5
Bit7~Bit0 MD0<7:0>: 32bit/16bit division operation: write bit7-bit0 as the dividend, read bit7-bit0 as the quotient;
16bit/16bit division operation: write bit7-bit0 as the dividend, read bit7-bit0 as the quotient;
16bit*16bit multiplication operation: write bit7-bit0 as the first multiplier, read bit7-bit0 as
the product;
During shift operation: bit7-bit0 of write/read data;
During normalization operation: bit7-bit0 of write/read data.
Bit7~Bit0 MD1<7:0>: 32bit/16bit division operation: write bit15-bit8 as the dividend, read bit15-bit8 as the
During quotient; during
16bit/16bit division operation: Write bit15-bit8 as dividend, read bit15-bit8 as quotient;
16bit*16bit multiplication operation: write bit15-bit8 as the first multiplier, read bit15-bit8 as
product;
During shift operation Time: bit15-bit8 for writing/reading data;
During normalization operation: bit15-bit8 for writing/reading data.
Bit7~Bit0 MD2<7:0>: 32bit/16bit division operation: write bit23-bit16 as the dividend, read bit23-bit16 as
During quotient; during
16bit*16bit multiplication operation: Read as product bit23-bit16; during
During shift operation: write/read data bit23-bit16; during
During normalization operation: write/read data bit23-bit16.
Bit7~Bit0 MD3<7:0>: 32bit/16bit division operation: write bit31-bit24 as the dividend, read bit31-bit24 as the
During quotient; during
16bit*16bit multiplication: Read as product bit31-bit24; during
During shift operation: write/read data bit31-bit24; during
During normalization operation: write/read data bit31-bit24.
Bit7~Bit0 MD4<7:0>: 32bit/16bit division: write bit7-bit0 as the divisor, read bit7-bit0 as the remainder; during
During
16bit/16bit division: Write to bit7-bit0 of the divisor and read bit7-bit0 of the remainder;
16bit*16bit multiplication operation: Write to bit7-bit0 of the second multiplier.
Bit7~Bit0 MD5<7:0>: 32bit/16bit division operation: write bit15-bit8 as divisor, read bit15-bit8 as remainder;
During during
16bit/16bit division operation: Write bit15-bit8 as the divisor, read bit15-bit8 as the
remainder;
16bit*16bit multiplication operation: write bit15-bit8 as the second multiplier.
MDUAll calculations of MDU are completed by hardware, and the conversion rate is fast, which can save a lot of time for
program operation. The calculation time of the second stage of the five operations of the MDU module is shown in the following
table:
calculation time (second
Function calculation result digits remainder digits
stage)
32bit/16bit division 32bit 16 bit 16 Tsys
16bit/16bit division 16 bit 16 bit 8 Tsys
16bit*16bit multiplication 32bit - 8 Tsys
32bit shift operation 32bit - 2~17 Tsys
32bit normalization
32bit - 1~17 Tsys Tsys in the
operation
Tsys in the above table is the clock period of the MDU module; the calculation time is the calculation time of the MDU
module, excluding the time for reading and writing registers; the calculation time of the shift operation and the normalization
operation depends on the number of shift bits and operands, respectively , The minimum operation time of shift operation is 2
Tsys and the maximum is 17 Tsys; the minimum operation time of normalization operation is 1 Tsys, and the maximum is 17
Tsys.
If the operation result is not read after the operation is completed, MD0 can be written again to start the next operation.
If the dividend is 0X87654321 and the divisor is 0X1234, write MD0=0X21, MD1=0X43, MD2=0X65, MD3=0X87,
MD4=0X34, MD5=0X12, the read result after MDU calculation is: MD0=0X23, MD1 =0X70, MD2=0X07, MD3=0X00,
MD4=0X05, MD5=0X06.
If the operation result is not read after the operation is completed, MD0 can be written again to start the next operation.
For example, when the dividend is 0X4321 and the divisor is 0X1234, write MD0=0X21, MD1=0X43, MD4=0X34,
MD5=0X12, and the read result after MDU calculation is: MD0=0X03, MD1=0X00, MD4=0X85, MD5 =0X0C.
If the operation result is not read after the operation is completed, MD0 can be written again to start the next operation.
For example, when the first multiplier is 0X8765 and the second multiplier is 0X1234, write MD0=0X65, MD4=0X34,
MD1=0X87, MD5=0X12, and the read result after MDU calculation is: MD0=0X84, MD1 =0X9A, MD2=0XA0, MD3=0X09.
If the operation result is not read after the operation is completed, MD0 can be written again to start the next operation.
If the operand is 0X12345678, when shifting to the right by 5 bits, write MD0=0X78, MD1=0X56, MD2=0X34, MD3=0X12,
ARCON=0X25, and the read result after the MDU operation is completed: MD0=0XB3, MD1= 0XA2, MD2=0X91, MD3=0X00.
If the operation result is not read after the operation is completed, MD0 can be written again to start the next operation.
If the operand is 0X12345678, during normalization operation, write MD0=0X78, MD1=0X56, MD2=0X34, MD3=0X12,
ARCON=0X00, and the read result after MDU operation is completed: MD0=0XC0, MD1=0XB3 , MD2=0XA2, MD3=0X91,
ARCON=0X03.
18.2 Feature
Enhanced PWM module has the following features:
◆ 6 independent 16-bit PWM control modes.
- 6 independent outputs: PG0, PG1, PG2, PG3, PG4, PG5;
- 3 sets of complementary PWM pair outputs: (PG0-PG1), (PG2-PG3), (PG4-PG5), programmable dead time
can be inserted;
- Three groups of synchronous PWM pair output: (PG0-PG1), (PG2-PG3), (PG4-PG5), each group of PWM pair
pins are synchronized.
◆ Support group control, PG0, PG2, PG4 output synchronization, PG1, PG3, PG5 output synchronization.
◆ Support two modes of edge alignment and center alignment.
◆ The center-aligned mode supports symmetric counting and asymmetric counting.
◆ Support single mode or auto-load mode.
◆ Each PWM has independent polarity control.
◆ Mask output function.
◆ Hardware brake protection (external FB0/FB1 trigger, ADC comparison event trigger, ACMP output trigger).
◆ The PWM edge or cycle can trigger the start of AD conversion.
ACMP0 ACMP1
PWMDnH& PWMDnL
PWMPnH &
PWMDDnH& PWMDDnL
PWMPnL ADC
PG4
PWM PWM4 compare
Prescaler4/5 Divider4
Counter4 circuit
PWM4/5 wave PG5
generator
PWM PWM5 compare
Divider5
Counter5 circuit
Interrupt
Period =(PERIODn+1)×Tpwm
CMPn+1
duty cycle = (CMPn≥1) When
PERIODn+1
CMPn=0, The duty cycle is 0%.
PERIODn(new) 1A34H
PERIODn(old) 07FFH
CMPn(new) 012FH
CMPn(old) 0080H
0 0000H
PIFn/ZIFn
DIFn
PGn
Period =(PERIODn)×2×Tpwm;
PERIODn(new) 1A34H
PERIODn(old) 07FFH
CMPn(new) 012FH
CMPn(old) 0080H
0 0000H
PIFn
ZIFn
UIFn
DIFn
PGn
The center-aligned counter waveform (symmetric counting) is shown in the figure below:
When PWMnCNTM=1, continuous mode is enabled, when CNTn counts to zero, reload
PERIODn and CMPn
PWMn clock
PERIODn(new) 6
PERIODn(old) 5
4
CMPn(new) 3
CMPn(old) 2
1
0
PGn
period =(PERIODn)×2×Tpwm
PERIODn×2-CMPDn-CMPn-1
duty cycle =
PERIODn ×2 When
PERIODn(new) 1A34H
PERIODn(old) 07FFH
CMPDn(new) 022FH
CMPDn(old) 012FH
CMPn(old) 0080H
0 0000H
PIFn
ZIFn
UIFn
DIFn
PGn
PWMn clock
PERIODn(new) 6
PERIODn(old) 5
CMPDn(new) 4
CMPDn(old) 3
2
CMPn 1
0
PGn
PERIOD0
CMP0
PG0
PG1
Take PG0/PG1 as an example, the waveform diagram with dead zone in complementary mode is shown in the figure below:
PWMP0
PWMD0
PG0
PG1
1= enable;
0= disable.
Bit0 PWM0OE: PWM channel 0 output enable bit;
1= enable;
0= disable.
18.5.16 PWM down compare data register low 8 bits PWMDDnL (n=0-5)
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PWMDDnL PWMDDnL7 PWMDDnL6 PWMDDnL5 PWMDDnL4 PWMDDnL3 PWMDDnL2 PWMDDnL1 PWMDDnL0
18.5.17 PWM down compare data register high 8 bits PWMDDnH (n=0-5)
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PWMDDnH PWMDDnH7 PWMDDnH6 PWMDDnH5 PWMDDnH4 PWMDDnH3 PWMDDnH2 PWMDDnH1 PWMDDnH0
Bit1 PWMFB1EN: PWM external hardware brake channel (FB1) enable bit;
1= enable;
0= disable.
Bit0 PWMFB0EN: PWM external hardware brake channel (FB0) enable bit;
1= enable;
0= disable.
19.2 Features
The LCD driver has the following features:
◆ Maximum supported LCD channels: 8COM x 32SEG, 6COM x 34SEG, 5COM x 35SEG, 4COM x 36SEG.
◆ Support contrast adjustment.
◆ Optional bias voltage: 1/2, 1/3, 1/4.
◆ The duty cycle is optional: 1/4, 1/5, 1/6, 1/8.
◆ Three kinds of clock sources are optional: system clock, LSI, LSE.
◆ It supports two modes: traditional resistance and fast charging.
◆ Choice of fast charging time.
DUTY COM_MOD COM_SEL ICOM0 ICOM1 ICOM2 ICOM3 ICOM4 ICOM5 ICOM6 ICOM7 有效 SEG 口
1 LCD_S39-36
0 LCD_C7 LCD_C6 LCD_C5 LCD_C4 - - - -
LCD_S0-31
11
LCD_S39-36
1 LCD_C4 LCD_C5 LCD_C6 LCD_C7 - - - -
0 LCD_S0-31
LCD_S39-37
1 - LCD_C7 LCD_C6 LCD_C5 LCD_C4 LCD_C3 - - -
10 LCD_S0-31
LCD_S39-38
1 - LCD_C7 LCD_C6 LCD_C5 LCD_C4 LCD_C3 LCD_C2 - -
01 LCD_S0-31
Note: BIAS and DUTY are independent of each other. Regardless of the bias voltage setting, you can select 1/4, 1/5, 1/6,
1/8 duty cycle.
20.2 Features
The hardware LED driver has the following features:
◆ 1/4, 1/5, 1/6, 1/8 four kinds of DUTY are optional.
◆ System clock, LSI, LSE three clock sources are optional.
◆ 16-bit clock source divider controller.
◆ Supports up to 8 COM ports and 24 SEG ports.
◆ Two drive modes of common cathode and common anode for COM port are optional.
◆ The COM port current 50 mA andmA are two options (VOL150=1.5V@VDD=5V).
◆ The SEG port current 16selectable, the maximum current can reach 40mA (V OHlevels are=3.5V@VDD=5V).
1
0 LED_C7 LED_C6 LED_C5 LED_C4 - - - - LED_S27-24
11 LED_S0-23
1 LED_C4 LED_C5 LED_C6 LED_C7 - - - - LED_S0-23
0
0 LED_C0 LED_C1 LED_C2 LED_C3 - - - - LED_S0-23
Note: ICOM0-ICOM7 in the above table are the LED internal COM drive output signals.
LED_C0-LED_C7, LED_S0-LED_S28 are the pin names to which the internal drive signal of the LED is finally mapped.
SEG0-23
2) LED configuration 1/4DUTY, common cathode drive mode, COM_SEL=1, MODE0 mode, the waveform is shown in
the figure below:
SEG0-23
3) LED configuration 1 / 4DUTY, were positive drive mode, COM_SEL = 0, MODE1 mode, a waveform as shown below:
SEG0-27
4) LED configuration 1 / 4DUTY, were positive drive mode, COM_SEL = 1, MODE1 mode, a waveform as shown below:
SEG0-23
◆ The bit rate generates 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256, 1/512 of the system clock.
◆ Supports four transmission formats.
◆ The simple interface allows easy connection to the microcontroller.
Configured as SCLK, MOSI, MISO and NSS ports, the pull-up resistor and open-drain output switch are forcibly closed.
The schematic diagram of the multi-machine SPI communication structure is shown in the figure below:
MOSI
MISO
SCLK
MOSI
MISO
Read Data Buffer
CPHA
SPR
CPOL
The pins associated with SPI are: NSS, SCLK, MOSI, MISO.
The NSS output pin in the master mode is used to select the slave device, and the NSS input pin in the slave mode is used
to enable transmission.
In master mode, the SCLK pin is used as the SPI clock signal reference. When the host device starts the transfer, eight
clock cycles are automatically generated on the SCLK pin.
When SPI is configured as a slave device, the SI pin is the input data line of the slave device, and SO is the output data
line of the slave device.
When SPI is configured as a host device, MI pin is the input data line of the host device, and MO is the output data line of
the host device.
The SPI status register (SPSR) contains a flag indicating the completion of the transfer or the occurrence of a system error.
When the corresponding event occurs and is cleared by software in sequence, all the flags will be automatically set. By reading
SPSR and then accessing SPDR, SPISIF and WCOL will be cleared automatically.
The SSCEN bit is the enable bit for automatic slave selection output. When SSCEN is set to 1, the NSS line outputs the
contents of the SSCR register when the transmission is in progress, and the NSS is high when the transmission is idle. When
the SSCEN bit is cleared, the NSS line always displays the contents of the SSCR register.
NSS
MOSI D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCLK
SPIIF
When SSCEN=0, configure the SPI clock polarity CPOL=0, clock phase CPHA=0, the slave selection line is used as shown
in the figure below:
NSS
MOSI D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCLK
SPIIF
NSS
MOSI D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCLK
WCOL
SPIIF
The specific conditions for the write conflict are: during data transmission, when NSS is low, the first From the time when a
data is sent to the eighth falling edge of SCLK, if SPDR is written during this period, a write conflict will occur and WCOL will be
set to 1.
Note: When starting to send data, after writing SPDR, NSS does not change to low level immediately, it needs to wait at
most one SPI clock before starting to be low. After NSS is low, it needs to wait for a system clock to start sending the first data,
and then it enters the real data transmission state. During the period from writing SPDR to entering the real data transmission
state, writing to SPDR again does not produce a write conflict. But this operation will update the data to be sent. If there are
multiple write operations to SPDR, the data sent will be the last value written to SPDR.
Since SPI has only one transmit buffer, it is recommended to determine whether the last data has been sent before writing
SPDR, and write the SPDR register after confirming that the transmission is completed to prevent write conflicts.
NSS
MISO D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
SCLK
WCOL
SPIIF
In case CPHA is cleared, WCOL generation can also be caused by writing to the SPDR register when any NSS line is
cleared. At this time, the SPI master does not generate the serial clock SCLK. can be completed. This is because the start of
the transfer is not explicitly specified, and the NSS being driven low after the full byte transfer may indicate the start of the next
byte transfer. When the NSS transmission line is low and the clock phase CPHA = 0, writing SPDR causes a write conflict error
as shown in the following figure:
NSS
MISO D7 D6 D5 D4 D3 D2 D1 D0
SCLK
WCOL
In addition, after writing SPDR in the slave mode, the NSS controlled by the host does not immediately become low. When
NSS is low, you need to wait for the second edge of SCLK to start before entering the real data transmission state.
During the period from writing SPDR to the beginning of sending the first data, writing to SPDR again will not cause a write
conflict. But this operation will update the data to be sent. If there are multiple write operations to SPDR, the data sent will be
the last value written to SPDR.
During the period when the first data is sent to the second edge of SCLK, writing SPDR again will not cause a write conflict,
nor will it update the data being sent. That is, the operation of writing SPDR this time is ignored.
Since SPI has only one transmit buffer, it is recommended to determine whether the last data has been sent before writing
SPDR, and write the SPDR register after confirming that the transmission is completed to prevent write conflicts.
SCLK
(CPOL=0)
SCLK
(CPOL=1)
MOSI D7 D6 D5 D4 D3 D2 D1 D0
MISO D7 D6 D5 D4 D3 D2 D1 D0
NSS
When CPHA=0, the NSS line must be de-set and reset between each successive serial byte. In addition, if the slave writes
data to the SPI data register (SPDR) when NSS is at low level, a write conflict error will occur. When CPHA = 1, the NSS line
may remain low between consecutive transmissions (it can always remain low). In a system with a single fixed master and a
single slave driving the MISO data line, this format is sometimes preferred.
SCLK
(CPOL=0)
SCLK
(CPOL=1)
MOSI D7 D6 D5 D4 D3 D2 D1 D0
MISO D7 D6 D5 D4 D3 D2 D1 D0
NSS
SCLK
MOSI D7 D6 D5 D4 D3 D2 D1 D0
SCLK
max 1 CLK
MISO
D7 D6 D5 D4 D3 D2 D1 D0
NSS
max 1 CLK
SCLK
2 CLK
SPIIF
MOSI D7 D6 D5 D4 D3 D2 D1 D0
VDD
Rp Rp
SDA
SCL
Rs Rs
Rs Rs
SDA SDA
SCL SCL
After configuring I2C channel, this group of ports is in open drain state by default. You can configure whether to enable
SCL, internal pull-up resistance of SDA port, or add pull-up resistance outside the chip through PxUP.
In the master control mode, IIC outputs SCL to the slave. After sending the address or data, the slave needs to pull the SCL
down and send back the corresponding response signal to the host. The host needs to read back the SCL port line status to
detect whether the slave releases the SCL to determine whether the next frame data transmission is required. If the pull-up
resistance or board-level parasitic capacitance of SCL is larger, the reading back time will be longer, which will affect the
communication speed of IIC. Please refer to IIC application manual for details.
Master mode control register I2CMCR and the master mode status register I2CMSR share a register address, but they are
physically two different registers.
The main control sending data register and the main control receiving data register share a register address. The write
operation accesses the sending register I2CMBUF, and the read operation accesses the receiving register I2CMBUF.
During write operation, it is used as a control register to write, and read operation is used as a status register to read.
Various operations in the master control mode can be realized through the following control bit combination list:
START: Send start signal.
SEND: Send data or address.
RECEIVE: Receive data.
STOP: Send end signal.
The status register consists of three bits: SENDFIN bit, RREQ bit, and TREQ bit. The sent SENDFIN bit indicates that the
host I2C controller has completed the data reception during the I2CS single or continuous sending operation. The RREQ bit of
the receive request indicates that the I2CS device hasfrom the I 2received a data byteC host, and the I2CS device should read
a data byte from the receive data register I2CSBUF. The transmit request TREQ bit indicates that the I2CS device is addressed
as a slave transmitter, and the I2CS device should write a data byte into the transmit data register I2CSBUF. If the I2C interrupt
enable is turned on, setting any of the three flag bits will generate an interrupt.
In the slave mode, the bus busy flag bit is judged by Bit6 (BUS_BUSY) of the master mode status register I2CMSR. I2CMSR
is 0x20 when the bus is idle, and the I2CMSR register is 0x60 when the start condition is generated until the stop condition is
generated. When the stop condition is generated , I2CMSR is 0x20.
Slave mode status register I2CSSR
0xF2 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
I2CSSR -- -- -- -- -- SENDFIN TREQ RREQ
R/W -- -- -- -- -- R R R
Reset value 0 0 0 0 0 0 0 0
SCL
SDA
I2CIF
SCL
SDA
I2CIF
SCL
SDA
I2CIF
SCL
SDA
I2CIF
UART1 port RXD1 can be selected by PS_RXD1 P11, P14, P22 (RXD1 pin Only one of them can be selected), TXD1 port
can select P13, P23 through the port configuration register (can be selected at the same time, or select one. If selected at the
same time, P13/P23 will output the corresponding waveform). For example, select P11 as the RXD1 pin of UART1 and P13 as
the TXD1 pin, and the configuration is as follows:
PS_RXD1 = 0x11;//Select P11 as the RXD1 pin
P11CFG = 0x02; //P11 is multiplexed as RXD1 function
P13CFG = 0x02; //P13 When multiplexing for TXD1 function
When using, it is recommended to set the working mode first, and then configure the corresponding port as a serial port.
SMODn is the baud rate selection bit, which is set by the register PCON/PCON1. T1M is the timer 1 clock selection bit,
which is set by the register CKCON[4], and T4M is the timer 4 clock selection bit, which is set by the register T34MOD[6]. That
is, the TH1/TH4 value of Timer1 or Timer4 at the corresponding baud rate should be set to:
Fsys×2SMODn
THx=256- (x=1,4)
32×(4×31-TxM )×BaudRate
2)The formula of the baud rate when Timer2 works in overflow auto-reload mode:
Fsys×2SMODn
BaudRate= T2PS
32×(12×2 )×(65536-{RLDH,RLDL})
T2PS is the timer 2 clock prescaler selection bit, which is set by register T2CON[7]. That is, the value of "{RLDH,RLDL}"
should be set to "{RLDH,RLDL}" under the corresponding baud rate of Timer2:
Fsys×2SMODn
{RLDH,RLDL}=65536-
32×(12×2T2PS )×BaudRate
3)When BRT is used as a baud rate generator, the baud rate formula:
Fsys×2SMODn
BaudRate=
32×(65536-{BRTDH,BRTDL})×2BRTCKDIV
BRTCKDIV is the BRT timer prescaler selection bit, which is set by the register BRTCON. That is, the value of
"{BRTDH,BRTDL}" should be set as BRT at the corresponding baud rate:
Fsys×2SMODn
{BRTDH,BRTDL}=65536-
32×2BRTCKDIV ×BaudRate
4)When BRT1 is used as a baud rate generator, the baud rate formula:
Fsys×2SMODn
BaudRate=
32×(65536-{BRTDH1,BRTDL1})×2BRT1CKDIV
BRT1CKDIV is the BRT1 timer prescaler selection bit, which is set by the register BRT1CON. That is, the value of
"{BRTDH1,BRTDL1}" should be set to BRT1 at the corresponding baud rate:
Fsys×2SMODn
{BRTDH1,BRTDL1}=65536-
32×2BRT1CKDIV ×BaudRate
Baud
Fsys=8MHz Fsys=16MHz Fsys=24MHz Fsys=48MHz
rate
{TH1, Actual % {TH1, Actual % {TH1, Actual % {TH1, Actual %
bps
TH4} Rate Error TH4} Rate Error TH4} Rate Error TH4} Rate Error
4800 243 4808 -0.16 230 4808 -0.16 217 4808 -0.16 178 4808 -0.16
9600 -- -- -- 247 9615 -0.16 236 9375 2.34 217 9615 -0.16
19200 -- -- -- -- -- -- 246 18750 2.34 236 18750 2.34
38400 -- -- -- -- -- -- 251 37500 2.34 246 37500 2.34
115200 -- -- -- -- -- -- -- -- -- -- -- --
250000 -- -- -- -- -- -- -- -- -- -- -- --
500000 -- -- -- -- -- -- -- -- -- -- -- --
2) SMODn=1,T1M=1/T4M=1
Baud
Fsys=8MHz Fsys=16MHz Fsys=24MHz Fsys=48MHz
rate
{TH1, Actual % {TH1, Actual % {TH1, Actual % {TH1, Actual %
bps
TH4} Rate Error TH4} Rate Error TH4} Rate Error TH4} Rate Error
4800 230 4808 -0.16 204 4808 -0.16 178 4808 -0.16 100 4808 -0.16
9600 243 9615 -0.16 230 9615 -0.16 217 9615 -0.16 178 9615 -0.16
19200 -- -- -- 243 19230 -0.16 236 18750 2.34 217 19231 -0.16
38400 -- -- -- -- -- -- 246 37500 2.34 236 37500 2.34
115200 -- -- -- -- -- -- -- -- -- -- -- --
250000 -- -- -- -- -- -- -- -- -- -- -- --
500000 -- -- -- -- -- -- -- -- -- -- -- --
3) SMODn=0,BRTCKDIV=0/BRT1CKDIV=0
BRTL} Rate Error BRTL} Rate Error BRTL} Rate Error BRTL} Rate Error
4800 65484 4808 -0.16 65432 4808 -0.16 65380 4808 -0.16 65224 4808 -0.16
9600 65510 9615 -0.16 65484 9615 -0.16 65458 9615 -0.16 65380 9615 -0.16
19200 65523 19231 -0.16 65510 19231 -0.16 65497 19231 -0.16 65458 19231 -0.16
38400 -- -- -- 65523 38462 -0.16 65516 37500 2.34 65497 38462 -0.16
115200 -- -- -- -- -- -- -- -- -- 65523 115385 -0.16
250000 -- -- -- -- -- -- -- -- -- 65530 250000 0
500000 -- -- -- -- -- -- -- -- -- 65533 500000 0
4)SMODn=1,BRTCKDIV=0/BRT1CKDIV=0
Baud rate Fsys=8MHz Fsys=16MHz Fsys=24MHz Fsys=48MHz
BRTL} Rate Error BRTL} Rate Error BRTL} Rate Error BRTL} Rate Error
4800 65432 4808 -0.16 65328 4808 -0.16 65224 4792 0.16 64911 4800 0
9600 65484 9615 -0.16 65432 9615 -0.16 65380 9615 -0.16 65224 9615 -0.16
19200 65510 19231 -0.16 65484 19231 -0.16 65458 19231 -0.16 65380 19231 -0.16
38400 65523 38462 -0.16 65510 38462 -0.16 65497 38462 -0.16 65458 38462 -0.16
115200 -- -- -- -- -- -- 65523 115385 -0.16 65510 115385 -0.16
250000 -- -- -- -- -- -- -- -- -- 65524 250000 0
500000 -- -- -- -- -- -- -- -- -- 65530 500000 0
1000000 -- -- -- -- -- -- -- -- -- 65533 1000000 0
Read
and R/W R/W R/W R/W R/W R/W R/W R/W
write
Reset
X X X X X X X X
value
BANK0: register SBUF0 address 0x99; register SBUF1 address 0xEB.
BANK1: register SBUF2 address 0xE5; register SBUF3 address 0xE7.
Bit7~Bit0 BUFFERn<7:0>: buffer data register.
Write: UARTn starts to send data.
Read: read the received data.
TXDn
RXDn D0 D1 D2 D3 D4 D5 D6 D7
TIn
RXDn
TXDn
START D0 D1 D2 D3 D4 D5 D6 D7 STOP
TIn
RXDn
TXDn
START D0 D1 D2 D3 D4 D5 D6 D7 TB8 STOP
TIn
RXDn
TXDn
START D0 D1 D2 D3 D4 D5 D6 D7 TB8 STOP
TIn
ADC-MUX
AVDD
AN0 00000 ADC-LDO
AN1 00001 1.2V/2V/2.4V/3V
AN2 00010
AVSS ADC_VREF
AN3 00011
AN4 00100
AN5 00101
AN6 00110 ADC-IN
ADC
AN7 00111
ADGO
ADFM 0=左对齐
1=右对齐
AN22 10110 ADEN
BGR
ACMP_VREF 11111
AN31 VSS
OP1_O ADRESH ADRESL
OP0_O MUX
VSS
VDD CHS<4:0> DCMP ADCMPO
ADCMPH ADCMPL
Note: Applying analog voltage to pins defined as digital inputs may cause overcurrent in the input buffer.
Note: Any change in the system clock frequency will change the ADC clock frequency, which will negatively affect the
ADC conversion result.
CLK
ADEN (ADCON1[7])
PWM0
ADGO (ADCON0[1])
Tdelay
Note: Device reset will force all registers to enter the reset state. Therefore, the reset will shut down the ADC module
and terminate any pending conversions.
Note: If the user attempts to resume sequential code execution after waking the device from sleep mode, the global
interrupt must be disabled.
Bit7 ADCHS4 The 4th bit of ADC analog channel selection bit;
1= Refer to the description of register ADCON1 for channel selection;
0= -
Bit6 ADFM: ADC conversion result format selection bit;
1= Align to the right;
0= Align to the left.
Bit5 - Reserved
Bit4~Bit2 AN31SEL<2:0>: ADC channel 31 input source selection bits;
000 = BGR (1.2V);
001 = ACMP_VREF (the negative reference voltage of the comparator, see the ACMP
chapter for details);
010= OP1_O;
011= OP0_O;
100= BGR (1.2V)
101= VSS (ADC reference ground);
110= reserved, forbidden to use;
111= VDD (ADC default reference voltage).
Bit1 ADGO: ADC conversion start bit (when the bit is set to 1, ADEN must be 1, otherwise the
operation is invalid);
1= write: start ADC conversion, (the bit will be 1 when ADC is triggered by hardware);
read: ADC is Perform the conversion.
0= Write: invalid.
Read: ADC is idle/conversion completed;
during ADC conversion (ADGO=1), any software and hardware trigger signals will
be ignored.
Bit0 - Reserved, must be zero.
01001 =
AN9; 01010
= AN10;
Bit7 ADFBEN: ADC comparator result control PWM brake enable bit;
1= enable;
0= disable.
Bit6 ADCMPPS: ADC comparator output polarity selection bit;
1= if ADRES<ADCMP, then ADCMPO=1;
0= if ADRES>=ADCMP, then ADCMPO=1.
Bit5 - Reserved, must be zero.
Bit4 ADCMPO: ADC comparator output bit.
This bit outputs the result of the ADC comparator output, and it will be updated every
time the ADC conversion ends.
Bit3 ~ - Reserved, must be 0's.
Bit2
Bit1~Bit0 ADDLY<9:8>: ADC hardware trigger delay data[9:8] bits.
C0P0
C0P4 C0EN,C0COFM,C0CRS,C0ADJ
C0P5
C0P6 To PWM Brake
C0P7 +
C0N0 number
C0N C0 Filter C0_0
1.2V C0N1
1.2V -
Coeffi VREF To Interrupt
VDD cient k
C1EN,C1COFM,C1CRS,C1ADJ
C1P0
To PWM Brake
ACMP_VREF +
number C1_0
C1 Filter
C1N
-
To Interrupt
To ADC
The negative terminal voltage of the comparator is fixed, and The positive terminal voltage of the comparator is fixed,
the output waveform is changed when the positive terminal and the negative terminal voltage is changed, and its
voltage is changed output waveform
Hysteresis Hysteresis
Comparator negative terminal voltage Comparator positive terminal
Hysteresis voltage Cn+ voltage Hysteresis
voltage Cn-
voltage voltage
Comparator positive terminal Comparator negative terminal
voltage Cn+ voltage Cn-
It is recommended to start the comparator after setting the parameters of the comparator, otherwise, the output jump of the
comparator may be detected by mistake during the setting process.
26.2 Structure
block diagram of theis shown in the figure below:
OP0EN,OP0ADJ,OP0COFM,OP0CRS,OP0FIL
BGR(1.2V)
OP0_P +
OP0 OP0_O(端口)
OP0_N -
To ADC-AN31
OP1EN,OP1ADJ,OP1COFM,OP1CRS,OP1FIL
BGR(1.2V)
OP1_P
+
OP1 OP1_O(端口)
OP1_N -
To ADC-AN31
Bit7~Bit0 MLOCK< 7:0>: Memory operation enable bit (this register only supports write operations, read as
00H);
AAH= allow memory-related R/W/E operations;
00H/FFH/55H= do not allow operations;
others= prohibit writing.
Bit7~Bit0 MADRL<7:0>: Specify the lower 8 bits of the address for memory read/write operations.
Bit7~Bit0 MADRH<7:0>: Specify the upper 8 bits of the address for memory read/write operations.
27.2.5 Lower 8 bits of the program CRC operation result data register PCRCDL
0xF9 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PCRCDL PCRCD<7:0>
R/W R/W R/W R/W R/W R/W R/W R/W R/W
reset value 0 0 0 0 0 0 0 0
27.2.6 Program CRC operation result data register high 8 bits PCRCDH
0xFA Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PCRCDH PCRCD<15:8>
R/W R/W R/W R/W R/W R/W R/W R/W R/W
Reset
0 0 0 0 0 0 0 0
value
Bit7~Bit0 PCRCD<15: 8> program CRC calculation result of the higher 8 bits of data
Bit7~Bit6 -- Reserved
Bit5 MERR: Operation error flag (write 0 to clear);
1= Before the programming operation starts, check that the data in the programming
address is not "FFH" (not erased), and the writing operation is terminated immediately.
0= -
Bit4 MREG: Flash area selection bit;
1= Select data area (lower 10 bits address is valid);
0= Select program area (lower 16 bits address is valid).
Bit3~Bit2 MMODE<1:0>: Operation mode selection bits:
11= Erase operation mode (the range of erase operation is: the entire sector where the
current address is located);
10= Write operation mode;
01= CRC mode;
00 = Read operation mode.
Bit1 CRCADR: Program CRC check address selection bit;
1= End address selection bit;
0= Start address selection bit.
Bit0 MSTART: Operation start control bit;
1= Start the program memory R/W/E/CRC check operation (after the operation is
completed, it can be automatically cleared by hardware);
0= Write: Terminate or not start the program memory R/W/E /CRC check operation;
read: the operation is completed or the operation is not started.
The program CRC check command is set by the register MCTRL[3:2], the start address and the end address can be freely
configured through the register MADRL/MADRH, and the result is stored in the register PCRCDL/PCRCDH.
This CRC operation can only access the program storage space, but not the data storage space. In the program space
CRC check process, the CPU stops working and waits for the CPU to continue running after the CRC calculation is completed.
The CRC check is performed in byte mode, from the initial address to the end address. After the current CRC check is performed,
the MMODE[1:0]=00 of MCTRL must be set. The CRC check operation steps are as follows:
1) Enable access to the program memory register: MLOCK=0xAA (the default value is AA).
2) Check result before clearing program CRC: PCRCDL=0x00, PCRCDH=0x00.
3) Set the start and end addresses of the program CRC check: MCTRL[1]=0, set the start address through
MADRL/MADRH; MCTRL[1]=1, set the end address through MADRL/MADRH.
4) Start program CRC check command: MCTRL=0x05.
5) Wait for the end of the program CRC check: MCTRL[0] is cleared to 0 by hardware after the CRC check ends.
6) Read the program CRC check result: PCRCDL stores the low 8 bits of the program CRC operation result; PCRCDH
stores the high 8 bits of the program CRC operation result.
Bit7~Bit0 UID<7:0>
UID1
F5E1H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID1 UID15 UID14 UID13 UID12 UID11 UID10 UID9 UID8
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<15:8>
UID2
F5E2H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID2 UID23 UID22 UID21 UID20 UID19 UID18 UID17 UID16
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<23:16>
UID3
F5E3H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID3 UID31 UID30 UID29 UID28 UID27 UID26 UID25 UID24
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<31:24>
UID4
F5E4H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID4 UID39 UID38 UID37 UID36 UID35 UID34 UID33 UID32
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<39:32>
UID5
F5E5H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID5 UID47 UID46 UID45 UID44 UID43 UID42 UID41 UID40
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<47:40>
UID6
F5E6H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID6 UID55 UID54 UID53 UID52 UID51 UID50 UID49 UID48
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<55:48>
UID7
F5E7H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID7 UID63 UID62 UID61 UID60 UID59 UID58 UID57 UID56
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<63:56>
UID8
F5E8H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID8 UID71 UID70 UID69 UID68 UID67 UID66 UID65 UID64
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<71:64>
UID9
F5E9H Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID9 UID79 UID78 UID77 UID76 UID75 UID74 UID73 UID72
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<79:72>
UID10(0xF5EA)
F5EAH Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID10 UID87 UID86 UID85 UID84 UID83 UID82 UID81 UID80
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<87:80>
UID11
F5EBH Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
UID11 UID95 UID94 UID93 UID92 UID91 UID90 UID89 UID88
R/W R R R R R R R R
Reset
X X X X X X X X
value
Bit7~Bit0 UID<95:88>
To normal connection (such as connecting VDD, GND or driving LED, transistor, etc.)
R1 R2
Emulator/burner signal
CMS MCU
VDD VDD
GND GND
DAT DSDA
CLK DSCK
In the above figure, R1 and R2 are electrical isolation devices, which are often replaced by resistors. The resistance values
are as follows: R1≥4.7K, R2≥4.7K.
Note that during programming and debugging, DSDA is forbidden to connect a pull-down resistor. If the actual circuit
requires a pull-down resistor, it is recommended to use a jumper structure to disconnect the pull-down resistor during
programming/debugging, and then connect the pull-down resistor after completion.
31. Instructions
There are 5 types of assembly instructions: arithmetic operations, logic operations, data transfer operations, Boolean
operations, and program branch instructions, all of which are compatible with the standard 8051.