5. Special function register SFR

5. Special function register SFR

The following abbreviations may be used in describing the registers in this manual:

AbbreviationDescription
ROIndicates access type: read only
WOIndicates the access type: write only, the value read is invalid
RWIndicates access type: readable and writable
hEnd with hexadecimal number
bExpressed as a binary number

5.1 SFR profile and address distribution

The CH559 uses the special function registers SFR and xSFR to control, manage, and set the operating mode.

The SFR occupies the 80h-FFh address range of the internal data storage space and can only be accessed by direct address mode instructions.

Registers whose address is x0h or x8h are bit-addressable, which avoids changing the value of other bits when accessing a specific bit; registers other than a multiple of 8 can only be accessed byte by byte.

Some SFRs can only write data in safe mode, but are read-only in non-secure mode, such as: GLOBAL_CFG, PLL_CFG, CLOCK_CFG, SLEEP_CTRL, WAKE_CTRL.

Some SFRs have one or more aliases, such as: SPI0_CK_SE/SPI0_S_PRE, UDEV_CTRL/UHUB0_CTRL, UEP1_CTRL/UH_SETUP, UEP2_CTRL/UH_RX_CTRL, UEP2_T_LEN/UH_EP_PID, UEP3_CTRL/UH_TX_CTRL, UEP3_T_LEN/UH_TX_LEN, P5_PIN/P4_CFG.

Partial addresses correspond to multiple independent SFRs, for example: TL2/T2CAP1L, TH2/T2CAP1H, SAFE_MOD/CHIP_ID, T3_COUNT_L/T3_CK_SE_L, T3_COUNT_H/T3_CK_SE_H, SER1_FIFO/SER1_RBR/SER1_THR/SER1_DLL, SER1_IER/SER1_DLM, SER1_IIR/SER1_FCR, SER1_ADDR/SER1_DIV, ROM_CTRL/ROM_STATUS.

xSFR occupies the 2440h-298Fh address range of the xdata type of the external data storage space, or the 40H-8Fh address range of the pdata type. xSFR can only be accessed in bytes by indirect addressing via the MOVX instruction.

The default is based on the DPTR pointer; however, after bXIR_XSFR is set, the faster R0 or R1 can be used as a pdata type pointer to access xSFRs named pU* and pLED_*.

Some xSFRs have one or more aliases, for example: UEP2_3_MOD/UH_EP_MOD, UEP2_DMA_H/UH_RX_DMA_H, UEP2_DMA_L/UH_RX_DMA_L, UEP2_DMA/UH_RX_DMA, UEP3_DMA_H/UH_TX_DMA_H, UEP3_DMA_L/UH_TX_DMA_L, UEP3_DMA/UH_TX_DMA.

Partial addresses correspond to multiple independent xSFRs, for example: LED_DATA/LED_FIFO_CN.

The CH559 contains all the registers of the 8051 standard SFR, and other device control registers have been added. The specific SFR is shown in the table below.

Table 5.1 Special Function Register Table

SFR_Table

Remarks: (1), Text in red means it can be addressed by bit; (2), the following is the corresponding description of the color box.

ColorDescription
Register address
SPI0 related register
ADC related register
USB related register
Timer/Counter 2 Related Registers
Port setting related register
SPI1 related register
PWM1 and PWM2 related registers
UART1 related register
Timer/Counter 0 and 1 related registers
Flash-ROM related register

5.2 SFR types and reset values

