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 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 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 -...
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.
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) ✓...
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).
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...
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...
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...
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 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...
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 -...
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...
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 -...
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 -...
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.
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.
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.
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.
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 -...
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.
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...
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.
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 -...
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.
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.
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 ≈...
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.
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.
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.
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...
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();...
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;...
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...
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...
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 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...
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 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...
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 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...
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 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...
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.
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.
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.
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.
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...
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.
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...
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...
±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.
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 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...
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...
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 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 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...
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 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...
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 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...
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 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 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...
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...
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...
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.
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...
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.
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.
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.
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;...
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.
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...
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 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 -...
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...
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.
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...
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...
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;...
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...
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...
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...
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...
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 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...
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...
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 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...
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;...
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.
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...
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...
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 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...
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.
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.
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.
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.
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)
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.
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.
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)
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 -...
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.
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.
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.
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.
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;...
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...
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...
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...
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...
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;...
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...
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...
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"...
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 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...
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;...
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 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 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...
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;...
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 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...
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.
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...
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.
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.
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.
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.
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.
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 -...
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 -...
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 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 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...
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 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...
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 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...
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 -...
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 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;...
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.
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...
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...
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 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...
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...
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.
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.
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 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 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...
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 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.
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 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.
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.
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...
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...
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时钟)
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 ...
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 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...
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 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...
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.
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...
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.
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 -...
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...
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.
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...
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.
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.
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...
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 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 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...
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 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...
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.
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.
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.
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}.
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 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...
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)
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...
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.
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.
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.
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.
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 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...
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;...
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 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...
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.)
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.
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 -...
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.
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.
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...
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 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...
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();...
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 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...
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 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...
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.
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.
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’...
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...
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...
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.
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;...
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...
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.
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...
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 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 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 -...
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...
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.
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 ->...
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 ;...
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) ➢...
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.
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)
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 .
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.
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...
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 -...
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 -...
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 -...
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.
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.
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...
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.
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.
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.
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.
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...
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.
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 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 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 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.
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 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 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 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 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 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.
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...
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 -...
Need help?
Do you have a question about the micro STC8A8K64D4 Series and is the answer not in the manual?
Questions and answers