Download Print this page

Advertisement

Quick Links

STC8A8K64D4 series of
Microcontrollers
Reference Manual
Date of update: 2022/3/1

Advertisement

loading
Need help?

Need help?

Do you have a question about the micro STC8A8K64D4 Series and is the answer not in the manual?

Questions and answers

Summary of Contents for STC micro STC8A8K64D4 Series

  • Page 1 STC8A8K64D4 series of Microcontrollers Reference Manual Date of update: 2022/3/1...
  • Page 2: Table Of Contents

    STC8A8K64D4 Series Manual Contents 1 Overview ................................1 2 Features, Price and Pins ..........................2 2.1 STC8A8K64D4-64Pin/48Pin family ....................... 2 2.1.1 Features and Price(Quasi 16-bit MCU with 16-bit hardware multiplier and divider MDU16) ..2 2.1.2 Pinouts ............................5 2.1.3 Pin descriptions ..........................9 3 Function pins switch............................
  • Page 3 STC8A8K64D4 Series Manual 5.1.6 Download using U8W tool, Support ISP online and offline download, also support emulation .. 47 5.1.7 Software simulation USB ISP download directly, and does not support simulation ....49 5.1.8 Microcontroller Power supply Control Reference Circuit ............50 6.
  • Page 4 STC8A8K64D4 Series Manual power-down wake-up timer)........................92 6.7.13 Wake up MCU from Power Saving Mode using comparator interrupt ( Recommended for use with power-down wake-up timer) ......................95 6.7.14 Detect the Operating Voltage (Battery Voltage) using LVD ............97 7 Memory ................................102 7.1 Program Memory ..........................102 7.2 Data Memory ............................102 7.2.1 Internal RAM ..........................103...
  • Page 5 STC8A8K64D4 Series Manual 9.1.6 Drive Current Control Registers (PxDR) ..................166 9.1.7 Port digital signal input enable control register (PxIE) ...............167 9.2 Configure I/O Ports ..........................168 9.3 I/O Ports Structure ..........................168 9.3.1 Quasi-Bidirectional I/O (weak pull-up) ..................168 9.3.2 Push-Pull Output .........................169 9.3.3 High Impedance Input .........................169 9.3.4 Open-Drain Output ........................169 9.3.5 4.1K Pull-up Resistor ........................170...
  • Page 6 STC8A8K64D4 Series Manual 11.5.13 UART1 Interrupt ........................242 11.5.14 UART2 Interrupt ........................244 11.5.15 UART3 Interrupt ........................246 11.5.16 UART4 Interrupt ........................249 11.5.17 LVD Interrupt ..........................251 11.5.18 SPI Interrupt ..........................253 11.5.19 Comparator Interrupt .......................255 11.5.21 I2C Interrupt ..........................257 12 I/O port interrupt ............................260 12.1 I/O port interrupt related registers .......................260 12.1.1 Port interrupt enable registers (PxINTE) ...................261 12.1.2 Port interrupt flag registers (PxINTF) ..................261...
  • Page 7 STC8A8K64D4 Series Manual 13.3.5 Timer 2 working mode ......................290 13.3.6 Timer 2 calculation formula ......................291 13.4 Timer 3/4 (24-bit timer, 8-bit prescaler + 16-bit timing) ..............291 13.4.1 Timer4 and Timer 3 Control Register (T4T3M) ................291 13.4.2 Timer 3 Counting Registers .......................292 13.4.3 Timer 4 Counting Registers .......................292 13.4.4 Timer 3 8-bit Prescaler Register (TM3PS) ................292 13.4.5 Timer 4 8-bit Prescaler Register (TM4PS) ................293...
  • Page 8 STC8A8K64D4 Series Manual 14.1 UART function pin switch ........................372 14.2 Registers Related to UARTs .......................372 14.3 UART1 373 14.3.1 UART1 control register ......................373 14.3.2 UART1 data register ........................373 14.3.3 Power control register ........................374 14.3.4 Auxiliary register 1 ........................374 14.3.5 UART1 Mode 0 .........................374 14.3.6 UART1 Mode 1 .........................375 14.3.7 UART1 Mode 2 .........................377 14.3.8 UART1 Mode 3 .........................378...
  • Page 9 STC8A8K64D4 Series Manual 15.3.1 Comparator control register 1 ....................434 15.3.2 Comparator control register 2 ....................434 15.3.3 Comparator Extended Configuration Register (CMPEXCFG) ..........435 15.4 Example Routines ..........................436 15.4.1 Using Comparator (Interrupt Mode) ..................436 15.4.2 Using Comparator (Polling Mode) ....................439 15.4.3 Comparator is Used for External Power-down Detection (User data should be saved to EEPROM in time during power down) .........................442 15.4.4 Comparator is Used to Detect the Operation Voltage (Battery Voltage) ........443 16 IAP/EEPROM/DATA-FLASH ........................448...
  • Page 10 STC8A8K64D4 Series Manual 17.5.3 Format ADC Conversion Result ....................493 17.5.4 ADC converts multiple times to take average automatically .............495 17.5.5 Detect External Voltage or Battery Voltage using ADC 15th Channel ........498 17.5.6 Using ADC as Capacitive Sensing Touch Keys ................501 17.5.7 Key-scan Application Circuit Diagram using ADC ..............514 17.5.8 Reference circuit diagram for detecting negative voltage ............515 17.5.9 The application of common addition circuit in ADC ..............516...
  • Page 11 STC8A8K64D4 Series Manual 19.3.3 PWM Implements Gradient Light (Breathing Light) ..............556 19.3.4 Use PWM to trigger ADC conversion ..................561 20 Sysnchronous Serial Peripheral Interface (SPI) ..................566 20.1 SPI function pin switch ........................566 20.2 Registers Related to SPI ........................566 20.2.1 SPI Status register (SPSTAT) ....................566 20.2.2 SPI Control Register (SPCTL) ....................566 20.2.3 SPI Data Register (SPDAT) .......................567 20.3 SPI Communication Modes ........................567...
  • Page 12 STC8A8K64D4 Series Manual 22.2.1 LCM Interface Configuration Register (LCMIFCFG) ..............628 22.2.2 LCM Interface Configuration Register 2 (LCMIFCFG2) ............629 22.2.3 LCM Interface Control Register (LCMIFCR) ................629 22.2.4 LCM Interface Status Register (LCMIFSTA) ................629 22.2.5 LCM interface Data Registers (LCMIFDATL, LCMIFDATH) ..........630 22.3 LCM interface timing diagram ......................631 22.3.1 I8080 mode ..........................631 22.3.2 M6800 mode ..........................633...
  • Page 13 STC8A8K64D4 Series Manual 23.5.9 UR1R_DMA Status Register (DMA_UR1R_STA) ..............646 23.5.10 UR1R_DMA transfer total byte register (DMA_UR1R_AMT) ..........647 23.5.11 UR1R_DMA transfer complete byte register (DMA_UR1R_DONE) ........647 23.5.12 UR1R_DMA Receive Address Registers (DMA_UR1T_RXAx) ...........647 23.6 Data exchange between UART2 and memory (UR2T_DMA,UR2R_DMA) ........648 23.6.1 UR2T_DMA Configuration Register (DMA_UR2T_CFG) ............648 23.6.2 UR2T_DMA Control Register (DMA_UR2T_CR) ..............648 23.6.3 UR2T_DMA Status Register (DMA_UR2T_STA) ..............648...
  • Page 14 29.2 Netizens' application of MDU16 (provide ideas, for reference only) ..........679 25.3 Example Routines ..........................681 Appendix A STC Emulator User Guide ......................682 Appendix B How to Test I/O Ports.........................691 Appendix C How to Make the Traditional 8051 MCU EVB Emulatable ...........692 Appendix D STC-USB Driver Installation Instructions ................694...
  • Page 15 Appendix M Example Routine of ISP download for STC8A8K64D4 series MCUs using third-party MCU Appendix N Use a third-party application program to call the STC release project program to download the ISP of the MCU ............................855 Appendix O Method for Creating Multi-file Projects in Keil ..............859 Appendix P Handling of Compilation Error in Keil with Interrupt Numbers Greater Than 31 .....863...
  • Page 16 STC8A8K64D4 Series Manual Appendix S PCB design guidance for touch keys ..................877 Appendix T QFN/DFN packaged components welding method ..............879 Appendix U Precautions for STC8A8K64D4 series MCU to replace STC8A8K64S4A12 series .....882 Appendix V Update Records ..........................884 Product Authorization Letter .........................886 - xv -...
  • Page 17: Overview

    8051 requires 1944 clocks. STC8A8K64D4 series of microcontrollers are single clock/machine cycle (1T) microcontrollers produced by STC. They are new generation 8051 microcontrollers with wide voltage/high speed / high reliability / low power consumption / strong antistatic / strong anti-interference, and is super encrypted. The instruction codes are fully compatible with traditional 8051.
  • Page 18: Features, Price And Pins

    STC8A8K64D4 Series Manual 2 Features, Price and Pins 2.1 STC8A8K64D4-64Pin/48Pin family 2.1.1 Features and Price(Quasi 16-bit MCU with 16-bit hardware multiplier and divider MDU16) ➢ Selection and price (No external crystal and external reset required with 9 channels 10-bit ADC) (...
  • Page 19 STC8A8K64D4 Series Manual ✓ Online debugging with single chip is supported, and no dedicated emulator is needed. The number of breakpoints is unlimited theoratically. ➢ SRAM ✓ 128 bytes internal direct access RAM (DATA, use keyword data to declare in C language program) ✓...
  • Page 20 STC8A8K64D4 Series Manual ➢ Analog peripherals ✓ 15 channels (channel 0 to channel 14) ultra high speed ADC which supports 12-bit precision. The maximum speed can be 800K(800,000 ADC conversions per second) ✓ Channel 15 of ADC is used to test the internal reference voltage. (The default internal reference voltage is 1.19V when the chip is shipped) ✓...
  • Page 21: Pinouts

    STC8A8K64D4 Series Manual 2.1.2 Pinouts Note: If USB download is not required, P3.0/P3.1/P3.2 cannot be low at the same time when the chip is reset, otherwise, the chip will always be in USB download mode without running user code. CCP3_2/PWM6/A14/P2.6 P3.5/T1/T0CLKO/ECI_4/SS_4/PWMFLT PWM7/A15/P2.7 P3.4/T0/T1CLKO/MOSI_4/CMPO...
  • Page 22 STC8A8K64D4 Series Manual Note: If USB download is not required, P3.0/P3.1/P3.2 cannot be low at the same time when the chip is reset, otherwise, the chip will always be in USB download mode without running user code. CCP3_2/PWM6/A14/P2.6 P3.5/T1/T0CLKO/ECI_4/SS_4/PWMFLT PWM7/A15/P2.7 P3.4/T0/T1CLKO/MOSI_4/CMPO RxD3/ADC8/AD0/P0.0 P3.3/INT1/CCP0_4/MISO_4/I2CSDA_4...
  • Page 23 STC8A8K64D4 Series Manual Note: If USB download is not required, P3.0/P3.1/P3.2 cannot be low at the same time when the chip is reset, otherwise, the chip will always be in USB download mode without running user code. CCP3_2/PWM6/A14/P2.6 P3.4/T0/T1CLKO/MOSI_4/CMPO PWM7/A15/P2.7 P3.3/INT1/CCP0_4/MISO_4/I2CSDA_4 RxD3/ADC8/AD0/P0.0 P3.2/INT0/CCP1_4/SCLK_4/I2CSCL_4...
  • Page 24 Note: When the tool is powered on for the first time, there is no external power supply, so if it is the first time to use this tool, you can skip this step. 3. Click the "Download/Program" button in the STC-ISP download software. 4. Press the power button again to power on the target chip (the power-on LED is on).
  • Page 25: Pin Descriptions

    STC8A8K64D4 Series Manual 2.1.3 Pin descriptions Pin number name type description LQFP64 LQFP48 LQFP44 PDIP40 P5.2 Standard IO port RxD4_2 Serial input of UART4 P5.3 Standard IO port TxD4_2 Serial Transmit pin of UART4 P1.1 Standard IO port ADC1 ADC analog input 1 PWM1_2 Output pin of Enhance PWM 1 TxD2...
  • Page 26 STC8A8K64D4 Series Manual Pin number name type description LQFP64 LQFP48 LQFP44 PDIP40 P1.4 Standard IO port ADC4 ADC analog input 4 PWM4_2 Enhanced PWM channel 4 output pin MISO Master Iutput/Slave Onput of SPI Serial data line of I2C CCP3 Capture input and pulse output of PCA P4.4 Standard IO port...
  • Page 27 STC8A8K64D4 Series Manual Pin number description name type LQFP64 LQFP48 LQFP44 PDIP40 P4.0 Standard IO port WR_3 WRITE signal of external bus RxD2_2 Input of USART2 P6.4 Standard IO port PWM4_3 Enhanced PWM channel 4 output pin P6.5 Standard IO port PWM5_3 Enhanced PWM channel 5 output pin P6.6...
  • Page 28 STC8A8K64D4 Series Manual Pin number name type description LQFP64 LQFP48 LQFP44 PDIP40 P3.5 Standard IO port Timer1 external input T0CLKO Clock out of timer 0 ECI_4 External pulse input of PCA SS_4 Slave selection of SPI (it is output with regard to master) PWMFLT Enhance PWM external anomaly detection pin P5.0...
  • Page 29 STC8A8K64D4 Series Manual Pin number name type description LQFP64 LQFP48 LQFP44 PDIP40 P2.1 Standard IO port Address bus PWM1 Enhanced PWM channel 1 output pin P2.2 Standard IO port Address bus PWM2 Enhanced PWM channel 2 output pin Slave selection of SPI (it is output with regard to SS_2 master) ECI_2...
  • Page 30 STC8A8K64D4 Series Manual Pin number name type description LQFP64 LQFP48 LQFP44 PDIP40 P0.1 Standard IO port Address bus ADC9 ADC analog input 9 TxD3 Transmit pin of USART3 P0.2 Standard IO port Address bus ADC10 ADC analog input 10 RxD4 Serial input of UART4 P7.4 Standard IO port...
  • Page 31: Function Pins Switch

    STC8A8K64D4 Series Manual 3 Function pins switch Some special peripherals of STC8A8K64D4 series of microcontrollers can be switched among several I/O pins to realize one peripheral used as multiple device through time-sharing, such as UART, SPI, PCA, I2C and bus control pins. 3.1 Register related to function pin switch Bit Address and Symbol Reset...
  • Page 32: Clock Selection Register(Mclkocr)

    STC8A8K64D4 Series Manual P7.4 P7.0 P7.1 P7.2 P7.3 P3.5 P3.3 P3.2 P3.1 P3.0 SPI_S[1:0]:SPI pin selection bits SPI_S[1:0] MOSI MISO SCLK P1.2 P1.3 P1.4 P1.5 P2.2 P2.3 P2.4 P2.5 P7.4 P7.5 P7.6 P7.7 P3.5 P3.4 P3.3 P3.2 3.1.3 Peripheral port switch register 2(P_SW2) (for UART2/3/4, I2C, Comparator output switching) Symbol Address...
  • Page 33: Enhanced Pwm Control Register (Pwmncr)

    STC8A8K64D4 Series Manual 3.1.5 Enhanced PWM Control Register (PWMnCR) Symbol Address PWM0CR FF14H ENC0O C0INI C0_S[1:0] EC0I EC0T2SI EC0T1SI PWM1CR FF1CH ENC1O C1INI C1_S[1:0] EC1I EC1T2SI EC1T1SI PWM2CR FF24H ENC2O C2INI C2_S[1:0] EC2I EC2T2SI EC2T1SI PWM3CR FF2CH ENC3O C3INI C3_S[1:0] EC3I EC3T2SI EC3T1SI...
  • Page 34: Lcm Interface Configuration Register (Lcmifcfg)

    STC8A8K64D4 Series Manual 3.1.6 LCM Interface Configuration Register (LCMIFCFG) Symbol Address LCMIFCFG FE50H LCMIFIE LCMIFIP[1:0] LCMIFDPS[1:0] D16_D8 M68_I80 LCMIFCFG2 FE51H LCMIFCPS[1:0] SETUPT[2:0] HOLDT[1:0] LCMIFCPS[1:0]: LCM interface control pin selection bits READ signal (RD)of I8080 Wirte signal (WR) of I8080 LCMIFCPS [1:0] Enable signal (E ) of M6800 Write/Read signal (RW) of M6800 P4.1...
  • Page 35: Example Routines

    STC8A8K64D4 Series Manual 3.2 Example Routines 3.2.1 USART1 switch C language code // Operating frequency for test is 11.0592MHz #include “reg51.h” P_SW1 0xa2; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3;...
  • Page 36: Usart2 Switch

    STC8A8K64D4 Series Manual P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H...
  • Page 37 STC8A8K64D4 Series Manual P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x00; //RXD2/P1.0, TXD2/P1.1 P_SW2 = 0x01;...
  • Page 38: Uart3 Switch

    STC8A8K64D4 Series Manual 3.2.3 UART3 switch C language code // Operating frequency for test is 11.0592MHz #include “reg51.h” P_SW2 0xba; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 39: Uart4 Switch

    STC8A8K64D4 Series Manual P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H...
  • Page 40 STC8A8K64D4 Series Manual P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x00; //RXD4/P0.2, TXD4/P0.3 P_SW2 = 0x04; //RXD4_2/P5.2, TXD4_2/P5.3 while (1); Assembly code ;...
  • Page 41: Spi Switch

    STC8A8K64D4 Series Manual 3.2.5 SPI switch C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" P_SW1 0xa2; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 42: Pwm Switch

    STC8A8K64D4 Series Manual P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P_SW1,#00H ;SS/P1.2, MOSI/P1.3, MISO/P1.4, SCLK/P1.5...
  • Page 43 STC8A8K64D4 Series Manual 0000H LJMP MAIN 0100H MAIN: SP, #3FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P_SW2,#80H A,#00H ;PWM0/P2.0 A,#08H ;PWM0_2/P1.0 A,#10H ;PWM0_3/P6.0 DPTR,#PWM0CR MOVX...
  • Page 44 STC8A8K64D4 Series Manual SJMP C language code #include "reg51.h" #define PWM0CR (*(unsigned char volatile xdata *)0xff14) #define PWM1CR (*(unsigned char volatile xdata *)0xff1c) #define PWM2CR (*(unsigned char volatile xdata *)0xff24) #define PWM3CR (*(unsigned char volatile xdata *)0xff2c) #define PWM4CR (*(unsigned char volatile xdata *)0xff34) #define PWM5CR (*(unsigned char volatile xdata *)0xff3c) #define PWM6CR...
  • Page 45: Pca/Ccp/Pwm Switch

    STC8A8K64D4 Series Manual PWM4CR = 0x00; //PWM4/P2.4 PWM4CR = 0x08; //PWM4_2/P1.4 PWM4CR = 0x10; //PWM4_3/P6.4 PWM5CR = 0x00; //PWM5/P2.5 PWM5CR = 0x08; //PWM5_2/P1.5 PWM5CR = 0x10; //PWM5_3/P6.5 PWM6CR = 0x00; //PWM6/P2.6 PWM6CR = 0x08; //PWM6_2/P1.6 PWM6CR = 0x10; //PWM6_3/P6.6 PWM7CR = 0x00; //PWM7/P2.7 PWM7CR = 0x08;...
  • Page 46: I2C Switch

    STC8A8K64D4 Series Manual C language code #include "reg51.h" P_SW1 0xa2; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00;...
  • Page 47 STC8A8K64D4 Series Manual P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00;...
  • Page 48: Comparator Output Switch

    STC8A8K64D4 Series Manual P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P_SW2,#00H ;SCL/P1.5, SDA/P1.4 P_SW2,#10H ;SCL_2/P2.5, SDA_2/P2.4 P_SW2,#20H ;SCL_3/P7.7, SDA_3/P7.6 P_SW2,#30H ;SCL_4/P3.2, SDA_4/P3.3 SJMP 3.2.9 Comparator output switch C language code // Operating frequency for test is 11.0592MHz #include “reg51.h”...
  • Page 49: Main Clock Output Switch

    STC8A8K64D4 Series Manual Assembly code ; Operating frequency for test is 11.0592MHz P_SW2 DATA 0BAH P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0...
  • Page 50 STC8A8K64D4 Series Manual P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00;...
  • Page 51 STC8A8K64D4 Series Manual Assembly code ; Operating frequency for test is 11.0592MHz P_SW2 DATA 0BAH CLKOCR 0FE05H P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA...
  • Page 52: Package Dimensions

    STC8A8K64D4 Series Manual 4 Package Dimensions 4.1 LQFP44 Package mechanical data (12mm*12mm) D (12mm) General size D1 (10mm) SYMBOL 1.60 0.05 0.15 1.35 1.40 1.45 0.59 0.64 0.69 0.33 0.42 0.32 0.35 0.38 0.13 0.18 0.12 0.13 0.14 11.95 12.00 12.05 9.90 10.00...
  • Page 53: Lqfp48 Package Mechanical Data(9Mm*9Mm

    STC8A8K64D4 Series Manual 4.2 LQFP48 Package mechanical data(9mm*9mm) D (9mm) General size D1 (7mm) SYMBOL 1.60 0.05 0.15 1.35 1.40 1.45 0.59 0.64 0.69 0.18 0.27 0.17 0.20 0.23 0.13 0.18 0.12 0.127 0.134 8.80 9.00 9.20 6.90 7.00 7.10 8.80 9.00 9.20...
  • Page 54: Qfn48 Package Mechanical Data (6Mm*6Mm)

    0.09 b(0.20mm) The back metal sheet (substrate) of STC's existing QFN48packaged chip is not grounded inside the chip. It can be grounded or ungrounded on the user's PCB board, which will not affect the performance of the chip. - 38 -...
  • Page 55: Lqfp64 Package Mechanical Data(12Mm*12Mm

    STC8A8K64D4 Series Manual 4.4 LQFP64 Package mechanical data(12mm*12mm) D (12mm) D1 (10mm) TOP E-MARK 2-Φ1.8± 0.1 DEPTH 0.1± 0.05 BTM E-MARK 2-Φ1.8± 0.1 DEPTH 0.1± 0.05 INDEX Φ1.2± 0.1 DEPTH 0.2± 0.1 e (0.5mm) General size SYMBOL 1.60 0.05 0.15 1.35 1.40 1.45...
  • Page 56: Qfn64 Package Mechanical Data(8Mm*8Mm

    0.09 b(0.20mm) The back metal sheet (substrate) of STC's existing DFN8 packaged chip is not grounded inside the chip. It can be grounded or ungrounded on the user's PCB board, which will not affect the performance of the chip. 4.6 Naming rules of STC8A8K64D4 family...
  • Page 57 STC8A8K64D4 Series Manual 4: 4 UARTs Flash size 60: 60K bytes 64: 64K bytes SRAM size 8K: 8K bytes Sub-series 8A: STC8A series - 41 -...
  • Page 58: Isp Download And Typical Application Circuit

    0.1u Monolithic capacitor (package 0603) diodes can be omitted ISP download steps: 1. Power off the target chip. 2. Click the "Download/Program" button in the STC-ISP download software. 3. Power on the target chip. 4. Start ISP download. - 42 -...
  • Page 59: Download Using Rs-232 Converter (General Precision Adc), Emulation Supported

    10u Monolithic capacitor (package 0603) 104(0.1uF) 103(0.01uF) 0.1u Monolithic capacitor (package 0603) ISP download steps: 1. Power off the target chip. 2. Click the “Download/Program” button in the STC-ISP download software. 3. Power on the target chip. 4. Start ISP download. - 43 -...
  • Page 60: Download Using Pl2303-Gl, Emulation Supported

    P3.0 port of the target chip and the sending pin of the USB-to-serial chip, otherwise the target chip cannot be completely powered off. The goal of powering down the target chip is not reached. 3. Click the "Download/Program" button in the STC-ISP download software 4. Power on the target chip 5.
  • Page 61: Download Using Universal Usb To Serial Tool, Emulation Supported

    3. Click the "Download/Program" button in the STC-ISP download software 4. Press the power button again to power on the target chip (the power-on indicator is on) 5.
  • Page 62 ISP download steps: 1. Connect the U8-Mini and the target chip according to the connection method shown in the figure. 2. Click the "Download/Program" button in the STC-ISP download software 3. Start ISP download Note: If the U8-Mini is used to power the target system, the total current of the target system cannot be greater than 200mA, otherwise the download will fail.
  • Page 63: Download Using U8W Tool, Support Isp Online And Offline Download, Also Support Emulation

    ISP download steps(Connection method): 1. Connect the U8W and the target chip according to the connection method shown in the figure. 2. Click the "Download/Program" button in the STC-ISP download software 3. Start ISP download Note: If the U8W is used to power the target system, the total current of the target system cannot be greater than 200mA, otherwise the download will fail.
  • Page 64 STC8A8K64D4 Series Manual (power) button again. - 48 -...
  • Page 65: Software Simulation Usb Isp Download Directly, And Does Not Support Simulation

    2. Connect P3.0/P3.1 to the USB port according to the connection method shown in the figure. 3. Short-circuit P3.2 with GND. 4. Power on the target chip and wait for "STC USB Writer (USB1)" to be automatically recognized in the STC-ISP download software.
  • Page 66: Microcontroller Power Supply Control Reference Circuit

    STC8A8K64D4 Series Manual 5.1.8 Microcontroller Power supply Control Reference Circuit SS8550 Target chip power supply External power supply input MCU_Vcc 0.1u Power control pin - 50 -...
  • Page 67: Clock, Reset, Power Saving Mode And Power Management

    STC8A8K64D4 Series Manual 6. Clock, Reset, Power saving mode and Power Management 6.1 System Clock Control The system clock controller provides the clock sources for the microcontroller's CPU and all peripherals. One of the following three clock sources can be selected as the system clock: internal high-precision IRC, internal 32KHz IRC with large error, external crystal oscillator.
  • Page 68: Internal High Speed High Precision Irc Control Register (Hirccr)

    STC8A8K64D4 Series Manual MCLK/3 … … MCLK/x … … MCLK/255 Note: After the user program is reset, the system will set the initial value of this register automatically according to the frequency division factor required for the operating frequency set during the last ISP download. 6.1.3 Internal high speed high precision IRC control register (HIRCCR) Symbol Address...
  • Page 69: Main Clock Output Control Register (Mclkocr)

    STC8A8K64D4 Series Manual of the oscillator to become stable. The clock controller will set the IRC32KST flag automatically after the internal oscillator frequency stabilizes. When the user program needs to switch the clock to the internal 32KHz low speed IRC, ENIRC32K must be set at first to enable the oscillator and then keep polling the oscillator stable flag IRC32KST until the flag changes to 1.
  • Page 70: Stc8A8K64D4 Series Internal Irc Frequency Adjustment

    STC8A8K64D4 Series Manual 6.2 STC8A8K64D4 series internal IRC frequency adjustment All STC8A8K64D4 series of microcontrollers integrate a high-precision internal IRC oscillator. The ISP download software will automatically adjust the frequency according to the frequency selected / set by the user when users download user program using ISP.
  • Page 71 STC8A8K64D4 Series Manual CLKDIV: Frequency division factor of the main clock. The system clock SYSCLK is a clock signal obtained by dividing the main clock MCLK. CLKDIV System clock frequency MCLK/1 MCLK/1 MCLK/2 MCLK/3 … … MCLK/x … … MCLK/255 - 55 -...
  • Page 72: Example Of Fine-Tuning To Get A User Frequency Of 3Mhz

    STC8A8K64D4 Series Manual 6.2.5 Example of fine-tuning to get a user frequency of 3MHz To get a frequency of 3MHz, you can use the method of 24MHz divided by 8. Select the internal IRC operating frequency as 24MHz firstly when downloading the ISP, as shown in the figure below. Then select the internal IRC as the clock source in the code and use the CLKDIV register to divide by 8.
  • Page 73 STC8A8K64D4 Series Manual P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; CKSEL = 0x00; // Select internal IRC (default) CLKDIV = 0x08; // Clock divided by 8 P_SW2 = 0x00;...
  • Page 74 STC8A8K64D4 Series Manual P5M1, #00H P_SW2,#80H A,#00H ; Select internal IRC DPTR,#CKSEL MOVX @DPTR,A A,#08H ; Clock divided by 8 DPTR,#CLKDIV MOVX @DPTR,A P_SW2,#00H IRTRIM ;IRC Fine-tune frequency up 3 ‰ (pay attention to judging boundaries) IRTRIM ;IRC Fine-tune frequency down 3 ‰ (pay attention to judging boundaries) - 58 -...
  • Page 75: System Reset

    STC8A8K64D4 Series Manual 6.3 System reset There are two types of resets in STC8A8K64D4 series of microcontrollers, hardware reset and software reset. When hardware reset occurs, all registers are reset to their original values and the system rereads all hardware options. At the same time, after being powered on, the system will wait for some time according to the hardware power-on wait time option set.
  • Page 76: Software Reset (Iap_Contr)

    STC8A8K64D4 Series Manual CLR_WDT: WDT clear bit. 0: No operation 1: WDT is cleared. This bit will be cleared by hardware automatically. IDL_WDT: WDT control bit in IDLE mode. 0: WDT is disabled in IDLE mode. 1: WDT is enabled in IDLE mode, and the WDT will continue counting. WDT_PS[2:0]: Watchdog timer clock division factor WDT_PS[2:0] division factor Overflow time @12MHz Overflow time @20MHz ≈...
  • Page 77: Low Voltage Reset (Rstcfg)

    STC8A8K64D4 Series Manual 6.3.3 Low voltage reset (RSTCFG) RSTCFG (Reset Configuration Register) Symbol Address RSTCFG ENLVR P54RST LVDS[1:0] ENLVR: Low voltage detection reset enable bit 0: Disable low voltage detection reset. When the system detects a low-voltage event, a low-voltage interrupt will occur. 1: Enable low voltage detection reset.
  • Page 78: Traditional 8051 High Voltage Power-On Reset Reference Circuit

    STC8A8K64D4 Series Manual 6.3.6 Traditional 8051 high voltage power-on reset reference circuit 10uF 301R Traditional 8051 reset pin Optional Traditional 8051 high voltage reset circuit The picture above shows the high-level reset circuit of the traditional 8051. The reset of the STC8A8K64D4 is a low-level reset, which is different from the traditional reset circuit.
  • Page 79: External Crystal Oscillator And External Clock Circuit

    STC8A8K64D4 Series Manual 6.4 External crystal oscillator and external clock circuit 6.4.1 External crystal input circuit 6.4.2 External clock input circuit (P1.6 cannot be used as general I/O) P1.6/XTALO 4~45MHz P1.7/XTALI 6.5 Clock stop / Power Saving Mode and System Power Management Bit Address and Symbol Reset Symbol...
  • Page 80 STC8A8K64D4 Series Manual 1: Make the microcontroller entering Clock stop mode / Power-Down mode / Power stop mode. CPU and all peripherals stop working. It is cleared by hardware automatically after the microcontroller wakes up. (Note: In the clock stop mode, the CPU and all peripherals stop working, but the data in the SRAM and XRAM remain unchanged.) IDL: IDLE mode control bit 0: No operation.
  • Page 81: Power-Down Wake-Up Timer

    STC8A8K64D4 Series Manual 6.6 Power-down wake-up timer The internal power-down wake-up timer is a 15-bit counter (composed of {WKTCH[6:0],WKTCL[7:0]}), which is used to wake up an MCU in power off mode. 6.6.1 Power-down wake-up timer count register (WKTCL,WKTCH) Symbol Address WKTCL WKTCH WKTEN...
  • Page 82: Example Routines

    STC8A8K64D4 Series Manual 6.7 Example Routines 6.7.1 System Clock Soure Selection C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define CKSEL (*(unsigned char volatile xdata *)0xfe00) #define CLKDIV (*(unsigned char volatile xdata *)0xfe01) #define HIRCCR (*(unsigned char volatile xdata *)0xfe02) #define...
  • Page 83 STC8A8K64D4 Series Manual P_SW2 = 0x80; IRC32KCR = 0x80; //Start internal 32KHz IRC while (!(IRC32KCR & 1)); //Waiting for the clock to stabilize CLKDIV = 0x00; //Clock is not divided CKSEL = 0x03; //Select internal 32KHz P_SW2 = 0x00; while (1); Assembly code ;...
  • Page 84: Main Clock Output

    STC8A8K64D4 Series Manual P_SW2,#80H A,#0C0H ;Start external crystal DPTR,#XOSCCR MOVX @DPTR,A MOVX A,@DPTR ACC.0,$-1 ;Waiting for the clock to stabilize ;Clock is not divided DPTR,#CLKDIV MOVX @DPTR,A A,#01H ;Select external crystal DPTR,#CKSEL MOVX @DPTR,A P_SW2,#00H P_SW2,#80H A,#80H ;Start internal 32KHz IRC DPTR,#IRC32KCR MOVX @DPTR,A...
  • Page 85 STC8A8K64D4 Series Manual P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; MCLKOCR = 0x01;...
  • Page 86: Application Of Watch-Dog Timer

    STC8A8K64D4 Series Manual P5M0, #00H P5M1, #00H P_SW2,#80H A,#01H ;Main clock output to P5.4 A,#02H ;Divide the main clock by 2 and output to P5.4 A,#04H ;Divide the main clock by 4 and output to P5.4 A,#84H ;Divide the main clock by 4 and output to P1.6 DPTR,#MCLKOCR MOVX @DPTR,A...
  • Page 87 STC8A8K64D4 Series Manual while (1) WDT_CONTR = 0x33; // Clear watchdog timer, otherwise system reset WDT_CONTR = 0x34; // Clear watchdog timer, otherwise system reset WDT_CONTR = 0x37; // Clear watchdog timer, otherwise system reset Display(); //Call Display module Scankey(); //Call Key scan module MotorDriver();...
  • Page 88: User Defined Downloading By Using Software Reset

    STC8A8K64D4 Series Manual LCALL SCANKEY ;Call Key scan module LCALL MOTORDRIVER ;Call Motor drive module LOOP 6.7.4 User Defined Downloading by Using Software Reset C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" IAP_CONTR 0xc7; sbit P3^2;...
  • Page 89: Low Voltage Detection

    STC8A8K64D4 Series Manual Assembly code ; Operating frequency for test is 11.0592MHz IAP_CONTR DATA 0C7H P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0...
  • Page 90 STC8A8K64D4 Series Manual #define LVD2V4 0x01 //LVD@2.4V #define LVD2V7 0x02 //LVD@2.7V #define LVD3V0 0x03 //LVD@3.0V sbit ELVD IE^6; #define LVDF 0x20 //PCON.5 sbit P3^2; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3;...
  • Page 91: Power Saving Mode

    STC8A8K64D4 Series Manual ELVD IE.6 LVDF ;PCON.5 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH...
  • Page 92 STC8A8K64D4 Series Manual #define 0x02 //PCON.1 sbit P3^4; sbit P3^5; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; void INT0_Isr() interrupt 0 P34 = ~P34; //Test port void main() P0M0 = 0x00;...
  • Page 93: Wake Up Mcu From Power Saving Mode Using Int0/Int1/Int2/Int3/Int4 Interrupts

    STC8A8K64D4 Series Manual P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0003H...
  • Page 94 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" INTCLKO 0x8f; #define 0x10 #define 0x20 #define 0x40 sbit P1^0; sbit P1^1; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 95 STC8A8K64D4 Series Manual P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; IT0 = 0; //Enable INT0 rising edge and falling edge interrupts IT0 = 1; //Enable INT0 falling edge interrupt EX0 = 1; //Enable INT0 interrupt IT1 = 0; //Enable INT1 rising edge and falling edge interrupts IT1 = 1;...
  • Page 96 STC8A8K64D4 Series Manual LJMP INT2ISR 005BH LJMP INT3ISR 0083H LJMP INT4ISR 0100H INT0ISR: P1.0 ;Test port RETI INT1ISR: P1.0 ;Test port RETI INT2ISR: P1.0 ;Test port RETI INT3ISR: P1.0 ;Test port RETI INT4ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H...
  • Page 97: Wake Up Mcu From Power Saving Mode Using T0/T1/T2/T3/T4 Pin Interrupts

    STC8A8K64D4 Series Manual 6.7.8 Wake up MCU from Power Saving Mode using T0/T1/T2/T3/T4 pin interrupts C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" 0xd7; 0xd6; 0xd5; 0xd4; 0xd3; 0xd2; T4T3M 0xd1; AUXR 0x8e; 0xaf; #define 0x04 #define...
  • Page 98 STC8A8K64D4 Series Manual P10 = !P10; //Test port void TM3_Isr() interrupt 19 P10 = !P10; //Test port void TM4_Isr() interrupt 20 P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00;...
  • Page 99 STC8A8K64D4 Series Manual _nop_(); while (1) P11 = ~P11; Assembly code ; Operating frequency for test is 11.0592MHz DATA 0D7H DATA 0D6H DATA 0D5H DATA 0D4H DATA 0D3H DATA 0D2H T4T3M DATA 0D1H AUXR DATA DATA 0AFH AUXINTIF DATA 0EFH T2IF T3IF T4IF...
  • Page 100 STC8A8K64D4 Series Manual TM1ISR: P1.0 ;Test port RETI TM2ISR: P1.0 ;Test port RETI TM3ISR: P1.0 ;Test port RETI TM4ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H...
  • Page 101: Wake Up Mcu From Power Saving Mode Using Rxd/Rxd2/Rxd3/Rxd4 Pin Interrupts

    STC8A8K64D4 Series Manual LOOP: P1.1 LOOP 6.7.9 Wake up MCU from Power Saving Mode using RxD/RxD2/RxD3/RxD4 pin interrupts C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" 0xaf; #define 0x01 #define 0x08 #define 0x10 P_SW1 0xa2;...
  • Page 102 STC8A8K64D4 Series Manual P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW1 = 0x00; //Wake up MCU on the falling edge of RXD / P3.0 P_SW1 = 0x40;...
  • Page 103 STC8A8K64D4 Series Manual P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0023H LJMP UART1ISR 0043H LJMP UART2ISR 008BH LJMP UART3ISR 0093H LJMP UART4ISR 0100H...
  • Page 104: Wake Up Mcu From Power Saving Mode Using I2C Sda Pin

    STC8A8K64D4 Series Manual IE2,#ES3 ;Enable UART3 interrupt IE2,#ES4 ;Enable UART4 interrupt SETB PCON,#02H ;MCU enters power down mode ;It will not enter the interrupt service routine after wake-up from power down mode. LOOP: P1.1 LOOP 6.7.10 Wake up MCU from Power Saving Mode using I2C SDA pin C language code // Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 105 STC8A8K64D4 Series Manual P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x00; //Wake up MCU on the falling edge of SDA/P1.4 P_SW2 = 0x10;...
  • Page 106: Wake Up Mcu From Power Saving Mode Using Power-Down Wake-Up Timer

    STC8A8K64D4 Series Manual 0100H I2CISR: PUSH PUSH PUSH PSW2,#80H DPTR,#I2CSLST MOVX A,@DPTR A,#NOT 40H MOVX @DPTR,A RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P_SW2,#00H...
  • Page 107 STC8A8K64D4 Series Manual // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" WKTCL 0xaa; WKTCH 0xab; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca;...
  • Page 108: Wake Up Mcu From Power Saving Mode Using Lvd Interrupt

    STC8A8K64D4 Series Manual P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H WKTCL,#0FFH Set the power-down wake-up clock to be about 1 second WKTCH,#87H...
  • Page 109 STC8A8K64D4 Series Manual #define LVD2V7 0x02 //LVD@2.7V #define LVD3V0 0x03 //LVD@3.0V sbit ELVD IE^6; #define LVDF 0x20 //PCON.5 sbit P1^0; sbit P1^1; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4;...
  • Page 110 STC8A8K64D4 Series Manual Assembly code ; Operating frequency for test is 11.0592MHz RSTCFG DATA 0FFH ENLVR ;RSTCFG.6 LVD2V0 ;LVD@2.0V LVD2V4 ;LVD@2.4V LVD2V7 ;LVD@2.7V LVD3V0 ;LVD@3.0V ELVD IE.6 LVDF ;PCON.5 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA...
  • Page 111: Wake Up Mcu From Power Saving Mode Using Comparator Interrupt ( Recommended For Use With Power-Down Wake-Up Timer)

    STC8A8K64D4 Series Manual LOOP: P1.1 LOOP 6.7.13 Wake up MCU from Power Saving Mode using comparator interrupt ( Recommended for use with power-down wake-up timer) In the power saving mode when the clock is stopped, it is not recommended to start the LVD and comparator, or hardware system will automatically start internal high precision 1.19 V reference source which has a corresponding temperature drift and calibration circuit, and leads to about 300uA extra power consumption.
  • Page 112 STC8A8K64D4 Series Manual P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; CMPCR2 = 0x00; CMPCR1 = 0x80; //Enable comparator module CMPCR1 |= 0x30;...
  • Page 113: Detect The Operating Voltage (Battery Voltage) Using Lvd

    STC8A8K64D4 Series Manual MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H CMPCR2,#00H CMPCR1,#80H ;Enable comparator module CMPCR1,#30H ;Enable edge interrupt of comparator CMPCR1,#NOT 08H ;P3.6 is CMP + input pin CMPCR1,#04H...
  • Page 114 STC8A8K64D4 Series Manual #define T1MS (65536 - FOSC/4/100) RSTCFG 0xff; #define LVD2V0 0x00 //LVD@2.0V #define LVD2V4 0x01 //LVD@2.4V #define LVD2V7 0x02 //LVD@2.7V #define LVD3V0 0x03 //LVD@3.0V #define LVDF 0x20 //PCON.5 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96;...
  • Page 115 STC8A8K64D4 Series Manual delay(); PCON &= ~LVDF; delay(); if (PCON & LVDF) power >>= 1; RSTCFG = LVD2V7; delay(); PCON &= ~LVDF; delay(); if (PCON & LVDF) power >>= 1; RSTCFG = LVD2V4; delay(); PCON &= ~LVDF; delay(); if (PCON & LVDF) power >>= 1;...
  • Page 116 STC8A8K64D4 Series Manual 0000H MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H PCON,#NOT LVDF RSTCFG,#LVD3V0 LOOP: B,#0FH RSTCFG,#LVD3V0 CALL DELAY PCON,#NOT LVDF CALL...
  • Page 117 STC8A8K64D4 Series Manual RSTCFG,#LVD2V2 CALL DELAY PCON,#NOT LVDF CALL DELAY A,PCON A,#LVDF SKIP SKIP: P2,A ; P2.3 ~ P2.0 are used to display battery level LOOP DELAY: R0,#100 NEXT: DJNZ R0,NEXT - 101 -...
  • Page 118: Memory

    STC8A8K64D4 Series Manual 7 Memory The STC8A8K64D4 series of microcontrollers have separate address spaces for Program Memory and Data Memory. Since no bus is provided for accessing external program memory, all program memory for all microcontrollers is on-chip Flash memory. The microcontrollers can not access external program memory. Large-capacity data memory is integrated in STC8A8K64D4 series of microcontrollers.
  • Page 119: Internal Ram

    STC8A8K64D4 Series Manual family 7.2.1 Internal RAM A total of 256 bytes of internal RAM can be divided into two parts: Lower 128 bytes of RAM and Upper 128 bytes of RAM. The Lower 128 bytes of data memory are compatible with the traditional 8051 microcontroller, which can be access by either Direct addressing or Indirect addressing.
  • Page 120: On-Chip Extended Ram

    STC8A8K64D4 Series Manual Bank 3 (18H~1FH) OV: Overflow flag bit。 F1: User flag bit 1。 P: Parity flag bit. There are 16 bytes in the bit addressable space, 20H to 2FH. They can either be accessed by byte like ordinary RAM or be individually accessed by any one bit in the byte unit.
  • Page 121: Bus Speed Control Register (Bus_Speed)

    STC8A8K64D4 Series Manual 7.2.6 Bus speed control register (BUS_SPEED) Symbol Address BUS_SPEED RW_S[1:0] SPEED[2:0] RW_S[1:0]: RD/WR control line selection bit 00: P4.4 is RD, P4.3 is WR 01: P3.7 is RD,P3.6 is WR 10: P4.2 is RD,P4.0 is WR 1: Reserved. SPEED[2:0]: Bus read and write speed control (preparation time and hold time of control signal and data signal when reading and writing data) Number of clocks...
  • Page 122 STC8A8K64D4 Series Manual E8H (P6) E8H.7 E8H.6 E8H.5 E8H.4 E8H.3 E8H.2 E8H.1 E8H.0 E0H (ACC) E0H.7 E0H.6 E0H.5 E0H.4 E0H.3 E0H.2 E0H.1 E0H.0 D8H (CCON) D8H.7 D8H.6 D8H.5 D8H.4 D8H.3 D8H.2 D8H.1 D8H.0 D0H (PSW) D0H.7 D0H.6 D0H.5 D0H.4 D0H.3 D0H.2 D0H.1 D0H.0...
  • Page 123: Special Parameters Of Memory

    STC8A8K64D4 Series Manual 7.3 Special parameters of memory The data memory and program memory of the STC8A8K64D4 series of microcontrollers store some special parameters related to the chip, including the global unique ID, the frequency of the 32K power-down wake-up timer, the internal reference voltage value, and the IRC parameters.
  • Page 124 STC8A8K64D4 Series Manual Special Note 1. Since the parameters in RAM may be modified, it is generally not recommended to be used. Especially, it is strongly recommended to read ID data in FLASH program memory (ROM) when you use ID for encryption. 2.
  • Page 125: Unique Id Number And Important Parameter (Chipid) Stored In Read-Only Special Function Register

    Some STC8A8K64D4 series microcontrollers have built-in 32-byte read-only special function register CHIPID. The content in CHIPID can only be read by the user program and cannot be modified. Using the data in CHIPID to encrypt user programs is the optimal solution officially recommended by STC. Related registers...
  • Page 126: Interpretation Of The Internal Reference Signal Source In Chip

    STC8A8K64D4 Series Manual 7.4.2 Interpretation of the internal reference signal source in CHIP Bit address and symbol Reset Symbol Description Address value CHIPID07 hardware digital ID07 FDE7H Internal 1.19V reference signal source (high byte) nnnn,nnnn Internal 1.19V reference signal source (low byte) CHIPID08 hardware digital ID08 FDE8H...
  • Page 127: Interpretation Of Test Time Parameters In Chip

    ±5%. In order to obtain accurate user frequencies, IRTRIM can be used to fine-tune the frequency. When using the download software provided by STC to download the user program, the system will automatically set the VRTRIM and IRTRIM registers according to the frequency set by the user.
  • Page 128: Example Routines

    STC8A8K64D4 Series Manual 7.5 Example Routines 7.5.1 Read Internal Referrence Voltage Value (Read from CHIPID) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define FOSC 11059200UL #define (65536 - FOSC / 115200 / 4) #define CPUIDBASE 0xfde0 #define...
  • Page 129 STC8A8K64D4 Series Manual busy = 0; if (RI) RI = 0; void UartInit() SCON = 0x50; TMOD = 0x00; TL1 = BRT; TH1 = BRT >> 8; TR1 = 1; AUXR = 0x40; busy = 0; void UartSend(char dat) while (busy); busy = 1;...
  • Page 130 STC8A8K64D4 Series Manual T24M_ADDR CPUIDBASE + 0CH ;24MHz T20M_ADDR CPUIDBASE + 0DH ;20MHz T27M_ADDR CPUIDBASE + 0EH ;27MHz T30M_ADDR CPUIDBASE + 0FH ;30MHz T33M_ADDR CPUIDBASE + 10H ;33.1776MHz T35M_ADDR CPUIDBASE + 11H ;35MHz T36M_ADDR CPUIDBASE + 12H ;36.864MHz T40M_ADDR CPUIDBASE + 13H ;40MHz T45M_ADDR CPUIDBASE + 14H...
  • Page 131: Read Internal Referrence Voltage (From Flash)

    STC8A8K64D4 Series Manual SETB BUSY SBUF,A MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB P_SW2,#80H DPTR,# VREF_ADDR MOVX A,@DPTR ;...
  • Page 132 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; busy; *BGV; void UartIsr() interrupt 4 if (TI) TI = 0; busy = 0; if (RI) RI = 0; void UartInit() SCON = 0x50; TMOD = 0x00; TL1 = BRT; TH1 = BRT >> 8; TR1 = 1;...
  • Page 133 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz AUXR DATA 0EFF7H ;STC8A8K60S4 BUSY 20H.0 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA...
  • Page 134: Read Internal Referrence Voltage (Read From Ram)

    STC8A8K64D4 Series Manual P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#BGV MOVC A,@A+DPTR ;Read the high byte of the internal reference voltage LCALL UART_SEND A,#1 MOVC A,@A+DPTR ;Read the low byte of the internal reference voltage LCALL UART_SEND...
  • Page 135 STC8A8K64D4 Series Manual TI = 0; busy = 0; if (RI) RI = 0; void UartInit() SCON = 0x50; TMOD = 0x00; TL1 = BRT; TH1 = BRT >> 8; TR1 = 1; AUXR = 0x40; busy = 0; void UartSend(char dat) while (busy);...
  • Page 136 STC8A8K64D4 Series Manual P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0023H LJMP UART_ISR 0100H...
  • Page 137: Read The Unique Id (Read From Chipid)

    STC8A8K64D4 Series Manual SETB SETB R0,#BGV A,@R0 ;Read the high byte of the internal reference voltage LCALL UART_SEND A,@R0 ;Read the low byte of the internal reference voltage LCALL UART_SEND LOOP: LOOP 7.5.4 Read the Unique ID (Read from CHIPID) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 138 STC8A8K64D4 Series Manual P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; void UartIsr() interrupt 4 if (TI) TI = 0; busy = 0; if (RI) RI = 0; void UartInit() SCON = 0x50; TMOD = 0x00; TL1 = BRT; TH1 = BRT >> 8; TR1 = 1;...
  • Page 139 STC8A8K64D4 Series Manual UartSend(ID_ADDR[i]); while (1); Assembly code ;Operating frequency for test is 11.0592MHz CPUIDBASE EQU 0FDE0H ID_ADDR CPUIDBASE + 00H VREF_ADDR CPUIDBASE + 07H F32K_ADDR CPUIDBASE + 09H T22M_ADDR CPUIDBASE + 0BH ;22.1184MHz T24M_ADDR CPUIDBASE + 0CH ;24MHz T20M_ADDR CPUIDBASE + 0DH ;20MHz T27M_ADDR...
  • Page 140: Read The Unique Id (Read From Flash)

    STC8A8K64D4 Series Manual UARTISR_EXIT: RETI UART_INIT: SCON,#50H TMOD,#00H TL1,#0E8H ;65536-11059200/115200/4=0FFE8H TH1,#0FFH SETB AUXR,#40H BUSY UART_SEND: BUSY,$ SETB BUSY SBUF,A MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H...
  • Page 141 STC8A8K64D4 Series Manual #include "intrins.h" #define FOSC 11059200UL #define (65536 - FOSC / 115200 / 4) AUXR 0x8e; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca;...
  • Page 142 STC8A8K64D4 Series Manual P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; char i; ID = (char code *)0xeff9; // STC8A8K60S4 UartInit(); ES = 1; EA = 1; for (i=0;...
  • Page 143: Read The Unique Id (Read From Ram)

    STC8A8K64D4 Series Manual UART_INIT: SCON,#50H TMOD,#00H TL1,#0E8H ;65536-11059200/115200/4=0FFE8H TH1,#0FFH SETB AUXR,#40H BUSY UART_SEND: BUSY,$ SETB BUSY SBUF,A MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL...
  • Page 144 STC8A8K64D4 Series Manual AUXR 0x8e; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char *ID; void UartIsr() interrupt 4 if (TI) TI = 0; busy = 0;...
  • Page 145 STC8A8K64D4 Series Manual P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; char i; ID = (char idata *)0xf1; UartInit(); ES = 1; EA = 1; for (i=0; i<7; i++) UartSend(ID[i]); while (1); Assembly code ;Operating frequency for test is 11.0592MHz AUXR DATA DATA...
  • Page 146: Read The Frequency Of 32K Power-Down Wake-Up Timer (Read From Chipid)

    STC8A8K64D4 Series Manual TL1,#0E8H ;65536-11059200/115200/4=0FFE8H TH1,#0FFH SETB AUXR,#40H BUSY UART_SEND: BUSY,$ SETB BUSY SBUF,A MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB...
  • Page 147 STC8A8K64D4 Series Manual #define ID_ADDR ((unsigned char volatile xdata *)(CPUIDBASE + 0x00)) #define VREF_ADDR (*(unsigned int volatile xdata *)(CPUIDBASE + 0x07)) #define F32K_ADDR (*(unsigned int volatile xdata *)(CPUIDBASE + 0x09)) #define T22M_ADDR (*(unsigned char volatile xdata *)(CPUIDBASE + 0x0b)) //22.1184MHz #define T24M_ADDR (*(unsigned char volatile xdata *)(CPUIDBASE + 0x0c))
  • Page 148 STC8A8K64D4 Series Manual void UartSend(char dat) while (busy); busy = 1; SBUF = dat; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00;...
  • Page 149 STC8A8K64D4 Series Manual BUSY 20H.0 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP...
  • Page 150: Read The Frequency Of 32K Power-Down Wake-Up Timer (Read From Flash)

    STC8A8K64D4 Series Manual P5M1, #00H LCALL UART_INIT SETB SETB P_SW2,#80H DPTR,# F32K_ADDR MOVX A,@DPTR ; Read high byte of 32K frequency LCALL UART_SEND DPTR MOVX A,@ DPTR ; Read low byte of 32K frequency LCALL UART_SEND LOOP: LOOP 7.5.8 Read the Frequency of 32K Power-down Wake-up Timer (Read from Flash) C language code //Operating frequency for test is 11.0592MHz...
  • Page 151 STC8A8K64D4 Series Manual if (RI) RI = 0; void UartInit() SCON = 0x50; TMOD = 0x00; TL1 = BRT; TH1 = BRT >> 8; TR1 = 1; AUXR = 0x40; busy = 0; void UartSend(char dat) while (busy); busy = 1; SBUF = dat;...
  • Page 152 STC8A8K64D4 Series Manual P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0023H LJMP UART_ISR 0100H...
  • Page 153: Read The Frequency Of 32K Power-Down Wake-Up Timer (Read From Ram)

    STC8A8K64D4 Series Manual SETB SETB DPTR,#F32K MOVC A,@A+DPTR ;Read high byte of 32K frequency LCALL UART_SEND DPTR MOVC A,@A+DPTR ;Read low byte of 32K frequency LCALL UART_SEND LOOP: LOOP 7.5.9 Read the Frequency of 32K Power-down Wake-up Timer (Read from RAM) C language code //Operating frequency for test is 11.0592MHz...
  • Page 154 STC8A8K64D4 Series Manual void UartInit() SCON = 0x50; TMOD = 0x00; TL1 = BRT; TH1 = BRT >> 8; TR1 = 1; AUXR = 0x40; busy = 0; void UartSend(char dat) while (busy); busy = 1; SBUF = dat; void main() P0M0 = 0x00;...
  • Page 155 STC8A8K64D4 Series Manual P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0023H LJMP UART_ISR 0100H UART_ISR: TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT UARTISR_EXIT: RETI UART_INIT: SCON,#50H TMOD,#00H TL1,#0E8H ;65536-11059200/115200/4=0FFE8H...
  • Page 156: Read The User-Defined Internal Irc Frequency (Read From Chipid)

    STC8A8K64D4 Series Manual A,@R0 ;Read high byte of 32K frequency LCALL UART_SEND A,@R0 ;Read low byte of 32K frequency LCALL UART_SEND LOOP: LOOP 7.5.10 Read the User-defined internal IRC Frequency (Read from CHIPID) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 157 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; //Select 20MHz P_SW2 = 0x80;...
  • Page 158 STC8A8K64D4 Series Manual IRCBAND = 0x02; CLKDIV = 0x00; // Select 35MHz P_SW2 = 0x80; CLKDIV = 0x04; IRTRIM = T35M_ADDR; VRTRIM = VRT44M_ADDR; IRCBAND = 0x03; CLKDIV = 0x00; // Select 40MHz P_SW2 = 0x80; CLKDIV = 0x04; IRTRIM = T40M_ADDR; VRTRIM = VRT44M_ADDR;...
  • Page 159 STC8A8K64D4 Series Manual P1M1 DATA 091H P1M0 DATA 092H P0M1 DATA 093H P0M0 DATA 094H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H...
  • Page 160 STC8A8K64D4 Series Manual DPTR,#VRT27M_ADDR MOVX A,@DPTR VRTRIM,A IRCBAND,#02H A,#0 DPTR,#CLKDIV MOVX @DPTR,A P_SW2,#00H ; Select 24MHz P_SW2,#80H A,#4 DPTR,#CLKDIV @DPTR,A DPTR,#T24M_ADDR MOVX A,@DPTR IRTRIM,A DPTR,#VRT27M_ADDR MOVX A,@DPTR VRTRIM,A IRCBAND,#02H A,#0 DPTR,#CLKDIV @DPTR,A P_SW2,#00H ; Select 27MHz P_SW2,#80H A,#4 DPTR,#CLKDIV MOVX @DPTR,A DPTR,#T27M_ADDR MOVX...
  • Page 161 STC8A8K64D4 Series Manual IRCBAND,#02H A,#0 DPTR,#CLKDIV MOVX @DPTR,A P_SW2,#00H ; Select 33.1776MHz P_SW2,#80H A,#4 DPTR,#CLKDIV MOVX @DPTR,A DPTR,#T33M_ADDR MOVX A,@DPTR IRTRIM,A DPTR,#VRT27M_ADDR MOVX A,@DPTR VRTRIM,A IRCBAND,#02H A,#0 DPTR,#CLKDIV MOVX @DPTR,A P_SW2,#00H ; Select 35MHz P_SW2,#80H A,#4 DPTR,#CLKDIV MOVX @DPTR,A DPTR,#T35M_ADDR MOVX A,@DPTR IRTRIM,A...
  • Page 162: Read The User-Defined Internal Irc Frequency (Read From Flash)

    STC8A8K64D4 Series Manual P_SW2,#00H ; Select 40MHz P_SW2,#80H A,#4 DPTR,#CLKDIV MOVX @DPTR,A DPTR,#T40M_ADDR MOVX A,@DPTR IRTRIM,A DPTR,#VRT44M_ADDR MOVX A,@DPTR VRTRIM,A IRCBAND,#03H A,#0 DPTR,#CLKDIV MOVX @DPTR,A P_SW2,#00H ; Select 45MHz P_SW2,#80H A,#4 DPTR,#CLKDIV MOVX @DPTR,A DPTR,#T45M_ADDR MOVX A,@DPTR IRTRIM,A DPTR,#VRT44M_ADDR MOVX A,@DPTR VRTRIM,A IRCBAND,#03H...
  • Page 163 STC8A8K64D4 Series Manual #define F32K_ROMADDR (*(unsigned int code *)0xeff5) #define T22M_ROMADDR (*(unsigned char code *)0xeff4) //22.1184MHz #define T24M_ROMADDR (*(unsigned char code *)0xeff3) //24MHz #define T20M_ROMADDR (*(unsigned char code *)0xeff2) //20MHz #define T27M_ROMADDR (*(unsigned char code *)0xeff1) //27MHz #define T30M_ROMADDR (*(unsigned char code *)0xeff0) //30MHz #define T33M_ROMADDR...
  • Page 164 STC8A8K64D4 Series Manual // Select 24MHz P_SW2 = 0x80; CLKDIV = 0x04; IRTRIM = T24M_ROMADDR; VRTRIM = VRT20M_ROMADDR; IRCBAND = 0x00; CLKDIV = 0x00; // Select 27MHz P_SW2 = 0x80; CLKDIV = 0x04; IRTRIM = T27M_ROMADDR; VRTRIM = VRT35M_ROMADDR; IRCBAND = 0x01; CLKDIV = 0x00;...
  • Page 165 STC8A8K64D4 Series Manual P_SW2 DATA 0BAH CKSEL 0FE00H CLKDIV 0FE01H IRCBAND DATA 09DH IRCTRIM DATA 09FH VRTRIM DATA 0A6H P1M1 DATA 091H P1M0 DATA 092H P0M1 DATA 093H P0M0 DATA 094H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H...
  • Page 166 STC8A8K64D4 Series Manual DPTR,#CLKDIV DPTR,#T22M_ROMADDR MOVC A,@A+DPTR IRTRIM,A DPTR,#VRT20M_ROMADDR MOVC A,@A+DPTR VRTRIM,A IRCBAND,#00H A,#0 DPTR,#CLKDIV P_SW2,#00H ; Select 24MHz P_SW2,#80H A,#4 DPTR,#CLKDIV DPTR,#T24M_ROMADDR MOVC A,@A+DPTR IRTRIM,A DPTR,#VRT20M_ROMADDR MOVC A,@A+DPTR VRTRIM,A IRCBAND,#00H A,#0 DPTR,#CLKDIV P_SW2,#00H ; Select 27MHz P_SW2,#80H A,#4 DPTR,#CLKDIV DPTR,#T27M_ROMADDR MOVC A,@A+DPTR...
  • Page 167 STC8A8K64D4 Series Manual A,#0 DPTR,#CLKDIV P_SW2,#00H ; Select 33.1776MHz P_SW2,#80H A,#4 DPTR,#CLKDIV DPTR,#T33M_ROMADDR MOVC A,@A+DPTR IRTRIM,A DPTR,#VRT35M_ROMADDR MOVC A,@A+DPTR VRTRIM,A IRCBAND,#01H A,#0 DPTR,#CLKDIV P_SW2,#00H ; Select 35MHz P_SW2,#80H A,#4 DPTR,#CLKDIV DPTR,#T35M_ROMADDR MOVC A,@A+DPTR IRTRIM,A DPTR,#VRT35M_ROMADDR MOVC A,@A+DPTR VRTRIM,A IRCBAND,#01H A,#0 DPTR,#CLKDIV P_SW2,#00H ;...
  • Page 168: Read The User-Defined Internal Irc Frequency (Read From Ram)

    STC8A8K64D4 Series Manual 7.5.12 Read the User-defined internal IRC Frequency (Read from RAM) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define CLKDIV (*(unsigned char volatile xdata *)0xfe01) P_SW2 0xba; IRTRIM 0x9f; P1M1 0x91; P1M0 0x92;...
  • Page 169 STC8A8K64D4 Series Manual P_SW2 DATA 0BAH CLKDIV 0FE01H IRCCR DATA 09FH IRC22M DATA 0FAH IRC24M DATA 0FBH P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA...
  • Page 170: Special Function Registers

    STC8A8K64D4 Series Manual 8 Special Function Registers 8.1 STC8A8K64D4-64Pin/48Pin family CCAP0H CCAP1H CCAL2H RSTCFG PWMSET PCA_PWM0 PCA_PWM1 PCA_PWM2 IAP_TPS PWMCFG CCAP0L CCAP1L CCAL2L IP3H AUXINTIF P7M1 P7M0 DPL1 DPH1 CMPCR1 CMPCR2 CCON CMOD CCAPM0 CCAPM1 CCAPM2 ADCCFG T4T3M P5M1 P5M0 P6M1 P6M0 SPSTAT...
  • Page 171 STC8A8K64D4 Series Manual FA78H DMA_LCM_RXAL FA70H DMA_LCM_CFG DMA_LCM_CR DMA_LCM_STA DMA_LCM_AMT DMA_LCM_DONE DMA_LCM_TXAH DMA_LCM_TXAL DMA_LCM_RXAH FA68H DMA_UR4R_CFG DMA_UR4R_CR DMA_UR4R_STA DMA_UR4R_AMT DMA_UR4R_DONE DMA_UR4R_RXAH DMA_UR4R_RXAL DMA_UR4T_CFG DMA_UR4T_CR DMA_UR4T_STA DMA_UR4T_AMT DMA_UR4T_DONE DMA_UR4T_TXAH DMA_UR4T_TXAL FA60H FA58H DMA_UR3R_CFG DMA_UR3R_CR DMA_UR3R_STA DMA_UR3R_AMT DMA_UR3R_DONE DMA_UR3R_RXAH DMA_UR3R_RXAL FA50H DMA_UR3T_CFG DMA_UR3T_CR DMA_UR3T_STA DMA_UR3T_AMT...
  • Page 172: List Of Special Function Registers

    STC8A8K64D4 Series Manual 8.2 List of Special Function Registers Note: The register address can be bit-addressable only if it is divisible by 8, and it cannot be bit-addressable if it is not divisible by 8. Registers in STC8A8K64D4 which can be bit-addressable are: P0 (80H), TCON (88H), P1 (90H), SCON (98H), P2 (A0H), IE (A8H), P3 (B0H), IP (B8H), P4 (C0H), P5 (C8H), PSW (D0H), ACC (E0H), B (F0H) Bit Address and Symbol Value after...
  • Page 173 STC8A8K64D4 Series Manual SPSTAT SPI Status register SPIF WCOL 00xx,xxxx SPCTL SPI Control Register SSIG SPEN DORD MSTR CPOL CPHA SPR[1:0] 0000,0100 SPDAT SPI Data Register 0000,0000 Program Status Word Register 0000,00x0 T4T3M Timer4 and Timer 3 Control Register T4_C/T T4x12 T4CLKO T3_C/T...
  • Page 174 STC8A8K64D4 Series Manual P7 Pull-up Resistor Control P7PU FE17H P77PU P76PU P75PU P74PU P73PU P72PU P71PU P70PU 0000,0000 Register P0 Schmitt Trigger Control P07NCS P06NCS P05NCS P04NCS P03NCS P02NCS P01NCS P00NCS P0NCS FE18H 0000,0000 Register P1 Schmitt Trigger Control P1NCS FE19H P17NCS P16NCS...
  • Page 175 STC8A8K64D4 Series Manual LCM Interface Configuration LCMIFCFG FE50H LCMIFIE LCMIFIP[1:0] LCMIFDPS[1:0] D16_D8 M68_I80 0x00,0000 Register LCM Interface Configuration LCMIFCPS[1:0] SETUPT[2:0] HOLDT[1:0] LCMIFCFG2 FE51H x000,0000 Register 2 Interface Control LCMIFCR FE52H ENLCMIF CMD[2:0] 0xxx,x000 Register LCMIFIF LCMIFSTA LCM Interface Status Register FE53H xxxx,xxx0 LCMIFDAT[7:0]...
  • Page 176 STC8A8K64D4 Series Manual PWMCH PWM0 Counter high byte FF00H x000,0000 PWMCL PWM0 Counter low byte FF01H 0000,0000 PWMCKS PWM0 clock selection FF02H SELT2 PWM_PS[3:0] xxx0,0000 PWM0 Trigger ADC count high PWMTADCH FF03H x000,0000 byte PWM0 Trigger ADC count low PWMTADCL FF04H 0000,0000 byte...
  • Page 177 STC8A8K64D4 Series Manual P2INTF P2 Interrupt flag register FD12H P27INTF P26INTF P25INTF P24INTF P23INTF P22INTF P21INTF P20INTF 0000,0000 P3INTF P3 Interrupt flag register FD13H P37INTF P36INTF P35INTF P34INTF P33INTF P32INTF P31INTF P30INTF 0000,0000 P4INTF P4 Interrupt flag register FD14H P47INTF P46INTF P45INTF P44INTF...
  • Page 178 STC8A8K64D4 Series Manual CCAPM3 PCA3 Mode Control Register FD54H ECOM3 CCAPP3 CCAPN3 MAT3 TOG3 PWM3 ECCF3 x000,0000 CCAP3L PCA3 low byte FD55H 0000,0000 CCAP3H PCA3 high byte FD56H 0000,0000 PCA_PWM3 PCA3 的 PWM mode register FD57H EBS3[1:0] XCCAP3H[1:0] XCCAP3L[1:0] EPC3H EPC3L 0000,0000 I/O port interrupt priority low...
  • Page 179 STC8A8K64D4 Series Manual UR1R_DMA status register FA3AH RXLOSS UR1RIF xxxx,xx00 DMA_UR1R_STA UR1R_DMA total bytes to be FA3BH 0000,0000 DMA_UR1R_AMT transferred UR1R_DMA transfer completed FA3CH 0000,0000 DMA_UR1R_DONE bytes UR1R_DMA send address high byte FA3DH 0000,0000 DMA_UR1R_TXAH UR1R_DMA send address low byte FA3EH 0000,0000 DMA_UR1R_TXAL...
  • Page 180: O Ports

    STC8A8K64D4 Series Manual 9 I/O Ports There are 4 modes for all GPIOs, quasi bidirectional or weak pull-up mode (standard 8051 output mode), push-pull output / strong pull-up mode, high-impedance input mode (where current can neither flow in nor out), open drain mode. It is easy to configure the I/O mode using software.
  • Page 181: Port Data Register (Px)

    STC8A8K64D4 Series Manual P27IE P26IE P25IE P24IE P23IE P22IE P21IE P20IE P2IE P2 Input Enable Control Register FE32H 1111,1111 P3IE P3 Input Enable Control Register FE33H P37IE P36IE P35IE P34IE P33IE P32IE P31IE P30IE 1111,1111 P4IE P4 Input Enable Control Register FE34H P47IE P46IE...
  • Page 182: Pull-Up Resistor Control Registers (Pxpu)

    STC8A8K64D4 Series Manual 9.1.3 Pull-up Resistor Control Registers (PxPU) Symbol Address P0PU FE10H P07PU P06PU P05PU P04PU P03PU P02PU P01PU P00PU P1PU FE11H P17PU P16PU P15PU P14PU P13PU P12PU P11PU P10PU P2PU FE12H P27PU P26PU P25PU P24PU P23PU P22PU P21PU P20PU P3PU FE13H...
  • Page 183: Port Digital Signal Input Enable Control Register (Pxie)

    STC8A8K64D4 Series Manual P5DR FE2DH P55DR P54DR P53DR P52DR P51DR P50DR xx11,1111 P6DR FE2EH P67DR P66DR P65DR P64DR P63DR P62DR P61DR P60DR 1111,1111 P7DR FE2FH P77DR P76DR P75DR P74DR P73DR P72DR P71DR P70DR 1111,1111 Drive capability control bit: 0: Enhanced drive ability 1: General drive ability 9.1.7 Port digital signal input enable control register (PxIE) Symbol...
  • Page 184: Configure I/O Ports

    STC8A8K64D4 Series Manual 9.2 Configure I/O Ports Two registers are used to configure each I/O mode. Taking Port 0 as an example, two registers, P0M0 and P0M1, are used to configure Port 0, as shown in the following figure: P0.7 P0.5 P0.3 P0.1...
  • Page 185: Push-Pull Output

    STC8A8K64D4 Series Manual If one of the pin outputs logic “1” and the external device pulls it low, the weak pull-up transistor is off and the “very weak pull-up” maintains on. To pull the pin low, the external device must have sufficient sink capability to make the voltage on the pin drop below the threshold voltage.
  • Page 186: K Pull-Up Resistor

    STC8A8K64D4 Series Manual be an external pull-up resistor in this configuration when the port outputs a logic high, typically the port pin is externally connected to VCC through a resistor. An open-drain I/O port pin can read the external state if the external pull-up resistor is connected, and the open-drain mode I/O port pin can be used as input mode.
  • Page 187: How To Set I/O Port Current Drive Capability

    STC8A8K64D4 Series Manual Set the PxDR register, which can be used to control the drive current of the I/O port. When set to 1, I/O output is general drive current, and when set to 0, it is strong drive current. 9.3.7 How to set I/O port current drive capability If you need to change the current drive capability of the I/O port, you can do so by setting the PxDR register Set the PxDR register, which can be used to control the drive current of the I/O port.
  • Page 188: Example Routines

    STC8A8K64D4 Series Manual 9.4 Example Routines 9.4.1 Port Mode Setting C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M0 0x94; P0M1 0x93; P1M0 0x92; P1M1 0x91; P2M0 0x96; P2M1 0x95; P3M0 0xb2; P3M1 0xb1; P4M0 0xb4;...
  • Page 189: Reading And Writing Operation Of Bidirection Port

    STC8A8K64D4 Series Manual P7M1 DATA 0E1H 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0,#00H ;Set P0.0 ~ P0.7 as bidirectional port mode P0M1,#00H P1M0,#0FFH ;Set P1.0 ~ P1.7 as push-pull output mode P1M1,#00H P2M0,#00H ;Set P2.0 ~ P2.7 as high impedance input mode P2M1,#0FFH P3M0,#0FFH ;Set P3.0 ~ P3.7 as open-drain mode...
  • Page 190 STC8A8K64D4 Series Manual P5M1 = 0x00; P0M0 = 0x00; //Set P0.0 ~ P0.7 as bidirectional port mode P0M1 = 0x00; P00 = 1; //P0.0 output high level P00 = 0; //P0.0 output low level P00 = 1; //Enable the internal weak pull-up resistor before reading the port _nop_();...
  • Page 191 STC8A8K64D4 Series Manual ;Wait for two clocks C,P0.0 ;Read port status - 175 -...
  • Page 192: A Typical Circuit Controlled By Triode

    When STC's 3V microcontroller is connected to a 5V device and the corresponding I/O port is used as an output, it can be isolated with an NPN transistor in order to prevent the 3V microcontroller from bearing 5V. The circuit is as follows.
  • Page 193: Make I/O Port Output Low When Power On Reset

    I/O to strong push-pull output and output high level to the outside. Now you can connect a pull-down resistor (about 10K) to the I/O port of STC microcontroller. In this way, during power-on reset, except the download ports P3.0 and P3.1 are weak pull-ups (quasi-bidirectional ports), other I/O ports are in high-impedance...
  • Page 194: Circuit Diagram Of Driving 8 Digital Leds Using 74Hc595

    STC8A8K64D4 Series Manual 9.9 Circuit Diagram of Driving 8 Digital LEDs using 74HC595 - 178 -...
  • Page 195: Digital Leds Driven Directly By I/O Port Circuit

    STC8A8K64D4 Series Manual 9.10 Digital LEDs Driven Directly by I/O Port Circuit 9.11 LCD Segment LCD Driven Directly by I/O Port Circuit An external LCD driver IC is needed when you design a product having segment LCD display requirement using MCU without LCD driver is used, which will increase cost.
  • Page 196 STC8A8K64D4 Series Manual The simple principle of segment code LCD driving is shown in Figure 1. LCD is a special kind of liquid crystal. The arrangement direction of the crystal will be reversed under the action of an electric field, which changes its light transmittance, so that the display content can be seen. LCD has a torsional voltage threshold.
  • Page 197 STC8A8K64D4 Series Manual Figure 1 Circuit for driving a ‘1/4Duty, 1/2BIAS, 3V’ LCD Figure 2 Segment name - 181 -...
  • Page 198 STC8A8K64D4 Series Manual Figure 3 Principle of ‘1/4Duty, 1/2BIAS’ scanning - 182 -...
  • Page 199 STC8A8K64D4 Series Manual Figure 4 Driving circuit of ‘1/4Duty, 1/3BIAS, 3V’ LCD - 183 -...
  • Page 200 STC8A8K64D4 Series Manual Figure 5 Principle of ‘1/4Duty, 1/3BIAS’ scanning For ease of use, the display contents are stored in display memory where each bit corresponds to the LCD segment one by one, as shown in Figure 6. Figure 6 LCD truth table and memory mapping table Figure 7: Driving effect photo - 184 -...
  • Page 201 STC8A8K64D4 Series Manual Only two functions are required in the LCD scanning program: 1. LCD segment code scan function void LCD_scan(void) The program calls this function at a certain interval, and it will display the contents of the LCD display buffer on the LCD. It takes 8 calling cycles to scan all of them.
  • Page 202 STC8A8K64D4 Series Manual #define MAIN_Fosc 11059200L //Define the main clock #define DIS_BLACK 0x10 #define DIS_ 0x11 #define DIS_A 0x0A #define DIS_B 0x0B #define DIS_C 0x0C #define DIS_D 0x0D #define DIS_E 0x0E #define DIS_F 0x0F #define LCD_SET_DP2 LCD_buff[0] |= 0x08 #define LCD_CLR_DP2 LCD_buff[0] &= ~0x08 #define LCD_FLASH_DP2 LCD_buff[0] ^= 0x08...
  • Page 203 STC8A8K64D4 Series Manual TMOD = 0x00; TL0 = (65536 - (MAIN_Fosc / 500)); TH0 = (65536 - (MAIN_Fosc / 500)) >> 8; TR0 = 1; ET0 = 1; EA = 1; //Initialize LCD memory for(i=0; i<8; i++) LCD_buff[i] = 0; P2n_push_pull(0xf0);...
  • Page 204 STC8A8K64D4 Series Manual delay_ms(50); while(!INT0) delay_ms(10); //Waiting for the key to be released once more TR0 = 0; 关闭定时器 外中断 标志位 IE0 = 0; EX0 = 1; //INT0 Enable IT0 = 1; //INT0 下降沿中断 P1n_push_pull(0xff); //com 和 全部输出 P2n_push_pull(0xff); P1 = 0; P2 = 0;...
  • Page 205 STC8A8K64D4 Series Manual ’ P2n_pure_input(0x0f); //All COM outputs are high impedance, and COM s voltage is the midpoint if(scan_index & 1) // Reverse scan P1 = ~LCD_buff[j]; P2 = ~(LCD_buff[j|4] & 0xf0); else // Normal phase scan P1 = LCD_buff[j]; P2 = LCD_buff[j|4] &...
  • Page 206 STC8A8K64D4 Series Manual if(i & 0x01) k |= 0x40; if(i & 0x20) k |= 0x80; *p = (*p & T_LCD_mask[n]) | (k>>2*n); /********************Display time **************************/ void LoadRTC(void) LCD_load(1,hour/10); LCD_load(2,hour%10); LCD_load(3,minute/10); LCD_load(4,minute%10); LCD_load(5,second/10); LCD_load(6,second%10); Assembly code ;STC8 series of microcontrollers are used to test segment LCD driven by I/O directly (6 8-word LCDs, 1/4 Dutys, 1/3 bias). ;Time (hours, minutes and seconds) is displayed after power-on.
  • Page 207 STC8A8K64D4 Series Manual minute DATA hour DATA scan_index DATA LCD_buff DATA ;40H~47H ;************************************************************ 0000H LJMP F_Main 000BH LJMP F_Timer0_Interrupt ;************************************************************ 0100H F_Main: P3M1, A ;Set as a quasi-bidirectional port P3M0, A P5M1, A ;Set as a quasi-bidirectional port P5M0, A P1M1, #0 ;...
  • Page 208 STC8A8K64D4 Series Manual LCD_buff, #020H ;Flashing hour-minute interval: LCD_buff, #002H ;Flashing minute-second interval: B_Second B_Second, L_Main_Loop second A, second CJNE A, #60, L_Main_Load second, #0 ; reach to 1 minute minute A, minute CJNE A, #60, L_Main_Load minute, #0; hour A, hour CJNE A, #24, L_Main_Load...
  • Page 209 STC8A8K64D4 Series Manual B, #10 R7, A LCALL F_LCD_load ;R6 is the number, which is 1~6, R7 is the number to be displayed R6, #2 ;LCD_load(2,hour%10); A, hour B, #10 R7, B LCALL F_LCD_load ;R6 is the number, which is 1~6, R7 is the number to be displayed R6, #3 ;LCD_load(3,minute/10);...
  • Page 210 STC8A8K64D4 Series Manual P1, A A, R0 ;P2 = ~(LCD_buff[j|4] & 0xf0); A, #4 R0, A A, @R0 A, #0f0H P2, A SJMP L_LCD_Scan3 L_LCD_Scan2: ; Normal phase scan A, @R0 ;P1 = LCD_buff[j]; P1, A A, R0 ;P2 = (LCD_buff[j|4] & 0xf0); A, #4 R0, A A, @R0...
  • Page 211 STC8A8K64D4 Series Manual ACC.6, C C, B.4 ACC.7, C @R0, A A, @R0 C, B.1 ACC.6, C C, B.6 ACC.7, C @R0, A A, @R0 C, B.0 ACC.6, C C, B.5 ACC.7, C @R0, A L_NotLoadChar1: CJNE A, #2, L_NotLoadChar2 R0,#LCD_buff A, @R0 C, B.3...
  • Page 212 STC8A8K64D4 Series Manual @R0, A A, @R0 C, B.2 ACC.2, C C, B.4 ACC.3, C @R0, A A, @R0 C, B.1 ACC.2, C C, B.6 ACC.3, C @R0, A A, @R0 C, B.0 ACC.2, C C, B.5 ACC.3, C @R0, A L_NotLoadChar3: CJNE A, #4, L_NotLoadChar4...
  • Page 213 STC8A8K64D4 Series Manual CJNE A, #5, L_NotLoadChar5 R0,#LCD_buff+4 A, @R0 C, B.3 ACC.6, C @R0, A A, @R0 C, B.2 ACC.6, C C, B.4 ACC.7, C @R0, A A, @R0 C, B.1 ACC.6, C C, B.6 ACC.7, C @R0, A A, @R0 C, B.0 ACC.6, C...
  • Page 214 STC8A8K64D4 Series Manual ACC.5, C @R0, A L_NotLoadChar6: - 198 -...
  • Page 215: Instruction Set

    STC8A8K64D4 Series Manual 10 Instruction Set Mnemonic Description Bytes Cycle A,Rn Add register to Accumulator A,direct Add ditect byte to Accumulator A,@Ri Add indirect RAM to Accumulator A,#data Add immediate data to Accumulator ADDC A,Rn Add register to Accumulator with Carry ADDC A,direct Add ditect byte to Accumulator with Carry...
  • Page 216 STC8A8K64D4 Series Manual Clear Accumulator Complement Accumulator Rotate Accumulator Left Rotate Accumulator Left through the Carry Rotate Accumulator Right Rotate Accumulator Right through the Carry SWAP Swap nibbles within the Accumulator Clear Carry Clear direct bit SETB Set Carry SETB Set direct bit Complement Carry Complement direct bit...
  • Page 217 STC8A8K64D4 Series Manual Return from Subroutine RETI Return from interrupt AJMP addr11 Absolute Jump LJMP addr16 Long Jump SJMP Short Jump (relative addr) @A+DPTR Jump indirect relative to the DPTR Jump if Accumulator is Zero Jump if Accumulator is not Zero Jump if Carry is set Jump if Carry not set bit,rel...
  • Page 218: Interrupt System

    STC8A8K64D4 Series Manual 11 Interrupt System (An error will be reported when compiled in Keil when using an interrupt with an interrupt number greater than 31 in a C program. Please refer to Appendix for the solution.) The interrupt system is set up to give the CPU real-time processing capabilities for external emergencies. If an emergency request occurrs while CPU is dealing with something, the CPU is required to suspend the current work to handle the emergency.
  • Page 219 STC8A8K64D4 Series Manual √ Timer 3 interrrupt (Timer3) √ Timer 4 interrrupt (Timer4) √ Comparator interrupt (CMP) √ Enhanced PWM interrupt √ PWM abnormal detection interrupt √ I2C interrupt Port0 interrupt √ Supports falling edge, rising edge, high level and low level interrupts Port1 interrupt √...
  • Page 220: Structure Of Stc8A8K64D4 Interrupt

    STC8A8K64D4 Series Manual 11.2 Structure of STC8A8K64D4 Interrupt Interrupt priority Lowest priority Lower priority Interrupt request Interrupt enable control control Higher priority Highest priority TCON.0/IT0=0 PX0/PX0H INT0 TCON.0/IT0=1 PT0/PT0H Timer0 TCON.2/IT1=0 PX1/PX1H INT1 TCON.2/IT1=1 PT1/PT1H Timer1 PS/PSH UART1 EADC PADC/PADCH ADC_Flag ELVD PLVD/PLVDH...
  • Page 221: Interrupt List Of Stc8A8K64D4 Series

    STC8A8K64D4 Series Manual 11.3 Interrupt List of STC8A8K64D4 Series Interrupt Interrupt Priority level Priority Interrupt Order Interrupt enable bit source vector setup bit level request flag PX0PX0H 0/1/2/3 INT0 0003H PT0,PT0H 0/1/2/3 Timer0 000BH PX1,PX1H 0/1/2/3 INT1 0013H PT1,PT1H 0/1/2/3 Timer1 001BH PS,PSH...
  • Page 222 STC8A8K64D4 Series Manual vector setup bit level request flag MSIF EMSI STAIF ESTAI PI2C,PI2CH 0/1/2/3 RXIF ERXI 00C3H TXIF ETXI STOIF ESTOI P0IP,P0IPH 0/1/2/3 P0INTF P0INTE P0 interrupt 012BH 0/1/2/3 P1IP,P1IPH P1INTF P1INTE P1 interrupt 0133H P2IP,P2IPH 0/1/2/3 P2INTF P2INTE P2 interrupt 013BH P3IP,P3IPH...
  • Page 223: Registers Related To Interrupt

    STC8A8K64D4 Series Manual 11.4 Registers Related to Interrupt Bit Address and Symbol Reset Symbol Description Address value Interrupt enable register ELVD EADC 0000,0000 Interrupt enable register2 ESPI 0000,0000 External interrupt and clock output INTCLKO T2CLKO T1CLKO T0CLKO x000,x000 control register Interrupt Priority Low Byte PPCA PLVD...
  • Page 224: Interrupt Enable Registers (Interrupt Enable Bits)

    STC8A8K64D4 Series Manual UR2R_DMA configuration FA48H UR2RIE UR2RIP[1:0] UR2RPTY[1:0] 0xxx,0000 DMA_UR2R_CFG register UR3T_DMA configuration FA50H UR3TIE UR3TIP[1:0] UR3TPTY[1:0] 0xxx,0000 DMA_UR3T_CFG register UR3R_DMA configuration FA58H UR3RIE UR3RIP[1:0] UR3RPTY[1:0] 0xxx,0000 DMA_UR3R_CFG register UR4T_DMA configuration FA60H UR4TIE UR4TIP[1:0] UR4TPTY[1:0] 0xxx,0000 DMA_UR4T_CFG register UR4R_DMA configuration FA68H UR4RIE...
  • Page 225 STC8A8K64D4 Series Manual 1: enable Timer 3 interrupt. ES4: UART4 interrupt enable bit. 0: disable UART4 interrupt. 1: enable UART4 interrupt. ES3: UART3 interrupt enable bit. 0: disable UART3 interrupt. 1: enable UART3 interrupt. ET2: Timer 2 interrupt enable bit. 0: disable Timer 2 interrupt.
  • Page 226 STC8A8K64D4 Series Manual 0: disable comparator falling-edge interrupt. 1: enable comparator falling-edge interrupt. Enhanced PWM Configuration Register Symbol Address PWMCFG PWMCBIF EPWMCBI ENPWMTA PWMCEN EPWMCBI: Enhanced PWM0 counter interrupt enable bit. 0: disable PWM0 counter interrupt 1: enable PWM0 counter interrupt Enhanced PWM Abnormal Detection Control Register Symbol Address...
  • Page 227 STC8A8K64D4 Series Manual Symbol Address P0INTE FD00H P07INTE P06INTE P05INTE P04INTE P03INTE P02INTE P01INTE P00INTE P1INTE FD01H P17INTE P16INTE P15INTE P14INTE P13INTE P12INTE P11INTE P10INTE P2INTE FD02H P27INTE P26INTE P25INTE P24INTE P23INTE P22INTE P21INTE P20INTE P3INTE FD03H P37INTE P36INTE P35INTE P34INTE P33INTE P32INTE...
  • Page 228: Interrupt Request Registers (Interrupt Flags)

    Ealy 1T 8051 MCU using 0.35um process, STC15 series added a 16-bit reload timer which was the world's first big innovation of 8051. Due to high manufacturing cost, STC 16-bit reloadable timer 2/3/4 did not design the interrupt request flag registers for users to access.
  • Page 229 1, and request an interrupt and wait, it is mistakenly cleared by the user. This is different from the traditional INTEL8048, 8051, but INTEL has been discontinued, so the new design of STC does not consider the specifications compatible with traditional INTEL.
  • Page 230 STC8A8K64D4 Series Manual ERXI: I C slave completes receiving data event interrupt request flag, which must be cleared by software. ETXI: I C slave completes transmitting data event interrupt request flag, which must be cleared by software. ESTOI: I C slave receives the STOP event interrupt request flag, which should be must by software. Enhanced PWM Configuration Register Symbol Address...
  • Page 231: Interrupt Priority Registers

    STC8A8K64D4 Series Manual DMA_UR2R_STA FA4AH RXLOSS UR2RIF DMA_UR3T_STA FA52H TXOVW UR3TIF DMA_UR3R_STA FA5AH RXLOSS UR3RIF DMA_UR4T_STA FA62H TXOVW UR4TIF DMA_UR4R_STA FA6AH RXLOSS UR4RIF DMA_LCM_STA FA72H TXOVW LCMIF M2MIF: DMA_M2M(Memory-to-Memory DMA) interrupt request flag. Need to be cleared by software. ADCIF: DMA_ADC(ADC DMA) interrupt request flag. Need to be cleared by software. SPIIF: DMA_SPI(SPI DMA) interrupt request flag.
  • Page 232 STC8A8K64D4 Series Manual PADCH,PADC: ADC interrupt priority control bit. 00: ADC interrupt priority level is 0 (lowest) 01: ADC interrupt priority level is 1 (lower) 10: ADC interrupt priority level is 2 (higher) 11: ADC interrupt priority level is 3 (highest) PLVDH,PLVD: Low voltage detection interrupt priority control bit.
  • Page 233 STC8A8K64D4 Series Manual 10: UART4 interrupt priority level is 2 (higher) 11: UART4 interrupt priority level is 3 (highest) LCM Interface Configuration Register Symbol Address LCMIFCFG FE50H LCMIFIE LCMIFIP[1:0] LCMIFDPS[1:0] D16_D8 M68_I80 LCMIFIP[1:0]: LCM interface interrupt priority control bits 00: LCM interface interrupt priority level is 0 (lowest level) 01: LCM interface interrupt priority is level 1 (lower level) 10: LCM interface interrupt priority is level 2 (higher level) 11: LCM interface interrupt priority level is 3 (the highest level)
  • Page 234 STC8A8K64D4 Series Manual Symbol Address DMA_M2M_CFG FA00H M2MIE TXACO RXACO M2MIP[1:0] M2MPTY[1:0] DMA_ADC_CFG FA10H ADCIE ADCMIP[1:0] ADCPTY[1:0] DMA_SPI_CFG FA20H SPIIE ACT_TX ACT_RX SPIIP[1:0] SPIPTY[1:0] DMA_UR1T_CFG FA30H UR1TIE UR1TIP[1:0] UR1TPTY[1:0] DMA_UR1R_CFG FA38H UR1RIE UR1RIP[1:0] UR1RPTY[1:0] DMA_UR2T_CFG FA40H UR2TIE UR2TIP[1:0] UR2TPTY[1:0] DMA_UR2R_CFG FA48H UR2RIE UR2RIP[1:0]...
  • Page 235 STC8A8K64D4 Series Manual 01: DMA_UR3R interrupt priority is level 1 (lower level) 10: DMA_UR3R interrupt priority is level 2 (higher level) 11: DMA_UR3R interrupt priority level is 3 (the highest level) UR4RIP: DMA_UR4R(UART 4 receive DMA)interrupt priority control bits 00: DMA_UR4R interrupt priority level is 0 (lowest level) 01: DMA_UR4R interrupt priority is level 1 (lower level) 10: DMA_UR4R interrupt priority is level 2 (higher level) 11: DMA_UR4R interrupt priority level is 3 (the highest level)
  • Page 236: Example Routines

    STC8A8K64D4 Series Manual 11.5 Example Routines 11.5.1 INT0 Interrupt (Rising and Falling Edges) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2;...
  • Page 237: Int0 Interrupt (Falling Edge)

    STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA...
  • Page 238 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void INT0_Isr() interrupt 0 P10 = !P10; //Test port void main() P0M0 = 0x00;...
  • Page 239: Int1 Interrupt (Rising And Falling Edges)

    STC8A8K64D4 Series Manual 0000H LJMP MAIN 0003H LJMP INT0ISR 0100H INT0ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H SETB ;Enable INT0 falling edge interrupt...
  • Page 240 STC8A8K64D4 Series Manual if (INT1) //Judging rising and falling edges P10 = !P10; //Test port else P11 = !P11; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00;...
  • Page 241: Int1 Interrupt (Falling Edge)

    STC8A8K64D4 Series Manual RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H ;Enable INT1 rising edge and falling edge interrupts SETB ;Enable INT1 interrupt SETB 11.5.4 INT1 Interrupt (Falling Edge)
  • Page 242 STC8A8K64D4 Series Manual P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; IT1 = 1; //Enable INT1 falling edge interrupt EX1 = 1; //Enable INT1 interrupt EA = 1; while (1);...
  • Page 243: Int2 Interrupt (Falling Edge Only)

    STC8A8K64D4 Series Manual 11.5.5 INT2 Interrupt (Falling Edge only) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4;...
  • Page 244: Int3 Interrupt (Falling Edge Only)

    STC8A8K64D4 Series Manual INTCLKO DATA P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP...
  • Page 245 STC8A8K64D4 Series Manual P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; INTCLKO 0x8f; #define 0x10 #define 0x20 #define 0x40 sbit P1^0; void INT3_Isr() interrupt 11 P10 = !P10; //Test port void main() P0M0 = 0x00;...
  • Page 246: Int4 Interrupt (Falling Edge Only)

    STC8A8K64D4 Series Manual P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 005BH LJMP INT3ISR 0100H INT3ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H...
  • Page 247 STC8A8K64D4 Series Manual #define 0x20 #define 0x40 sbit P1^0; void INT4_Isr() interrupt 16 P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00;...
  • Page 248: Timer0 Interrupt

    STC8A8K64D4 Series Manual MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H INTCLKO,#EX4 ;Enable INT4 interrupt SETB 11.5.8 Timer0 Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 249 STC8A8K64D4 Series Manual P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; TMOD = 0x00; TL0 = 0x66; //65536-11.0592M/12/1000 TH0 = 0xfc; TR0 = 1; //Start timer ET0 = 1; //Enable timer0 interrupt EA = 1; while (1);...
  • Page 250: Timer1 Interrupt

    STC8A8K64D4 Series Manual SETB ;Start timer SETB ;Enable timer0 interrupt SETB 11.5.9 Timer1 Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1;...
  • Page 251: Timer2 Interrupt

    STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA...
  • Page 252 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" 0xd7; 0xd6; AUXR 0x8e; 0xaf; #define 0x04 AUXINTIF 0xef; #define T2IF 0x01 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 253: Timer3 Interrupt

    STC8A8K64D4 Series Manual DATA 0D6H AUXR DATA DATA 0AFH AUXINTIF DATA 0EFH T2IF P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H...
  • Page 254 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" 0xd5; 0xd4; T4T3M 0xd1; 0xaf; #define 0x20 AUXINTIF 0xef; #define T3IF 0x02 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 255: Timer4 Interrupt

    STC8A8K64D4 Series Manual DATA 0D4H T4T3M DATA 0D1H DATA 0AFH AUXINTIF DATA 0EFH T3IF P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA...
  • Page 256 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" 0xd5; 0xd4; 0xd3; 0xd2; T4T3M 0xd1; 0xaf; #define 0x20 #define 0x40 AUXINTIF 0xef; #define T3IF 0x02 #define T4IF 0x04 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2;...
  • Page 257 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz DATA 0D5H DATA 0D4H DATA 0D3H DATA 0D2H T4T3M DATA 0D1H DATA 0AFH AUXINTIF DATA 0EFH T3IF T4IF P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA...
  • Page 258: Uart1 Interrupt

    STC8A8K64D4 Series Manual 11.5.13 UART1 Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" 0xd7; 0xd6; AUXR 0x8e; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3;...
  • Page 259 STC8A8K64D4 Series Manual SCON = 0x50; T2L = 0xe8; //65536-11059200/115200/4=0FFE8H T2H = 0xff; AUXR = 0x15; //Start timer ES = 1; //Enable UART1 interrupt EA = 1; SBUF = 0x5a; // Send test data while (1); Assembly code ;Operating frequency for test is 11.0592MHz DATA 0D7H DATA...
  • Page 260: Uart2 Interrupt

    STC8A8K64D4 Series Manual P5M0, #00H P5M1, #00H SCON,#50H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#15H ;Start timer SETB ;Enable UART1 interrupt SETB SBUF,#5AH ; Send test data 11.5.14 UART2 Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" 0xd7;...
  • Page 261 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; S2CON = 0x10;...
  • Page 262: Uart3 Interrupt

    STC8A8K64D4 Series Manual PUSH A,S2CON ACC.1,CHECKRI S2CON,#NOT 02H ;Clear interrupt flag P1.2 ;Test port CHECKRI: A,S2CON ACC.0,ISREXIT S2CON,#NOT 01H ;Clear interrupt flag P1.3 ;Test port ISREXIT: RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H...
  • Page 263 STC8A8K64D4 Series Manual P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^2; sbit P1^3; void UART3_Isr() interrupt 17 if (S3CON & 0x02) S3CON &= ~0x02; //Clear interrupt flag P12 = !P12;...
  • Page 264 STC8A8K64D4 Series Manual AUXR DATA S3CON DATA 0ACH S3BUF DATA 0ADH DATA 0AFH P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H...
  • Page 265: Uart4 Interrupt

    STC8A8K64D4 Series Manual IE2,#ES3 ;Enable UART3 interrupt SETB S3BUF,#5AH ;Send test data 11.5.16 UART4 Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" 0xd7; 0xd6; AUXR 0x8e; S4CON 0x84; S4BUF 0x85; 0xaf; #define 0x10 P0M1 0x93;...
  • Page 266 STC8A8K64D4 Series Manual P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; S4CON = 0x10; T2L = 0xe8; //65536-11059200/115200/4=0FFE8H T2H = 0xff; AUXR = 0x14;...
  • Page 267: Lvd Interrupt

    STC8A8K64D4 Series Manual ACC.0,ISREXIT S4CON,#NOT 01H ;Clear interrupt flag P1.3 ;Test port ISREXIT: RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H S4CON,#10H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H...
  • Page 268 STC8A8K64D4 Series Manual P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void LVD_Isr() interrupt 6 PCON &= ~LVDF; //Clear interrupt flag P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00;...
  • Page 269: Spi Interrupt

    STC8A8K64D4 Series Manual 0000H LJMP MAIN 0033H LJMP LVDISR 0100H LVDISR: PCON,#NOT LVDF ;Clear interrupt flag P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H...
  • Page 270 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; sbit P1^0; void SPI_Isr() interrupt 9 SPSTAT = 0xc0; //Clear interrupt flag P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00;...
  • Page 271: Comparator Interrupt

    STC8A8K64D4 Series Manual LJMP SPIISR 0100H SPIISR: SPSTAT,#0C0H ;Clear interrupt flag P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H SPCTL,#50H ;Enable SPI master mode...
  • Page 272 STC8A8K64D4 Series Manual test port P10 = !P10; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00;...
  • Page 273: I2C Interrupt

    STC8A8K64D4 Series Manual P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H CMPCR2,#00H Enable comparator module CMPCR1,#80H CMPCR1,#30H Enable comparator edge interrupt CMPCR1,#NOT 08H ;P3.6 CMP+ input pin input pin CMPCR1,#04H ; P3.7 CMP- CMPCR1,#02H Enable comparator output SETB 11.5.21 I2C Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 274 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80;...
  • Page 275 STC8A8K64D4 Series Manual LJMP I2CISR 0100H I2CISR: PUSH PUSH PUSH PUSH P_SW2 P_SW2,#80H DPTR,#I2CMSST MOVX A,@DPTR A,#NOT 40H ;Clear interrupt flag MOVX @DPTR,A P1.0 ;Test port P_SW2 RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H...
  • Page 276: O Port Interrupt

    STC8A8K64D4 Series Manual 12 I/O port interrupt The STC8A8K64D4 series MCUs support all I/O interrupts, and support 4 interrupt modes: falling edge interrupt, rising edge interrupt, low-level interrupt, and high-level interrupt. Every group of I/O ports has an independent interrupt entry address, and each I/O can independently set the interrupt mode.
  • Page 277: Port Interrupt Enable Registers (Pxinte)

    STC8A8K64D4 Series Manual P7IM1 P7 Interrupt mode register 1 FD37H P77IM1 P76IM1 P75IM1 P74IM1 P73IM1 P72IM1 P71IM1 P70IM1 0000,0000 I/O port interrupt priority low PINIPL FD60H P7IP P6IP P5IP P4IP P3IP P2IP P1IP P0IP 0000,0000 register I/O port interrupt priority high PINIPH FD61H P7IPH...
  • Page 278: Port Interrupt Mode Configuration Registers (Pxim0,Pxim1)

    STC8A8K64D4 Series Manual 12.1.3 Port interrupt mode configuration registers (PxIM0,PxIM1) Symbol Address P0IM0 FD20H P07IM0 P06IM0 P05IM0 P04IM0 P03IM0 P02IM0 P01IM0 P00IM0 P0IM1 FD30H P07IM1 P06IM1 P05IM1 P04IM1 P03IM1 P02IM1 P01IM1 P00IM1 P1IM0 FD21H P17IM0 P16IM0 P15IM0 P14IM0 P13IM0 P12IM0 P11IM0 P10IM0 P1IM1...
  • Page 279 STC8A8K64D4 Series Manual 1: enable Pn.x interrupt power-down wake-up function - 263 -...
  • Page 280: Example Routines

    STC8A8K64D4 Series Manual 12.2 Example Routines 12.2.1 P0 Falling edge interrupt C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M0 0x94; P0M1 0x93; P1M0 0x92; P1M1 0x91; P2M0 0x96; P2M1 0x95; P3M0 0xb2; P3M1 0xb1;...
  • Page 281 STC8A8K64D4 Series Manual while (1); //Because the interrupt vector is greater than 31, it cannot be directly compiled in KEIL //The 13th interrupt entry address must be borrowed void common_isr() interrupt 13 unsigned char psw2_st; unsigned char intf; psw2_st = P_SW2; P_SW2 |= 0x80;...
  • Page 282 STC8A8K64D4 Series Manual P0INT_ISR: Borrow the entry address of the 13th interrupt 006BH Assembly code ;Operating frequency for test is 11.0592MHz P0M0 DATA 094H P0M1 DATA 093H P1M0 DATA 092H P1M1 DATA 091H P2M0 DATA 096H P2M1 DATA 095H P3M0 DATA 0B2H P3M1...
  • Page 283 STC8A8K64D4 Series Manual ACC.2,CHECKP03 interrupt ;P0.2 CHECKP03 ACC.3,CHECKP04 interrupt ;P0.3 CHECKP04: ACC.4,CHECKP05 interrupt ;P0.4 CHECKP05: ACC.5,CHECKP06 interrupt ;P0.5 CHECKP06: ACC.6,CHECKP07 interrupt ;P0.6 CHECKP07: ACC.7,P0ISREXIT interrupt ;P0.7 P0ISREXIT: P_SW2 RETI 0200H MAIN: SP, #5FH P0M0,#00H P0M1,#00H P1M0,#00H P1M1,#00H P2M0,#00H P2M1,#00H P3M0,#00H P3M1,#00H P_SW2,#80H Falling edge interrupt...
  • Page 284: P1 Rising Edge Interrupt

    STC8A8K64D4 Series Manual 12.2.2 P1 rising edge interrupt C language code ;Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M0 0x94; P0M1 0x93; P1M0 0x92; P1M1 0x91; P2M0 0x96; P2M1 0x95; P3M0 0xb2; P3M1 0xb1; P4M0 0xb4; P4M1 0xb3;...
  • Page 285 STC8A8K64D4 Series Manual while (1); //Because the interrupt vector is greater than 31, it cannot be directly compiled in KEIL //The 13th interrupt entry address must be borrowed void common_isr() interrupt 13 unsigned char psw2_st; unsigned char intf; psw2_st = P_SW2; P_SW2 |= 0x80;...
  • Page 286 STC8A8K64D4 Series Manual P1INT_ISR: Borrow the entry address of the 13th interrupt 006BH Assembly code ;Operating frequency for test is 11.0592MHz P0M0 DATA 094H P0M1 DATA 093H P1M0 DATA 092H P1M1 DATA 091H P2M0 DATA 096H P2M1 DATA 095H P3M0 DATA 0B2H P3M1...
  • Page 287 STC8A8K64D4 Series Manual ACC.2,CHECKP13 ;P1.2 interrupt CHECKP13 ACC.3,CHECKP14 ;P1.3 interrupt CHECKP14: ACC.4,CHECKP15 ;P1.4 interrupt CHECKP15: ACC.5,CHECKP16 ;P1.5 interrupt CHECKP16: ACC.6,CHECKP17 ;P1.6 interrupt CHECKP17: ACC.7,P1ISREXIT ;P1.7 interrupt P1ISREXIT: P_SW2 RETI 0200H MAIN: SP, #5FH P0M0,#00H P0M1,#00H P1M0,#00H P1M1,#00H P2M0,#00H P2M1,#00H P3M0,#00H P3M1,#00H P_SW2,#80H Falling edge interrupt...
  • Page 288: P2 Low Level Interrupt

    STC8A8K64D4 Series Manual 12.2.3 P2 low level interrupt C language code ;Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M0 0x94; P0M1 0x93; P1M0 0x92; P1M1 0x91; P2M0 0x96; P2M1 0x95; P3M0 0xb2; P3M1 0xb1; P4M0 0xb4; P4M1 0xb3;...
  • Page 289 STC8A8K64D4 Series Manual //Because the interrupt vector is greater than 31, it cannot be directly compiled in KEIL //The 13th interrupt entry address must be borrowed void common_isr() interrupt 13 unsigned char psw2_st; unsigned char intf; psw2_st = P_SW2; P_SW2 |= 0x80; intf = P2INTF;...
  • Page 290 STC8A8K64D4 Series Manual Borrow the entry address of the 13th interrupt 006BH Assembly code ;Operating frequency for test is 11.0592MHz P0M0 DATA 094H P0M1 DATA 093H P1M0 DATA 092H P1M1 DATA 091H P2M0 DATA 096H P2M1 DATA 095H P3M0 DATA 0B2H P3M1 DATA...
  • Page 291: Port3 High Level Interrupt

    STC8A8K64D4 Series Manual CHECKP26: ACC.6,CHECKP27 interrupt ;P2.6 CHECKP27: ACC.7,P2ISREXIT interrupt ;P2.7 P2ISREXIT: P_SW2 RETI 0200H MAIN: SP, #5FH P0M0,#00H P0M1,#00H P1M0,#00H P1M1,#00H P2M0,#00H P2M1,#00H P3M0,#00H P3M1,#00H P_SW2,#80H DPTR,# P2IM0 low level interrupt MOVX @DPTR,A DPTR,# P2IM1 MOVX @DPTR,A DPTR,# P2INTE A,#0FFH enable interrupt...
  • Page 292 STC8A8K64D4 Series Manual P6M0 0xcc; P6M1 0xcb; P7M0 0xe2; P7M1 0xe1; P_SW2 0xba; #define P3INTE (*(unsigned char volatile xdata *)0xfd03) #define P3INTF (*(unsigned char volatile xdata *)0xfd13) #define P3IM0 (*(unsigned char volatile xdata *)0xfd23) #define P3IM1 (*(unsigned char volatile xdata *)0xfd33) void main() P0M0 = 0x00;...
  • Page 293 STC8A8K64D4 Series Manual interrupt //P3.2 if (intf & 0x08) interrupt //P3.3 if (intf & 0x10) interrupt //P3.4 if (intf & 0x20) interrupt //P3.5 if (intf & 0x40) interrupt //P3.6 if (intf & 0x80) interrupt //P3.7 P_SW2 = psw2_st; // ISR.ASM //Save the following code as ISP.ASM, and then add the file to the project CSEG AT 0143H...
  • Page 294 STC8A8K64D4 Series Manual interrupt entry address ORG 0143H P3INT_ISR: PUSH PUSH PUSH PUSH PUSH P_SW2 DPTR,#P3INTF MOVX A,@DPTR MOVX @DPTR,A CHECKP30: ACC.0,CHECKP31 interrupt ;P3.0 CHECKP31: ACC.1,CHECKP32 ;P3.1 interrupt CHECKP32: ACC.2,CHECKP33 interrupt ;P3.2 CHECKP33 ACC.3,CHECKP34 ;P3.3 interrupt CHECKP34: ACC.4,CHECKP35 ;P3.4 interrupt CHECKP35: ACC.5,CHECKP36 interrupt...
  • Page 295 STC8A8K64D4 Series Manual DPTR,# P3INTE A,#0FFH enable interrupt MOVX @DPTR,A P_SW2,#7FH SETB - 279 -...
  • Page 296: Timer/Counter

    STC8A8K64D4 Series Manual 13 Timer/Counter Five 16-bit Timers/Counters are integrated in STC8A8K64D4 series of microcontrollers: T0, T1, T2, T3 and T4. All of them can be used as timer or counter. For T0 and T1, the ‘timer’ or ‘counter’ function is selected by the control bits C/T in the special function register TMOD.
  • Page 297: Timer 0/1

    STC8A8K64D4 Series Manual 13.2 Timer 0/1 13.2.1 Timer 0 and 1 Control Register Symbol Address TCON TF1: T1 overflow flag. After T1 is enabled to count, it performs adding 1 count from the initial value. TF1 is set by hardware on T1 overflow and requests interrupt to CPU. It will keep the status until CPU responds the interrupt and is cleared by hardware automatically.
  • Page 298: Timer0 Mode 0 (16-Bit Auto-Reloadable Mode)

    P3.4/T0, and T0 works in counting mode. Timer0 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 299: Timer0 Mode 1 (16-Bit Non-Autoreloadable Mode)

    P3.4/T0, and T0 works in counting mode. Timer0 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 300: Timer 0 Mode 2 (8-Bit Auto-Reloadable Mode)

    STC8A8K64D4 Series Manual 13.2.5 Timer 0 mode 2 (8-bit auto-reloadable mode) In this mode, Timer/Counter 0 is an 8-bit counter that can be automatically reloaded, as shown in the figure below. AUXR.7/T0x12=0 ÷ 12 SYSclk Interrupt C/T=0 Toggle ÷ 1 AUXR.7/T0x12=1 T0CLKO (8bits)
  • Page 301: Timer 1 Mode 0 (16-Bit Auto-Reloadable Mode)

    P3.5/T1, and T1 works in counting mode. Timer1 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 302: Timer1 Mode 1 (16-Bit Non-Autoreloadable Mode)

    P3.5/T1, and T1 works in counting mode. Timer1 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 303: Timer 1 Mode 2 (8-Bit Auto-Reloadable Mode)

    STC8A8K64D4 Series Manual 13.2.9 Timer 1 mode 2 (8-bit auto-reloadable mode) In this mode, Timer/Counter 1 is an 8-bit counter that can be automatically reloaded, as shown in the figure below. AUXR.6/T1x12=0 ÷ 12 SYSclk Interrupt C/T=0 Toggle ÷ 1 AUXR.6/T1x12=1 T1CLKO (8bits)
  • Page 304: Auxiliary Register 1 (Auxr)

    STC8A8K64D4 Series Manual 13.2.12 Auxiliary Register 1 (AUXR) Symbol Address AUXR T0x12 T1x12 UART_M0x6 T2_C/T T2x12 EXTRAM S1ST2 T0x12: T0 speed control bit. 0: The clock source of T0 is SYSclk/12. 1: The clock source of T0 is SYSclk/1. T1x12: T1 speed control bit. 0: The clock source of T1 is SYSclk/12.
  • Page 305 STC8A8K64D4 Series Manual 65536−[����1,����1] Mode 1 (Soft reload) Timer period = SYSclk (16-bit does not 65536−[����1,����1] automatically reload) (Soft reload) Timer period = ∗ 12 SYSclk 256−����1 (Auto-reload) Timer period = Mode 2 SYSclk (8-bit automatic reload) 256−����1 ∗ 12 (Auto-reload) Timer period = SYSclk - 289 -...
  • Page 306: Timer 2 (24-Bit Timer, 8-Bit Prescaler + 16-Bit Timing)

    STC8A8K64D4 Series Manual 13.3 Timer 2 (24-bit timer, 8-bit prescaler + 16-bit timing) 13.3.1 Auxiliary Register 1 (AUXR) Symbol Address AUXR T0x12 T1x12 UART_M0x6 T2_C/T T2x12 EXTRAM S1ST2 TR2: T2 run control bit. 0: T2 stops counting. 1: T2 start counting. T2_C/T: T2 mode select bit.
  • Page 307: Timer 2 Calculation Formula

    T2, and T2 works in counting mode. Timer2 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 308: Timer 3 Counting Registers

    STC8A8K64D4 Series Manual 0: T4 stops counting. 1: T4 start counting. T4_C/T: T4 mode select bit. 0: T4 is used as a timer (input pulse is from internal system clock); 1: T4 is used as a counter (input pulse is from external T4/P0.6 pin). T4x12: T4 speed control bit.
  • Page 309: Timer 4 8-Bit Prescaler Register (Tm4Ps)

    T3, and T3 works in counting mode. Timer3 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 310: Timer 3 Calculation Formula

    T4, and T4 works in counting mode. Timer4 of STC microcontroller has two counting rates: one is 12T mode, which is increased by 1 for every 12 clocks, which is the same as traditional 8051 microcontroller, the other is 1T mode, which is increased by 1 for each clock, and the speed is 12 times of traditional 8051.
  • Page 311: Example Routines

    STC8A8K64D4 Series Manual 13.5 Example Routines 13.5.1 Timer 0 (Mode 0 – 16-bit auto reload) C language code //Operating frequency for test is 11.0592MHz #include “reg51.h” #include “intrins.h” P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1;...
  • Page 312: Timer 0 (Mode 1 - 16-Bit Non-Auto Reload)

    STC8A8K64D4 Series Manual ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0...
  • Page 313 STC8A8K64D4 Series Manual #include “reg51.h” #include “intrins.h” P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void TM0_Isr() interrupt 1 TL0 = 0x66; //Reset parameters TH0 = 0xfc;...
  • Page 314: Timer 0 (Mode 2 - 8-Bit Auto Reload)

    STC8A8K64D4 Series Manual P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 000BH LJMP TM0ISR 0100H TM0ISR: TL0,#66H ;Reset parameters TH0,#0FCH P1.0 ;Test port...
  • Page 315 STC8A8K64D4 Series Manual P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void TM0_Isr() interrupt 1 P10 = !P10; //Test port void main() P0M0 = 0x00;...
  • Page 316: Timer 0 (Mode 3 - 16-Bit Auto Reload With Non-Maskable Interrupt)

    STC8A8K64D4 Series Manual P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 000BH LJMP TM0ISR 0100H TM0ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H...
  • Page 317 STC8A8K64D4 Series Manual P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void TM0_Isr() interrupt 1 P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00;...
  • Page 318: Timer 0 (External Count - T0 Is Extended For External Falling Edge Interrupt)

    STC8A8K64D4 Series Manual 000BH LJMP TM0ISR 0100H TM0ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H TMOD,#03H ;Mode 3 TL0,#66H ;65536-11.0592M/12/1000...
  • Page 319 STC8A8K64D4 Series Manual P5M0 0xca; sbit P1^0; void TM0_Isr() interrupt 1 P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00;...
  • Page 320: Timer 0 (Pulse Width Measurement For High-Level Width Of Int0)

    STC8A8K64D4 Series Manual P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H TMOD,#04H ;External counting mode TL0,#0FFH TH0,#0FFH SETB ;Start timer SETB...
  • Page 321 STC8A8K64D4 Series Manual P1 = TH0; //TH0 is the high byte of the measured value void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00;...
  • Page 322: Timer 0 (Mode 0, Divided Clock Output)

    STC8A8K64D4 Series Manual RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H AUXR,#80H ;1T mode TMOD,#08H ;Enable GATE, and enable timing when INT0 is 1 TL0,#00H TH0,#00H INT0,$...
  • Page 323 STC8A8K64D4 Series Manual P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; TMOD = 0x00; //Mode 0 TL0 = 0x66;...
  • Page 324: Timer 1 (Mode 0 - 16-Bit Auto Reload)

    STC8A8K64D4 Series Manual P5M1, #00H TMOD,#00H ;Mode 0 TL0,#66H ;65536-11.0592M/12/1000 TH0,#0FCH SETB ;Start timer INTCLKO,#01H ;Enable clock output 13.5.8 Timer 1 (Mode 0 - 16-bit auto reload) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93;...
  • Page 325 STC8A8K64D4 Series Manual TMOD = 0x00; //Mode 0 TL1 = 0x66; //65536-11.0592M/12/1000 TH1 = 0xfc; TR1 = 1; //Start timer ET1 = 1; //Enable timer interrupt EA = 1; while (1); Assembly code ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0...
  • Page 326: Timer 1 (Mode 1 - 16-Bit Non-Auto Reload)

    STC8A8K64D4 Series Manual 13.5.9 Timer 1 (Mode 1 - 16-bit non-auto reload) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2;...
  • Page 327 STC8A8K64D4 Series Manual EA = 1; while (1); Assembly code ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H...
  • Page 328: Timer 1 (Mode 2 - 8-Bit Auto Reload)

    STC8A8K64D4 Series Manual 13.5.10 Timer 1 (Mode 2 - 8-bit auto reload) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2;...
  • Page 329 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA...
  • Page 330: Timer 1 (External Count - T1 Is Extended For External Falling Edge Interrupt)

    STC8A8K64D4 Series Manual 13.5.11 Timer 1 (External count – T1 is extended for external falling edge interrupt) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96;...
  • Page 331: Timer 1 (Pulse Width Measurement For High-Level Width Of Int1)

    STC8A8K64D4 Series Manual ;Operating frequency for test is 11.0592MHz P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0...
  • Page 332 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; AUXR 0x8e; void INT1_Isr() interrupt 2 P0 = TL1; //TL1 is the low byte of the measured value P1 = TH1;...
  • Page 333 STC8A8K64D4 Series Manual P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0013H...
  • Page 334: Timer 1 (Mode 0, Divided Clock Output)

    STC8A8K64D4 Series Manual 13.5.13 Timer 1 (Mode 0, Divided clock output) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" INTCLKO 0x8f; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2;...
  • Page 335: Timer 1 (Mode 0) Is Used As Baud Rate Generator Of Uart1

    STC8A8K64D4 Series Manual P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H...
  • Page 336 STC8A8K64D4 Series Manual P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void UartIsr() interrupt 4 if (TI) TI = 0; busy = 0; if (RI) RI = 0; buffer[wptr++] = SBUF;...
  • Page 337 STC8A8K64D4 Series Manual P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; UartInit(); ES = 1;...
  • Page 338 STC8A8K64D4 Series Manual UART_ISR: PUSH PUSH PSW,#08H TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT A,WPTR A,#0FH A,#BUFFER R0,A @R0,SBUF WPTR UARTISR_EXIT: RETI UART_INIT: SCON,#50H TMOD,#00H TL1,#0E8H ;65536-11059200/115200/4=0FFE8H TH1,#0FFH SETB AUXR,#40H BUSY WPTR,#00H RPTR,#00H UART_SEND: BUSY,$ SETB BUSY SBUF,A UART_SENDSTR: MOVC A,@A+DPTR SENDEND LCALL UART_SEND DPTR UART_SENDSTR...
  • Page 339: Timer 1 (Mode 2) Is Used As Baud Rate Generator Of Uart1

    STC8A8K64D4 Series Manual P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#STRING LCALL UART_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 13.5.15 Timer 1 (Mode 2) is used as baud rate generator of UART1 C language code //Operating frequency for test is 11.0592MHz...
  • Page 340 STC8A8K64D4 Series Manual P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void UartIsr() interrupt 4 if (TI) TI = 0; busy = 0; if (RI) RI = 0; buffer[wptr++] = SBUF; wptr &= 0x0f; void UartInit() SCON = 0x50;...
  • Page 341 STC8A8K64D4 Series Manual P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; UartInit(); ES = 1; EA = 1; UartSENDStr(“Uart Test !\r\n”); while (1) if (rptr != wptr) UartSEND(buffer[rptr++]);...
  • Page 342 STC8A8K64D4 Series Manual PSW,#08H TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT A,WPTR A,#0FH A,#BUFFER R0,A @R0,SBUF WPTR UARTISR_EXIT: RETI UART_INIT: SCON,#50H TMOD,#20H TL1,#0FDH ;256-11059200/115200/32=0FDH TH1,#0FDH SETB AUXR,#40H BUSY WPTR,#00H RPTR,#00H UART_SEND: BUSY,$ SETB BUSY SBUF,A UART_SENDSTR: MOVC A,@A+DPTR SENDEND LCALL UART_SEND DPTR UART_SENDSTR SENDEND: MAIN: SP, #5FH...
  • Page 343: Timer 2 (16-Bit Auto Reload)

    STC8A8K64D4 Series Manual P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#STRING LCALL UART_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 13.5.16 Timer 2 (16-bit auto reload) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 344 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; sbit P1^0; void TM2_Isr() interrupt 12 P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00;...
  • Page 345: Timer 2 (External Count - T2 Is Extended For External Falling Edge Interrupt)

    STC8A8K64D4 Series Manual 0000H LJMP MAIN 0063H LJMP TM2ISR 0100H TM2ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H T2L,#66H ;65536-11.0592M/12/1000...
  • Page 346 STC8A8K64D4 Series Manual P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void TM2_Isr() interrupt 12 P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00;...
  • Page 347: Timer 2 (Divided Clock Output)

    STC8A8K64D4 Series Manual P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0063H LJMP TM2ISR 0100H TM2ISR: P1.0 ;Test port RETI MAIN: SP, #5FH...
  • Page 348 STC8A8K64D4 Series Manual AUXR 0x8e; INTCLKO 0x8f; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00;...
  • Page 349: Timer 2 Is Used As Baud Rate Generator Of Uart1

    STC8A8K64D4 Series Manual P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H T2L,#66H ;65536-11.0592M/12/1000 T2H,#0FCH...
  • Page 350 STC8A8K64D4 Series Manual P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void UartIsr() interrupt 4 if (TI) TI = 0; busy = 0; if (RI) RI = 0; buffer[wptr++] = SBUF; wptr &= 0x0f; void UartInit() SCON = 0x50;...
  • Page 351 STC8A8K64D4 Series Manual P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; UartInit(); ES = 1; EA = 1; UartSENDStr(“Uart Test !\r\n”); while (1) if (rptr != wptr) UartSEND(buffer[rptr++]); rptr &= 0x0f; Assembly code ;Operating frequency for test is 11.0592MHz AUXR...
  • Page 352 STC8A8K64D4 Series Manual PSW,#08H TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT A,WPTR A,#0FH A,#BUFFER R0,A @R0,SBUF WPTR UARTISR_EXIT: RETI UART_INIT: SCON,#50H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#15H BUSY WPTR,#00H RPTR,#00H UART_SEND: BUSY,$ SETB BUSY SBUF,A UART_SENDSTR: MOVC A,@A+DPTR SENDEND LCALL UART_SEND DPTR UART_SENDSTR SENDEND: MAIN: SP, #5FH P0M0, #00H P0M1, #00H...
  • Page 353: Timer 2 Is Used As Baud Rate Generator Of Uart2

    STC8A8K64D4 Series Manual P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#STRING LCALL UART_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 13.5.20 Timer 2 is used as baud rate generator of UART2 C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 354 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void Uart2Isr() interrupt 8 if (S2CON & 0x02) S2CON &= ~0x02; busy = 0; if (S2CON & 0x01) S2CON &= ~0x01; buffer[wptr++] = S2BUF; wptr &= 0x0f; void Uart2Init() S2CON = 0x10;...
  • Page 355 STC8A8K64D4 Series Manual P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; Uart2Init(); IE2 = 0x01; EA = 1; Uart2SENDStr(“Uart Test !\r\n”); while (1) if (rptr != wptr) Uart2SEND(buffer[rptr++]); rptr &= 0x0f; Assembly code ;Operating frequency for test is 11.0592MHz AUXR DATA...
  • Page 356 STC8A8K64D4 Series Manual PUSH PUSH PSW,#08H A,S2CON ACC.1,CHKRI S2CON,#NOT 02H BUSY CHKRI: ACC.0,UART2ISR_EXIT S2CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S2BUF WPTR UART2ISR_EXIT: RETI UART2_INIT: S2CON,#10H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#14H BUSY WPTR,#00H RPTR,#00H UART2_SEND: BUSY,$ SETB BUSY S2BUF,A UART2_SENDSTR: MOVC A,@A+DPTR SEND2END LCALL UART2_SEND...
  • Page 357: Timer 2 Is Used As Baud Rate Generator Of Uart3

    STC8A8K64D4 Series Manual P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART2_INIT IE2,#01H SETB DPTR,#STRING LCALL UART2_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART2_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 13.5.21 Timer 2 is used as baud rate generator of UART3 C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 358 STC8A8K64D4 Series Manual P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void Uart3Isr() interrupt 17 if (S3CON & 0x02) S3CON &= ~0x02; busy = 0; if (S3CON & 0x01) S3CON &= ~0x01; buffer[wptr++] = S3BUF;...
  • Page 359 STC8A8K64D4 Series Manual P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; Uart3Init(); IE2 = 0x08; EA = 1; Uart3SENDStr(“Uart Test !\r\n”); while (1) if (rptr != wptr) Uart3SEND(buffer[rptr++]);...
  • Page 360 STC8A8K64D4 Series Manual 0100H UART3_ISR: PUSH PUSH PSW,#08H A,S3CON ACC.1,CHKRI S3CON,#NOT 02H BUSY CHKRI: ACC.0,UART3ISR_EXIT S3CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S3BUF WPTR UART3ISR_EXIT: RETI UART3_INIT: S3CON,#10H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#14H BUSY WPTR,#00H RPTR,#00H UART3_SEND: BUSY,$ SETB BUSY S3BUF,A UART3_SENDSTR: MOVC A,@A+DPTR SEND3END...
  • Page 361: Timer 2 Is Used As Baud Rate Generator Of Uart4

    STC8A8K64D4 Series Manual P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART3_INIT IE2,#08H SETB DPTR,#STRING LCALL UART3_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART3_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 13.5.22 Timer 2 is used as baud rate generator of UART4 C language code //Operating frequency for test is 11.0592MHz...
  • Page 362 STC8A8K64D4 Series Manual P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void Uart4Isr() interrupt 18 if (S4CON & 0x02) S4CON &= ~0x02; busy = 0; if (S4CON &...
  • Page 363 STC8A8K64D4 Series Manual P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; Uart4Init(); IE2 = 0x10; EA = 1;...
  • Page 364 STC8A8K64D4 Series Manual 0093H LJMP UART4_ISR 0100H UART4_ISR: PUSH PUSH PSW,#08H A,S4CON ACC.1,CHKRI S4CON,#NOT 02H BUSY CHKRI: ACC.0,UART4ISR_EXIT S4CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S4BUF WPTR UART4ISR_EXIT: RETI UART4_INIT: S4CON,#10H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#14H BUSY WPTR,#00H RPTR,#00H UART4_SEND: BUSY,$ SETB BUSY S4BUF,A UART4_SENDSTR:...
  • Page 365: Timer 3 (16-Bit Auto Reload)

    STC8A8K64D4 Series Manual P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART4_INIT IE2,#10H SETB DPTR,#STRING LCALL UART4_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART4_SEND RPTR...
  • Page 366 STC8A8K64D4 Series Manual #define 0x40 AUXINTIF 0xef; #define T2IF 0x01 #define T3IF 0x02 #define T4IF 0x04 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0;...
  • Page 367 STC8A8K64D4 Series Manual DATA 0D4H DATA 0D7H DATA 0D6H AUXR DATA DATA 0AFH AUXINTIF DATA 0EFH T2IF T3IF T4IF P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H...
  • Page 368: Timer 3 (External Count - T3 Is Extended For External Falling Edge Interrupt)

    STC8A8K64D4 Series Manual 13.5.24 Timer 3 (External count – T3 is extended for external falling edge interrupt) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" T4T3M 0xd1; 0xd3; 0xd2; 0xd5; 0xd4; 0xd7; 0xd6; AUXR 0x8e; 0xaf;...
  • Page 369 STC8A8K64D4 Series Manual P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; T3L = 0x66; //65536-11.0592M/12/1000 T3H = 0xfc; T4T3M = 0x0c; //Set external counting mode and start timer IE2 = ET3;...
  • Page 370: Timer 3 (Divided Clock Output)

    STC8A8K64D4 Series Manual TM3ISR: P1.0 ;Test port RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H T3L,#66H ;65536-11.0592M/12/1000 T3H,#0FCH T4T3M,#0CH ;Set external counting mode and start timer IE2,#ET3 ;Enable timer interrupt SETB...
  • Page 371 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00;...
  • Page 372: Timer 3 Is Used As Baud Rate Generator Of Uart3

    STC8A8K64D4 Series Manual P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H T3L,#66H ;65536-11.0592M/12/1000 T3H,#0FCH T4T3M,#09H ;Enable clock output and start timer 13.5.26 Timer 3 is used as baud rate generator of UART3 C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 373 STC8A8K64D4 Series Manual char wptr; char rptr; char buffer[16]; void Uart3Isr() interrupt 17 if (S3CON & 0x02) S3CON &= ~0x02; busy = 0; if (S3CON & 0x01) S3CON &= ~0x01; buffer[wptr++] = S3BUF; wptr &= 0x0f; void Uart3Init() S3CON = 0x50; T3L = BRT;...
  • Page 374 STC8A8K64D4 Series Manual P5M1 = 0x00; Uart3Init(); IE2 = 0x08; EA = 1; Uart3SENDStr(“Uart Test !\r\n”); while (1) if (rptr != wptr) Uart3SEND(buffer[rptr++]); rptr &= 0x0f; Assembly code ;Operating frequency for test is 11.0592MHz T4T3M DATA 0D1H DATA 0D3H DATA 0D2H DATA 0D5H...
  • Page 375 STC8A8K64D4 Series Manual PUSH PUSH PSW,#08H A,S3CON ACC.1,CHKRI S3CON,#NOT 02H BUSY CHKRI: ACC.0,UART3ISR_EXIT S3CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S3BUF WPTR UART3ISR_EXIT: RETI UART3_INIT: S3CON,#50H T3L,#0E8H ;65536-11059200/115200/4=0FFE8H T3H,#0FFH T4T3M,#0AH BUSY WPTR,#00H RPTR,#00H UART3_SEND: BUSY,$ SETB BUSY S3BUF,A UART3_SENDSTR: MOVC A,@A+DPTR SEND3END LCALL UART3_SEND...
  • Page 376: Timer 4 (16-Bit Auto Reload)

    STC8A8K64D4 Series Manual P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART3_INIT IE2,#08H SETB DPTR,#STRING LCALL UART3_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART3_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 13.5.27 Timer 4 (16-bit auto reload) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 377 STC8A8K64D4 Series Manual P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void TM4_Isr() interrupt 20 P10 = !P10; //Test port void main() P0M0 = 0x00;...
  • Page 378 STC8A8K64D4 Series Manual AUXINTIF DATA 0EFH T2IF T3IF T4IF P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0...
  • Page 379: Timer 4 (External Count - T4 Is Extended For External Falling Edge Interrupt)

    STC8A8K64D4 Series Manual 13.5.28 Timer 4 (External count – T4 is extended for external falling edge interrupt) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" T4T3M 0xd1; 0xd3; 0xd2; 0xd5; 0xd4; 0xd7; 0xd6; AUXR 0x8e; 0xaf;...
  • Page 380 STC8A8K64D4 Series Manual P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; T4L = 0x66; //65536-11.0592M/12/1000 T4H = 0xfc; T4T3M = 0xc0; //Set external counting mode and start timer IE2 = ET4; //Enable timer interrupt EA = 1;...
  • Page 381: Timer 4 (Divided Clock Output)

    STC8A8K64D4 Series Manual MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H T4L,#66H ;65536-11.0592M/12/1000 T4H,#0FCH T4T3M,#0C0H ;Set external counting mode and start timer IE2,#ET4 ;Enable timer interrupt SETB...
  • Page 382 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P3M1 = 0x00; T4L = 0x66;...
  • Page 383: Timer 4 Is Used As Baud Rate Generator Of Uart4

    STC8A8K64D4 Series Manual P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H T4L,#66H ;65536-11.0592M/12/1000 T4H,#0FCH T4T3M,#90H ;Enable clock output and start timer 13.5.30 Timer 4 is used as baud rate generator of UART4 C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 384 STC8A8K64D4 Series Manual void Uart4Isr() interrupt 18 if (S4CON & 0x02) S4CON &= ~0x02; busy = 0; if (S4CON & 0x01) S4CON &= ~0x01; buffer[wptr++] = S4BUF; wptr &= 0x0f; void Uart4Init() S4CON = 0x50; T4L = BRT; T4H = BRT >> 8; T4T3M = 0xa0;...
  • Page 385 STC8A8K64D4 Series Manual IE2 = 0x10; EA = 1; Uart4SENDStr(“Uart Test !\r\n”); while (1) if (rptr != wptr) Uart4SEND(buffer[rptr++]); rptr &= 0x0f; Assembly code ;Operating frequency for test is 11.0592MHz T4T3M DATA 0D1H DATA 0D3H DATA 0D2H DATA 0D5H DATA 0D4H DATA 0D7H...
  • Page 386 STC8A8K64D4 Series Manual A,S4CON ACC.1,CHKRI S4CON,#NOT 02H BUSY CHKRI: ACC.0,UART4ISR_EXIT S4CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S4BUF WPTR UART4ISR_EXIT: RETI UART4_INIT: S4CON,#50H T4L,#0E8H ;65536-11059200/115200/4=0FFE8H T4H,#0FFH T4T3M,#0A0H BUSY WPTR,#00H RPTR,#00H UART4_SEND: BUSY,$ SETB BUSY S4BUF,A UART4_SENDSTR: MOVC A,@A+DPTR SEND4END LCALL UART4_SEND DPTR UART4_SENDSTR SEND4END:...
  • Page 387 STC8A8K64D4 Series Manual P5M1, #00H LCALL UART4_INIT IE2,#10H SETB DPTR,#STRING LCALL UART4_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART4_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H - 371 -...
  • Page 388: Uart Communication

    STC8A8K64D4 Series Manual 14 UART Communication There are 4 full duplex asynchronous serial communication ports (UART in short) in STC8A8K64D4 series of microcontrollers. Each UART consists of two data buffers, a shift register, a serial control register and a baud rate generator. Each UART data buffer consists of two independent receive and transmit buffers, which can transmit and receive data simultaneously.
  • Page 389: Uart1

    STC8A8K64D4 Series Manual 14.3 UART1 14.3.1 UART1 control register Symbol Address SCON SM0/FE SM0/FE: If the SMOD0 bit in the PCON register is 1, this bit is the frame error detection flag. When the UART detects an invalid stop bit during reception, it is set by the UART receiver and must be cleared by software. If SMOD0 bit in PCON register is 0, this bit and SM1 specify the communication mode of UART1 as shown in the following table: SM0 SM1 Mode of UART1...
  • Page 390: Power Control Register

    STC8A8K64D4 Series Manual 14.3.3 Power control register Symbol Address PCON SMOD SMOD0 LVDF SMOD: double Baud rate of UART1 control bit. 0: disable double baud rate of the UART1. 1: enable double baud rate of the UART1. SMOD0: Frame error detection control bit. 0: No frame error detection function, SCON.7 is SM0 function.
  • Page 391: Uart1 Mode 1

    STC8A8K64D4 Series Manual Write SBUF Transmitting data (UART1 mode 0) Write REN=1, RI=0 SCON Receiving data (UART1 mode 0) In mode 0, SM2 must be cleared so that TB8 and RB8 bits are not affected. Since the baud rate is fixed at SYSclk/12 or SYSclk/2, no timer is required and the clock of the microcontroller is used as the synchronous shift pulse directly.
  • Page 392 STC8A8K64D4 Series Manual resets the receiving counter of the baud rate generator immediately, loads 1FFH into the shift register. The received datum is shifted in from the right of the receiving shift register, the loaded 1FFH is shifted out to the left. When the start bit "0" is shifted to the far left of the shift register, the RX controller shifts for the last time and completes a frame receiving.
  • Page 393: Uart1 Mode 2

    STC8A8K64D4 Series Manual 57600 FFD0H FFFCH FFD0H FFFCH 38400 FFB8H FFFAH FFB8H FFFAH 19200 FF70H FFF4H FF70H FFF4H 9600 FEE0H FFE8H FEE0H FFE8H 115200 FFD8H FFD8H 57600 FFB0H FFB0H 18.432 38400 FF88H FFF6H FF88H FFF6H 19200 FF10H FFECH FF10H FFECH 9600 FE20H FFD8H...
  • Page 394: Uart1 Mode 3

    STC8A8K64D4 Series Manual REN=1,RI=0 Start Stop 14.3.8 UART1 Mode 3 If the two bits of SM0 and SM1 are ‘11’, UART1 operates in mode 3. UART1 operating in mode 3 is a 9-bit data asynchronous communication UART. One frame of data consists of 11 bits: 1 start bit, 8 data bits (LSB first), 1 programmable bit ( 9 bit) and 1 stop bit.
  • Page 395: Automatic Address Recognition

    STC8A8K64D4 Series Manual 14.3.9 Automatic Address Recognition 14.3.10 UART1 slave address control registers Symbol Address SADDR SADEN SADDR: Slave address register SADEN: Slave address mask register The automatic address recognition function is typically used in the field of multi-machine communications. Its main principle is that the slave system identifies the address information from the master serial port data stream through the hardware comparison function.
  • Page 396: Uart2

    STC8A8K64D4 Series Manual 14.4 UART2 14.4.1 UART2 control register Symbol Address S2CON S2SM0 S2SM2 S2REN S2TB8 S2RB8 S2TI S2RI S2SM0: Serial port 2 mode select bit. S2SM0 UART 2 mode Function description Mode 0 8-bit UART, whose baud-rate is variable Mode 1 9-bit UART, whose baud-rate is variable S2SM2: UART2 multi-machine communication control enable bit.
  • Page 397: Uart2 Mode 1

    STC8A8K64D4 Series Manual Start Stop Write S2REN=1, S2RI=0 S2CON RxD2 Start Stop S2RI Receiving data (UART2 mode 0) The baud rate of UART2 is variable. It is generated by T2. If the timer is in 1T mode (12x speed), the corresponding baud rate is increased by 12 times.
  • Page 398 STC8A8K64D4 Series Manual - 382 -...
  • Page 399: Uart3

    STC8A8K64D4 Series Manual 14.5 UART3 14.5.1 UART3 control register Symbol Address S3CON S3SM0 S3ST3 S3SM2 S3REN S3TB8 S3RB8 S3TI S3RI S3SM0: UART3 mode select bit. S3SM0 UART3 mode Function description Mode 0 8-bit UART, whose baud-rate is variable Mode 1 9-bit UART, whose baud-rate is variable S3ST3: UART3 baud rate generator select bit.
  • Page 400: Uart3 Mode 1

    STC8A8K64D4 Series Manual data transmitting pin, and RxD3 is the data receiving pin, the serial port is a full duplex receiver/transmitter. Start Stop S3REN=1, S3RI=0 Start Stop The baud rate of UART3 is variable. It is generated by T2 or T3. If the timer is in 1T mode (12x speed), the corresponding baud rate is increased by 12 times.
  • Page 401 STC8A8K64D4 Series Manual S3REN=1,S3RI=0 Start Stop The baud rate calculation formula of UART3 mode 1 is exactly the same as that of mode 0. Please refer to the mode 0 baud rate calculation formula. - 385 -...
  • Page 402: Uart4

    STC8A8K64D4 Series Manual 14.6 UART4 14.6.1 UART4 control register Symbol Address S4CON S4SM0 S4ST4 S4SM2 S4REN S4TB8 S4RB8 S4TI S4RI S4SM0: UART4 mode select bit. S4SM0 UART4 mode Function description Mode 0 8-bit UART, whose baud-rate is variable Mode 1 9-bit UART, whose baud-rate is variable S4ST4: UART4 baud rate generator select bit.
  • Page 403: Uart4 Mode 1

    STC8A8K64D4 Series Manual data transmitting pin, and RxD4 is the data receiving pin, the serial port is a full duplex receiver/transmitter. Start Stop S4REN=1, S4RI=0 Start Stop The baud rate of UART4 is variable. It is generated by T2 or T4. If the timer is in 1T mode (12x speed), the corresponding baud rate is increased by 12 times.
  • Page 404 STC8A8K64D4 Series Manual S4REN=1,S4RI=0 Start Stop The baud rate calculation formula of UART4 mode 1 is exactly the same as that of mode 0. Please refer to the mode 0 baud rate calculation formula. - 388 -...
  • Page 405: Precautions Of Uarts

    STC8A8K64D4 Series Manual 14.7 Precautions of UARTs Regarding the UART interrupts requests, the following issues need to be noted. UART1, UART2, UART3, and UART4 are all similar, and serial port 1 is used as an example below. In 8-bit data mode, TI interrupt request is generated after the entire stop bit is transmitted, as shown in the following figure: Start Stop...
  • Page 406 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" #define FOSC 11059200UL #define (65536 - FOSC / 115200 / 4) AUXR 0x8e; 0xd6; 0xd7; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4;...
  • Page 407 STC8A8K64D4 Series Manual SBUF = dat; void UartSendStr(char *p) while (*p) UartSEND(*p++); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00;...
  • Page 408 STC8A8K64D4 Series Manual P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0023H LJMP UART_ISR 0100H UART_ISR: PUSH PUSH PSW,#08H TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT A,WPTR...
  • Page 409: Uart1 Using T1 (Mode 0) As Baud Rate Generator

    STC8A8K64D4 Series Manual LCALL UART_SEND DPTR UART_SENDSTR SENDEND: MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#STRING LCALL UART_SENDSTR LOOP:...
  • Page 410 STC8A8K64D4 Series Manual #define (65536 - FOSC / 115200 / 4) AUXR 0x8e; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr;...
  • Page 411 STC8A8K64D4 Series Manual while (*p) UartSEND(*p++); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00;...
  • Page 412 STC8A8K64D4 Series Manual P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0023H LJMP UART_ISR 0100H UART_ISR: PUSH PUSH PSW,#08H TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT A,WPTR A,#0FH A,#BUFFER R0,A @R0,SBUF WPTR UARTISR_EXIT: RETI UART_INIT: SCON,#50H TMOD,#00H TL1,#0E8H ;65536-11059200/115200/4=0FFE8H TH1,#0FFH SETB AUXR,#40H BUSY WPTR,#00H RPTR,#00H...
  • Page 413: Uart1 Using T1 (Mode 2) As Baud Rate Generator

    STC8A8K64D4 Series Manual MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#STRING LCALL UART_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR...
  • Page 414 STC8A8K64D4 Series Manual P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void UartIsr() interrupt 4 if (TI) TI = 0;...
  • Page 415 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; UartInit();...
  • Page 416 STC8A8K64D4 Series Manual LJMP MAIN 0023H LJMP UART_ISR 0100H UART_ISR: PUSH PUSH PSW,#08H TI,CHKRI BUSY CHKRI: RI,UARTISR_EXIT A,WPTR A,#0FH A,#BUFFER R0,A @R0,SBUF WPTR UARTISR_EXIT: RETI UART_INIT: SCON,#50H TMOD,#20H TL1,#0FDH ;256-11059200/115200/32=0FDH TH1,#0FDH SETB AUXR,#40H BUSY WPTR,#00H RPTR,#00H UART_SEND: BUSY,$ SETB BUSY SBUF,A UART_SENDSTR: MOVC...
  • Page 417: Uart2 Using T2 As Baud Rate Generator

    STC8A8K64D4 Series Manual P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART_INIT SETB SETB DPTR,#STRING LCALL UART_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR A,#0FH A,#BUFFER R0,A...
  • Page 418 STC8A8K64D4 Series Manual P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void Uart2Isr() interrupt 8 if (S2CON & 0x02) S2CON &= ~0x02;...
  • Page 419 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; Uart2Init();...
  • Page 420 STC8A8K64D4 Series Manual P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0043H LJMP UART2_ISR 0100H UART2_ISR: PUSH PUSH PSW,#08H A,S2CON ACC.1,CHKRI S2CON,#NOT 02H BUSY CHKRI: ACC.0,UART2ISR_EXIT S2CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S2BUF WPTR UART2ISR_EXIT: RETI UART2_INIT: S2CON,#10H T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#14H...
  • Page 421: Uart3 Using T2 As Baud Rate Generator

    STC8A8K64D4 Series Manual MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART2_INIT IE2,#01H SETB DPTR,#STRING LCALL UART2_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH LOOP A,RPTR...
  • Page 422 STC8A8K64D4 Series Manual S3CON 0xac; S3BUF 0xad; 0xaf; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy; char wptr; char rptr; char buffer[16]; void Uart3Isr() interrupt 17 if (S3CON &...
  • Page 423 STC8A8K64D4 Series Manual Uart3SEND(*p++); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; Uart3Init();...
  • Page 424 STC8A8K64D4 Series Manual P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 008BH LJMP UART3_ISR 0100H UART3_ISR: PUSH PUSH PSW,#08H A,S3CON ACC.1,CHKRI S3CON,#NOT 02H BUSY CHKRI: ACC.0,UART3ISR_EXIT S3CON,#NOT 01H A,WPTR A,#0FH A,#BUFFER R0,A @R0,S3BUF...
  • Page 425: Uart3 Using T3 As Baud Rate Generator

    STC8A8K64D4 Series Manual UART3_SENDSTR SEND3END: MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART3_INIT IE2,#08H SETB DPTR,#STRING LCALL UART3_SENDSTR LOOP: A,RPTR A,WPTR A,#0FH...
  • Page 426 STC8A8K64D4 Series Manual T4T3M 0xd1; 0xd3; 0xd2; 0xd5; 0xd4; 0xd7; 0xd6; S3CON 0xac; S3BUF 0xad; 0xaf; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; busy;...
  • Page 427 STC8A8K64D4 Series Manual busy = 1; S3BUF = dat; void Uart3SendStr(char *p) while (*p) Uart3SEND(*p++); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00;...
  • Page 428 STC8A8K64D4 Series Manual WPTR DATA RPTR DATA BUFFER DATA ;16 bytes P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA...
  • Page 429 STC8A8K64D4 Series Manual BUSY,$ SETB BUSY S3BUF,A UART3_SENDSTR: MOVC A,@A+DPTR SEND3END LCALL UART3_SEND DPTR UART3_SENDSTR SEND3END: MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL UART3_INIT...
  • Page 430: Uart4 Using T2 As Baud Rate Generator

    STC8A8K64D4 Series Manual 14.8.7 UART4 using T2 as baud rate generator C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define FOSC 11059200UL #define (65536 - FOSC / 115200 / 4) AUXR 0x8e; 0xd6; 0xd7; S4CON 0x84;...
  • Page 431 STC8A8K64D4 Series Manual wptr = 0x00; rptr = 0x00; busy = 0; void Uart4Send(char dat) while (busy); busy = 1; S4BUF = dat; void Uart4SendStr(char *p) while (*p) Uart4SEND(*p++); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00;...
  • Page 432 STC8A8K64D4 Series Manual S4BUF DATA DATA 0AFH BUSY 20H.0 WPTR DATA RPTR DATA BUFFER DATA ;16 bytes P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA...
  • Page 433 STC8A8K64D4 Series Manual RPTR,#00H UART4_SEND: BUSY,$ SETB BUSY S4BUF,A UART4_SENDSTR: MOVC A,@A+DPTR SEND4END LCALL UART4_SEND DPTR UART4_SENDSTR SEND4END: MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H LCALL...
  • Page 434: Uart4 Using T4 As Baud Rate Generator

    STC8A8K64D4 Series Manual 14.8.8 UART4 using T4 as baud rate generator C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define FOSC 11059200UL #define (65536 - FOSC / 115200 / 4) T4T3M 0xd1; 0xd3; 0xd2; 0xd5; 0xd4;...
  • Page 435 STC8A8K64D4 Series Manual void Uart4Init() S4CON = 0x50; T4L = BRT; T4H = BRT >> 8; T4T3M = 0xa0; wptr = 0x00; rptr = 0x00; busy = 0; void Uart4Send(char dat) while (busy); busy = 1; S4BUF = dat; void Uart4SendStr(char *p) while (*p) Uart4SEND(*p++);...
  • Page 436 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz T4T3M DATA 0D1H DATA 0D3H DATA 0D2H DATA 0D5H DATA 0D4H DATA 0D7H DATA 0D6H S4CON DATA S4BUF DATA DATA 0AFH BUSY 20H.0 WPTR DATA RPTR DATA BUFFER DATA ;16 bytes P0M1 DATA...
  • Page 437 STC8A8K64D4 Series Manual WPTR UART4ISR_EXIT: RETI UART4_INIT: S4CON,#50H T4L,#0E8H ;65536-11059200/115200/4=0FFE8H T4H,#0FFH T4T3M,#0A0H BUSY WPTR,#00H RPTR,#00H UART4_SEND: BUSY,$ SETB BUSY S4BUF,A UART4_SENDSTR: MOVC A,@A+DPTR SEND4END LCALL UART4_SEND DPTR UART4_SENDSTR SEND4END: MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H...
  • Page 438: Serial Multi-Mcus Communication

    STC8A8K64D4 Series Manual LOOP A,RPTR A,#0FH A,#BUFFER R0,A A,@R0 LCALL UART4_SEND RPTR LOOP STRING: 'Uart Test !',0DH,0AH,00H 14.8.9 Serial multi-MCUs communication Now refer to the STC15 series data sheet, which will be supplemented later. - 422 -...
  • Page 439: Uart To Lin Bus

    STC8A8K64D4 Series Manual 14.8.10 UART to LIN BUS C language code // Operating frequency for test is 22.1184MHz /************* Function Description ************** This routine is based on the experiment box 8 to program and test, whose main control chip is STC8H8K64U. It is can be used for general reference when using STC8G and STC8H series chips.
  • Page 440 STC8A8K64D4 Series Manual sbit P0^0; sbit P0^1; sbit P0^2; sbit P0^3; sbit P0^4; sbit P0^5; sbit P0^6; sbit P0^7; sbit P1^0; sbit P1^1; sbit P1^2; sbit P1^3; sbit P1^4; sbit P1^5; sbit P1^6; sbit P1^7; sbit P2^0; sbit P2^1; sbit P2^2;...
  • Page 441 STC8A8K64D4 Series Manual Signal #define UART1_BUF_LENGTH #define UART2_BUF_LENGTH #define LIN_ID 0x31 u8 TX1_Cnt; // count of sendding u8 RX1_Cnt; //count of recieving u8 TX2_Cnt; // count of sendding u8 RX2_Cnt; // count of recieving bit B_TX1_Busy; // busy flag of sendding bit B_TX2_Busy;...
  • Page 442 STC8A8K64D4 Series Manual delay_ms(1); if(RX1_TimeOut > 0) if(--RX1_TimeOut == 0) // If it times out, the serial port reception ends if(RX1_Cnt > 0) Lin_Send(RX1_Buffer); // Send the data received by UART1 to the LIN bus RX1_Cnt = 0; if(RX2_TimeOut > 0) if(--RX2_TimeOut == 0) // If it times out, the serial port reception ends if(RX2_Cnt >...
  • Page 443 STC8A8K64D4 Series Manual u8 Lin_CheckPID(u8 id) u8 returnpid ; u8 P0 ; u8 P1 ; P0 = (((id)^(id>>1)^(id>>2)^(id>>4))&0x01)<<6; P1 = ((~((id>>1)^(id>>3)^(id>>4)^(id>>5)))&0x01)<<7; returnpid = id|P0|P1 ; return returnpid ; //======================================================================== // function: u8 LINCalcChecksum(u8 *dat) // description: Calculate the checksum. // parameters: The data transmitted by the data field. // return: checksum.
  • Page 444 STC8A8K64D4 Series Manual // description: Send LIN bus message. // parameters: The content of the data field to be sent. // return: none. // version: VER1.0 // date: 2020-12-2 // remark: //======================================================================== void Lin_Send(u8 *puts) u8 i; Lin_SendBreak(); //Break UART2_TxByte(0x55); //SYNC UART2_TxByte(Lin_CheckPID(LIN_ID));...
  • Page 445 STC8A8K64D4 Series Manual void PrintString1(u8 *puts) (; *puts != 0; puts++) // End with stop 0 SBUF = *puts; B_TX1_Busy = 1; while(B_TX1_Busy); //======================================================================== // function: void PrintString2(u8 *puts) // description: UART1 sends a string function // parameters: puts: String pointer. // return: none.
  • Page 446 STC8A8K64D4 Series Manual void UART1_config(u8 brt) /*********** select Timer2 as baud rate generator *****************/ if(brt == 2) AUXR |= 0x01; //S1 BRT Use Timer2; SetTimer2Baudraye(Baudrate1); /*********** select Timer1 as baud rate generator *****************/ else TR1 = 0; AUXR &= ~0x01; //S1 BRT Use Timer1;...
  • Page 447 STC8A8K64D4 Series Manual S2CON &= ~(1<<7); //8-bit data, 1 start bit, 1 stop bit, no checking IE2 |= 1; //enable interrupt S2CON |= (1<<4); //enable recieving P_SW2 &= ~0x01; P_SW2 |= 1; //UART2 switch to: 0: P1.0/P1.1, 1: P4.6/P4.7 B_TX2_Busy = 0; TX2_Cnt = 0;...
  • Page 448 STC8A8K64D4 Series Manual if((S2CON & 2) != 0) S2CON &= ~2; //Clear Tx flag B_TX2_Busy = 0; - 432 -...
  • Page 449: Comparator, Power-Down Detection, Internal Reference Voltage

    STC8A8K64D4 Series Manual 15 Comparator, Power-down Detection, Internal Reference Voltage A comparator is integrated in STC8A8K64D4 series of microcontrollers. The positive terminal of the comparator can be P3.7, P5.0, P5.1 or ADC analog input, and the negative can be P3.6 or the REFV voltage of the internal BandGap after amplified.
  • Page 450: Registers Related To Comparator

    STC8A8K64D4 Series Manual 15.3 Registers Related to Comparator Bit Address and Symbol Reset Symbol Description Address Value CMPCR1 Comparator Control Register 1 CMPEN CMPIF CMPOE CMPRES 0000,xx00 CMPCR2 Comparator Control Register 2 INVCMPO DISFLT LCDTY[5:0] 0000,0000 CMPEXCFG Comparator Extended Configuration Register FEAEH CHYS[1:0] CMPNS...
  • Page 451: Comparator Extended Configuration Register (Cmpexcfg)

    STC8A8K64D4 Series Manual if LCDTY is set to a non-zero value n (n =1~63), the actual digital filtering time is (n+2) system clocks The digital filtering function is disabled if LCDTY is set to 0. 15.3.3 Comparator Extended Configuration Register (CMPEXCFG) Symbol Address CMPEXCFG...
  • Page 452: Example Routines

    STC8A8K64D4 Series Manual 15.4 Example Routines 15.4.1 Using Comparator (Interrupt Mode) C language code // Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define CMPEXCFG (*(unsigned char volatile xdata *)0xfeae) P_SW2 0xba; CMPCR1 0xe6; CMPCR2 0xe7; P1M1 0x91; P1M0 0x92;...
  • Page 453 STC8A8K64D4 Series Manual P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; // Enable XFR access CMPEXCFG = 0x00; CMPEXCFG &= ~0x03; //P3.7 is CMP+ input pin CMPEXCFG |= 0x01; //P5.0 is CMP+ input pin CMPEXCFG |= 0x02;...
  • Page 454 STC8A8K64D4 Series Manual P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 00ABH LJMP CMPISR 0100H CMPISR: PUSH CMPCR1,#NOT 40H ; Clear interrupt flag A,CMPCR1 ACC.0,RSING FALLING: P1.0 ; Falling edge interrupt test port RETI RSING: P1.1 ; Rising edge interrupt test port RETI MAIN: SP, #5FH...
  • Page 455: Using Comparator (Polling Mode)

    STC8A8K64D4 Series Manual CMPCR1,#30H ; Enable edge interrupt of comparator CMPCR1,#NOT 20H ; Disable comparator rising edge interrupt CMPCR1,#20H ; Enable comparator rising edge interrupt CMPCR1,#NOT 10H ; Disable comparator falling edge interrupt CMPCR1,#10H ; Enable comparator falling edge interrupt CMPCR1,#NOT 08H ;P3.7 is CMP+ input pin CMPCR1,#08H...
  • Page 456 STC8A8K64D4 Series Manual P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; // Enable XFR access CMPEXCFG = 0x00; CMPEXCFG &= ~0x03; //P3.7 is CMP+ input pin CMPEXCFG |= 0x01;...
  • Page 457 STC8A8K64D4 Series Manual P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H...
  • Page 458: Comparator Is Used For External Power-Down Detection

    STC8A8K64D4 Series Manual P1.0,C ; Read comparator comparison result LOOP 15.4.3 Comparator is Used for External Power-down Detection (User data should be saved to EEPROM in time during power down) 100K P1.2 P1.1 or greater P1.3 P1.0 P1.4 CMP+ / P3.7 P1.5 CMP- / P3.6 P1.6...
  • Page 459: Comparator Is Used To Detect The Operation Voltage (Battery Voltage)

    STC8A8K64D4 Series Manual 15.4.4 Comparator is Used to Detect the Operation Voltage (Battery Voltage) 100K 35.3K (about 5.0V) 40.6K (about 4.5V) 47.9K (about 4.0V) 58.2K (about 3.5V) 74.3K (about 3.0V) P1.2 P1.1 103K (about 2.5V) P1.3 P1.0 P1.4 CMP+/P3.7 P1.5 CMP-/P3.6 P1.6 P3.5...
  • Page 460 STC8A8K64D4 Series Manual #include "intrins.h" #define CMPEXCFG (*(unsigned char volatile xdata *)0xfeae) P_SW2 0xba; CMPCR1 0xe6; CMPCR2 0xe7; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca;...
  • Page 461 STC8A8K64D4 Series Manual CMPCR2 = 0x10; //Output comparator result after 16 debounce clocks CMPCR1 = 0x00; CMPCR1 &= ~0x02; //Disable comparator output CMPCR1 |= 0x80; //Enable comparator module while (1) v = 0x00; //Voltage <2.5V P1 = 0xfe; //P1.0 outputs 0 delay();...
  • Page 462 STC8A8K64D4 Series Manual P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H...
  • Page 463 STC8A8K64D4 Series Manual A,CMPCR1 ACC.0,SKIP R0,#00001111B ;Voltage>4.0V P1,#11101111B ;P1.4 outputs 0 CALL DELAY A,CMPCR1 ACC.0,SKIP R0,#00011111B ;Voltage>4.5V P1,#11011111B ;P1.5 outputs 0 CALL DELAY A,CMPCR1 ACC.0,SKIP R0,#00111111B ;Voltage>5.0V SKIP: P2,#11111111B A,R0 P0,A ;P0.5 ~ P0.0 display voltage LOOP DELAY: R0,#20 DJNZ R0,$ - 447 -...
  • Page 464: Iap/Eeprom/Data-Flash

    STC8A8K64D4 Series Manual 16 IAP/EEPROM/DATA-FLASH Large capacity of internal EEPROM is integrated in STC8A8K64D4 series of microcontrollers. The internal Data Flash can be used as EEPROM by using ISP / IAP technology. And it can be repeatedly erased more than 100,000 times.
  • Page 465: Eeprom Address Registers (Iap_Addr)

    STC8A8K64D4 Series Manual During EEPROM being read operation, the EEPROM data be read after the command execution is completed is stored in the IAP_DATA register. When writing the EEPROM, the data to be written must be stored in the IAP_DATA register before the write command is sent.
  • Page 466: Eeprom Erase Wait Time Control Register (Iap_Tps)

    STC8A8K64D4 Series Manual SWRST: Software reset control bit. 0: No operation. 1: Generate software reset. CMD_FAIL: Command fail status bit for EEPROM operation which should be cleared by software. 0: EEPROM operation is right. 1: EEPROMoperation fails. 16.2.6 EEPROM erase wait time control register (IAP_TPS) Symbol Address IAP_TPS...
  • Page 467 STC8A8K64D4 Series Manual EEPROM is read by MOVC, the flash program memory (ROM) space must be added in addition to F000h. That is, the DPTR must be set to F234h before the MOVC instruction can be used for reading. Note: Because the erasing is performed in 512-byte units, the lower 9 bits of the target address set when performing the erasing operation are meaningless.
  • Page 468 STC8A8K64D4 Series Manual - 452 -...
  • Page 469: Example Routines

    STC8A8K64D4 Series Manual 16.4 Example Routines 16.4.1 EEPROM Basic Operation C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3;...
  • Page 470 STC8A8K64D4 Series Manual void IapProgram(int addr, char dat) IAP_CONTR = 0x80; //Enable IAP IAP_TPS = 12; //Set the erasing wait parameter of 12MHz IAP_CMD = 2; //Set IAP writing command IAP_ADDRL = addr; //Set IAP low address IAP_ADDRH = addr >> 8; //Set IAP high address IAP_DATA = dat;...
  • Page 471 STC8A8K64D4 Series Manual IAP_ADDRL DATA 0C4H IAP_CMD DATA 0C5H IAP_TRIG DATA 0C6H IAP_CONTR DATA 0C7H IAP_TPS DATA 0F5H P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1...
  • Page 472: Read Eeprom Using Movc

    STC8A8K64D4 Series Manual IAP_ERASE: IAP_CONTR,#80H ;Enable IAP IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz IAP_CMD,#3 ;Set IAP erasing command IAP_ADDRL,DPL ;Set IAP low address IAP_ADDRH,DPH ;Set IAP high address IAP_TRIG,#5AH ;Write trigger command (0x5a) IAP_TRIG,#0A5H ;Write trigger command (0xa5) LCALL IAP_IDLE ;Disable IAP function...
  • Page 473 STC8A8K64D4 Series Manual P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; IAP_DATA 0xC2; IAP_ADDRH 0xC3; IAP_ADDRL 0xC4; IAP_CMD 0xC5; IAP_TRIG 0xC6; IAP_CONTR 0xC7; IAP_TPS 0xF5; #define IAP_OFFSET 0xF000H // STC8A8K60S4 void IapIdle() IAP_CONTR = 0;...
  • Page 474 STC8A8K64D4 Series Manual _nop_(); IapIdle(); //Disable IAP function void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00;...
  • Page 475 STC8A8K64D4 Series Manual IAP_IDLE: IAP_CONTR,#0 ;Disable IAP function IAP_CMD,#0 ;Clear command register IAP_TRIG,#0 ;Clear trigger register IAP_ADDRH,#80H ;Set the address to a non-IAP area IAP_ADDRL,#0 IAP_READ: A,#LOW IAP_OFFSET ;Using MOVC to read the EEPROM needs to add the corresponding offset A,DPL DPL,A A,@HIGH IAP_OFFSET...
  • Page 476: Send Out The Data In Eeprom Using Uart

    STC8A8K64D4 Series Manual P5M0, #00H P5M1, #00H DPTR,#0400H LCALL IAP_ERASE DPTR,#0400H LCALL IAP_READ P0,A ;P0=0FFH DPTR,#0400H A,#12H LCALL IAP_PROGRAM DPTR,#0400H LCALL IAP_READ P1,A ;P1=12H SJMP 16.4.3 Send Out the Data in EEPROM Using UART C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 477 STC8A8K64D4 Series Manual void UartInit() SCON = 0x5a; T2L = BRT; T2H = BRT >> 8; AUXR = 0x15; void UartSend(char dat) while (!TI); TI = 0; SBUF = dat; void IapIdle() IAP_CONTR = 0; //Disable IAP function IAP_CMD = 0; //Clear command register IAP_TRIG = 0;...
  • Page 478 STC8A8K64D4 Series Manual IAP_CONTR = 0x80; //Enable IAP IAP_TPS = 12; //Set the erasing wait parameter of 12MHz IAP_CMD = 3; //Set IAP erasing command IAP_ADDRL = addr; //Set IAP low address IAP_ADDRH = addr >> 8; //Set IAP high address IAP_TRIG = 0x5a;...
  • Page 479 STC8A8K64D4 Series Manual P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H UART_INIT: SCON,#5AH T2L,#0E8H ;65536-11059200/115200/4=0FFE8H T2H,#0FFH AUXR,#15H UART_SEND: TI,$ SBUF,A IAP_IDLE: IAP_CONTR,#0 ;Disable IAP function IAP_CMD,#0 ;Clear command register IAP_TRIG,#0 ;Clear trigger register IAP_ADDRH,#80H...
  • Page 480: Uart1 Reads And Writes Eeprom - Read Using Movc

    STC8A8K64D4 Series Manual IAP_ERASE: IAP_CONTR,#80H ;Enable IAP IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz IAP_CMD,#3 ;Set IAP erasing command IAP_ADDRL,DPL ;Set IAP low address IAP_ADDRH,DPH ;Set IAP high address IAP_TRIG,#5AH ;Write trigger command (0x5a) IAP_TRIG,#0A5H ;Write trigger command (0xa5) LCALL IAP_IDLE ;Disable IAP function...
  • Page 481 STC8A8K64D4 Series Manual Please do not modify the program firstly, and download the "UART-EEPROM.hex" directly to test "02-UART 1 reads and writes EEPROM- using MOVC to read". Select the frequency 11.0592MHZ when downloading. PC serial port setting: baud rate 115200,8,n,1. Do sector erase, write 64 bytes, and read 64 bytes of EEPROM.
  • Page 482 STC8A8K64D4 Series Manual u16 GetAddress(void) u16 address; address = 0; if(RX1_Cnt < 3) return 65535; //error if(RX1_Cnt <= 5) //Within 5 bytes is sector operation, decimal, //Command supported: E 0, E 12, E 120 W 0, W 12, W 120 R 0, R 12, R 120 for(i=2;...
  • Page 483 STC8A8K64D4 Series Manual while(--i) ; }while(--ms); //Read EEPROM using MOVC void EEPROM_MOVC_read_n(u16 EE_address, u8 *DataAddress, u16 number) code *pc; pc = EE_address + EEADDR_OFFSET; *DataAddress = *pc; //Data be read DataAddress++; pc++; }while(--number); /********************* main function *************************/ void main(void) u16 addr; UART1_config();...
  • Page 484 STC8A8K64D4 Series Manual for(i=0; i<64; i++) TX1_write2buff(tmp[i]); // Return data to serial port TX1_write2buff(0x0d); TX1_write2buff(0x0a); else if(RX1_Buffer[0] == 'M') //PC requests to return 64 bytes of EEPROM data PrintString1("MOVCData be read \r\n"); 如下: EEPROM_MOVC_read_n(addr,tmp,64); for(i=0; i<64; i++) TX1_write2buff(tmp[i]); // Return data to serial port TX1_write2buff(0x0d);...
  • Page 485 STC8A8K64D4 Series Manual // Remark: //======================================================================== void UART1_config(void) TR1 = 0; AUXR &= ~0x01; //S1 BRT Use Timer1; AUXR |= (1<<6); //Timer1 set as 1T mode TMOD &= ~(1<<6); //Timer1 set As Timer TMOD &= ~0x30; //Timer1_16bitAutoReload; TH1 = (u8)((65536L-(MAIN_Fosc / 4) / Baudrate1) >> 8); TL1 = (u8)(65536L-(MAIN_Fosc / 4) / Baudrate1);...
  • Page 486 STC8A8K64D4 Series Manual C language code (EEPROM.c) //Operating frequency for test is 11.0592MHz This program is the built-in EEPROM read and write program of STC series. #include "config.h" #include "eeprom.h" //======================================================================== // Function: void ISP_Disable(void) // Description: Disable access ISP/IAP.
  • Page 487 STC8A8K64D4 Series Manual *DataAddress = ISP_DATA; //Data be read EE_address++; DataAddress++; }while(--number); DisableEEPROM(); EA = 1; //re-enable interrupt /******************** Sector Erase Function *****************/ //======================================================================== // Function: void EEPROM_SectorErase(u16 EE_address) // Description: Erase the EEPROM sector at the specified address. // Parameters:EE_address: The address of the sector EEPROM to be erased. // Return: non.
  • Page 488: Password Erasing And Writing - Multi-Sector Backup - Uart1 Operation

    STC8A8K64D4 Series Manual ISP_ADDRL = EE_address % 256; //Send the low byte of the address ISP_DATA = *DataAddress; //Send data to ISP_DATA, and only need to send it again when the data changes. ISP_TRIG(); _nop_(); _nop_(); _nop_(); EE_address++; DataAddress++; }while(--number); DisableEEPROM();...
  • Page 489 STC8A8K64D4 Series Manual Note: For general purpose, the program does not recognize whether the sector is valid or not, and the user decides according to the specific model. Date: 2021-11-5 ******************************************/ #include "config.H" #include "EEPROM.h" #define Baudrate1 115200L /************* local constant declaration **************/ code T_StringD[]={"...
  • Page 490 STC8A8K64D4 Series Manual ChckSum += SaveTmp[i]; //Calculate the cumulative sum ChckSum ^= 0x5555; //Invert every other bit, avoid all 0s SaveTmp[64] = (u8)(ChckSum >> 8); SaveTmp[65] = (u8)ChckSum; PassWord = D_PASSWORD; //given password EEPROM_SectorErase(addr); //Erase a sector PassWord = D_PASSWORD; //given password EEPROM_write_n(addr, SaveTmp, 66);...
  • Page 491 STC8A8K64D4 Series Manual for(i=0; i<64; i++) SaveTmp[i] = T_StringD[i]; //Read the default value else PrintString1(" 上电读取 个扇区数据均正确 !\r\n"); //UART1 send a string prompt if((status & 0x01) == 0) // If sector 0 is wrong, write default value if(SaveRecord(0x0000) == 0) PrintString1("write a sector0 !\r\n");...
  • Page 492 STC8A8K64D4 Series Manual if(SaveRecord(0x0400) == 0) PrintString1("write a sector2 正确 !\r\n"); // Writing record 2 sector is correct else PrintString1("write a sector2 错误 !\r\n"); // Writing record 2 sector is wrong else if(cmd == 'R') //PC requests to return 64 bytes of EEPROM data if(ReadRecord(0x0000) == 0) //read data of sector 0 PrintString1("read sector 0...
  • Page 493 STC8A8K64D4 Series Manual // Version: VER1.0 // Date: 2014-11-28 // Remark: //======================================================================== void PrintString1(u8 *puts) //send a string for (; *puts != 0; puts++) //End with stop 0 TX1_write2buff(*puts); //======================================================================== // Function: void UART1_config(void) // Description: UART1 initialization function. // Parameters:none. // Return: none.
  • Page 494 = SBUF; if(TI) TI = 0; B_TX1_Busy = 0; C language code (EEPROM.c) //Operating frequency for test is 11.0592MHz This program is the built-in EEPROM read and write program of STC series. #include "config.h" #include "EEPROM.h" PassWord; // Password required for erasing and writing...
  • Page 495 STC8A8K64D4 Series Manual ISP_CONTR = ISP_EN; //Allow ISP/IAP operation IAP_TPS = (u8)(MAIN_Fosc / 1000000L); //Working frequency setting ISP_READ(); //Send byte read command, when the command does not need to be changed, there is no need to send the command again ISP_ADDRH = EE_address / 256;...
  • Page 496 STC8A8K64D4 Series Manual immediately //The CPU waits for the IAP to complete before continuing to execute the program. _nop_(); _nop_(); _nop_(); DisableEEPROM(); EA = 1; //re-enable interrupt PassWord = 0; //Clear password //======================================================================== // Function: void EEPROM_write_n(u16 EE_address,u8 *DataAddress,u16 number) // Description: Write the buffered n bytes into the EEPROM of the specified first address.
  • Page 497 STC8A8K64D4 Series Manual - 481 -...
  • Page 498: Adc, Internal Reference Voltage

    STC8A8K64D4 Series Manual 17 ADC, Internal Reference Voltage A 12-bit high-speed Analog to Digital Converter is integrated in STC8A8K64D4 family of microcontrollers. The system frequency is divided by 2 and then divided again by the user-set division ratio as the clock frequency of the ADC.
  • Page 499: Adc Configuration Register (Adccfg)

    STC8A8K64D4 Series Manual it still needs To enable the ADC channel, you need to set the PxIE register to close the digital input channel to prevent the external analog input signal from fluctuating high and low and causing additional power consumption) ADC_CHS[3:0] ADC channel...
  • Page 500: Adc Result Registers (Adc_Res, Adc_Resl)

    STC8A8K64D4 Series Manual 1111 SYSclk/2/16 17.1.3 ADC result registers (ADC_RES, ADC_RESL) Symbol Address ADC_RES ADC_RESL After the A/D conversion is completed, the 10-bit/12-bit conversion result is automatically saved to ADC_RES and ADC_RESL. Please refer to the RESFMT setting in the ADC_CFG register to see the result's data format. 17.1.4 ADC timing control register (ADCTIM) Symbol Address...
  • Page 501: Adc Extended Configuration Registers (Adcexcfg)

    STC8A8K64D4 Series Manual ADC clock F SYSclk/2/(SPEED+1) Enable signal of ADC_POWER Start signal ADC_START Finishing sigal ADC_FLAG Analog input channel ADCx_IN Begin Close channel and Conversion Begin selecting channel sampling sampling begin conversion finish 采样时间T Conversion time T convert duty (10位ADC为10个ADC时钟) (SMPDUTY+1) (12位ADC为12个ADC时钟)
  • Page 502: Adc Related Calculation Formula

    STC8A8K64D4 Series Manual 17.2 ADC related calculation formula 17.2.1 ADC speed calculation formula The ADC conversion speed is controlled by the SPEED and ADCTIM registers in the ADCCFG register. The calculation formula of the conversion speed is as follows: 12bit ADC conversion speed ������...
  • Page 503: Adc Application Reference Circuit Diagram

    STC8A8K64D4 Series Manual Overall error Offset error -0.1 Gain error Differential nonlinear error Integral nonlinear error Channel equivalent resistance ∞ Antistatic resistance connected in series before the sample and hold capacitor Internal sample and hold capacitor 16.5 17.4 ADC application reference circuit diagram 17.4.1 High-precision ADC reference circuit diagram CD431/TL431 (2.5V reference source) P0.3...
  • Page 504: Example Routines

    STC8A8K64D4 Series Manual P0.3 P0.2 P0.4 P0.1 P0.5 P0.0 P0.6 P2.7 P0.7 P2.6 External analog P1.0 P2.5 signal input P1.1 P2.4 P1.2 P2.3 System power P1.3 P2.2 (Can be powered from USB) P1.4 P2.1 P1.5 P2.0 P1.6 P4.1 P1.7 P3.7 AGnd P3.6 AVref...
  • Page 505 STC8A8K64D4 Series Manual P4M0 0xb4; P5M1 0xc9; P5M0 0xca; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00;...
  • Page 506: Adc Basic Operation (Interrupt Mode)

    STC8A8K64D4 Series Manual P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H...
  • Page 507 STC8A8K64D4 Series Manual ADC_RES 0xbd; ADC_RESL 0xbe; ADCCFG 0xde; P_SW2 0xba; #define ADCTIM (*(unsigned char volatile xdata *)0xfea8) sbit EADC IE^5; P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4;...
  • Page 508 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz ADC_CONTR DATA 0BCH ADC_RES DATA 0BDH ADC_RESL DATA 0BEH ADCCFG DATA 0DEH P_SW2 DATA 0BAH ADCTIM XDATA 0FEA8H EADC IE.5 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H...
  • Page 509: Format Adc Conversion Result

    STC8A8K64D4 Series Manual DPTR,#ADCTIM ; Set ADC internal timing A,#3FH MOVX @DPTR,A P_SW2,#00H ADCCFG,#0FH ;Set the ADC clock to the system clock/2/16 ADC_CONTR,#80H ;Enable ADC module SETB EADC ;Enable ADC interrupt SETB ADC_CONTR,#40H ;Start AD conversion SJMP 17.5.3 Format ADC Conversion Result C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 510 STC8A8K64D4 Series Manual P5M0 = 0x00; P5M1 = 0x00; P1M0 = 0x00; //Set P1.0 as ADC input P1M1 = 0x01; P_SW2 |= 0x80; ADCTIM = 0x3f; //Set ADC internal timing P_SW2 &= 0x7f; ADCCFG = 0x0f; //Set the ADC clock to the system clock/2/16 ADC_CONTR = 0x80;...
  • Page 511: Adc Converts Multiple Times To Take Average Automatically

    STC8A8K64D4 Series Manual P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P1M0,#00H ;Set P1.0 as ADC input P1M1,#01H P_SW2,#80H DPTR,#ADCTIM ; Set ADC internal timing A,#3FH MOVX @DPTR,A...
  • Page 512 STC8A8K64D4 Series Manual P_SW2 0xba; #define ADCTIM (*(unsigned char volatile xdata *)0xfea8) #define ADCEXCFG (*(unsigned char volatile xdata *)0xfead) P1M1 0x91; P1M0 0x92; P0M1 0x93; P0M0 0x94; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 513 STC8A8K64D4 Series Manual ADC_CONTR DATA 0BCH ADC_RES DATA 0BDH ADC_RESL DATA 0BEH ADCCFG DATA 0DEH P_SW2 DATA 0BAH ADCTIM XDATA 0FEA8H ADCEXCFG XDATA 0FEAdH P1M1 DATA 091H P1M0 DATA 092H P0M1 DATA 093H P0M0 DATA 094H P2M1 DATA 095H P2M0 DATA 096H P3M1...
  • Page 514: Detect External Voltage Or Battery Voltage Using Adc 15Th Channel

    STC8A8K64D4 Series Manual ADC_CONTR,#40H ; Start AD conversion A,ADC_CONTR ; Query ADC completion flag ACC.5,$-2 ADC_CONTR,#NOT 20H ; Clear completion flag P2,ADC_RES ; Read ADC result SJMP LOOP 17.5.5 Detect External Voltage or Battery Voltage using ADC 15th Channel The 15th channel of ADC in the STC8A8K64D4 family of microcontrollers is used to measure the internal reference voltage.
  • Page 515 STC8A8K64D4 Series Manual ADC_CONTR 0xbc; ADC_RES 0xbd; ADC_RESL 0xbe; ADCCFG 0xde; P_SW2 0xba; #define ADCTIM (*(unsigned char volatile xdata *)0xfea8) P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9;...
  • Page 516 STC8A8K64D4 Series Manual P_SW2 |= 0x80; // Set ADC internal timing ADCTIM = 0x3f; P_SW2 &= 0x7f; ADCCFG = 0x2f; //Set the ADC clock to the system clock/2/16 ADC_CONTR = 0x8f; //Enable ADC module, and select channel 15 ADCRead() int res; ADC_CONTR |= 0x40;...
  • Page 517: Using Adc As Capacitive Sensing Touch Keys

    The most typical and reliable one is the solution using ADC. The solution of using STC series MCUs with ADC is described in detail in this document. Any MCU with ADC function can be used to implement the scheme. The first three diagrams below are the most commonly used methods.
  • Page 518 STC8A8K64D4 Series Manual In general applications, the induction spring shown in Figure 4 is used to increase the area pressed by a finger. The induction spring is equivalent to a metal plate to the ground. There is a capacitor CP to the ground. After pressing the finger, a capacitor CF is connected in parallel to the ground, as shown in the figure below.
  • Page 519 STC8A8K64D4 Series Manual C language code //Operating frequency for testing is 24MHz #include "reg51.h" #include "intrins.h" #define MAIN_Fosc 24000000UL //Define the main clock #define Timer0_Reload (65536UL -(MAIN_Fosc / 600000)) //Timer 0 reload value corresponds to 300KHz typedef unsigned char typedef unsigned int u16;...
  • Page 520 STC8A8K64D4 Series Manual sbit P_LED5 P2^5; sbit P_LED4 P2^4; sbit P_LED3 P2^3; sbit P_LED2 P2^2; sbit P_LED1 P2^1; sbit P_LED0 P2^0; u16 idata adc[TOUCH_CHANNEL]; //Current ADC value u16 idata adc_prev[TOUCH_CHANNEL]; //Previous ADC value u16 idata TouchZero[TOUCH_CHANNEL]; //ADC value of 0-point u8 idata TouchZeroCnt[TOUCH_CHANNEL];...
  • Page 521 STC8A8K64D4 Series Manual ShowLED(); if (++cnt_250ms >= 5) cnt_250ms = 0; AutoZero(); //Process 0-point auto-tracking every 250ms void delay_ms(u8 ms) unsigned int i; i = MAIN_Fosc / 13000; while(--i) ; } while(--ms); void ADC_init(void) P1M0 = 0x00; //8 channels ADC P1M1 = 0xff;...
  • Page 522 STC8A8K64D4 Series Manual else // If the change is relatively small, then creep, track 0-point automatically if(++TouchZeroCnt[i] >= 20) // Continuously detect small changes 20 times/4 = 5 seconds. TouchZeroCnt[i] = 0; TouchZero[i] = adc_prev[i]; // Use slowly changing values as 0 points adc_prev[i] = j;...
  • Page 523 STC8A8K64D4 Series Manual Fosc_KHZ 24000 ;Define the main clock KHZ Reload (65536 - Fosc_KHZ/600) ;Timer 0 reload value, corresponding to 300KHz ADC_CONTR DATA 0xBC ; microcontrollers with ADC ADC_RES DATA 0xBD ; microcontrollers with ADC ADC_RESL DATA 0xBE ; microcontrollers with ADC AUXR DATA 0x8E...
  • Page 524 STC8A8K64D4 Series Manual P3M0,#00H P3M1,#00H P4M0,#00H P4M1,#00H P5M0,#00H P5M1,#00H R7,#50 LCALL F_delay_ms ;Initialize Timer0 to output a 300KHz clock AUXR,#080H ;Timer0 set as 1T mode AUXR2,#01H ;Enable clock output TMOD,#0 ;Timer0 set as Timer,16 bits Auto Reload. TH0,#HIGH Reload TL0,#LOW Reload SETB LCALL F_ADC_init...
  • Page 525 STC8A8K64D4 Series Manual F_Get_ADC10bitResult: ADC_RES,#0 ADC_RESL,#0 A,R7 A,#0E8H ;Trigger ADC ADC_CONTR,A L_10bitADC_Loop1: A,ADC_CONTR ACC.4,L_10bitADC_Loop1 ;Wait for the ADC conversion complement ADC_CONTR,#080H ;Clear flag A,ADC_RES B,#04H R7,A R6,B A,ADC_RESL A,#03H A,R7 R7,A F_AutoZero: ; Call once every 250ms ; This is detected using the sum of the absolute values of the differences between two adjacent samples. R5,A L_AutoZero_Loop: A,R5...
  • Page 526 STC8A8K64D4 Series Manual A,R3 SUBB A,R2 R2,A L_AutoZero_1: ;Calculate [R2 R3] - #20,if(k >= 20) A,R3 SUBB A,#20 A,R2 SUBB A,#00H L_AutoZero_2 ;[R2 R3] ,20, Jump A,#LOW (TouchZeroCnt) ; If the change is large, clear the counter TouchZeroCnt[i] = 0; A,R5 R0,A @R0,#0...
  • Page 527 STC8A8K64D4 Series Manual @R0,7 A,R5 A,#08H $ + 5H LJMP L_AutoZero_Loop F_check_adc: ; Judge key is pressed or released, with hysteresis control MOV R4,7 LCALL F_Get_ADC10bitResult ; The ADC value returned is [R6 R7] A,#0FFH SUBB A,R7 R7,A A,#03H SUBB A,R6 R6,A A,R4...
  • Page 528 STC8A8K64D4 Series Manual A,@R0 SUBB A,@R1 R6,A A,R7 SUBB A,#40 A,R6 SUBB A,#00H L_check_adc_2 ;if(delta < 40), jump R7,#1 ;if(delta >= 40) return 1; //Key pressed, return 1 L_check_adc_2: SETB A,R7 SUBB A,#20 A,R6 SUBB A,#00H L_check_adc_3 R7,#0 L_check_adc_3: R7,#2 F_ShowLED: R7,#0 LCALL...
  • Page 529 STC8A8K64D4 Series Manual LCALL F_check_adc A,R7 A,#0FEH L_QuitCheck3 A,R7 C,ACC.0 P_LED3,C L_QuitCheck3: R7,#4 LCALL F_check_adc A,R7 A,#0FEH L_QuitCheck4 A,R7 C,ACC.0 P_LED4,C L_QuitCheck4: R7,#5 LCALL F_check_adc A,R7 A,#0FEH L_QuitCheck5 A,R7 C,ACC.0 P_LED5,C L_QuitCheck5: R7,#6 LCALL F_check_adc A,R7 A,#0FEH L_QuitCheck6 A,R7 C,ACC.0 P_LED6,C L_QuitCheck6: R7,#7...
  • Page 530: Key-Scan Application Circuit Diagram Using Adc

    STC8A8K64D4 Series Manual A,R4 L_delay_ms_3 L_delay_ms_3: A,R3 L_delay_ms_2 DJNZ R7,L_delay_ms_1 17.5.7 Key-scan Application Circuit Diagram using ADC Method for reading the ADC key is reading the ADC value every 10ms or so and saving the last 3 readings. If the change is relatively small, judge the key.
  • Page 531: Reference Circuit Diagram For Detecting Negative Voltage

    STC8A8K64D4 Series Manual 17.5.8 Reference circuit diagram for detecting negative voltage Test-OUT 0~+5V, which can be connected to MCU AD detection port Test-IN -5V~+5V Negative Voltage Conversion Circuit - 515 -...
  • Page 532: The Application Of Common Addition Circuit In Adc

    STC8A8K64D4 Series Manual 17.5.9 The application of common addition circuit in ADC Commonly used Simplified addition Deformed into the form of adding circuits circuit a voltage divider circuit Refer to the voltage divider circuit to get formula 1 Formula 1: Vo = Vin + i2 * R2 Formula 2: i2 = (Vcc-Vin) / (R1 + R2) {Condition: the current flowing to Vo ≈0} Substituting R1=R2 into formula 2 gives formula 3 Formula 3: i2 = (Vcc-Vin) / 2R2...
  • Page 533: Application Of Pca/Ccp/Pwm

    STC8A8K64D4 Series Manual 18 Application of PCA/CCP/PWM Four groups of programmable counter array (PCA/CCP/PWM) modules are integrated in STC8A8K64D4 series of microcontrollers, which can be used for software timer, external pulse capture, high-speed pulse output and pulse width modulation (PWM) output. PCA contains a special 16-bit counter, with which four groups of PCA modules are connected.
  • Page 534: Pca Control Register (Ccon)

    STC8A8K64D4 Series Manual PCA_PWM3 PCA3 PWM Mode Register FD57H EBS3[1:0] XCCAP3H[1:0] XCCAP3L[1:0] EPC3H EPC3L 0000,0000 PCA Counter High Byte 0000,0000 CCAP0H PCA 0 Capture Register High Byte 0000,0000 CCAP1H PCA 1 Capture Register High Byte 0000,0000 CCAP2H PCA 2 Capture Register High Byte 0000,0000 CCAP3H PCA 3 Capture Register High Byte...
  • Page 535: Pca Capture Value/Compare Value Registers (Ccapnl, Ccapnh)

    STC8A8K64D4 Series Manual CCAPNn: PCAn Capture on falling edge enable bit MATn: PCAn match function enable bit TOGn: PCAn high speed pulse output function enable bit PWMn: PCAn PWM output function enable bit ECCFn: PCAn match/capture interrupt enable bit 18.2.5 PCA capture value/compare value registers (CCAPnL, CCAPnH) Symbol Address CCAP0L...
  • Page 536: Capture Mode

    STC8A8K64D4 Series Manual interrupt 6/7/8/10 bit PWM mode, rising and falling edge interrup 16 bit rising edge capture mode 16 bit falling edge capture mode 16 bit rising and falling edge capture mode 16 bit software timer mode 16 bit high speed pulse output mode 18.3.1 Capture Mode At least one of CAPNn and CAPPn bits in CCAPMn must be set (or all of them are set) for a PCA module to operate in capture mode.
  • Page 537: High Speed Pulse Output Mode

    STC8A8K64D4 Series Manual Write Then CCON CF CR - CF3 CF2 CF1 CF0 CCAPnL write firstly CCAPnH enable matched 16 bit comparator interrupt CCAPnH CCAPnL ECOMn=0, stop comparison ECOMn=1, continue comparison CCAPMn ECOMn CAPPn CAPNn MATn TOGn PWMn ECCFn PCA software timer mode 18.3.3 High Speed Pulse Output Mode When the count value of the PCA counter matches the value of the capture register, the CCPn output of the PCA module will hop.
  • Page 538 STC8A8K64D4 Series Manual [7: 0]} are reloaded into {EPCnL, CCAPnL [7: 0]}. This makes it possible to update the PWM without interference. The structure of PCA module working in 8-bit PWM mode is shown below. EPCnH CCAPnH[7:0] reload Output 0 EPCnL CCAPnL[7:0] {0,CL[7:0]}<{EPCnL,CCAPnL[7:0]}...
  • Page 539 STC8A8K64D4 Series Manual EPCnH CCAPnH[6:0] reload Output 0 EPCnL CCAPnL[6:0] {0,CL[6:0]}<{EPCnL,CCAPnL[6:0]} enable CCPn 8-bit comparator {0,CL[6:0]}>={EPCnL,CCAPnL[6:0]} CL[6:0] Output 1 CL overflow CCAPMn ECOMn CAPPn CAPNn MATn TOGn PWMn ECCFn 18.3.4.3 6-bit PWM Mode When EBSn [1: 0] in the PCA_PWMn register is set to 10, PCAn operates in 6-bit PWM mode, where {0, CL [5: 0]} is compared with the capture registers {EPCnL, CCAPnL [5: 0] }.
  • Page 540 STC8A8K64D4 Series Manual 18.3.4.4 10-bit PWM Mode When EBSn [1: 0] in the PCA_PWMn register is set to 11, PCAn operates in 10-bit PWM mode, where {CH[1:0],CL[7:0]} is compared with the capture registers{EPCnL,XCCAPnL[1:0],CCAPnL[7:0]}. When PCA modules are operating in 10-bit PWM mode, the output frequencies of them are the same because all the modules share a single PCA counter.
  • Page 541: Reference Circuit For Implementing 8 ~ 16-Bit Dac Using Ccp / Pca Module

    STC8A8K64D4 Series Manual 18.4 Reference Circuit for Implementing 8 ~ 16-bit DAC using CCP / PCA module - 525 -...
  • Page 542: Example Routines

    STC8A8K64D4 Series Manual 18.5 Example Routines 18.5.1 PCA Output PWM (6/7/8/10 bit) C language code //Operating frequency for test is 11.0592MHz #include “reg51.h” #include “intrins.h” CCON 0xd8; sbit CCON^7; sbit CCON^6; sbit CCF2 CCON^2; sbit CCF1 CCON^1; sbit CCF0 CCON^0; CMOD 0xd9;...
  • Page 543 STC8A8K64D4 Series Manual P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; CCON = 0x00; CMOD = 0x08; //PCA clock is the system clock CL = 0x00; CH = 0x00; ―― 6 bit PWM ―― CCAPM0 = 0x42; //PCA 0 is in PWM mode PCA_PWM0 = 0x80;...
  • Page 544 STC8A8K64D4 Series Manual PCA_PWM2 DATA 0F4H P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H...
  • Page 545: Pca Capture And Measure Pulse Width

    STC8A8K64D4 Series Manual SETB ;Start PCA timer 18.5.2 PCA Capture and Measure Pulse Width C language code //Operating frequency for test is 11.0592MHz #include “reg51.h” #include “intrins.h” CCON 0xd8; sbit CCON^7; sbit CCON^6; sbit CCF2 CCON^2; sbit CCF1 CCON^1; sbit CCF0 CCON^0;...
  • Page 546 STC8A8K64D4 Series Manual void PCA_Isr() interrupt 7 if (CF) CF = 0; cnt++; //PCA timing overflow times+1 if (CCF0) CCF0 = 0; count0 = count1; //Back up the last captured value ((unsigned char *)&count1)[3] = CCAP0L; ((unsigned char *)&count1)[2] = CCAP0H; ((unsigned char *)&count1)[1] = cnt;...
  • Page 547 STC8A8K64D4 Series Manual CCON.7 CCON.6 CCF2 CCON.2 CCF1 CCON.1 CCF0 CCON.0 CMOD DATA 0D9H DATA 0E9H DATA 0F9H CCAPM0 DATA 0DAH CCAP0L DATA 0EAH CCAP0H DATA 0FAH PCA_PWM0 DATA 0F2H CCAPM1 DATA 0DBH CCAP1L DATA 0EBH CCAP1H DATA 0FBH PCA_PWM1 DATA 0F3H CCAPM2...
  • Page 548 STC8A8K64D4 Series Manual COUNT1+1,CCAP0H COUNT1+2,CCAP0L ;Calculate two captures’ differences A,COUNT1+2 SUBB A,COUNT0+2 LENGTH+2,A A,COUNT1+1 SUBB A,COUNT0+1 LENGTH+1,A A,COUNT1 SUBB A,COUNT0 LENGTH,A ;LENGTH saved is the captured pulse width ISREXIT: RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H...
  • Page 549: Pca Implements 16-Bit Software Timing

    STC8A8K64D4 Series Manual 18.5.3 PCA Implements 16-bit Software Timing C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define T50HZ (11059200L / 12 / 2 / 50) CCON 0xd8; sbit CCON^7; sbit CCON^6; sbit CCF2 CCON^2; sbit CCF1 CCON^1;...
  • Page 550 STC8A8K64D4 Series Manual CCAP0L = value; CCAP0H = value >> 8; value += T50HZ; P10 = !P10; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00;...
  • Page 551 STC8A8K64D4 Series Manual CCAPM2 DATA 0DCH CCAP2L DATA 0ECH CCAP2H DATA 0FCH PCA_PWM2 DATA 0F4H T50HZ 2400H ;11059200/12/2/50 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1...
  • Page 552: Pca Output High-Speed Pulse

    STC8A8K64D4 Series Manual CL,#00H CH,#0H CCAPM0,#49H ;PCA module 0 is 16-bit timer mode CCAP0L,#LOW T50HZ CCAP0H,#HIGH T50HZ SETB ;Start PCA timer SETB 18.5.4 PCA Output High-speed Pulse C language code //Operating frequency for test is 11.0592MHz #include “reg51.h” #include “intrins.h” #define T38K4HZ (11059200L / 2 / 38400)
  • Page 553 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; unsigned int value; void PCA_Isr() interrupt 7 CCF0 = 0; CCAP0L = value; CCAP0H = value >> 8; value += T38K4HZ; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00;...
  • Page 554 STC8A8K64D4 Series Manual CCAP0H DATA 0FAH PCA_PWM0 DATA 0F2H CCAPM1 DATA 0DBH CCAP1L DATA 0EBH CCAP1H DATA 0FBH PCA_PWM1 DATA 0F3H CCAPM2 DATA 0DCH CCAP2L DATA 0ECH CCAP2H DATA 0FCH PCA_PWM2 DATA 0F4H T38K4HZ ;11059200/2/38400 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA...
  • Page 555: Pca Extends External Interrupt

    STC8A8K64D4 Series Manual P5M0, #00H P5M1, #00H CCON,#00H CMOD,#08H ;PCA clock is the system clock CL,#00H CH,#0H CCAPM0,#4DH ;PCA module 0 is 16-bit timer mode, and enable pulse output CCAP0L,#LOW T38K4HZ CCAP0H,#HIGH T38K4HZ SETB ;Start PCA timer SETB 18.5.5 PCA Extends External Interrupt C language code //Operating frequency for test is 11.0592MHz #include "reg51.h"...
  • Page 556 STC8A8K64D4 Series Manual P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; void PCA_Isr() interrupt 7 CCF0 = 0; P10 = !P10; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00;...
  • Page 557 STC8A8K64D4 Series Manual CCAP0L DATA 0EAH CCAP0H DATA 0FAH PCA_PWM0 DATA 0F2H CCAPM1 DATA 0DBH CCAP1L DATA 0EBH CCAP1H DATA 0FBH PCA_PWM1 DATA 0F3H CCAPM2 DATA 0DCH CCAP2L DATA 0ECH CCAP2H DATA 0FCH PCA_PWM2 DATA 0F4H P0M1 DATA 093H P0M0 DATA 094H P1M1...
  • Page 558 STC8A8K64D4 Series Manual CCAP0L,#0 CCAP0H,#0 SETB ;Start PCA timer SETB - 542 -...
  • Page 559: Enhanced Pwm With 15-Bit Accuracy

    ADC conversion function. The 16-bit advanced PWM timer: It is the PWM with the strongest function in STC products at present, which can output PWM waveforms of any frequency and any duty. It can output complementary/symmetrical with dead-time PWM waveform without software intervention.
  • Page 560: Registers Related To Pwm

    STC8A8K64D4 Series Manual C1_S[1:0] : Enhanced PWM channel 1 output pin selection bit C1_S[1:0] PWM1 P2.1 P1.1 P6.1 Reserved C2_S[1:0] : Enhanced PWM channel 2 output pin selection bit C2_S[1:0] PWM2 P2.2 P1.2 P6.2 Reserved C3_S[1:0] : Enhanced PWM channel 3 output pin selection bit C3_S[1:0] PWM3 P2.3...
  • Page 561: Enhanced Pwm Global Configuration Register (Pwmset)

    STC8A8K64D4 Series Manual PWMIF PWM Interrupt Flag Register FF05H C7IF C6IF C5IF C4IF C3IF C2IF C1IF C0IF 0000,0000 PWMFDCR PWM Fault Detection Control Register FF06H INVCMP INVIO ENFD FLTFLIO EFDI FDCMP FDIO FDIF 0000,0000 PWM0T1H PWM0 T1 High Byte FF10H x000,0000 PWM0T1L PWM0 T1 Low Byte...
  • Page 562: Pwm Interrupt Flag Register (Pwmif)

    STC8A8K64D4 Series Manual 0: disable PWM counter returns to zero interrupt (PWMCBIF is still set by hardware) 1: enable PWM counter returns to zero interrupt EPWMTA: Whether the PWM is associated with the ADC or not. 0: PWM is not associated with the ADC. 1: PWM is associated with the ADC.
  • Page 563: Pwm Counter Registers (Pwmch, Pwmcl)

    STC8A8K64D4 Series Manual 0: PWMFLT level is not associated with PWM 1: the source of PWM fault detection is PWMFLT. (The fault type is set by INVIO.) FDIF: the interrupt flag bit of PWM fault detection. It is set automatically by the hardware when a PWM fault occurs. If EFDI=1, the program will jump to the corresponding interrupt entry to execute interrupt service routine.
  • Page 564: Pwm Level Output Setting Count Value Registers (Pwmnt1,Pwmnt2)

    STC8A8K64D4 Series Manual PWMTADCH FF03H PWMTADCL FF04H PWMTADCH: the upper 7 bits of the PWM triggers ADC time. PWMTADCL: the lower 8 bits of the PWM triggers ADC time. If EPWMTA =1 and ADC_POWER=1, {PWMTADCH, PWMTADCL} forms a 15-bit register. In the PWM counting cycle, the hardware will trigger A/D conversion automatically when the internal PWM counting value equals to the value of {PWMTADCH, PWMTADCL}.
  • Page 565: Pwm Channel Control Registers (Pwmncr)

    STC8A8K64D4 Series Manual 19.2.9 PWM Channel Control Registers (PWMnCR) Symbol Address PWM0CR FF14H C0_S[1:0] ENT2I ENT1I PWM1CR FF1CH C1_S[1:0] ENT2I ENT1I PWM2CR FF24H C2_S[1:0] ENT2I ENT1I PWM3CR FF2CH C3_S[1:0] ENT2I ENT1I PWM4CR FF34H C4_S[1:0] ENT2I ENT1I PWM5CR FF3CH C5_S[1:0] ENT2I ENT1I PWM6CR FF44H...
  • Page 566: Example Routines

    STC8A8K64D4 Series Manual 19.3 Example Routines 19.3.1 Output waveforms with arbitrary period and arbitrary duty C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P_SW2 0xba; PWMSET 0xF1; PWMCFG1 0xF6; #define PWMC (*(unsigned int volatile xdata *)0xFF00) #define PWMCH (*(unsigned char volatile xdata *)0xFF00)
  • Page 567 STC8A8K64D4 Series Manual P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; PWMSET = 0x01; //Enable PWM0 module (The configuration is effective only after the module is enabled.) P_SW2 = 0x80; PWMCKS = 0x00; //The clock of PWM is the system clock PWMC = 0x1000;...
  • Page 568 STC8A8K64D4 Series Manual LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H PWMSET,#01H ;Enable PWM module (The configuration is effective only after the module is enabled.) P_SW2,#80H DPTR,#PWMCKS...
  • Page 569 STC8A8K64D4 Series Manual 19.3.2 Two-channel PWMs realize complementary symmetrical waveform with dead-time control C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P_SW2 0xba; PWMSET 0xF1; PWMCFG 0xF6; #define PWMC (*(unsigned int volatile xdata *)0xFF00) #define PWMCH (*(unsigned char volatile xdata *)0xFF00) #define...
  • Page 570 STC8A8K64D4 Series Manual P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; PWMSET = 0x01; //Enable PWM module (The configuration is effective only after the module is enabled.) P_SW2 = 0x80;...
  • Page 571 STC8A8K64D4 Series Manual PWM1T2L 0FF1BH PWM1CR 0FF1CH PWM1HLD 0FF1DH P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0...
  • Page 572: Pwm Implements Gradient Light (Breathing Light)

    STC8A8K64D4 Series Manual A,#00H DPTR,#PWM0T2L MOVX @DPTR,A A,#00H DPTR,#PWM1T2H ;At the count value of 0080H, PWM1 outputs high level. MOVX @DPTR,A A,#80H DPTR,#PWM1T2L MOVX @DPTR,A A,#07H DPTR,#PWM1T1H ;At the count value of 0780H, PWM1 outputs low level. MOVX @DPTR,A A,#80H DPTR,#PWM1T1L MOVX @DPTR,A...
  • Page 573 STC8A8K64D4 Series Manual #define PWM0T1H (*(unsigned char volatile xdata *)0xFF10) #define PWM0T1L (*(unsigned char volatile xdata *)0xFF11) #define PWM0T2H (*(unsigned char volatile xdata *)0xFF12) #define PWM0T2 (*(unsigned int volatile xdata *)0xFF12) #define PWM0T2L (*(unsigned char volatile xdata *)0xFF13) #define PWM0CR (*(unsigned char volatile xdata *)0xFF14) #define PWM0HLD...
  • Page 574 STC8A8K64D4 Series Manual P5M0 = 0x00; P5M1 = 0x00; PWMSET = 0x01; //Enable PWM module (The configuration is effective only after the module is enabled.) P_SW2 = 0x80; PWMCKS = 0x00; // The clock of PWM is the system clock PWMC = CYCLE;...
  • Page 575 STC8A8K64D4 Series Manual 20H.0 VALL DATA VALH DATA 0000H LJMP MAIN 00B3H LJMP PWM0ISR 0100H PWM0ISR: PUSH PUSH PUSH PUSH PUSH P_SW2 P_SW2,#80H A,PWMCFG ACC.3,ISREXIT PWMCFG,#NOT 08H ;Clear interrupt flag DIR,PWMDN PWMUP: A,VALL A,#1 VALL,A A,VALH ADDC A,#0 VALH,A CJNE A,#HIGH CYCLE,SETPWM A,VALL CJNE...
  • Page 576 STC8A8K64D4 Series Manual RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H SETB VALH,#00H VALL,#01H PWMSET,#01H ;Enable PWM module (The configuration is effective only after the module is enabled.) P_SW2,#80H DPTR,#PWMCKS...
  • Page 577: Use Pwm To Trigger Adc Conversion

    STC8A8K64D4 Series Manual 19.3.4 Use PWM to trigger ADC conversion C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P_SW2 0xba; PWMSET 0xF1; PWMCFG 0xF6; #define PWMC (*(unsigned int volatile xdata *)0xFF00) #define PWMCH (*(unsigned char volatile xdata *)0xFF00) #define PWMCL (*(unsigned char volatile xdata *)0xFF01)
  • Page 578 STC8A8K64D4 Series Manual int i; for (i=0; i<100; i++); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00;...
  • Page 579 STC8A8K64D4 Series Manual P_SW2 DATA 0BAH PWMSET DATA 0F1H PWMCFG DATA 0F6H PWMCH 0FF00H PWMCL 0FF01H PWMCKS 0FF02H PWMTADCH 0FF03H PWMTADCL 0FF04H PWMIF 0FF05H PWMFDCR 0FF06H PWM0T1H 0FF10H PWM0T1L 0FF11H PWM0T2H 0FF12H PWM0T2L 0FF13H PWM0CR 0FF14H PWM0HLD 0FF15H ADC_CONTR DATA 0BCH ADC_POWER EQU 080H...
  • Page 580 STC8A8K64D4 Series Manual ACC.3,ISREXIT PWMCFG,#NOT 08H ISREXIT: RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H ADC_CONTR,# ADC_POWER | ADC_EPWMT SETB EADC PWMSET,#01H ;Enable PWM module (The configuration is effective only after the...
  • Page 581 STC8A8K64D4 Series Manual DPTR,#PWM0CR ; Enable PWM0 output MOVX @DPTR,A P_SW2,#00H PWMCFG,#07H ; Start the PWM module and enable the PWM interrupt and ADC trigger SETB - 565 -...
  • Page 582: Sysnchronous Serial Peripheral Interface (Spi)

    STC8A8K64D4 Series Manual 20 Sysnchronous Serial Peripheral Interface (SPI) A high-speed serial communication interface, SPI, is integrated in STC8A8K64D4 series of microcontrollers. SPI is a full-duplex high-speed synchronous communication bus. SPI interface integrated in the STC8A8K64D4 series of microcontrollers offers two operation modes: master mode and slave mode. 20.1 SPI function pin switch Symbol Address...
  • Page 583: Spi Data Register (Spdat)

    STC8A8K64D4 Series Manual DORD: Set the transmitted or received SPI data order. 0: The MSB of the data is transmitted firstly. 1: The LSB of the data is transmitted firstly. MSTR: Master/Slave mode select bit. To set the mastert mode: If SSIG = 0, the SS pin must be high and set MSTR to 1.
  • Page 584: Dual Devices Configuration Mode

    STC8A8K64D4 Series Manual 20.3.2 Dual Devices Configuration Mode Two devices are connected, the master and the slave are not fixed. Setting Method 1: Both devices are initialized with SSIG set to 0, MSTR set to 1, and SS pin set to bi-directional mode and output high.
  • Page 585: Configure Spi

    STC8A8K64D4 Series Manual 20.4 Configure SPI Control bits Communication port pins Descriptions SPEN SSIG MSTR SS MISO MOSI SCLK SPI is disabled, SS/MOSI/MISO/SCLK input input input are used as general I/O ports output input input Selected as slave high input input Selected as slave, not selected.
  • Page 586: Data Format

    STC8A8K64D4 Series Manual can be considered as a 16-bit cyclic shift register. As data is shifted from the master to the slave, data is also shifted in the opposite direction simultaneously. This means that the data of the master and the slave are exchanged with each other in one shift period.
  • Page 587: Example Routines

    STC8A8K64D4 Series Manual SCLK ( CPOL=0 SCLK ( CPOL=1 Sample at the trailing edge DORD=0 MOSI ( input DORD=1 Drive at the leading edge DORD=0 MISO ( output DORD=1 Invalid data SS ( If SSIG=0 SPI slave transfer format with CPHA=1 SCLK ( CPOL=0 SCLK (...
  • Page 588 STC8A8K64D4 Series Manual #include "reg51.h" #include "intrins.h" SPSTAT 0xcd; SPCTL 0xce; SPDAT 0xcf; 0xaf; #define ESPI 0x02 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca;...
  • Page 589 STC8A8K64D4 Series Manual while (1) while (busy); busy = 1; SS = 0; //Pull down the slave SS pin SPDAT = 0x5a; //Send test data Assembly code ;Operating frequency for test is 11.0592MHz SPSTAT DATA 0CDH SPCTL DATA 0CEH SPDAT DATA 0CFH DATA...
  • Page 590: Slave Routine Of Single Master Single Slave Mode (Interrupt Mode)

    STC8A8K64D4 Series Manual P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H SETB SETB BUSY SPCTL,#50H ;Enable SPI master mode SPSTAT,#0C0H ;Clear interrupt flag IE2,#ESPI ;Enable SPI interrupt SETB LOOP: BUSY,$ SETB BUSY ;Pull down the slave SS pin SPDAT,#5AH ;Send test data LOOP...
  • Page 591 STC8A8K64D4 Series Manual SPSTAT = 0xc0; //Clear interrupt flag SPDAT = SPDAT; //Transmit the received data back to the master LED = !LED; //Test port void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00;...
  • Page 592: Master Routine Of Single Master Single Slave Mode (Polling Mode)

    STC8A8K64D4 Series Manual 0100H SPIISR: SPSTAT,#0C0H ;Clear interrupt flag SPDAT,SPDAT ;Transmit the received data back to the master RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H...
  • Page 593 STC8A8K64D4 Series Manual SPDAT 0xcf; 0xaf; #define ESPI 0x02 sbit P1^0; sbit P1^1; void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00;...
  • Page 594: Slave Routine Of Single Master Single Slave Mode (Polling Mode)

    STC8A8K64D4 Series Manual P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP MAIN 0100H MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H...
  • Page 595 STC8A8K64D4 Series Manual 0xaf; #define ESPI 0x02 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^1; void SPI_Isr() interrupt 9 SPSTAT = 0xc0; //Clear interrupt flag void main() P0M0 = 0x00;...
  • Page 596: Routine Of Mutual Master-Slave Mode (Interrupt Mode)

    STC8A8K64D4 Series Manual ESPI P1.1 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP...
  • Page 597 STC8A8K64D4 Series Manual #include "intrins.h" SPSTAT 0xcd; SPCTL 0xce; SPDAT 0xcf; 0xaf; #define ESPI 0x02 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0;...
  • Page 598 STC8A8K64D4 Series Manual SPCTL = 0x40; //Enable SPI slave modeand standby SPSTAT = 0xc0; //Clear interrupt flag IE2 = ESPI; //Enable SPI interrupt EA = 1; while (1) if (!KEY) //Wait for the key to trigger SPCTL = 0x50; //Enable SPI master mode SS = 0;...
  • Page 599: Routine Of Mutual Master-Slave Mode (Polling Mode)

    STC8A8K64D4 Series Manual ISREXIT MASTER: SETB ;Pull up the SS pin of the slave SPCTL,#40H ;Reset to slave and standby ISREXIT: RETI MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H...
  • Page 600 STC8A8K64D4 Series Manual #define ESPI 0x02 P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca; sbit P1^0; sbit P1^1; sbit P0^0; void main() P0M0 = 0x00; P0M1 = 0x00;...
  • Page 601 STC8A8K64D4 Series Manual else //Slave mode SPDAT = SPDAT; //Transmit the received data back to the master LED = !LED; //Test port Assembly code ;Operating frequency for test is 11.0592MHz SPSTAT DATA 0CDH SPCTL DATA 0CEH SPDAT DATA 0CFH DATA 0AFH ESPI P1.0...
  • Page 602 STC8A8K64D4 Series Manual SPCTL,#40H ;Enable SPI slave mode and standby SPSTAT,#0C0H ;Clear interrupt flag LOOP: KEY,SKIP ;Wait for the key to trigger SPCTL,#50H ;Enable SPI master mode ;Pull down the slave SS pin SPDAT,#5AH ;Send test data KEY,$ ;Wait for the keys to be released SKIP: A,SPSTAT ACC.7,LOOP...
  • Page 603: C Bus

    STC innovation: When the I C serial bus controller of STC works in slave mode, the falling edge signal of SDA pin can wake up the MCU which is in power-down mode. (Note: Due to the fast I C transmission speed, the first packet of data after the MCU wakes up is generally incorrect.)
  • Page 604: I 2 C Master Mode

    STC8A8K64D4 Series Manual 21.3 I C Master Mode 21.3.1 I2C Configuration Register (I2CCFG) Symbol Address I2CCFG FE80H ENI2C MSSL MSSPEED[5:0] ENI2C: I C function enable bit 0: disable I C function 1: enable I Cfunction MSSL: I C mode selection bit 0: Salve mode 1: Master mode MSSPEED[5:0]: I...
  • Page 605 STC8A8K64D4 Series Manual 0001: START command. Send a START signal. If the I C controller is in idle state currently, i.e. MSBUSY (I2CMSST.7) is 0, writing this command will make the controller enter the busy status, and the hardware will set the MSBUSY status bit automatically and start sending START signal.
  • Page 606: I 2 C Master Auxiliary Control Register (I2Cmsaux)

    STC8A8K64D4 Series Manual 0111: Reserved. 1000: Reserved. 1001: Start command + send data command + receive ACK command. This command is a combination of command 0001, command 0010 and command 0011. After wrting this command, the controller will execute these three commands in sequence. 1010: Send data command + receive ACK command.
  • Page 607 STC8A8K64D4 Series Manual MSACKO: In master mode, it is the ACK signal ready to be transmitted. When the “0101” command is sent to the MSCMD bit of I2CMSCR, the controller will read the datum of this bit automatically and send it as ACK to SDA. - 591 -...
  • Page 608: I 2 C Slave Mode

    STC8A8K64D4 Series Manual 21.4 I C Slave Mode 21.4.1 I C Slave Control Register (I2CSLCR) Symbol Address I2CSLCR FE83H ESTAI ERXI ETXI ESTOI SLRST ESTAI: interrupt enable bit when receiving START signal in slave mode. 0: disable interrupt when receiving START signal in slave mode. 1: enable interrupt when receiving START signal in slave mode.
  • Page 609: I 2 C Slave Address Register (I2Csladr)

    STC8A8K64D4 Series Manual TXIF: interrupt request bit after 1-byte datum transmission is completed in slave mode. After the I C controller in slave mode completes sending 1 byte of datum and receives a 1-bit ACK signal successfully, this bit is set by hardware automatically at the falling edge of the 9 clock and requests an interrupt to CPU.
  • Page 610: I 2 C Data Registers (I2Ctxd, I2Crxd)

    STC8A8K64D4 Series Manual slave address register MA (I2CSLADR.0) is 1, it means that the I2C slave can accept all device addresses. At this time, any device address sent by the host, that is, DATA0[7:1] is any value, the slave Can respond. When I2C device slave address register MA (I2CSLADR.0) When it is 0, the device address DATA0[7:1] sent by the host must be the same as the device address I2CSLADR[7:1] of the slave to access this slave device...
  • Page 611: Example Routines

    STC8A8K64D4 Series Manual 21.5 Example Routines 21.5.1 I C is Used to Access AT24C256 in Master Mode (Interrupt Mode) C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P_SW2 0xba; #define I2CCFG (*(unsigned char volatile xdata *)0xfe80) #define I2CMSCR (*(unsigned char volatile xdata *)0xfe81)
  • Page 612 STC8A8K64D4 Series Manual void SendData(char dat) I2CTXD = dat; //Write data to the data buffer busy = 1; I2CMSCR = 0x82; //Send a SEND command while (busy); void RecvACK() busy = 1; I2CMSCR = 0x83; //Send read ACK command while (busy); char RecvData() busy = 1;...
  • Page 613 STC8A8K64D4 Series Manual void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80;...
  • Page 614 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz P_SW2 DATA 0BAH I2CCFG XDATA 0FE80H I2CMSCR XDATA 0FE81H I2CMSST XDATA 0FE82H I2CSLCR XDATA 0FE83H I2CSLST XDATA 0FE84H I2CSLADR XDATA 0FE85H I2CTXD XDATA 0FE86H I2CRXD XDATA 0FE87H P1.4 P1.5 BUSY 20H.0 P0M1...
  • Page 615 STC8A8K64D4 Series Manual START: SETB BUSY A,#10000001B ;Send START command DPTR,#I2CMSCR MOVX @DPTR,A WAIT SENDDATA: DPTR,#I2CTXD ;Write data to the data buffer MOVX @DPTR,A SETB BUSY A,#10000010B ;Send a SEND command DPTR,#I2CMSCR MOVX @DPTR,A WAIT RECVACK: SETB BUSY A,#10000011B ;Send read ACK command DPTR,#I2CMSCR MOVX @DPTR,A...
  • Page 616 STC8A8K64D4 Series Manual R0,#0 R1,#0 DELAY1: DJNZ R1,DELAY1 DJNZ R0,DELAY1 MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P_SW2,#80H A,#11100000B ;Set the I2C module as master mode DPTR,#I2CCFG MOVX @DPTR,A...
  • Page 617: I 2 C Is Used To Access At24C256 In Master Mode At24C256 (Polling Mode)

    STC8A8K64D4 Series Manual CALL SENDDATA CALL RECVACK A,#000H ;Send storage address high byte CALL SENDDATA CALL RECVACK A,#000H ;Send storage address low byte CALL SENDDATA CALL RECVACK CALL START ;Send start command A,#0A1H ;Send device address + read command CALL SENDDATA CALL RECVACK...
  • Page 618 STC8A8K64D4 Series Manual P5M1 0xc9; P5M0 0xca; sbit P1^4; sbit P1^5; void Wait() while (!(I2CMSST & 0x40)); I2CMSST &= ~0x40; void Start() I2CMSCR = 0x01; //Send START command Wait(); void SendData(char dat) I2CTXD = dat; //Write data to the data buffer I2CMSCR = 0x02;...
  • Page 619 STC8A8K64D4 Series Manual void Delay() int i; for (i=0; i<3000; i++) _nop_(); _nop_(); _nop_(); _nop_(); void main() P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00;...
  • Page 620 STC8A8K64D4 Series Manual P0 = RecvData(); //Read data 1 SendACK(); P2 = RecvData(); //Read data 2 SendNAK(); Stop(); //Send stop command P_SW2 = 0x00; while (1); Assembly code ;Operating frequency for test is 11.0592MHz P_SW2 DATA 0BAH I2CCFG XDATA 0FE80H I2CMSCR XDATA 0FE81H...
  • Page 621 STC8A8K64D4 Series Manual RECVACK: A,#00000011B ;Send read ACK command DPTR,#I2CMSCR MOVX @DPTR,A WAIT RECVDATA: A,#00000100B ;Send RECV command DPTR,#I2CMSCR MOVX @DPTR,A CALL WAIT DPTR,#I2CRXD ;Read data from the data buffer MOVX A,@DPTR SENDACK: A,#00000000B ;Setup the ACK signal DPTR,#I2CMSST MOVX @DPTR,A A,#00000101B ;Send ACK command...
  • Page 622 STC8A8K64D4 Series Manual P1M0, #00H P1M1, #00H P2M0, #00H P2M1, #00H P3M0, #00H P3M1, #00H P4M0, #00H P4M1, #00H P5M0, #00H P5M1, #00H P_SW2,#80H A,#11100000B ;Set the I2C module as master mode DPTR,#I2CCFG MOVX @DPTR,A A,#00000000B DPTR,#I2CMSST MOVX @DPTR,A CALL START ;Send start command A,#0A0H...
  • Page 623: C Is Used To Access Pcf8563 In Master Mode

    STC8A8K64D4 Series Manual P2,A CALL SENDNAK CALL STOP ;Send stop command 21.5.3 I C is Used to Access PCF8563 in Master Mode C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P_SW2 0xba; #define I2CCFG (*(unsigned char volatile xdata *)0xfe80) #define I2CMSCR (*(unsigned char volatile xdata *)0xfe81)
  • Page 624 STC8A8K64D4 Series Manual void SendData(char dat) I2CTXD = dat; //Write data to the data buffer I2CMSCR = 0x02; //Send a SEND command Wait(); void RecvACK() I2CMSCR = 0x03; //Send read ACK command Wait(); char RecvData() I2CMSCR = 0x04; //Send RECV command Wait();...
  • Page 625 STC8A8K64D4 Series Manual P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; I2CCFG = 0xe0; //Enable I2C master mode I2CMSST = 0x00;...
  • Page 626 STC8A8K64D4 Series Manual I2CMSST XDATA 0FE82H I2CSLCR XDATA 0FE83H I2CSLST XDATA 0FE84H I2CSLADR XDATA 0FE85H I2CTXD XDATA 0FE86H I2CRXD XDATA 0FE87H P1.4 P1.5 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA...
  • Page 627 STC8A8K64D4 Series Manual MOVX @DPTR,A WAIT SENDNAK: A,#00000001B ;Setup the NAK signal DPTR,#I2CMSST MOVX @DPTR,A A,#00000101B ;Send ACK command DPTR,#I2CMSCR MOVX @DPTR,A WAIT STOP: A,#00000110B ;Send STOP command DPTR,#I2CMSCR MOVX @DPTR,A WAIT WAIT: DPTR,#I2CMSST ;Clear interrupt flag MOVX A,@DPTR ACC.6,WAIT A,#NOT 40H MOVX @DPTR,A...
  • Page 628: I 2 C Slave Mode (Polling Mode)

    STC8A8K64D4 Series Manual CALL START ;Send start command A,#0A2H CALL SENDDATA ;Send device address + write command CALL RECVACK A,#002H ;Send storage address CALL SENDDATA CALL RECVACK A,#00H ;Set second value CALL SENDDATA CALL RECVACK A,#00H ;Set minute value CALL SENDDATA CALL RECVACK...
  • Page 629 STC8A8K64D4 Series Manual P_SW2 0xba; #define I2CCFG (*(unsigned char volatile xdata *)0xfe80) #define I2CMSCR (*(unsigned char volatile xdata *)0xfe81) #define I2CMSST (*(unsigned char volatile xdata *)0xfe82) #define I2CSLCR (*(unsigned char volatile xdata *)0xfe83) #define I2CSLST (*(unsigned char volatile xdata *)0xfe84) #define I2CSLADR (*(unsigned char volatile xdata *)0xfe85)
  • Page 630 STC8A8K64D4 Series Manual else if (I2CSLST & 0x10) I2CSLST &= ~0x10; //Handle the SEND event if (I2CSLST & 0x02) I2CTXD = 0xff; //Stop receiving data when receiving NAK else I2CTXD = buffer[++addr]; //Continue reading data when receiving ACK else if (I2CSLST & 0x08) I2CSLST &= ~0x08;...
  • Page 631 STC8A8K64D4 Series Manual Assembly code ;Operating frequency for test is 11.0592MHz P_SW2 DATA 0BAH I2CCFG XDATA 0FE80H I2CMSCR XDATA 0FE81H I2CMSST XDATA 0FE82H I2CSLCR XDATA 0FE83H I2CSLST XDATA 0FE84H I2CSLADR XDATA 0FE85H I2CTXD XDATA 0FE86H I2CRXD XDATA 0FE87H P1.4 P1.5 ISDA 20H.0 ;Device address flag...
  • Page 632 STC8A8K64D4 Series Manual RETI STARTIF: A,#NOT 40H ;Handle the START event MOVX @DPTR,A ISREXIT RXIF: A,#NOT 20H ;Handle the RECV event MOVX @DPTR,A DPTR,#I2CRXD MOVX A,@DPTR ISDA,RXDA ISMA,RXMA R0,ADDR ;Handle the RECV event (RECV DATA) MOVX @R0,A ADDR ISREXIT RXDA: ISREXIT ;Handle the RECV event (RECV DEVICE ADDR) RXMA:...
  • Page 633: I 2 C Slave Mode (Polling Mode)

    STC8A8K64D4 Series Manual P4M1, #00H P5M0, #00H P5M1, #00H P_SW2,#80H A,#10000001B ;Enable I2C slave mode DPTR,#I2CCFG MOVX @DPTR,A A,#01011010B ;Set the slave device address to 5A ;That is, I2CSLADR[7:1]=010_1101B, MA=0B. ;Since MA is 0, the device address sent by the host must be ;...
  • Page 634 STC8A8K64D4 Series Manual #define I2CTXD (*(unsigned char volatile xdata *)0xfe86) #define I2CRXD (*(unsigned char volatile xdata *)0xfe87) P0M1 0x93; P0M0 0x94; P1M1 0x91; P1M0 0x92; P2M1 0x95; P2M0 0x96; P3M1 0xb1; P3M0 0xb2; P4M1 0xb3; P4M0 0xb4; P5M1 0xc9; P5M0 0xca;...
  • Page 635 STC8A8K64D4 Series Manual if (I2CSLST & 0x40) I2CSLST &= ~0x40; //Handle the START event else if (I2CSLST & 0x20) I2CSLST &= ~0x20; //Handle the RECV event if (isda) isda = 0; //Handle the RECV event (RECV DEVICE ADDR) else if (isma) isma = 0;...
  • Page 636 STC8A8K64D4 Series Manual P1.4 P1.5 ISDA 20H.0 ;Device address flag ISMA 20H.1 ;Storage address flag ADDR DATA P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA...
  • Page 637 STC8A8K64D4 Series Manual MOVX @DPTR,A SETB ISDA ;User variable initialization SETB ISMA ADDR,A R0,A MOVX A,@R0 DPTR,#I2CTXD MOVX @DPTR,A LOOP: DPTR,#I2CSLST ;Detect slave status MOVX A,@DPTR ACC.6,STARTIF ACC.5,RXIF ACC.4,TXIF ACC.3,STOPIF LOOP STARTIF: A,#NOT 40H ;Handle the START event MOVX @DPTR,A LOOP RXIF: A,#NOT 20H...
  • Page 638: Master Codes For Testing I

    STC8A8K64D4 Series Manual STOPIF: A,#NOT 08H ;Handle the STOP event MOVX @DPTR,A SETB ISDA SETB ISMA LOOP 21.5.6 Master Codes for testing I C Slave Mode C language code //Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" P_SW2 0xba;...
  • Page 639 STC8A8K64D4 Series Manual void SendData(char dat) I2CTXD = dat; //Write data to the data buffer I2CMSCR = 0x02; //Send a SEND command Wait(); void RecvACK() I2CMSCR = 0x03; //Send read ACK command Wait(); char RecvData() I2CMSCR = 0x04; //Send RECV command Wait();...
  • Page 640 STC8A8K64D4 Series Manual P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P5M0 = 0x00; P5M1 = 0x00; P_SW2 = 0x80; I2CCFG = 0xe0; //Enable I2C master mode I2CMSST = 0x00; Start(); //Send start command SendData(0x5a);...
  • Page 641 STC8A8K64D4 Series Manual P1.4 P1.5 P0M1 DATA 093H P0M0 DATA 094H P1M1 DATA 091H P1M0 DATA 092H P2M1 DATA 095H P2M0 DATA 096H P3M1 DATA 0B1H P3M0 DATA 0B2H P4M1 DATA 0B3H P4M0 DATA 0B4H P5M1 DATA 0C9H P5M0 DATA 0CAH 0000H LJMP...
  • Page 642 STC8A8K64D4 Series Manual DPTR,#I2CMSCR MOVX @DPTR,A WAIT STOP: A,#00000110B ;Send STOP command DPTR,#I2CMSCR MOVX @DPTR,A WAIT WAIT: DPTR,#I2CMSST ;Clear interrupt flag MOVX A,@DPTR ACC.6,WAIT A,#NOT 40H MOVX @DPTR,A DELAY: R0,#0 R1,#0 DELAY1: DJNZ R1,DELAY1 DJNZ R0,DELAY1 MAIN: SP, #5FH P0M0, #00H P0M1, #00H P1M0, #00H P1M1, #00H...
  • Page 643 STC8A8K64D4 Series Manual CALL RECVACK A,#12H ;Write test data 1 CALL SENDDATA CALL RECVACK A,#78H ;Write test data 2 CALL SENDDATA CALL RECVACK CALL STOP ;Send stop command CALL DELAY ;Waiting for the device to write data CALL START ;Send start command A,#5AH ;Send device address (010_1101B) + write command (0b) CALL...
  • Page 644: Lcm Interface

    STC8A8K64D4 Series Manual 22 LCM interface STC8A8K64D4 series of microcontrollers integrate an LCM interface controller, which can be used to drive the current popular LCD modules. It can drive I8080 interface and M6800 interface color screen, support 8-bit and 16-bit data width.
  • Page 645: Lcm Interface Configuration Register 2 (Lcmifcfg2)

    STC8A8K64D4 Series Manual Lowest (0) Lower (1) Higher (2) Highest (3) LCMIFDPS[1:0]: LCM interface data pin selection bit LCMIFDPS [1:0] D16_D8 High byte DAT[15:8] Low byte DAT[7:0] P2[7:0] P6[7:0] P2[7:0] P6[7:0] P2[7:0] P0[7:0] P6[7:0] P2[7:0] P2[7:0] P7[7:0] P6[7:0] P7[7:0] D16_D8: LCM interface data width control bit 0: 8-bit data width 1: 16-bit data width M68_I80: LCM interface mode selection bit...
  • Page 646: Lcm Interface Data Registers (Lcmifdatl, Lcmifdath)

    STC8A8K64D4 Series Manual LCMIFSTA FE53H LCMIFIF LCMIFIF: LCM interface interrupt request flag, needs to be cleared by software 22.2.5 LCM interface Data Registers (LCMIFDATL, LCMIFDATH) Symbol Address LCMIFDATL FE54H LCMIFDAT[7:0] LCMIFDATH FE55H LCMIFDAT[15:8] LCMIFDAT: LCM interface data register When the data width is 8 bits, only the LCMDATL data is valid. When the data width is 16 bits, it is combined into 16-bit data by LCMDATL and LCMDATH.
  • Page 647: Lcm Interface Timing Diagram

    STC8A8K64D4 Series Manual 22.3 LCM interface timing diagram Note: T =1 system clock ready = (SETUPT +1) system clocks setup = (HOLDT+1) system clocks hold 22.3.1 I8080 mode ‘1’ Data DAT ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ Setup time T setup Preparation Holding time T...
  • Page 648 STC8A8K64D4 Series Manual High ‘1’ impedance Data DAT state ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ Setup time T setup Preparation Holding time T hold time T ready Read command (CMD=110B) High ‘1’ impedance Data DAT state ‘0’ ‘1’ ‘0’ ‘1’...
  • Page 649: M6800 Mode

    STC8A8K64D4 Series Manual 22.3.2 M6800 mode ‘1’ Data DAT ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ Setup time T setup Preparation Holding time T hold time T ready Send command (CMD=100B) ‘1’ Data DAT ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ ‘1’ ‘0’...
  • Page 650 STC8A8K64D4 Series Manual ‘1’ Data DAT ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ Setup time T setup Preparation Holding time T hold time T ready Read command (CMD=110B) ‘1’ Data DAT ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ ‘1’ ‘0’ Setup time T setup Preparation Holding time T...
  • Page 651: Dma

    STC8A8K64D4 Series Manual 23 DMA STC8A8K64D4 series of microcomputers support the function of batch data storage, that is, traditional DMA. The following DMA operations are supported: ⚫ M2M_DMA: read and write data from XRAM memory to XRAM memory ⚫ ADC_DMA: automatically scan the enabled ADC channels and automatically store the converted ADC data into XRAM ⚫...
  • Page 652 STC8A8K64D4 Series Manual UR1T_DMA Total Bytes Need to be FA33H 0000,0000 DMA_UR1T_AMT Transferred UR1T_DMA Transfer Completed FA34H 0000,0000 DMA_UR1T_DONE Bytes UR1T_DMA Send High Address FA35H 0000,0000 DMA_UR1T_TXAH UR1T_DMA Send Low Address FA36H 0000,0000 DMA_UR1T_TXAL UR1R_DMA Configuration FA38H UR1RIE UR1RIP[1:0] UR1RPTY[1:0] 0xxx,0000 DMA_UR1R_CFG Register...
  • Page 653: Data Read And Write Between Memory And Memory (M2M_Dma)

    STC8A8K64D4 Series Manual LCM_DMA Send High Address FA75H 0000,0000 DMA_LCM_TXAH LCM_DMA Send Low Address FA76H 0000,0000 DMA_LCM_TXAL LCM_DMA Receive High Address FA77H 0000,0000 DMA_LCM_RXAH LCM_DMA Receive Low Address FA78H 0000,0000 DMA_LCM_RXAL 23.2 Data read and write between memory and memory (M2M_DMA) 23.2.1 M2M_DMA Configuration Register (DMA_M2M_CFG) Symbol Address...
  • Page 654: M2M_Dma Transfer Complete Byte Register (Dma_M2M_Done)

    STC8A8K64D4 Series Manual DMA_M2M_AMT FA03H DMA_M2M_AMT: number bytes that need read write data. Note: The actual number of bytes read and written is (DMA_M2M_AMT+1), that is, when DMA_M2M_AMT is set to 0, 1 byte is read and written, and when DMA_M2M_AMT is set to 255, 256 bytes are read and written.
  • Page 655: Adc Automatic Data Storage (Adc_Dma)

    STC8A8K64D4 Series Manual 23.3 ADC Automatic Data Storage (ADC_DMA) 23.3.1 ADC_DMA Configuration Register (DMA_ADC_CFG) Symbol Address DMA_ADC_CFG FA10H ADCIE ADCIP[1:0] ADCPTY[1:0] ADCIE: ADC_DMA interrupt enable control bit 0: Disable ADC_DMA interrupt 1: Enable ADC_DMA interrupt ADCIP[1:0]: ADC_DMA interrupt priority control bits ADCIP[1:0] Interrupt priority Lowest (0) Lower (1)
  • Page 656: Adc_Dma Channel Enable Registers (Dma_Adc_Chswx)

    STC8A8K64D4 Series Manual CVTIMESEL[3:0] Number of ADC conversions 0xxx 1000 1001 1010 1011 1100 1101 1110 1111 23.3.6 ADC_DMA Channel Enable Registers (DMA_ADC_CHSWx) Symbol Address DMA_ADC_CHSW0 FA1AH CH15 CH14 CH13 CH12 CH11 CH10 DMA_ADC_CHSW1 FA1BH CHn: The ADC channel to be scanned automatically when setting ADC_DMA operation. Channel scanning always starts from the lower-numbered channel.
  • Page 657: Data Storage Format Of Adc_Dma

    STC8A8K64D4 Series Manual 23.3.7 Data storage format of ADC_DMA Note: ADC conversion speed and conversion result alignment are set by ADC related registers. XRAM[DMA_ADC_RXA+0] = high byte of the 1st ADC conversion result of the 1st enabled channel; XRAM[DMA_ADC_RXA+1] = low byte of the 1st ADC conversion result of the 1st enabled channel; XRAM[DMA_ADC_RXA+2] = high byte of the 2nd ADC conversion result of the 1st enabled channel;...
  • Page 658: Data Exchange Between Spi And Memory (Spi_Dma)

    STC8A8K64D4 Series Manual The form is as follows: Offset address Data channel high byte of the 1st ADC conversion result of the 1st enabled channel low byte of the 1st ADC conversion result of the 1st enabled channel high byte of the 2nd ADC conversion result of the 1st enabled channel low byte of the 2nd ADC conversion result of the 1st enabled channel 2n-2 high byte of the nth ADC conversion result of the 1st enabled channel...
  • Page 659: Spi_Dma Control Register (Dma_Spi_Cr)

    STC8A8K64D4 Series Manual 0: Disable SPI_DMA to send data. In master mode, SPI only sends clock to SCLK port, but does not read data from XRAM, nor send data to MOSI port; in slave mode, SPI does not read data from XRAM, nor send data to MISO port.
  • Page 660: Spi_Dma Transfer Total Byte Register (Dma_Spi_Amt)

    STC8A8K64D4 Series Manual 23.4.4 SPI_DMA transfer total byte register (DMA_SPI_AMT) Symbol Address DMA_SPI_AMT FA23H DMA_SPI_AMT: number bytes that need read write data. Note: The actual number of bytes read and written is (DMA_SPI_AMT+1), that is, when DMA_SPI_AMT is set to 0, 1 byte is transferred, and when DMA_SPI_AMT is set to 255, 256 bytes are transferred. 23.4.5 SPI_DMA transfer complete byte register (DMA_SPI_DONE) Symbol Address...
  • Page 661: Data Exchange Between Uart1 And Memory (Ur1T_Dma,Ur1R_Dma)

    STC8A8K64D4 Series Manual 23.5 Data exchange between UART1 and memory (UR1T_DMA, UR1R_DMA) 23.5.1 UR1T_DMA Configuration Register (DMA_UR1T_CFG) Symbol Address DMA_UR1T_CFG FA30H UR1TIE UR1TIP[1:0] UR1TPTY[1:0] UR1TIE: UR1T_DMA interrupt enable control bit 0: Disable UR1T_DMA interrupt 1: Enable UR1T_DMA interrupt UR1TIP[1:0]: UR1T_DMA interrupt priority control bits UR1TIP[1:0] Interrupt priority Lowest (0)
  • Page 662: Ur1T_Dma Transfer Complete Byte Register (Dma_Ur1T_Done)

    STC8A8K64D4 Series Manual 23.5.5 UR1T_DMA transfer complete byte register (DMA_UR1T_DONE) Symbol Address DMA_UR1T_DONE FA34H DMA_UR1T_DONE: The number of bytes that have been sent so far. 23.5.6 UR1T_DMA Send Address Registers (DMA_UR1T_TXAx) Symbol Address DMA_UR1T_TXAH FA35H ADDR[15:8] DMA_UR1T_TXAL FA36H ADDR[7:0] DMA_UR1T_TXA: Set the source address of automatic data transmission. Data is read from this address when performing a UR1T_DMA operation.
  • Page 663: Ur1R_Dma Transfer Total Byte Register (Dma_Ur1R_Amt)

    STC8A8K64D4 Series Manual UR1RIF to 1. If the UR1R_DMA interrupt is enabled, it will enter the interrupt service routine. The flag bit needs to be cleared by software RXLOSS: UR1R_DMA receive data discard flag. During the UR1R_DMA operation, when the XRAM bus is too busy to clear the receive FIFO of the UR1R_DMA and the data received by the UR1R_DMA is automatically discarded, the hardware will automatically set RXLOSS to 1.
  • Page 664: Data Exchange Between Uart2 And Memory (Ur2T_Dma,Ur2R_Dma)

    STC8A8K64D4 Series Manual 23.6 Data exchange between UART2 and memory (UR2T_DMA, UR2R_DMA) 23.6.1 UR2T_DMA Configuration Register (DMA_UR2T_CFG) Symbol Address DMA_UR2T_CFG FA40H UR2TIE UR2TIP[1:0] UR2TPTY[1:0] UR2TIE: UR2T_DMA interrupt enable control bit 0: Disable UR2T_DMA interrupt 1: Enable UR2T_DMA interrupt UR2TIP[1:0]: UR2T_DMA interrupt priority control bits UR2TIP[1:0] Interrupt priority Lowest (0)
  • Page 665: Ur2T_Dma Transfer Complete Byte Register (Dma_Ur2T_Done)

    STC8A8K64D4 Series Manual 23.6.5 UR2T_DMA transfer complete byte register (DMA_UR2T_DONE) Symbol Address DMA_UR2T_DONE FA44H DMA_UR2T_DONE: The number of bytes that have been sent so far. 23.6.6 UR2T_DMA Send Address Registers (DMA_UR2T_TXAx) Symbol Address DMA_UR2T_TXAH FA45H ADDR[15:8] DMA_UR2T_TXAL FA46H ADDR[7:0] DMA_UR2T_TXA: Set the source address of automatic data transmission. Data is read from this address when performing a UR2T_DMA operation.
  • Page 666: Ur2R_Dma Transfer Total Byte Register (Dma_Ur2R_Amt)

    STC8A8K64D4 Series Manual UR2RIF: UR2R_DMA interrupt request flag bit. When UR2R_DMA receives data, the hardware will automatically set UR2RIF to 1. If the UR2R_DMA interrupt is enabled, it will enter the interrupt service routine. The flag bit needs to be cleared by software RXLOSS: UR2R_DMA receive data discard flag.
  • Page 667: Data Exchange Between Uart3 And Memory (Ur3T_Dma,Ur3R_Dma)

    STC8A8K64D4 Series Manual 23.7 Data exchange between UART3 and memory (UR3T_DMA, UR3R_DMA) 23.7.1 UR3T_DMA Configuration Register (DMA_UR3T_CFG) Symbol Address DMA_UR3T_CFG FA50H UR3TIE UR3TIP[1:0] UR3TPTY[1:0] UR3TIE: UR3T_DMA interrupt enable control bit 0: Disable UR3T_DMA interrupt 1: Enable UR3T_DMA interrupt UR3TIP[1:0]: UR3T_DMA interrupt priority control bits UR3TIP[1:0] Interrupt priority Lowest (0)
  • Page 668: Ur3T_Dma Transfer Complete Byte Register (Dma_Ur3T_Done)

    STC8A8K64D4 Series Manual 23.7.5 UR3T_DMA transfer complete byte register (DMA_UR3T_DONE) Symbol Address DMA_UR3T_DONE FA54H DMA_UR3T_DONE: The number of bytes that have been sent so far. 23.7.6 UR3T_DMA Send Address Registers (DMA_UR3T_TXAx) Symbol Address DMA_UR3T_TXAH FA55H ADDR[15:8] DMA_UR3T_TXAL FA56H ADDR[7:0] DMA_UR3T_TXA: Set the source address of automatic data transmission. Data is read from this address when performing a UR3T_DMA operation.
  • Page 669: Ur3R_Dma Transfer Total Byte Register (Dma_Ur3R_Amt)

    STC8A8K64D4 Series Manual UR3RIF to 1. If the UR3R_DMA interrupt is enabled, it will enter the interrupt service routine. The flag bit needs to be cleared by software RXLOSS: UR3R_DMA receive data discard flag. During the UR3R_DMA operation, when the XRAM bus is too busy to clear the receive FIFO of the UR3R_DMA and the data received by the UR3R_DMA is automatically discarded, the hardware will automatically set RXLOSS to 1.
  • Page 670: Data Exchange Between Uart4 And Memory (Ur4T_Dma,Ur4R_Dma)

    STC8A8K64D4 Series Manual 23.8 Data exchange between UART4 and memory (UR4T_DMA, UR4R_DMA) 23.8.1 UR4T_DMA Configuration Register (DMA_UR4T_CFG) Symbol Address DMA_UR4T_CFG FA50H UR4TIE UR4TIP[1:0] UR4TPTY[1:0] UR4TIE: UR4T_DMA interrupt enable control bit 0: Disable UR4T_DMA interrupt 1: Enable UR4T_DMA interrupt UR4TIP[1:0]: UR4T_DMA interrupt priority control bits UR4TIP[1:0] Interrupt priority Lowest (0)
  • Page 671: Ur4T_Dma Transfer Complete Byte Register (Dma_Ur4T_Done)

    STC8A8K64D4 Series Manual 23.8.5 UR4T_DMA transfer complete byte register (DMA_UR4T_DONE) Symbol Address DMA_UR4T_DONE FA54H DMA_UR4T_DONE: The number of bytes that have been sent so far. 23.8.6 UR4T_DMA Send Address Registers (DMA_UR4T_TXAx) Symbol Address DMA_UR4T_TXAH FA55H ADDR[15:8] DMA_UR4T_TXAL FA56H ADDR[7:0] DMA_UR4T_TXA: Set the source address of automatic data transmission. Data is read from this address when performing a UR4T_DMA operation.
  • Page 672: Ur4R_Dma Transfer Total Byte Register (Dma_Ur4R_Amt)

    STC8A8K64D4 Series Manual UR4RIF to 1. If the UR4R_DMA interrupt is enabled, it will enter the interrupt service routine. The flag bit needs to be cleared by software RXLOSS: UR4R_DMA receive data discard flag. During the UR4R_DMA operation, when the XRAM bus is too busy to clear the receive FIFO of the UR4R_DMA and the data received by the UR4R_DMA is automatically discarded, the hardware will automatically set RXLOSS to 1.
  • Page 673: Data Exchange Between Lcm And Memory (Lcm_Dma)

    STC8A8K64D4 Series Manual 23.9 Data exchange between LCM and memory (LCM_DMA) 23.9.1 LCM_DMA Configuration Register (DMA_LCM_CFG) Symbol Address DMA_LCM_CFG FA70H LCMIE ACT_TX ACT_RX LCMIP[1:0] LCMPTY[1:0] LCMIE: LCM_DMA interrupt enable control bit 0: Disable LCM_DMA interrupt 1: Enable LCM_DMA interrupt LCMIP [1:0]: LCM_DMA interrupt priority control bits LCMIP[1:0] Interrupt priority Lowest (0)
  • Page 674: Lcm_Dma Transfer Total Byte Register (Dma_Lcm_Amt)

    STC8A8K64D4 Series Manual 23.9.4 LCM_DMA transfer total byte register (DMA_LCM_AMT) Symbol Address DMA_LCM_AMT FA73H DMA_LCM_AMT: number bytes that need read written. Note: The actual number of bytes read and written is (DMA_LCM_AMT+1), that is, when DMA_LCM_AMT is set to 0, 1 byte is transferred, and when DMA_LCM_AMT is set to 255, 256 bytes are transferred.
  • Page 675: Example Routines

    STC8A8K64D4 Series Manual 23.10 Example Routines 23.10.1 UART1 interrupt mode and computer transceiver test - DMA receive timeout interrupt C language code //Operating frequency for test is 11.0592MHz /************* Function Description ************** UART1 works in full-duplex interrupt mode to send and receive data. PC sends data to the MCU, and the MCU will automatically store the received data in the DMA space.
  • Page 676 STC8A8K64D4 Series Manual void main(void) u16 i; P0M1 = 0x00; P0M0 = 0x00; //set as quasi-bidirectional port P1M1 = 0x00; P1M0 = 0x00; //set as quasi-bidirectional port P2M1 = 0x00; P2M0 = 0x00; //set as quasi-bidirectional port P3M1 = 0x00; P3M0 = 0x00; //set as quasi-bidirectional port P4M1 = 0x00;...
  • Page 677 STC8A8K64D4 Series Manual for(i=0;i<Rx_cnt;i++) UartPutc(DMABuffer[i]); printf("\r\n"); Rx_cnt = 0; DMA_UR1R_CR = 0xa1; //bit7 1:Enable UART1_DMA, //bit5 1:Start UART1_DMA automatic reception, //bit0 1:clear FIFO void DMA_Config(void) P_SW2 = 0x80; DMA_UR1T_CFG = 0x80; //bit7 1:Enable Interrupt DMA_UR1T_STA = 0x00; DMA_UR1T_AMT = DMA_AMT_LEN; //Set total bytes to be transferred :...
  • Page 678 STC8A8K64D4 Series Manual TR1 = 0; AUXR &= ~0x01; //S1 BRT Use Timer1; AUXR |= (1<<6); //Timer1 set as 1T mode TMOD &= ~(1<<6); //Timer1 set As Timer TMOD &= ~0x30; //Timer1_16bitAutoReload; TH1 = (u8)((65536UL - (MAIN_Fosc / 4) / Baudrate1) / 256); TL1 = (u8)((65536UL - (MAIN_Fosc / 4) / Baudrate1) % 256);...
  • Page 679 STC8A8K64D4 Series Manual DMA_UR1T_STA &= ~0x01; DMATxFlag = 1; if (DMA_UR1T_STA & 0x04) //data coverage DMA_UR1T_STA &= ~0x04; if (DMA_UR1R_STA & 0x01) //Receive complete DMA_UR1R_STA &= ~0x01; DMARxFlag = 1; if (DMA_UR1R_STA & 0x02) //data is discarded DMA_UR1R_STA &= ~0x02; //File: ISR.ASM //Interrupts with interrupt numbers greater than 31 require interrupt entry address remapping processing CSEG...
  • Page 680: Uart1 Interrupt Mode And Computer Transceiver Test - Dma Data Check

    STC8A8K64D4 Series Manual CSEG 01BBH ;U3RXDMA_VECTOR U3RXDMA_ISR CSEG 01C3H ;U4TXDMA_VECTOR U4TXDMA_ISR CSEG 01CBH ;U4RXDMA_VECTOR U4RXDMA_ISR CSEG 01D3H ;LCMDMA_VECTOR LCMDMA_ISR CSEG 01DBH ;LCMIF_VECTOR LCMIF_ISR P0INT_ISR: P1INT_ISR: P2INT_ISR: P3INT_ISR: P4INT_ISR: P5INT_ISR: P6INT_ISR: P7INT_ISR: P8INT_ISR: P9INT_ISR: M2MDMA_ISR: ADCDMA_ISR: SPIDMA_ISR: U1TXDMA_ISR: U1RXDMA_ISR: U2TXDMA_ISR: U2RXDMA_ISR: U3TXDMA_ISR: U3RXDMA_ISR: U4TXDMA_ISR:...
  • Page 681 STC8A8K64D4 Series Manual When downloading, select the clock 22.1184MHz (users can modify the frequency by themselves). ******************************************/ #include "stdio.h" #include "STC8Hxxxxx.h" #include "crc16.h" #define MAIN_Fosc 22118400L // Define the main clock (accurately calculate 115200 baud rate) #define Baudrate1 115200L #define DMA_AMT_LEN ///Set total bytes to be transferred(0~255) :...
  • Page 682 STC8A8K64D4 Series Manual 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,...
  • Page 683 STC8A8K64D4 Series Manual if((DMATxFlag) && (DMARxFlag)) CheckSum = crc16_ccitt(DMABuffer,DMA_AMT_LEN-1); if(((u8)CheckSum == DMABuffer[DMA_AMT_LEN-1]) && ((u8)(CheckSum>>8) == DMABuffer[DMA_AMT_LEN])) printf("\r\nOK! CheckSum = %04x\r\n",CheckSum); else printf("\r\nERROR! CheckSum = %04x\r\n",CheckSum); DMATxFlag = 0; DMA_UR1T_CR = 0xc0; //bit7 1:Enable UART1_DMA, //bit6 1:Start UART1_DMA automatic transmission DMARxFlag = 0; DMA_UR1R_CR = 0xa1;...
  • Page 684 STC8A8K64D4 Series Manual //Other values: Use Timer1 as baud rate generator. /*********** Use Timer2 as baud rate generator *****************/ if(brt == 2) AUXR |= 0x01; //S1 BRT Use Timer2; SetTimer2Baudraye(65536UL - (MAIN_Fosc / 4) / Baudrate1); /*********** Use Timer1 as baud rate generator *****************/ else TR1 = 0;...
  • Page 685 STC8A8K64D4 Series Manual //File: ISR.ASM //Interrupts with interrupt numbers greater than 31 require interrupt entry address remapping processing CSEG 012BH ;P0INT_VECTOR P0INT_ISR CSEG 0133H ;P1INT_VECTOR P1INT_ISR CSEG 013BH ;P2INT_VECTOR P2INT_ISR CSEG 0143H ;P3INT_VECTOR P3INT_ISR CSEG 014BH ;P4INT_VECTOR P4INT_ISR CSEG 0153H ;P5INT_VECTOR P5INT_ISR CSEG...
  • Page 686 STC8A8K64D4 Series Manual P6INT_ISR: P7INT_ISR: P8INT_ISR: P9INT_ISR: M2MDMA_ISR: ADCDMA_ISR: SPIDMA_ISR: U1TXDMA_ISR: U1RXDMA_ISR: U2TXDMA_ISR: U2RXDMA_ISR: U3TXDMA_ISR: U3RXDMA_ISR: U4TXDMA_ISR: U4RXDMA_ISR: LCMDMA_ISR: LCMIF_ISR: 006BH Code testing method According to the predefined DMA packet length (for example: 256 bytes), send a packet of data (254 bytes) through the serial port tool, and add a 2-byte CCITT-CRC16 check code at the end: After the MCU receives the entire packet of data (256 bytes), it performs CRC16 check on the first 254 bytes of data, and the obtained check code is compared with the last two bytes.
  • Page 687 STC8A8K64D4 Series Manual If the checksum values are not equal, print "ERROR!" and the calculated checksum. - 671 -...
  • Page 688: Enhanced Dual Data Pointer

    STC8A8K64D4 Series Manual 24 Enhanced Dual Data Pointer Two 16-bit data pointers are integrated in STC8A8K64D4 series of microcontrollers. The data pointers can be increased or decreased automatically by the program control, and they can be switched automatically. 24.1 Related special function registers Bit Address and Symbol Reset Symbol...
  • Page 689: Data Pointer Control Register (Ta)

    STC8A8K64D4 Series Manual Instructions related to TSL include: DPTR,#data16 DPTR MOVC A,@A+DPTR MOVX A,@DPTR MOVX @DPTR,A AU1/AU0: Enable DPTR1 / DPTR0 Automatic increment / decrement control bit 0: disable Automatic increment / decrement function 1: enable Automatic increment / decrement function Note: In write-protect mode, AU0 and AU1 can not be enabled individually.
  • Page 690: Example Routines

    STC8A8K64D4 Series Manual 24.2 Example Routines 24.2.1 Example Routine 1 Copy 4 bytes of data stored in program space 1000H to 1003H in reverse to 0100H to 0103H of the extended RAM, that is, C:1000H -> X:0103H C:1001H -> X:0102H C:1002H ->...
  • Page 691: Example Routine 2

    STC8A8K64D4 Series Manual ; When done, DPTR1 decrements automatically and select DPTR0 as the current DPTR DJNZ R7,COPY_NEXT SJMP 24.2.2 Example Routine 2 Send the data stored in the extended RAM 0100H to 0103H to P0 port successively. Assembly code ;Operating frequency for test is 11.0592MHz P0M1 DATA...
  • Page 692 STC8A8K64D4 Series Manual ;and then DPTR0 increments automatically P0,A ; output the datum to Port0 MOVX A,@DPTR ; Read data from XRAM indicated by DPTR0, ;and then DPTR0 increments automatically P0,A ; output the datum to Port0 MOVX A,@DPTR ; Read data from XRAM indicated by DPTR0, ;and then DPTR0 increments automatically P0,A ;...
  • Page 693: Mdu16 Hardware 16-Bit Multiplier And Divider

    STC8A8K64D4 Series Manual 25 MDU16 Hardware 16-bit Multiplier and Divider A 16-bit hardware multiply / divide unit MDU16 is integrated in some microcontrollers of the STC8A8K64D4 series. The following data operations are supported: ➢ Data standardization (need 3-20 clocks of computing time) ➢...
  • Page 694: Mdu Mode Control Register (Arcon)

    STC8A8K64D4 Series Manual Multiplier: {MD5,MD4} Product: {MD3,MD2,MD1,MD0} 32-bit logical shift left / logical shift right Operand: {MD3,MD2,MD1,MD0} 32-bit data normalization: Operand: {MD3,MD2,MD1,MD0} 25.1.3 MDU Mode Control Register (ARCON) Symbol Address ARCON FCF6H MODE[2:0] SC[4:0] MODE[2:0]: MDU mode selection MODE[2:0] Mode Clocks Desciption Logical right...
  • Page 695: Netizens' Application Of Mdu16 (Provide Ideas, For Reference Only)

    STC8A8K64D4 Series Manual 29.2 Netizens' application of MDU16 (provide ideas, for reference only) Netizen 1: "Data normalization is illustrated with the following simple example" There is a 7-digit decimal precision data: 0.0000123. Due to the limited data bit width, if you need to use the bit width effectively, you need to shift the previous data to the left.
  • Page 696 STC8A8K64D4 Series Manual 16-bit integer multiplication and a very small amount of 32-bit multiplication and division. In this way, our early digital cameras were possible. Secondly, the various template processing common in PS image processing also uses the two-dimensional matrix convolution method, which also requires a huge amount of integers (8- bit image image size requires 16-bit and 32-bit intermediate calculation results) Multiplication Adding calculations, using discrete convolution will greatly improve the operation speed.
  • Page 697: Example Routines

    STC8A8K64D4 Series Manual 25.3 Example Routines C Language code ;Operating frequency for test is 11.0592MHz #include "reg51.h" #include "intrins.h" #define MD3U32 (*(unsigned long volatile xdata *)0xfcf0) #define MD3U16 (*(unsigned int volatile xdata *)0xfcf0) #define MD1U16 (*(unsigned int volatile xdata *)0xfcf2) #define MD5U16 (*(unsigned int volatile xdata *)0xfcf4)
  • Page 698: Appendix A Stc Emulator User Guide

    A: How to include header files in Keil environment Q: After installing the driver and header files according to the steps shown below, select the STC corresponding MCU model when creating a new project, and directly use "#include <stc8a8k64d4.h>" in the source file to complete the inclusion of the header file.
  • Page 699 2. Create a project in Keil If the driver installation is successful in the first step, there will be an option of "STC MCU Database" in selecting the chip model when creating a new project in Keil as shown below.
  • Page 700 STC8A8K64D4 Series Manual Add source code files to the project, as shown below: Save the project. If there is no error while compiling the project, you can set the following projects. - 684 -...
  • Page 701 17 bytes of RAM have the ID number and related test parameters, if you need to use this part of the data in the program, you must not define IDATALEN as 256. 3. Project settings, select STC simulation driver. - 685 -...
  • Page 702 As shown above, enter the project setting page firstly, select the "Debug" setting page, select the hardware emulation "Use…" on the right, and select "STC Monitor-51 Driver" in the emulation driver drop-down list. And then click the "Settings" button to enter the following setting screen. Set the port number and baud rate of the serial port. The baud rate is generally 115200.
  • Page 703 STC8A8K64D4 Series Manual Prepare a STC8A series or STC8F series chip, and connect it to the serial port of the computer through the download board. Then select the correct chip model as shown above, and enter the "Keil simulation settings" page, click the button of the corresponding model.
  • Page 704 STC8A8K64D4 Series Manual 6. During the simulation process, the viewing of the register During the simulation process, you can view the MCU-related registers. All registers are listed at the bottom of the "Debug" menu. As shown below: - 688 -...
  • Page 705 STC8A8K64D4 Series Manual At the bottom of the "Debug" menu in the picture above, there is also a small black triangle, which indicates that there are hidden items (mainly due to the display layout size) Drag the mouse on the small triangle to automatically drag out all the items, as shown below: - 689 -...
  • Page 706 STC8A8K64D4 Series Manual Simulation considerations: 1. The simulation monitoring program occupies the two ports P3.0/P3.1, but does not occupy the serial port 1. The user can switch the serial port 1 to P3.6/P3.7 or P1.6/P1.7 to be used. 2. The simulation monitoring program occupies the last 768 bytes of the internal extended RAM (XDATA), and the user cannot write to XDATA in this area .
  • Page 707: Appendix B How To Test I/O Ports

    STC8A8K64D4 Series Manual Appendix B How to Test I/O Ports Test I/O port steps: 1. Select the microcontroller model 2. Set the operating frequency of the test program (24MHz) 3. Open the "Example Program" page 4. Select the "I/O port test" program of STC8G or STC8H series 5.
  • Page 708: Appendix C How To Make The Traditional 8051 Mcu Evb Emulatable

    STC8A8K64D4 Series Manual Appendix C How to Make the Traditional 8051 MCU EVB Emulatable The traditional 8051 microcontroller EVB does not have simulation function. To enable the traditional 8051 microcontroller EVB to be simulated, a conversion board is needed. The physical picture of the conversion board is shown below.
  • Page 709 STC8A8K64D4 Series Manual This conversion board can be used for STC8H series LQFP48 to STC89C52RC / STC89C58RD + series simulation. The following figure is a functional diagram of the conversion board. RxD3/AD0/ADC8/PWM00/P0.0 TxD3/AD1/ADC9/PWM01/P0.1 P0.0/PWM00/ADC8/AD0/RxD3 RxD4/AD2/ADC10/PWM02/P0.2 P0.1/PWM01/ADC9/AD1/TxD3 P0.2/PWM02/ADC10/AD2/RxD4 TxD4/AD3/ADC11/PWM03/P0.3 T3/AD4/ADC12/PWM04/P0.4 P0.3/PWM03/ADC11/AD3/TxD4 T3CLKO/AD5/ADC13/PWM05/P0.5 P0.4/PWM04/ADC12/AD4/T3 PWMFLT2/T4/AD6/ADC14/PWM06/P0.6...
  • Page 710: Appendix D Stc-Usb Driver Installation Instructions

    STC8A8K64D4 Series Manual Appendix STC-USB Driver Installation Instructions Installation Instructions in Windows XP Open the STC-ISP download software of V6.79 (or later). The download software will copy the driver files to the relevant system directory automatically. - 694 -...
  • Page 711 STC8A8K64D4 Series Manual Plug in the USB device, the system will pop up the following dialog box automatically after finding the device, select "No, not this time". - 695 -...
  • Page 712 STC8A8K64D4 Series Manual Select "Install software automatically (recommended)" in the dialog below. - 696 -...
  • Page 713 STC8A8K64D4 Series Manual In the following dialog box that pops up, select the "Continue Anyway" button. - 697 -...
  • Page 714 STC8A8K64D4 Series Manual The system will automatically install the driver when connected, as shown below - 698 -...
  • Page 715 STC8A8K64D4 Series Manual The following dialog box appears to indicate that the driver installation is complete. - 699 -...
  • Page 716 STC8A8K64D4 Series Manual Now, the serial number list in the previously opened STC-ISP download software will select the inserted USB device automatically and display the device name as "STC USB Writer (USB1)", as shown below. - 700 -...
  • Page 717 STC8A8K64D4 Series Manual Installation Instructions in Windows 7 (32-bit) Open the STC-ISP download software of V6.79 (or later). The download software will copy the driver files to the relevant system directory automatically. - 701 -...
  • Page 718 STC8A8K64D4 Series Manual Plug in the USB device, and the system will install the driver automatically when it finds the device. After the installation is complete, the following prompt box will appear. - 702 -...
  • Page 719 STC8A8K64D4 Series Manual Now, the serial port number list in the previously opened STC-ISP download software will select the inserted USB device automatically and display the device name as "STC USB Writer (USB1)", as shown below. Note: If the system does not install the driver automatically in Windows 7, please refer to the installation method of Windows 8 (32-bit) for the driver installation method.
  • Page 720 By default, the driver without digital signature cannot be successfully installed in Windows 7 64-bit operating system. So, you need to follow the steps below before installing the STC-USB driver, skip the digital signature temporarily, and the installation will be successful.
  • Page 721 STC8A8K64D4 Series Manual Plug in the USB device and open the Device Manager. Find the USB device with a yellow exclamation mark in the device list, in the device's right-click menu, select "Update Driver Software". - 705 -...
  • Page 722 STC8A8K64D4 Series Manual Select "Browse my computer for driver software" in the dialog below. - 706 -...
  • Page 723 STC8A8K64D4 Series Manual Click the "Browse" button in the dialog below to find the directory of the previous STC-USB driver stored (for example: the previous example directory is "D:\STC-USB", locate the path to the actual decompression directory). - 707 -...
  • Page 724 STC8A8K64D4 Series Manual When the driver installation starts, the following dialog box will pop up, select "Always install this driver software". - 708 -...
  • Page 725 STC8A8K64D4 Series Manual Next, the system will install the driver automatically, as shown below. - 709 -...
  • Page 726 STC8A8K64D4 Series Manual The following dialog box appears to indicate that the driver installation is complete. - 710 -...
  • Page 727 STC8A8K64D4 Series Manual Now in the device manager, the device with the yellow exclamation mark before will be displayed as the device name of "STC USB Low Speed Writer". - 711 -...
  • Page 728 STC8A8K64D4 Series Manual The serial number list in the previously downloaded STC-ISP download software will select the inserted USB device automatically and display the device name as "STC USB Writer (USB1)", as shown below. - 712 -...
  • Page 729 Firstly, download "stc-isp-15xx-v6.79.zip" (or newer version) from the STC official website, and decompress it to the local disk after downloading, then the STC-USB driver file will also be decompressed to the "STC-USB Driver" folder of the current folder. (For example, decompress the downloaded compressed file" stc-isp-15xx-v6.79.zip "to"...
  • Page 730 STC8A8K64D4 Series Manual Plug in the USB device and open the Device Manager. Find the USB device with a yellow exclamation mark in the device list, in the device's right-click menu, select "Update Driver Software". - 714 -...
  • Page 731 STC8A8K64D4 Series Manual Select "Browse my computer for driver software" in the dialog below. - 715 -...
  • Page 732 STC8A8K64D4 Series Manual Click the "Browse" button in the dialog below to find the directory where the STC-USB driver was stored (for example: the previous example directory is "F: \ STC-USB Driver", locate the path to the actual decompression directory) .
  • Page 733 STC8A8K64D4 Series Manual When the driver installation begins, the following dialog box will pop up, select "Always install this driver software". - 717 -...
  • Page 734 STC8A8K64D4 Series Manual Next, the system will install the driver automatically, as shown below. - 718 -...
  • Page 735 STC8A8K64D4 Series Manual The following dialog box appears to indicate that the driver installation is complete. - 719 -...
  • Page 736 STC8A8K64D4 Series Manual Now in the device manager, the device with the yellow exclamation mark before will be displayed as the device name of "STC USB Low Speed Writer". - 720 -...
  • Page 737 STC8A8K64D4 Series Manual The serial number list in the previously downloaded STC-ISP download software will select the inserted USB device automatically and display the device name as "STC USB Writer (USB1)", as shown below: - 721 -...
  • Page 738 By default, the driver without digital signature cannot be successfully installed in Windows 8 64-bit operating system. So, you need to follow the steps below before installing the STC-USB driver, skip the digital signature temporarily, and the installation will be successful.
  • Page 739 STC8A8K64D4 Series Manual Then select the "Change PC settings" item in the settings window. - 723 -...
  • Page 740 STC8A8K64D4 Series Manual In the computer settings, select the "Start Now" button under the "Advanced Startup" item in the "General" property page. - 724 -...
  • Page 741 STC8A8K64D4 Series Manual In the window below, select the "Troubleshooting" item. - 725 -...
  • Page 742 STC8A8K64D4 Series Manual Then select "Advanced Options" in "Troubleshooting". - 726 -...
  • Page 743 STC8A8K64D4 Series Manual In the "Advanced Options" window below, select "Startup Settings". - 727 -...
  • Page 744 STC8A8K64D4 Series Manual In the "Startup Settings" window below, click the "Restart" button to restart the computer. - 728 -...
  • Page 745 STC8A8K64D4 Series Manual After the computer restarts, it will enter the "Startup Settings" window automatically as shown in the figure below. Press the number key "7" or press the function key "F7" to select "Disable driver forcing signature" to start. After booting to Windows 8, follow the Windows 8 (32-bit) installation method to complete the driver installation.
  • Page 746 STC8A8K64D4 Series Manual Installation Instructions in Windows 8.1 (64-bit) Windows 8.1 has different method for entering the advanced boot menu with respect to Windows 8, which is specifically explained here. Firstly, move the mouse to the lower right corner of the screen and select the "Settings" button. - 730 -...
  • Page 747 STC8A8K64D4 Series Manual Then select the "Change PC settings" item in the settings window. - 731 -...
  • Page 748 STC8A8K64D4 Series Manual In the computer settings, select "Update and Recovery" (this is not the same as Windows 8, which is "General"). - 732 -...
  • Page 749 STC8A8K64D4 Series Manual Select the "Restore" property page in the update and recovery page, and click the "Start Now" button under the "Advanced Startup" item. - 733 -...
  • Page 750 STC8A8K64D4 Series Manual The following steps are the same as those of Window 8. In the window below, select the "Troubleshooting" item. - 734 -...
  • Page 751 STC8A8K64D4 Series Manual Then select "Advanced Options" in "Troubleshooting". - 735 -...
  • Page 752 STC8A8K64D4 Series Manual In the "Advanced Options" window below, select "Startup Settings". - 736 -...
  • Page 753 STC8A8K64D4 Series Manual In the "Startup Settings" window below, click the "Restart" button to restart the computer. - 737 -...
  • Page 754 STC8A8K64D4 Series Manual After the computer restarts, it will enter the "Startup Settings" window automatically as shown in the figure below. Press the number key "7" or press the function key "F7" to select "Disable driver forcing signature" to start. After booting to Windows 8, follow the Windows 8 (32-bit) installation method to complete the driver installation.
  • Page 755 Before installing the driver, you need to extract the "STC-USB Driver" folder to the hard disk from the STC-ISP download software package downloaded from the STC official website. Prepare the chip with USB download function, but don't connect the computer firstly.
  • Page 756 STC8A8K64D4 Series Manual Then select the "Update and Security" item in the settings window. - 740 -...
  • Page 757 STC8A8K64D4 Series Manual Then select the "Restore" item in the settings window. - 741 -...
  • Page 758 STC8A8K64D4 Series Manual In the recovery window, click the "Restart Now" button in the "Advanced Startup" item. - 742 -...
  • Page 759 STC8A8K64D4 Series Manual Before the computer restarts, the system will enter the following boot menu firstly and select the "Troubleshooting" item. - 743 -...
  • Page 760 STC8A8K64D4 Series Manual Select "Advanced Options" in the troubleshooting window. - 744 -...
  • Page 761 STC8A8K64D4 Series Manual Then select "View more recovery options". - 745 -...
  • Page 762 STC8A8K64D4 Series Manual Select the "Startup Settings" item. - 746 -...
  • Page 763 STC8A8K64D4 Series Manual When the following screen appears, click the "Restart" button to restart the computer. - 747 -...
  • Page 764 STC8A8K64D4 Series Manual After the computer restarts, the "Startup Settings" window will pop up. Press the "F7" button to select the "Prohibit driver forcing signature" item. - 748 -...
  • Page 765 STC8A8K64D4 Series Manual After the computer is started, connect the prepared chip to the computer with a USB cable and open the "Device Manager". Now, the driver has not yet been installed, so it will appear as an unknown device with an exclamation point in the Device Manager.
  • Page 766 STC8A8K64D4 Series Manual Right-click the unknown device and select "Update Driver" from the right-click menu. - 750 -...
  • Page 767 STC8A8K64D4 Series Manual In the pop-up driver installer selection screen, select the "Browse my computer for driver software" item. - 751 -...
  • Page 768 STC8A8K64D4 Series Manual In the following window, click the "Browse" button. - 752 -...
  • Page 769 STC8A8K64D4 Series Manual Find the "STC-USB Driver" directory that was previously extracted to your hard disk, select the "64" directory in the directory, and press "OK" button. - 753 -...
  • Page 770 STC8A8K64D4 Series Manual Click "Next" to start the driver installation. During the driver installation process, the following warning screen will pop up, select "Always install this driver software". - 754 -...
  • Page 771 STC8A8K64D4 Series Manual When the following screen appears, the driver is successfully installed. - 755 -...
  • Page 772 STC8A8K64D4 Series Manual Back to the download software of STC-ISP, "STC USB Writer (USB1)" in the "Serial Port Number" drop-down list is selected automatically at this time, you can use USB for ISP download. - 756 -...
  • Page 773: Appendix E Download Step Demo Using Usb

    GND, and then connect the system to the USB port on the PC side. Open the ISP to download the software, and the serial number of the downloaded software will search for the "STC USB Writer (USB1)" USB device automatically.
  • Page 774 STC8A8K64D4 Series Manual 2. Open the user code program. - 758 -...
  • Page 775 STC8A8K64D4 Series Manual 3. Click the "Download / Program" button to start downloading the user code. - 759 -...
  • Page 776 STC8A8K64D4 Series Manual 4. Until the prompt "Operation succeeded", it means that the program code download is complete. - 760 -...
  • Page 777: Appendix F Rs485 Automatic Control Or I/O Port Control Circuit Diagram

    STC8A8K64D4 Series Manual Appendix F RS485 Automatic control or I/O port control circuit diagram 1. Use the USB to serial port to connect the computer's RS485 to control the download circuit diagram (automatic control or I/O port control) 2. Use RS232 to serial port to connect the computer's RS485 to control the download circuit diagram (automatic control or I/O port control) - 761 -...
  • Page 778: Appendix G Stc Tool Instruction Manual

    Appendix G STC tool instruction manual G.1 Overview U8W/U8W-Mini is a series of programming tools that integrates online download and offline download. STC Universal USB to Serial Port Tool is a programming tool that supports online download and online simulation.
  • Page 779: Usb Type Online/Offline Download Tool U8W/U8W-Mini

    G.3 USB type online/offline download tool U8W/U8W-Mini The application range of U8W/U8W-Min can support all current MCU series of STC, and the Flash program space and EEPROM data space are not restricted. Support includes the following and upcoming STC full series chips: The offline download tool can be used for downloading without the computer, and can be used for mass production and remote upgrades.
  • Page 780 STC8A8K64D4 Series Manual In addition, some wires and tools are used together as follows, such as: (1) Two-end male USB cable (shown on the left in the figure below) and USB-Micro cable (shown on the right in the figure below): Note: This USB cable is a USB enhanced cable specially customized by our company, which can ensure that the download can be successful when directly powered by USB.
  • Page 781: Install U8W/U8W-Mini Driver

    Obtain the driver by downloading the STC-ISP software package The following is the download location of the STC-ISP software package provided on the STC official website (www.STCMCUDATA.com): After downloading, decompress, the path of CH340 driver installation package is stc-isp-15xx-v6.87K\USB to UART...
  • Page 782 STC8A8K64D4 Series Manual Download the driver manually through STC's official website or in the latest STC-ISP download software Download the driver manually on the official website of STC or in the latest STC-ISP download software. The download link driver programmer...
  • Page 783: U8W Function Introduction

    STC8A8K64D4 Series Manual Then use the USB cable provided by STC to connect the U8W/U8W-Mini download board to the computer, open the device manager of the computer, and under the port device category, if there is a device similar to "USB-SERIAL CH340 (COMx)", it means U8W/U8W-Mini can be used normally.
  • Page 784: U8W Online Download Instructions

    The target chip is installed on the U8W locking base and connected to the computer by U8W for online download First use the USB cable provided by STC to connect the U8W to the computer, and then install the target MCU on the...
  • Page 785 STC8A8K64D4 Series Manual Then use STC-ISP to download the software to download the program, the steps are as follows: 1 Select the MCU model; 2 Select the number of pins. When the chip is directly installed on the U8W to download, be sure to select the correct number of pins, otherwise the download will fail;...
  • Page 786 Firstly, use the USB cable provided by STC to connect U8W to the computer, and then connect U8W to the target MCU of the user system through the download line. The connection method is shown in the following figure: Then use STC-ISP to download the software to download the program, the steps are as follows: 1.
  • Page 787: U8W Offline Download Instructions

    The steps to use USB to power U8W for offline download are as follows: (1) Use the USB cable provided by STC to connect the U8W download board to the computer, as shown below: (2) Set up in the STC-ISP download software according to the steps shown in the figure below:...
  • Page 788 U8W download tool. It is recommended that users use the latest version of STC-ISP to download the software (please always pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com. It is strongly recommended that users download the software from the official website http://www.STCMCUDATA.com).
  • Page 789 U8W for offline download. The steps for offline download using USB to supply power to U8W are as follows: (1) Use the USB cable provided by STC to connect the U8W download board to the computer, as shown below: - 773 -...
  • Page 790 (2) Set up in the STC-ISP download software according to the steps shown in the figure below: It is recommended that users use the latest version of STC-ISP to download the software (please always pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com. It is strongly recommended that users download the software from the official website http://www.STCMCUDATA.com).
  • Page 791 (1) Firstly, use the USB cable provided by STC to connect the U8W download board to the computer, as shown below: (2) Set up in the STC-ISP download software according to the steps shown in the figure below:...
  • Page 792 STC8A8K64D4 Series Manual 1. Select the MCU model; 2. Select the number of pins. When the chip is directly installed on the U8W to download, be sure to select the correct number of pins, otherwise the download will fail; 3. Select the serial port number corresponding to U8W; 4.
  • Page 793 (1) Firstly, use the USB cable provided by STC to connect the U8W download board to the computer, as shown below: (2) Set up in the STC-ISP download software according to the steps shown in the figure below: It is recommended that users use the latest version of STC-ISP to download the software (please always pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com.
  • Page 794 STC8A8K64D4 Series Manual 1. Select the MCU model; 2. Select the number of pins. When the chip is directly installed on the U8W to download, be sure to select the correct number of pins, otherwise the download will fail; 3. Select the serial port number corresponding to U8W; 4.
  • Page 795: U8W-Mini's Function Introduction

    STC8A8K64D4 Series Manual During the downloading process, the 4 LEDs on the U8W download tool will be displayed in marquee mode. After the download is complete, if the download is successful, the 4 LEDs will be on and off at the same time; if the download fails, all the 4 LEDs will be off.
  • Page 796: U8W-Mini Online Download Instructions

    Firstly, use the USB cable provided by STC to connect the U8W-Mini to the computer, and then connect the U8W-Mini to the target MCU of the user system through the download cable. The connection method is shown in the following...
  • Page 797: U8W-Mini Offline Download Instructions

    4 LEDs will be off. It is recommended that users use the latest version of STC-ISP to download the software (please pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com. It is strongly recommended that users download the software on the official website http://www.STCMCUDATA.com).
  • Page 798 U8W-Mini download tool. It is recommended that users use the latest version of STC-ISP to download the software (please pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com. It is strongly recommended that users download the software from the official website http://www.STCMCUDATA.com).
  • Page 799 The target chip is connected to the U8W-Mini by the user system lead, and the U8W-Mini is powered by the user system for offline download. (1) Firstly, use the USB cable provided by STC to connect the U8W-Mini download board to the computer, as shown below:...
  • Page 800 U8W-Mini download tool. It is recommended that users use the latest version of STC-ISP to download the software (please pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com. It is strongly recommended that users download the software from the official website http://www.STCMCUDATA.com)
  • Page 801 The target chip is connected to U8W-Mini by the user system lead, and U8W-Mini and the user system are independently powered for offline download. (1) Firstly, use the USB cable provided by STC to connect the U8W-Mini download board to the computer, as shown below:...
  • Page 802 U8W-Mini download tool. It is recommended that users use the latest version of STC-ISP to download the software (please pay attention to the updates of the STC-ISP download software on the STC official website http://www.STCMCUDATA.com. It is strongly recommended that users download the software from the official website http://www.STCMCUDATA.com).
  • Page 803 Then click the "Set U8W/U8-5V/U8-3V as the offline download master chip" button on the "U8W Offline/Online" page in the STC-ISP download program, as shown in the figure below: (Note: Be sure to select The serial port corresponding to U8W)
  • Page 804 STC8A8K64D4 Series Manual When the following screen appears, it indicates that the U8W control chip is made: After the production is completed, do not forget to dial the "Update/Download Selection Interface" of U8W back to the "Burn User Program" mode, and power on the U8W download tool again, as shown in the figure below: (Otherwise, programming will not be performed normally ) - 788 -...
  • Page 805 STC8A8K64D4 Series Manual G.3.9 U8W/U8W-Mini set through mode (can be used for simulation) To use U8W/U8-Mini for simulation, you must first set U8W/U8-Mini to pass-through mode. The method of U8W/U8W-Mini to realize USB to serial port pass-through mode is as follows: 1.
  • Page 806 STC8A8K64D4 Series Manual P3.6 Start signal Automatic burning tool P1.5 Completion signal Sorter signal P5.4 OK signal (good signal) P3.7 ERROR signal (defective product signal) P2.5 Buzzer (BEEP) control High effective (sound at high level) Reference circuit diagram for power control part: Reference circuit diagram of Flash control part: This Flash memory is required when the user program is larger than 41K The reference circuit diagram of the button part:...
  • Page 807 STC8A8K64D4 Series Manual Reference circuit diagram of serial port communication pin connection part: G.4 STC Universal USB to Serial Tool G.4.1 Appearance of STC Universal USB to Serial Tool Front: Back: - 791 -...
  • Page 808 For STC microcontrollers, if you want to perform ISP download, you must receive the serial port command at power- on reset to start executing the ISP program, so the correct steps to download the program to the MCU using the STC...
  • Page 809 5. Open the target file (HEX format or BIN format); 6. Click the "download/program" button in the ISP download software; 7. Press the "power switch" on the STC Universal USB to Serial Tool to power the MCU, and the download can start. 【Cold start burning】...
  • Page 810 Then the driver installation successful dialog box pops up, click the "OK" button to complete the installation: G.4.4 Use STC universal USB to serial port tool to download program to 1. Use the STC universal USB to serial port tool to connect the MCU to be burned to the computer: 2. Open the STC-ISP software;...
  • Page 811 3. Select the model corresponding to the burning chip; 4. Select the serial port number recognized by the STC universal USB to serial tool (when the STC universal USB to serial tool is correctly connected to the computer, the software will automatically scan and identify the serial port named "USB-SERIAL CH340 (COMx)", the specific COM The number will vary from computer to computer).
  • Page 812 G.4.5 Use STC universal USB to serial port tool to simulate user code The current STC simulation is based on the Keil environment, so if you need to use the STC universal USB to serial port tool to simulate user code, you must install the Keil software.
  • Page 813 STC8A8K64D4 Series Manual After pressing, the following screen will appear: Locate the directory to the installation directory of the Keil software, and then confirm. After the installation is successful, the following prompt box will pop up: - 797 -...
  • Page 814 You can see the following files in the relevant directory of Keil, which means that the driver is installed correctly. Since in the default state, the main control chip of STC is not an emulation chip and has no emulation function, if simulation is needed, the main control chip of STC needs to be set as an emulation chip.
  • Page 815 STC8A8K64D4 Series Manual Then click the "Set the selected target MCU as an emulation chip" button on the "Keil Simulation Settings" page in the right functional area of the software,After pressing, the following screen will appear: - 799 -...
  • Page 816 STC8A8K64D4 Series Manual Next, you need to press the "power switch" on the STC Universal USB to Serial Tool to supply power to the MCU [cold start], and you can start to make the simulation chip. If the setting is successful, the following screen will appear:...
  • Page 817 STC8A8K64D4 Series Manual At this point, the simulation chip has been made successfully. Next we open a project for simulation: Then make the following project settings: An additional note: When a C language project is created and the startup file "STARTUP.A51" is added to the project, there is a macro definition named "IDATALEN", which is used to define the size of IDATA.
  • Page 818 Step 5: Set the port number and baud rate of the serial port. The serial port number should be the serial port corresponding to the STC universal USB to serial port tool. The baud rate is generally 115200 or 57600.
  • Page 819 STC8A8K64D4 Series Manual After finishing all the above work, you can press "Ctrl+F5" in Keil software to start simulation debugging. If the hardware connection is correct, you will enter a debugging interface similar to the following, and display the current simulation driver version number and the current simulation monitoring code firmware version number in the command output window, as shown in the following figure: During the simulation debugging process, you can perform multiple operations such as resetting, running at full speed, single stepping, and setting breakpoints.
  • Page 820: Application Circuit Diagram

    STC8A8K64D4 Series Manual As shown in the figure above, multiple breakpoints can be set in the program, and the maximum number of breakpoint settings currently allowed is 20 (in theory, any number can be set, but setting too many breakpoints will affect the speed of debugging).
  • Page 821 STC8A8K64D4 Series Manual G.5.2 STC Universal USB to Serial Tool Application Reference Circuit Diagram - 805 -...
  • Page 822 STC8A8K64D4 Series Manual Appendix H STC Emulation Instruction Manual H.1 Overview All STC8G/8H series microcontrollers support online emulation, including downloading user code, chip reset, full-speed operation, single-step operation, setting breakpoints (the number of theoretical breakpoints is unlimited, but in order to improve the emulation efficiency, the current limit is up to 20 breakpoints), viewing variables, etc. The emulation operation is convenient for users to debug the code and find logical errors in the code, thereby shortening the project development cycle.
  • Page 823 STC8A8K64D4 Series Manual H.2 Install Keil software The emulation of STC microcontroller is based on the Keil development environment, so before the emulation, the Keil software must be installed. The C51 and C251 development kits can be downloaded from the addresses shown in the figure below Note: The latest Keil-UV5 software does not include 8051 and 80251 toolkits by default, and must be downloaded and installed manually.
  • Page 824 STC8A8K64D4 Series Manual H.3 Install the emulation driver After the Keil development environment is installed, you also need to install the STC-specific emulation driver. Proceed as follows: Firstly, download the latest STC-ISP download software from the STC official website After downloading and unzipping, open the "stc-isp-vxx.exe" executable in the package.
  • Page 825 STC8A8K64D4 Series Manual - 809 -...
  • Page 826 STC8A8K64D4 Series Manual In the pop-up "Browse Folder" window, select the Keil installation directory (usually Keil's installation directory is "c:\keil"), click OK, if "STC MCU model added successfully" pops up, it means the driver has been installed. . - 810 -...
  • Page 827 H.4.1 Make serial port emulation chip When the STC microcontroller is shipped, the emulation function is disabled by default. If you want to use the emulation function, you need to use the STC-ISP download software to set the target microcontroller as the emulation chip.
  • Page 828 STC8A8K64D4 Series Manual - 812 -...
  • Page 829 STC8A8K64D4 Series Manual After the download is complete, the emulation chip is completed. - 813 -...
  • Page 830 STC8A8K64D4 Series Manual H.4.2 Serial port emulation settings in Keil software Open the project file in Keil software, and click "Options for ..." in the right-click menu as shown in the figure below. - 814 -...
  • Page 831 STC8A8K64D4 Series Manual In the project options, follow the steps shown in the figure below to set the serial port emulation. Note: Please select the serial port according to the actual connection, and the baud rate is generally 115200. - 815 -...
  • Page 832 STC8A8K64D4 Series Manual H.4.3 Emulation using serial port in Keil software In the Keil environment, after editing the source code and compiling without errors, the emulationcan be started. - 816 -...
  • Page 833 STC8A8K64D4 Series Manual If the chip making and connection are correct, the emulation driver version will be displayed as shown in the figure above, and the user code can be downloaded to the microcontroller correctly, and then debugging functions such as running, single step, and breakpoint can be performed.
  • Page 834 If "STC USB Writer (HID1)" can be automatically scanned in the ISP software, it means the connection is correct. Next, in the STC-ISP download software, follow the steps shown in the figure below to set up the emulation chip. - 818 -...
  • Page 835 STC8A8K64D4 Series Manual - 819 -...
  • Page 836 STC8A8K64D4 Series Manual After the download is complete, it will be as shown below. - 820 -...
  • Page 837 After the production is completed, the grounding switch of the P3.2 port needs to be disconnected, and the MCU needs to be powered on again. If the "STC\USB-ICE" device can be detected in the "HID Assistant" in the downloaded software, it means that the USB emulation The chip was made successfully.
  • Page 838 STC8A8K64D4 Series Manual H.5.2 USB emulation settings in Keil software Open the project file in Keil software, and click "Options for ..." in the right-click menu as shown in the figure below. - 822 -...
  • Page 839 STC8A8K64D4 Series Manual In the project options, follow the steps shown in the figure below to set the USB emulation. - 823 -...
  • Page 840 STC8A8K64D4 Series Manual H.5.3 Emulation using USB in Keil software In the Keil environment, after editing the source code and compiling without errors, the emulation can be started. - 824 -...
  • Page 841 STC8A8K64D4 Series Manual If the chip making and connection are correct, the emulation driver version will be displayed as shown in the figure above, and the user code can be downloaded to the microcontroller correctly, and then debugging functions such as running, single step, and breakpoint can be performed.
  • Page 842: Download Tool

    STC8A8K64D4 Series Manual Appendix I Partial Circuit of RS485 in U8W Download Tool BOM list: Label Model Package Note SP3485EN SOP8 RS485 chip 0603 Resistor R107 3.3K 0603 Resistor R108 3.3K 0603 Resistor R109 3.3K 0603 Resistor R112 0603 Resistor R113 0603 Resistor...
  • Page 843 STC8A8K64D4 Series Manual Appendix J ISP Download Starts Automatically After Receiving User Command While Running User Program (no Power-down) "User-defined download" and "user-defined encrypted download" are two completely different functions. Compared with the function of user-defined encrypted download, the function of user-defined download is simpler. The specific functions is: Before the computer or offline download board starts to send the real ISP download programming handshake command, it first sends a user-defined string of commands (for this string of serial commands, user can set the baud rate, parity, and stop bits), and then immediately sends the ISP download programming handshake...
  • Page 844 STC8A8K64D4 Series Manual - 828 -...
  • Page 845 (In-System-Programming) program uses the IAP function to upgrade the user’s program online, but for the sake of user code safety, neither the underlying code nor the upper application is open source. For this reason, STC launched With the IAP series single-chip microcomputer, that is, the Flash space of the entire MCU, users can rewrite in their own programs, so that the idea that users need to develop their own ISP programs can be realized.
  • Page 846 STC8A8K64D4 Series Manual 0000 User program area 62.5K F9FF FA00 0.5K User ISP area FBFF FC00 0.5K reset entry map area FDFF FE00 User parameter area 0.5K (not runnable code) FFFF In the FLASH space, the continuous 62.5K bytes of space starting from address 0000H is the user program area. When the specific download conditions are met, the user is required to jump the PC to the user ISP program area.
  • Page 847 STC8A8K64D4 Series Manual ISP Code (assembly code) ; Operating frequency for test is 11.0592MHz UARTBAUD 0FFE8H ;Define the serial port baud rate (65536-11059200/4/115200) AUXR DATA 08EH ;Additional Function Control Register WDT_CONTR DATA 0C1H ;Watchdog Control Register IAP_DATA DATA 0C2H ;IAP data register IAP_ADDRH DATA 0C3H...
  • Page 848 STC8A8K64D4 Series Manual IAP_ADDRL,#0 ;First write the “LJMP ISP_ENTRY” instruction at the starting address of page 2 IAP_ADDRH,#02H LCALL ISP_ERASEIAP A,#02H LCALL ISP_PROGRAMIAP ;Programming User Code Reset Vector Code A,#HIGH ISP_ENTRY LCALL ISP_PROGRAMIAP ;Programming User Code Reset Vector Code A,#LOW ISP_ENTRY LCALL ISP_PROGRAMIAP ;Programming User Code Reset Vector Code...
  • Page 849 STC8A8K64D4 Series Manual LCALL ISP_RECVUART LCALL ISP_PROGRAMIAP ;0002 IAP_ADDRL,#03H ;User code start address IAP_ADDRH,#00H ISP_PROGRAMNEXT: LCALL ISP_RECVUART ;receive code data LCALL ISP_PROGRAMIAP ;Program the data into the user code area DPTR A,DPL A,DPH ISP_PROGRAMNEXT ;length detection ISP_SOFTRESET: IAP_CONTR,#20H ;Software reset system SJMP ISP_ENTRY: WDT_CONTR,#17H...
  • Page 850 STC8A8K64D4 Series Manual LCALL ISP_RECVACK ;Receive response data LJMP ISP_DOWNLOAD ;Jump to download interface GOTOAP: ; Reset SFR to reset value TCON,A TMOD,A TL0,A TH0,A TL1,A TH1,A SCON,A AUXR,A LJMP APENTRY ; Run the user program normally ISP_RECVACK: LCALL ISP_RECVUART GOTOAP A,#7FH ISP_RECVACK...
  • Page 851 STC8A8K64D4 Series Manual ISP_PROGRAMIAP: WDT_CONTR,#17H ;clear watchdog IAP_CMD,#2 ; programming command IAP_DATA,A ; send the current data to IAP data register IAP_TRIG,#5AH ; Trigger ISP command IAP_TRIG,#0A5H A,IAP_ADDRL ;IAP address +1 A,#01H IAP_ADDRL,A A,IAP_ADDRH ADDC A,#00H IAP_ADDRH,A APENTRY LJMP RESET The ISP code includes the following external interface modules: ISP_DOWNLOAD: program download entry address, absolute address FA00H...
  • Page 852 STC8A8K64D4 Series Manual if (cnt7f >= 16) IspProgram(); // Invoke the download module (****important statement ****) else cnt7f = 0; RI = 0; // Clear the reception completion flag void main() SCON = 0x50; // Define the serial port mode as 8-bit, variable baud rate, no parity AUXR = 0x40;...
  • Page 853 STC8A8K64D4 Series Manual A,SBUF CJNE A,#7FH,ISNOT7F CNT7F A,CNT7F CJNE A,#16,UARTISR_EXIT LJMP ISPPROGRAM ; Invoke the download module (****important statement ****) ISNOT7F: CNT7F,#0 UARTISR_EXIT: RETI START: R0,#7FH ;Clear RAM @R0,A DJNZ R0,$-1 SP,#7FH ; Initialize SP SCON,#50H ; Set UART mode (8-bit data, variable baud rate, no parity bit) AUXR,#15H ;...
  • Page 854 STC8A8K64D4 Series Manual In the C code, you must define a function pointer variable, and assign this variable to 0xFA00, and then call, as shown below: Step 4, the host computer application program description The program of the upper computer is a dialog box project based on MFC. The access to the serial port is to directly call the API function of Windows without using the serial port control, which saves the registration of the control and many problems of system version incompatibility.
  • Page 855 STC8A8K64D4 Series Manual 2. Select the serial port number, set the same serial port baud rate as the lower computer 3. Open the source data file to be downloaded, either in Bin or Intel hex format 4. Click the "download data" button to start downloading data The sixth step, how to use the firmware of the lower computer The target file of the lower computer has two "IAPISP.hex"...
  • Page 856 STC8A8K64D4 Series Manual - 840 -...
  • Page 857 Use P3.0 port to detect serial port start signal The serial port ISP of the STC microcontroller uses P3.0 and P3.1. When the ISP download software starts to download, it will send a handshake command to the P3.0 port of the microcontroller. If the user's P3.0 and P3.1 are only used for ISP download, you can use the P3.0 port to detect the start signal of the serial port to judge the ISP...
  • Page 858 Reset, so method C is to verify the serial port data. When STC's ISP download software performs ISP download, it will first use the lowest baud rate (usually 2400) + even parity 9+1 stop bit to continuously send the handshake command 7F, so the user can set the serial port to 9 in the program Bit data bit + 2400 baud rate, and then continue to detect 7F.
  • Page 859 If the user code needs to use the serial port for communication, the above 3 methods may not be applicable. At this time, you can use the interface provided by the STC ISP download software to customize a set of dedicated user download commands (you can specify the baud rate, Check bit and stop bit).
  • Page 860 STC8A8K64D4 Series Manual area to realize the ISP function without power failure. The following assumes that the user download command is the string "STCISP$", the serial port is set to 115200 baud rate, no parity bit and 1 stop bit. The settings in the ISP download software are as follows: User sample code is as follows: C Language Code // Operating frequency for test is 11.0592MHz...
  • Page 861 STC8A8K64D4 Series Manual if (RI) RI = 0; dat = SBUF; switch (stage) case 0: default: L_Check1st: if (dat == 'S') stage = 1; else stage = 0; break; case 1: if (dat == 'T') stage = 2; else goto L_Check1st; break;...
  • Page 862 STC8A8K64D4 Series Manual stage = 0; while (1) // User codes - 846 -...
  • Page 863 STC8A8K64D4 Series Manual Appendix M Example Routine of ISP download for STC8A8K64D4 series MCUs using third-party MCU C language code /*Note: When using this code to download the STC8A8K64D4 series of microcontrollers, you must execute the Download code before powering on the target chip, otherwise the target chip will not download correctly.*/ #include "reg51.h"...
  • Page 864 STC8A8K64D4 Series Manual void Initial(void); void DelayXms(WORD x); BYTE UartSend(BYTE dat); void CommInit(void); void CommSend(BYTE size); BOOL Download(BYTE *pdat, long size); // Main function entry void main(void) P3M0 = 0x00; P3M1 = 0x00; Initial(); if (Download(DEMO, 256)) // download successfully P3 = 0xff;...
  • Page 865 STC8A8K64D4 Series Manual if (Counter100-- == 0) Counter100 = 100; if (TimeOut) TimeOut--; // Serial port interrupt service routine void uart(void) interrupt 4 static WORD RecvSum; static BYTE RecvIndex; static BYTE RecvCount; BYTE dat; if (TI) TI = 0; UartBusy = FALSE; if (RI) RI = 0;...
  • Page 866 STC8A8K64D4 Series Manual case 8: if (dat != 0x16) goto L_CheckFirst; UartReceived = TRUE; UartRecvStep++; break; L_CheckFirst: case 0: default: CommInit(); UartRecvStep = (dat == 0x46 ? 1 : 0); break; // system initialization void Initial(void) UartBusy = FALSE; SCON = 0xd0; // Serial data format must be 8-bit data + 1-bit even check AUXR = 0xc0;...
  • Page 867 STC8A8K64D4 Series Manual void CommInit(void) UartRecvStep = 0; TimeOut = 20; UartReceived = FALSE; // Send serial communication packets void CommSend(BYTE size) WORD sum; BYTE i; UartSend(0x46); UartSend(0xb9); UartSend(0x6a); UartSend(0x00); sum = size + 6 + 0x6a; UartSend(size + 6); for (i=0;...
  • Page 868 STC8A8K64D4 Series Manual TxBuffer[1] = arg; TxBuffer[2] = 0x40; TxBuffer[3] = HIBYTE(RL(MAXBAUD)); TxBuffer[4] = LOBYTE(RL(MAXBAUD)); TxBuffer[5] = 0x00; TxBuffer[6] = 0x00; TxBuffer[7] = 0x97; CommSend(8); while (1) if (TimeOut == 0) return FALSE; if (UartReceived) if (RxBuffer[0] == 0x01) break; return FALSE;...
  • Page 869 //// If you write the hardware option, the MCU's internal IRC frequency will be fixed to 24MHz, //// and other options will be restored to the factory settings. ////Suggestion: Set the hardware options of the slave chip when you use STC-ISP download software the first time. //// Do not write hardware options when downloading programs from the master chip to the slave chip.
  • Page 870 STC8A8K64D4 Series Manual //while (1) if (TimeOut == 0) return FALSE; if (UartReceived) if ((RxBuffer[0] == 0x04) && (RxBuffer[1] == 'T')) break; return FALSE; // Download completed return TRUE; char code DEMO[256] = 0x80,0x00,0x75,0xB2,0xFF,0x75,0xB1,0x00,0x05,0xB0,0x11,0x0E,0x80,0xFA,0xD8,0xFE, 0xD9,0xFC,0x22, Note: If user needs to set different working frequencies, please refer to the example codes in chapters 7.3.7 and 7.3.8. - 854 -...
  • Page 871 ISP of the MCU The release project program generated by STC's ISP download software is an executable EXE format file. The user can directly double-click the released project program to run it for ISP download, or call the release project program in a third-party application for ISP download.
  • Page 872 STC8A8K64D4 Series Manual // clean up CloseHandle(pi.hThread); CloseHandle(pi.hProcess); return TRUE; else AfxMessageBox(_T(" 创建进程失败 !")); return FALSE; Advanced call The process of creating and publishing project programs in third-party applications, including selecting serial ports and starting ISP in third-party applications All ISP download operations such as programming, ISP programming with vibration stopped, and closing the release project program, do not require interface interaction in the release project program.
  • Page 873 STC8A8K64D4 Series Manual const UINT ID_PROGRESS = 1044; // Full path of publishing project program path = _T("D:\\Work\\Upgrade.exe"); // variable initialization memset(&si, 0, sizeof(STARTUPINFO)); memset(&pi, 0, sizeof(PROCESS_INFORMATION)); memset(&cp, 0, sizeof(CALLBACK_PARAM)); // Set startup variables si.cb = sizeof(STARTUPINFO); GetStartupInfo(&si); si.wShowWindow = SW_SHOWNORMAL; // If it is set to SW_HIDE here, the operation interface for publishing the project program will not be displayed, and all ISP operations can be performed in the background si.dwFlags = STARTF_USESHOWWINDOW;...
  • Page 874 STC8A8K64D4 Series Manual // clean up CloseHandle(pi.hThread); CloseHandle(pi.hProcess); return TRUE; else AfxMessageBox(_T(" 创建进程失败 !")); return FALSE; - 858 -...
  • Page 875 STC8A8K64D4 Series Manual Appendix O Method for Creating Multi-file Projects in Keil In Keil, relatively small projects generally have only one source file, but for some slightly more complex projects, multiple source files are often required. Here's how to set up a multi-file project: 1.
  • Page 876 STC8A8K64D4 Series Manual 3. In the file dialog that pops up, add the source file multiple times. - 860 -...
  • Page 877 STC8A8K64D4 Series Manual Complete the creation of the multi-file project as shown in the figure below. - 861 -...
  • Page 878 STC8A8K64D4 Series Manual - 862 -...
  • Page 879 In Keil's C51 compilation environment, only 0 ~ 31 of the interrupt number are supported, that is, the interrupt vector must be less than 0100H. The following table is a list of interrupts for all current STC series: Interrupt number...
  • Page 880 STC8A8K64D4 Series Manual 006B H 0073 H System internal interrupt 007B H System internal interrupt 0083 H INT4 008B H UART 3 0093 H UART 4 009B H Timer 3 00A3 H Timer 4 00AB H Comparator 00B3 H Waveform generator 0 00BB H Waveform generator fault 0 00C3 H...
  • Page 881 STC8A8K64D4 Series Manual There are three ways to deal with this kind of error: (All of them need the help of assembly code, the first method is recommended) - 865 -...
  • Page 882 STC8A8K64D4 Series Manual Method 1: Borrow Interrupt Vector 13 Among interrupts 0 ~ 31, the 13th is a reserved interrupt number, we can borrow this interrupt number. The steps are as follows: 1. Change the interrupt number the compilation reported error to "13", as shown below: 2.
  • Page 883 STC8A8K64D4 Series Manual at 0103H, as shown in the figure below: When the PWM5 interrupt occurs, the hardware will jump to the 0103H address automatically to execute "LJMP 006BH", and then execute "LJMP PWM5_ISR" at 006BH to jump to the real interrupt service routine, as shown in the figure below: After the execution of the interrupt service routine is completed, it returns through the RETI instruction.
  • Page 884 STC8A8K64D4 Series Manual Method 2: Similar to method 1, borrow unused interrupt numbers from 0 to 31 in user program. For example, in the user's code, if the INT0 interrupt is not used, the above code can be modified similarly to method - 868 -...
  • Page 885 STC8A8K64D4 Series Manual The execution effect is the same as Method 1. This method is applicable to the situation where multiple interrupt numbers greater than 31 need to be remapped. - 869 -...
  • Page 886 STC8A8K64D4 Series Manual Method 3: Define the interrupt service routine as a subroutine, and then use the LCALL instruction in the interrupt entry address in the assembly code to execute the service routine. The steps are as follows: 1. Remove the "interrupt" attribute from the interrupt service routine firstly and define it as an ordinary subroutine. 2.
  • Page 887 STC8A8K64D4 Series Manual This method does not need to remap interrupt entries. But there is a problem with this method. It requires the user to check the disassembly code of the C program to determine which registers need to be pushed onto the stack in the assembly file.
  • Page 888: Appendix Q Electrical Characteristics

    STC8A8K64D4 Series Manual Appendix Q Electrical Characteristics Q.1 Absolute Maximum Rating Parameters Minimum Maximum UNIT Description Storage temperature +125 ℃ If the operating temperature is higher than 85°C (such as around 125°C), due to the large temperature drift of the internal IRC clock frequency high temperature,...
  • Page 889 STC8A8K64D4 Series Manual Equivalent to 0.5M of Normal mode current(internal 32KHz 0.48 traditional 8051 ) Equivalent Normal mode current(500KHz) 0.88 traditional 8051 Equivalent Normal mode current(600KHz) 0.88 traditional 8051 Equivalent Normal mode current(700KHz) 0.90 traditional 8051 Equivalent to 11M of Normal mode current(800KHz)...
  • Page 890 STC8A8K64D4 Series Manual Q.3 DC ELECTRICAL CHARACTERISTICS (5V) (VSS=0V, VDD=5.0V, test temperature =25℃) Limits Symbol Parameter Test Conditions UNIT Power-down mode current Power-down Wake-up timer Low-voltage detection module Comparator power consumption ICMP Equivalent to 0.5M of 1.25 Idle mode current (internal 32KHz) traditional Equivalent to 79M of 0.58...
  • Page 891 STC8A8K64D4 Series Manual speed I/O high current drive, I/O fast conversion PxDR=1, PxSR=0 I/O low current drive, I/O slow conversion PxDR=0, PxSR=1 I/O low current drive, I/O slow conversion PxDR=1, PxSR=1 Turn off all analog Fastest speed and digital filtering Analog filter time Compara tors...
  • Page 892: Appendix R Application Considerations

    STC8A8K64D4 Series Manual Appendix R Application Considerations R.1 STC8A8K64D4-64Pin/48Pin series 1. A version of the chip is in example. - 876 -...
  • Page 893 STC8A8K64D4 Series Manual Appendix S PCB design guidance for touch keys The touch key has strict requirements on PCB design, otherwise its effect will be greatly reduced or even fail.It is recommended that users follow the following principles when designing PCB: 1.
  • Page 894 STC8A8K64D4 Series Manual 6. Copper plating The bottom layer can be covered with grid copper or solid copper. Note that the distance between the copper and the induction plate is 0.5mm. The silk screen information of the top layer is printed on the button.
  • Page 895 In the package form of STC products, the more popular QFN and DFN packages have been added. Since the pins of the chip in this package are at the bottom of the chip, manual soldering is difficult. There are small companies on the market that specialize in welding engineering samples, which can undertake engineering sample proofing.
  • Page 896 STC8A8K64D4 Series Manual 4. Then apply tin to the bottom of the chip. After the tin is applied, it should be flattened to reduce the tin as much as possible, but it cannot be eliminated. 5.Adjust the temperature of the hot air gun, the actual air output is about 240 degrees, because the quality of the air gun is different, adjust it according to the actual situation.
  • Page 897 STC8A8K64D4 Series Manual 7. Use a soldering iron to tin the pins on the chip side 8. The effect after welding - 881 -...
  • Page 898 STC8A8K64D4 Series Manual Appendix U Precautions for STC8A8K64D4 series MCU to replace STC8A8K64S4A12 series ◼ I/O port After the STC8A8K64D4 series MCU is powered on, the I/O mode is different from that of the STC8A8K64S4A12 series. All I/O ports of STC8A8K64S4A12 series single-chip microcomputers are in 8051 quasi- bidirectional port mode after power-on.
  • Page 899 STC8A8K64D4 Series Manual SYSclk/2. The 4 SPI clock frequencies of the STC8A8K64S4A12 series are: SYSclk/4, SYSclk/8, SYSclk/16 and SYSclk/32. ◼ PCA/CCP/PWM Among the PCA-related SFRs of the STC8A8K64D4 series, the SFRs of the first three groups of modules are the same as those of the STC8A8K64S4A12 series, and the control registers of the fourth group of modules (PCA3/CCP3/PWM3) are in the XFR area and are not compatible with the STC8A8K64S4A12 series.
  • Page 900 4. Update the selection price list 5. Add the package dimension drawing of LQFP44 6. Add a detailed description to the read-only special function register (CHIPID) 7. Added appendix "STC Simulation User Manual" chapter ⚫ 2021/10/16 8. Modify some chapter titles 9.
  • Page 901 STC8A8K64D4 Series Manual 1. Added the description of timer 2/3/4 interrupt flag bits 2. Modify the DMA read trigger control bit of serial port 1/2/3/4 ⚫ 2021/4/28 1. Create STC8A8K64D4 series MCU technical reference manual document - 885 -...

This manual is also suitable for:

Micro stc8a8k64d4-64pinMicro stc8a8k64d4-48pin