Function typeNameAddressDescriptionReset value
System settings registerBF0hB register0000 0000b
ACCE0haccumulator0000 0000b
PSWD0hProgram status register0000 0000b
GLOBAL_CFGB1hGlobal configuration register (in the bootloader state)1110 0000b
Global configuration register (in application state)1100 0000b
CHIP_IDA1hChip ID (read only)0101 1001b
SAFE_MODA1hSafe mode control register (write only)0000 0000b
DPH83hData address pointer is 8 bits high0000 0000b
DPL82hData address pointer is lower 8 bits0000 0000b
DPTR82hDPL and DPH form a 16-bit SFR0000h
SP81hStack pointer0000 0111b
Clock, sleep, and
power control registers
WDOG_COUNTFFhWatchdog count register0000 0000b
RESET_KEEPFEhReset holding register (in power-on reset state)0000 0000b
WAKE_CTRLEBhSleep wake control register0000 0000b
SLEEP_CTRLEAhSleep control register0000 0000b
CLOCK_CFGB3hSystem clock configuration register1001 1000b
PLL_CFGB2hPLL clock configuration register1101 1000b
PCON87hPower control register (in power-on reset state)0001 0000b
Interrupt control registerIP_EXE9hExtended interrupt priority control register0000 0000b
IE_EXE8hExtended interrupt enable register0000 0000b
GPIO_IECFhGPIO interrupt enable register0000 0000b
IPB8hInterrupt priority control register0000 0000b
IEA8hInterrupt enable register0000 0000b
Flash-ROM registerROM_DATA_H8Fhflash-ROM data register high bytexxxx xxxxb
ROM_DATA_L8EhFlash-ROM data register low bytexxxx xxxxb
ROM_DATA8EhROM_DATA_L and ROM_DATA_H form a 16-bit SFRxxxxh
ROM_STATUS86hflash-ROM status register (read only)1000 0000b
ROM_CTRL86hflash-ROM control register (write only)0000 0000b
ROM_ADDR_H85hflash-ROM address register high bytexxxx xxxxb
ROM_ADDR_L84hFlash-ROM address register low bytexxxx xxxxb
ROM_ADDR84hROM_ADDR_L and ROM_ADDR_H form a 16-bit SFRxxxxh
Port setting registerXBUS_SPEEDFDhExternal bus speed configuration register1111 1111b
XBUS_AUXFDhExternal bus auxiliary setting register0000 0000b
PIN_FUNCCEhPin function select register0000 0000b
P4_CFGC7hP4 port configuration register0000 0000b
P5_INC7hP5 port input register (read only)0000 0000b
PORT_CFGC6hPort configuration register0000 1111b
P0_PUC5hP0 port pull-up enable register (En_P0_Pullup=0)0000 0000b
P0 port pull-up enable register (En_P0_Pullup=1)1111 1111b
P0_DIRC4hP0 port direction control register0000 0000b
P4_PUC3hP4 port pull-up enable register1111 1111b
P4_DIRC2hP4 port direction control register0000 0000b
P4_INC1hP4 port input register (read only)1111 1111b
P4_OUTC0hP4 port output register0000 0000b
P3_PUBFhP3 port direction control register1111 1111b
P3_DIRBEhP3 port pull-up enable register0000 0000b
P2_PUBDhP2 port pull-up enable register1111 1111b
P2_DIRBChP2 port direction control register0000 0000b
P1_PUBBhP1 port pull-up enable register1111 1111b
P1_DIRBAhP1 port direction control register0000 0000b
P1_IEB9hP1 port input enable register1111 1111b
P3B0hP3 port input and output registers1111 1111b
P2A0hP2 port input and output registers1111 1111b
P190hP1 port input and output registers1111 1111b
P080hP0 port input and output registers1111 1111b
Timer/Counter 0 and 1 registersTH18DhTimer1 count high bytexxxx xxxxb
TH08ChTimer0 count high bytexxxx xxxxb
TL18Bh3Timer1 count low bytexxxx xxxxb
TL08AhTimer0 count low bytexxxx xxxxb
TMOD89hTimer0/1 mode register0000 0000b
TCON88hTimer0/1 Control Register0000 0000b
UART0 registerSBUF99hUART0 data registerxxxx xxxxb
SCON98hUART0 control register0000 0000b
Timer/Counter 2 RegistersTH2CDhTimer2 counter high byte0000 0000b
TL2CChTimer2 counter low byte0000 0000b
T2COUNTCChTL2 and TH2 form a 16-bit SFR0000h
T2CAP1HCDhTimer2 capture 1 data high byte (read only)xxxx xxxxb
T2CAP1LCChTimer2 capture 1 data low byte (read only)xxxx xxxxb
T2CAP1CChT2CAP1L and T2CAP1H form a 16-bit SFRxxxxh
RCAP2HCBhCount reload/capture 2 data register high byte0000 0000b
RCAP2LCAhCount reload/capture 2 data register low byte0000 0000b
RCAP2CAhRCAP2L and RCAP2H form a 16-bit SFR0000h
T2MODC9hTimer2 mode register0000 0000b
T2CONC8hTimer2 Control Register0000 0000b
Timer/counter 3 registersT3_FIFO_HAFhTimer3 FIFO high bytexxxx xxxxb
T3_FIFO_LAEhTimer3 FIFO low bytexxxx xxxxb
T3_FIFOAEhT3_FIFO_L and T3_FIFO_H form a 16-bit SFRxxxxh
T3_DMA_AHADhDMA current buffer address high byte0000 xxxxb
T3_DMA_ALAChDMA current buffer address low bytexxxx xxx0b
T3_DMAAChT3_DMA_AL and T3_DMA_AH form a 16-bit SFR0xxxh
T3_DMA_CNABhDMA residual count register0000 0000b
T3_CTRLAAhTimer3 Control Register0000 0010b
T3_STATA9hTimer3 Status Register0000 0000b
T3_END_HA7hTimer3 counts the final high bytexxxx xxxxb
T3_END_LA6hTimer3 counts the final low bytexxxx xxxxb
T3_ENDA6hT3_END_L and T3_END_H form a 16-bit SFRxxxxh
T3_COUNT_HA5hTimer3 current count high byte (read only)0000 0000b
T3_COUNT_LA4hTimer3 current count low byte (read only)0000 0000b
T3_COUNTA4hT3_COUNT_L and T3_COUNT_H form a 16-bit SFR0000h
T3_CK_SE_HA5hTimer3 clock divider setting high byte0000 0000b
T3_CK_SE_LA4hTimer3 clock divider sets the low byte0010 0000b
T3_CK_SEA4hT3_CK_SE_L and T3_CK_SE_H form a 16-bit SFR0020h
T3_SETUPA3hTimer3 setup register0000 0100b
PWM1 and PWM2 registersPWM_CYCLE9FhPWM cycle period registerxxxx xxxxb
PWM_CK_SE9EhPWM clock divider setting register0000 0000b
PWM_CTRL9DhPWM control register0000 0010b
PWM_DATA9ChPWM1 data registerxxxx xxxxb
PWM_DATA29BhPWM2 data registerxxxx xxxxb
SPI0 registerSPI0_SETUPFChSPI0 setting register0000 0000b
SPI0_S_PREFBhSPI0 slave mode preset data register0010 0000b
SPI0_CK_SEFBhSPI0 clock divider setting register0010 0000b
SPI0_CTRLFAhSPI0 control register0000 0010b
SPI0_DATAF9hSPI0 data transceiver registerxxxx xxxxb
SPI0_STATF8hSPI0 status register0000 1000b
SPI1 registerSPI1_CK_SEB7hSPI1 clock divider setting register0010 0000b
SPI1_CTRLB6hSPI1 control register0000 0010b
SPI1_DATAB5hSPI1 data transceiver registerxxxx xxxxb
SPI1_STATB4hSPI1 status register0000 1000b
UART1 registerSER1_DLL9AhUART1 Baud Rate Divisor Latch Low Bytexxxx xxxxb
SER1_FIFO9AhUART1 data FIFO read and write registersxxxx xxxxb
SER1_DIV97hUART1 prescaler divisor register0xxx xxxxb
SER1_ADDR97hUART1 bus address preload register1111 1111b
SER1_MSR96hUART1 Modem MODEM Status Register (Read Only)1111 0000b
SER1_LSR95hUART1 line status register (read only)0110 0000b
SER1_MCR94hUART1 Modem MODEM Control Register0000 0000b
SER1_LCR93hUART1 line control register0000 0000b
SER1_IIR92hUART1 Interrupt Identification Register (Read Only)0000 0001b
SER1_FCR92hFIFO control register (write only)0000 0000b
SER1_DLM91hUART1 baud rate divisor latch high byte1000 0000b
SER1_IER91hUART1 interrupt enable register0000 0000b
ADC registerADC_EX_SWF7hADC Extended Analog Switch Control Register0000 0000b
ADC_SETUPF6hADC setup register0000 1000b
ADC_FIFO_HF5hFIFO high byte of ADC (read only)0000 0xxxb
ADC_FIFO_LF4hADC FIFO low byte (read only)xxxx xxxxb
ADC_FIFOF4hADC_FIFO_L and ADC_FIFO_H form a 16-bit SFR0xxxh
ADC_CHANNF3hADC channel select register0000 0000b
ADC_CTRLF2hADC control register0000 0000b
ADC_STATF1hADC status register0000 0100b
ADC_CK_SEEFhADC clock divider setting register0001 0000b
ADC_DMA_CNEEhDMA residual count register0000 0000b
ADC_DMA_AHEDhDMA current buffer address high byte0000 xxxxb
ADC_DMA_ALEChDMA current buffer address low bytexxxx xxx0b
ADC_DMAEChADC_DMA_AL and ADC_DMA_AH form a 16-bit SFR0xxxh
USB registerUSB_DMA_AHE7hDMA current buffer address high byte (read only)000x xxxxb
USB_DMA_ALE6hDMA current buffer address low byte (read only)xxxx xxx0b
USB_DMAE6hUSB_DMA_AL and USB_DMA_AH form a 16-bit SFRxxxxh
UHUB1_CTRLE5hUSB host HUB1 port control register1100 x000b
UHUB0_CTRLE4hUSB host HUB0 port control register0100 x000b
UDEV_CTRLE4hUSB Device Port Control Register0100 x000b
USB_DEV_ADE3hUSB Device Address Register0000 0000b
USB_CTRLE2hUSB Control Register0000 0110b
USB_INT_ENE1hUSB Interrupt Enable Register0000 0000b
UEP4_T_LENDFhEndpoint 4 Transmit Length Register0xxx xxxxb
UEP4_CTRLDEhEndpoint 4 Control Register0000 0000b
UEP0_T_LENDDhEndpoint 0 Transmit Length Register0xxx xxxxb
UEP0_CTRLDChEndpoint 0 Control Register0000 0000b
USB_HUB_STDBhSB Host HUB Port Status Register (Read Only)0000 0000b
USB_MIS_STDAhSB Miscellaneous Status Register (Read Only)xx10 1000b
USB_INT_STD9hUSB Interrupt Status Register (Read Only)00xx xxxxb
USB_INT_FGD8hUSB Interrupt Flag Register0010 0000b
UEP3_T_LEND7hEndpoint 3 Transmit Length Register0xxx xxxxb
UH_TX_LEND7hUSB host send length register0xxx xxxxb
UEP3_CTRLD6hEndpoint 3 Control Register0000 0000b
UH_TX_CTRLD6hUSB host transmit endpoint control register0000 0000b
UEP2_T_LEND5hEndpoint 2 Transmit Length Register0000 0000b
UH_EP_PIDD5hUSB Host Token Setting Register0000 0000b
UEP2_CTRLD4hEndpoint 2 Control Register0000 0000b
UH_RX_CTRLD4hUSB host receive endpoint control register0000 0000b
UEP1_T_LEND3hEndpoint 1 Transmit Length Register0xxx xxxxb
UEP1_CTRLD2hEndpoint 1 Control Register0000 0000b
UH_SETUPD2hUSB Host Auxiliary Settings Register0000 0000b
USB_RX_LEND1hUSB Receive Length Register (Read Only)0xxx xxxxb
USB xSFR registerUEP4_1_MOD2446hEndpoint 1, 4 mode control register0000 0000b
UEP2_3_MOD2447hEndpoint 2, 3 Mode Control Register0000 0000b
UH_EP_MOD2447hUSB Host Endpoint Mode Control Register0000 0000b
UEP0_DMA_H2448hEndpoints 0 and 4 Buffer Start Address High Bytes000x xxxxb
UEP0_DMA_L2449hEndpoints 0 and 4 Buffer Start Address Low Bytexxxx xxx0b
UEP0_DMA2448hUEP0_DMA_L and UEP0_DMA_H form a 16-bit SFRxxxxh
UEP1_DMA_H244AhEndpoint 1 Buffer Start Address High Byte000x xxxxb
UEP1_DMA_L244BhEndpoint 1 Buffer Start Address Low Bytexxxx xxx0b
UEP1_DMA244AhUEP1_DMA_L and UEP1_DMA_H form 16-bit SFRxxxxh
UEP2_DMA_H244ChEndpoint 2 Buffer start address high byte000x xxxxb
UEP2_DMA_L244DhEndpoint 2 Buffer Start Address Low Bytexxxx xxx0b
UEP2_DMA244ChUEP2_DMA_L and UEP2_DMA_H form 16-bit SFRxxxxh
UH_RX_DMA_H244ChUSB host receive buffer start address high byte000x xxxxb
UH_RX_DMA_L244DhUSB host receive buffer start address low bytexxxx xxx0b
UH_RX_DMA244ChUH_RX_DMA_L and UH_RX_DMA_H form 16-bit SFRxxxxh
UEP3_DMA_H244EhEndpoint 3 Buffer start address high byte000x xxxxb
UEP3_DMA_L244FhEndpoint 3 Buffer Start Address Low Bytexxxx xxx0b
UEP3_DMA244EhUEP3_DMA_L and UEP3_DMA_H form 16-bit SFRxxxxh
UH_TX_DMA_H244EhUSB host transmit buffer start address high byte000x xxxxb
UH_TX_DMA_L244FhUSB host send buffer start address low bytexxxx xxx0b
UH_TX_DMA244EhUH_TX_DMA_L and UH_TX_DMA_H form a 16-bit SFRxxxxh
pU*254*hAfter bXIR_XSFR is set to 1, this name is used to address the above xSFR with pdata type, which is faster than xdata type addressing.
LED Control Card xSFR RegisterLED_STAT2880hLED Status Register010x 0000b
LED_CTRL2881hLED Control Register0000 0010b
LED_FIFO_CN2882hFIFO Count Status Register (Read Only)0000 0000b
LED_DATA2882hLED data register (write only)xxxx xxxxb
LED_CK_SE2883hLED Clock Divider Setting Register0001 0000b
LED_DMA_AH2884hDMA current buffer address high byte000x xxxxb
LED_DMA_AL2885hDMA Current buffer address low bytexxxx xxx0b
LED_DMA2884hLED_DMA_AL and LED_DMA_AH Compose 16-bit SFRxxxxh
LED_DMA_CN2886hLED DMA Remaining Count Registerxxxx xxxxb
LED_DMA_XH2888hDMA Current auxiliary buffer address high byte000x xxxxb
LED_DMA_XL2889hDMA Current auxiliary buffer address low bytexxxx xxx0b
LED_DMA_X2888hLED_DMA_XL and LED_DMA_XH form a 16-bit SFRxxxxh
pLED_*298*hAfter bXIR_XSFR is set to 1, this name is used to address the above xSFR with pdata type, which is faster than xdata type addressing.

5.3 General purpose 8051 register

Table 5.3.1 General 8051 Register List

NameAddressDescriptionReset value
BF0hB register00h
A, ACCE0haccumulator00h
PSWD0hprogram status register00h
GLOBAL_CFGB1hGlobal configuration register (in the bootloader state)E0h
Global configuration register (in application state)C0h
CHIP_IDA1hChip ID Identifier (Read Only)59h
SAFE_MODA1hSafety Mode Control Register (Write Only)00h
PCON87hpower control register (in power-on reset state)10h
DPH83hdata address pointer high 8 bit00h
DPL82hdata address pointer low 8 bits00h
DPTR82hDPL and DPH form 16-bit SFR0000h
SP81hstack pointer07h

B register (B):

BitNameAccessDescriptionReset value
[7:0]BRWArithmetic operation registers, mainly used for multiplication and division, bit-addressable00h

A accumulator (A, ACC):

BitNameAccessDescriptionReset value
[7:0]A/ACCRWArithmetic accumulator, bit addressable00h

Program Status Register (PSW):

BitNameAccessDescriptionReset value
7CYRW

Carry flag: Used to record the carry or borrow of the most significant bit when performing arithmetic and logic operations.

When the 8-bit addition is performed, the most significant bit is set, otherwise it is cleared.

when 8-bit subtraction is performed If the borrow is borrowed, the bit is set, otherwise it is cleared.

The logic instruction can make the bit bit or clear.

0
6ACRWAuxiliary carry flag: When recording and subtracting, the lower 4 bits have a carry or borrow from the upper 4 bits, AC is set, otherwise cleared.0
5F0RWUniversal flag bit addressable by bit 0: User can define it himself, can be cleared or set by software0
4RS1RWRegister bank select bit high0
3RS0RWRegister bank select bit low0
2OVRWOverflow flag: When adding or subtracting, the operation result exceeds 8 binary digits, then OV is set to 1, the flag overflows, otherwise cleared 00
1F1RWUniversal flag bit addressable by bit 1: User can define it, can be cleared or set by software0
0PR0Parity flag: Record the parity of 1 in accumulator A after the execution of the instruction. P1 for odd number 1 and P for even number 10

The state of the processor is stored in the status register PSW and the PSW supports bitwise addressing. The status word includes the carry flag, the auxiliary carry flag for BCD code processing, the parity flag, the overflow flag, and RS0 and RS1 for the working register bank selection. The area in which the working register set is located can be accessed either directly or indirectly.

Table 5.3.2 RS1 and RS0 Working Register Group Selection Table

RS1RS0Working register set
00Group 0 (00h-07h)
01Group 1 (08h-0Fh)
10Group 2 (10h-17h)
11Group 3 (18h-1Fh)

Table 5.3.3 Operations that affect the flag bit (X indicates that the flag bit is related to the operation result)

OperationCYOVAC
ADDXXX
ADDCXXX
SUBBXXX
MUL0X
DIV0X
DA AX
RRC AX
RLC AX
CJNEX
SETB C1
CLR C0
CPL CX
MOV C, bitX
ANL C, bitX
ANL C,/bitX
ORL C, bitX
ORL C,/bitX

Data Address Pointer (DPTR):

BitNameAccessDescriptionReset value
[7:0]DPLRWData pointer low byte00h
[7:0]DPHRWData pointer high byte00h

DPL and DPH form a 16-bit data pointer DPTR for accessing xSFR, xBUS, xRAM data memory or program memory. The actual DPTR corresponds to the physical 16-bit data pointers of DPTR0 and DPTR1, which are dynamically selected by DPS in XBUS_AUX.

Stack pointer (SP):

BitNameAccessDescriptionReset value
[7:0]SPRWStack pointer, mainly used for program calls and interrupt calls, and data in and out of the stack07h

Stack specific functions: protect endpoints and protect the site, and manage them on a first-come, first-out basis. When the stack is pushed, the SP pointer is automatically incremented by 1, and the data or breakpoint information is saved. When the stack is taken, the SP pointer points to the data unit, and the SP pointer is automatically decremented by 1. The initial value of the SP after reset is 07h, and the corresponding default stack storage starts at 08h.

5.4 Special registers

Global configuration register (GLOBAL_CFG), writable only in safe mode:

BitNameAccessDescriptionReset value
[7:6]ReservedROFixed value 1111b
5bBOOT_LOADRO

The Boot loader status bit is used to distinguish between the ISP bootloader status or the application state: set when the power is turned on, and cleared to 0 when the software is reset.

For chips with an ISP bootloader, this bit is 1 indicates that the software has never been reset, usually the ISP bootloader state that was run after power-up. this bit is 0 indicating that the software has been reset, usually the application state

1
4bSW_RESETRWSoftware reset control bit: Set to 1 to cause software reset, hardware auto-zero0
3bCODE_WERWFlash-ROM write enable bit: This bit is 0 for write protection; 1 for Flash-ROM writable erasable0
2bDATA_WERWDataFlash area write enable bit of Flash-ROM: This bit is 0 for write protection; 1 is for DataFlash area to be erasable and erasable0
1bXIR_XSFRRW

MOVX_@R0/R1 instruction access range control bits:

This bit is 0 to allow access to all xdata regions xRAM/xBUS/xSFR.

This bit is 1 for access to xSFR and cannot access xRAM/xBUS

0
0bWDOG_ENRWWatchdog reset enable bit: This bit is 0. The watchdog is only used as a timer. this bit is 1 to allow a watchdog reset when the timer overflows.0

Chip ID (CHIP_ID):

BitNameAccessDescriptionReset value
[7:0]CHIP_IDROFixed value 59h for identification chip59h

Safe Mode Control Register (SAFE_MOD):

BitNameAccessDescriptionReset value
[7:0]SAFE_MODWOUsed to enter or terminate safe mode00h

Some SFRs can only write data in safe mode, and are always read-only in non-secure mode. Steps to enter safe mode:

  1. write 55h to the register.
  2. then write AAh to the register.
  3. After that, about 13 to 23 system main frequency cycles are in safe mode, and one or more security class SFRs or ordinary SFRs can be rewritten during the validity period.
  4. automatically terminate the safe mode after the above validity period.
  5. Or write any value to this register to terminate the safe mode early.