STC8G en
STC8G en
Contents
1 Overview ................................................................................................................................. 1
2 Features, Price and Pins......................................................................................................... 3
2.1 STC8G1K08-38I-TSSOP20/QFN20/SOP16 family ................................................................ 3
2.1.1 Features and Price .................................................................................................................... 3
2.1.2 Pinouts ...................................................................................................................................... 5
2.1.3 Pin descriptions ........................................................................................................................ 8
2.2 STC8G1K08-36I-SOP8/DFN8 family ................................................................................... 10
2.2.1 Features and Price .................................................................................................................. 10
2.2.2 Pinouts .................................................................................................................................... 12
2.2.3 Pin descriptions ...................................................................................................................... 14
2.3 STC8G1K08A-36I-SOP8/DFN8/DIP8 family ....................................................................... 15
2.3.1 Features and Price .................................................................................................................. 15
2.3.2 Pinouts .................................................................................................................................... 17
2.3.3 Pin descriptions ...................................................................................................................... 18
2.4 STC8G2K64S4-36I-LQFP48/QFN48/LQFP32/QFN32 family ............................................. 20
2.4.1 Features and Price .................................................................................................................. 20
2.4.2 Pinouts .................................................................................................................................... 23
2.4.3 Pin descriptions ...................................................................................................................... 25
2.5 STC8G2K64S2-36I-LQFP48/QFN48 family......................................................................... 31
2.5.1 Features and Price .................................................................................................................. 31
2.5.2 Pinouts .................................................................................................................................... 34
2.5.3 Pin descriptions ...................................................................................................................... 35
2.6 STC8G1K08T-36I-TSSOP20 touch key family ..................................................................... 39
2.6.1 Features and Price .................................................................................................................. 39
2.6.2 Pinouts .................................................................................................................................... 42
2.6.3 Pin descriptions ...................................................................................................................... 42
2.7 STC15H family (Traditional STC15 series to enhance the performance of special models) . 46
2.7.1 Features and Price .................................................................................................................. 46
2.7.2 Pinouts .................................................................................................................................... 47
3 Function pins switch ............................................................................................................. 49
3.1 Register related to function pin switch ................................................................................... 49
3.1.1 Peripheral port switch register 1 (P_SW1), for UART1, CCP and SPI switch....................... 49
3.1.2 Peripheral port switch register 2 (P_SW2), for UART2/3/4, I2C and comparator switch ..... 50
3.1.3 Clock selection register (MCLKOCR) ................................................................................... 51
3.2 Example Routines................................................................................................................... 51
3.2.1 UART1 switch ........................................................................................................................ 51
3.2.2 UART2 switch ........................................................................................................................ 52
3.2.3 UART3 switch ........................................................................................................................ 54
3.2.4 UART4 switch ........................................................................................................................ 55
3.2.5 SPI switch ............................................................................................................................... 57
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -i-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - ii -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - iii -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - iv -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -v-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
12.2.6 Timer 0 mode 3 (16-bit auto-realoadable mode with non-maskable interrupt, which can be
used as real-time operating system metronome) ..................................................................................306
12.2.7 Timer 1 mode 0 (16-bit auto-reloadable mode) .....................................................................306
12.2.8 Timer1 mode 1 (16-bit non-autoreloadable mode) ................................................................308
12.2.9 Timer 1 mode 2 (8-bit auto-reloadable mode) .......................................................................308
12.2.10 Timer 0 Counting Register (TL0, TH0) ................................................................................309
12.2.11 Timer 1 Counting Register (TL1, TH1) ................................................................................309
12.2.12 Auxiliary Register 1 (AUXR) ...............................................................................................309
12.2.13 External Interrupt and Clock Output Control Register (INTCLKO) .....................................310
12.2.14 Timer 0 timing calculation formula .......................................................................................310
12.2.15 Timer 1 timing calculation formula .......................................................................................310
12.3 Timer 2 (24-bit timer, 8-bit prescaler + 16-bit timing) .......................................................... 311
12.3.1 Auxiliary Register 1 (AUXR) ............................................................................................... 311
12.3.2 External Interrupt and Clock Output Control Register (INTCLKO) ..................................... 311
12.3.3 Timer 2 Counting Register (T2L, T2H) ................................................................................ 311
12.3.4 Timer 2 8-bit Prescaler Register (TM2PS) ............................................................................312
12.3.5 Timer 2 working mode ..........................................................................................................312
12.3.6 Timer 2 timing calculation formula .......................................................................................313
12.4 Timer 3/4 (24-bit timer, 8-bit prescaler + 16-bit timing) .......................................................313
12.4.1 Timer4 and Timer 3 Control Register (T4T3M) ....................................................................313
12.4.2 Timer 3 Counting Register (T3L, T3H) ................................................................................313
12.4.3 Timer 4 Counting Register (T4L, T4H) ................................................................................314
12.4.4 Timer 3 8-bit Prescaler Register (TM3PS) ............................................................................314
12.4.5 Timer 4 8-bit Prescaler Register (TM4PS) ............................................................................314
12.4.6 Timer 3 working mode ..........................................................................................................314
12.4.7 Timer 4 working mode ..........................................................................................................315
12.4.8 Timer 3 timing calculation formula .......................................................................................316
12.4.9 Timer 4 timing calculation formula .......................................................................................316
12.5 Example Routines..................................................................................................................317
12.5.1 Timer 0 (Mode 0 - 16-bit auto reload) ...................................................................................317
12.5.2 Timer 0 (Mode 1 - 16-bit non-auto reloadable) .....................................................................318
12.5.3 Timer 0 (Mode 2 - 8-bit auto-reloadable) ..............................................................................320
12.5.4 Timer 0 (Mode 3 - 16-bit auto-reloadable with non-maskable interrupt) ..............................322
12.5.5 Timer 0 (External count - T0 is extended for external falling edge interrupt) .......................324
12.5.6 Timer 0 (Pulse width measurement for high-level width of INT0) .......................................326
12.5.7 Timer 0 (Divided clock output) .............................................................................................328
12.5.8 Timer 1 (Mode 0 - 16-bit auto-reloadable) ............................................................................330
12.5.9 Timer 1 (Mode 1 - 16-bit non-auto reloadable) .....................................................................332
12.5.10 Timer 1 (Mode 2 - 8-bit auto-reloadable) ..............................................................................334
12.5.11 Timer 1 (External count – T1 is extended for external falling edge interrupt) ......................336
12.5.12 Timer 1 (Pulse width measurement for high-level width of INT1) .......................................338
12.5.13 Timer 1 (mode 0, Divided clock output) ...............................................................................340
12.5.14 Timer 1 (Mode 0) is used as baud rate generator of UART1.................................................341
12.5.15 Timer 1 (Mode 2) is used as baud rate generator of UART1.................................................345
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - vi -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - vii -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - viii -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - ix -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -x-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - xi -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - xii -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Appendix H ISP Download Starts Automatically After Receiving User Command While Running
User Program (no Power-down) ....................................................................................................................788
Appendix I Use STC's IAP series MCU to develop your own ISP program ......................................790
Appendix J The method of resetting the user program to the system area for ISP download (without
power down) 800
Appendix K Example Routine of ISP download for STC8G series MCUs using third-party MCU..805
Appendix L Use a third-party application program to call the STC release project program to
download to MCU using the ISP ....................................................................................................................813
Appendix M Method for Creating Multi-file Projects in Keil ...............................................................816
Appendix N Handling of Compilation Error in Keil with Interrupt Numbers Greater Than 31 ......821
Appendix O Electrical Characteristics ....................................................................................................831
Appendix P Application note ...................................................................................................................835
Appendix Q PCB design guidance for touch buttons ............................................................................837
Appendix R QFN/DFN packaged components welding method...........................................................838
Appendix S Precautions for replacing STC15 series with STC8G series MCU..................................841
Appendix T Precautions for replacing STC8A/8F series with STC8G series MCU ...........................842
Appendix U Precautions for replacing STC15F/L/W series with STC15H series MCU ....................843
Appendix V Update Records....................................................................................................................845
Appendix W STC8 series naming tidbits .................................................................................................853
Appendix X Product Authorization Letter .............................................................................................854
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - xiii -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
1 Overview
STC8G series of microcontrollers are microcontrollers that do not need an external crystal oscillator and
external reset circuit. They are 8051 core microcontrollers with the goal of strong anti-interference, ultra low
price, high speed and low power consumption. Under the same operating frequency, STC8G series of
microcontrollers are about 12 times faster (11.2 ~ 13.2 times) than traditional 8051. To execute all 111
instructions in sequence, the STC8G series microcontroller only needs 147 clocks, while the traditional 8051
requires 1944 clocks. STC8G series of microcontrollers are single clock/machine cycle (1T) microcontrollers
produced by STC. It is a new generation 8051 microcontrollers with wide voltage, high speed, high reliability,
low power consumption, strong antistatic, strong anti-interference and super encrypted. The instruction codes
are fully compatible with traditional 8051.
High precision of ±0.3% @+25°C R/C clock is integrated in MCU with -1.38% to +1.42% temperature
drift under the temperature range of -40°C to +85°C, and 0.88% to +1.05% temperature drift under temperature
range from -20°C to +65°C. The frequency of RC clock can be set from 4MHz to 35MHz when programming a
MCU using ISP. Note: The maximum frequency must be limited below 35MHz when the temperature range is -
40°C to + 85°C. Moreover, high reliable reset circuit with 4 level optional reset threshold voltage can be selected.
So, external expensive crystal and the external reset circuit can be eliminated completely.
There are three optional clock sources inside the MCU, internal high precision IRC which can be adjusted
while ISP, internal 32KHz low speed IRC, external 4MHz~33MHz oscillator or external clock signal. The clock
source can be freely chosen in user codes. After the clock source is selected, it may be 8-bit divided and then be
supplied to the CPU and the peripherals, such as timers, UARTs, SPI, and so on.
Two low power modes are provided in MCU, the IDLE mode and the STOP mode. In IDLE mode, MCU
stops clocking CPU, CPU stops executing instructions without clock, while all peripherals are still working. At
this moment, the power consumption is about 1.0mA at 6MHz working frequency. The STOP mode is the
power off or power-down mode. At this momont, the main clock stops, CPU and all peripherals stop working,
and the power consumption can be reduced to about 0.6uA when VCC is 5.0V, 0.4uA when VCC is 3.3V.
The Power-down mode can be woke-up by one of the following interrupts: INT0(P3.2), INT1(P3.3),
INT2(P3.6), INT3(P3.7), INT4(P3.0), T0(P3.4), T1(P3.5), T2(P1.2), T3(P0.4), T4(P0.6), RXD(P3.0/P3.6/P1.6/
P4.3), RXD2(P1.4/P4.6), RXD3(P0.0/P5.0), RXD4(P0.2/P5.2), CCP0(P1.1/P3.5/P2.5), CCP1(P1.0/P3.6/P2.6),
CCP2(P3.7/P2.7), I2C_SDA(P1.4/P2.4/P3.3), Comparator, LVD, Power-down wake-up timer.
Rich digital peripherals and analog peripherals are provided in MCU, including UARTs, timers, PCAs,
PWMs and I2C, SPI, ultra-high speed ADC and comparator, which can meet the needs of users when designing
a product.
The enhanced dual data pointers are integrated in the STC8G series of microcontrollers. Using program
control, the function of automatic increasing or decreasing of data pointer and automatic switching of two sets
of data pointers can be realized.
Enhanced Touch
Products I/O UART Timers ADC PCA CMP SPI I2C MDU16 LED
PWM Key
STC8G1K08 family 18 2 3 15CH*10B ● ● ● ●
STC8G1K08-8Pin family 6 1 2 ● ● ●
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -1-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -2-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
voltage
Internal high reliable reset circuit with 4 level optional reset threshold
PCA/CCP/PWM (can be used as external interrupt and can wake-up CPU)
16-bit advanced PWM timer with complementary symmetrical dead-time
Package
15-bit high speed ADC (3 PCAs can be used as 3 DACs)
Online debugging
Watch-dog Timer
MCU model
QFN20 (3mm*3mm)
(
TSSOP20
SOP16
)
1.9-
STC8G1K04 4K 256B 1K 2 8K 18 2 Y Y 3 - - 3 Y 10bit Y Y Y Y Y Y Y Y Y Y Y √
5.5
1.9-
STC8G1K08 8K 256B 1K 2 4K 18 2 Y Y 3 - - 3 Y 10bit Y Y Y Y Y Y Y Y Y Y Y √ √ √ √ √ √
Available
5.5
1.9-
STC8G1K12 12K 256B 1K 2 IAP 18 2 Y Y 3 - - 3 Y 10bit Y Y Y Y Y Y Y Y Y Y Y √ √ √
5.5
1.9-
STC8G1K17 17K 256B 1K 2 IAP 18 2 Y Y 3 - - 3 Y 10bit Y Y Y Y Y Y Y Y Y - - √ √ √ √ √
5.5
Note: The above unit prices are for orders of quantity of 10K and above. If the quantity is small, an additional RMB
0.1 per piece will be required. When the total amount of the order reaches or exceeds 3,000 yuan, it can be shipped free of
charge, otherwise the customer will have to bear the freight. Retail sale starts at 10 pieces.
Core
Ultra-high speed 8051 core with single clock per machine cycle, which is called 1T and the speed is about 12
times faster than traditional 8051
Fully compatible instruction set with traditional 8051
16 interrupt sources and 4 interrupt priority levels
Online debugging is supported
Operating voltage
1.9V~5.5V
Built-in LDO
Operating temperature
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -3-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
-40℃~85℃(For applications beyond the temperature range, please refer to the description of the electrical
characteristics chapter)
Flash memory
Up to 17Kbytes of Flash memory to be used to store user code
Configurable size EEPROM, 512bytes single page erased, can be repeatedly erased more than 100 thousand
times.
In-System-Programming, ISP in short, can be used to update the application code, no need for special
programmer.
Online debugging with single chip is supported, and no special emulator is needed. The number of breakpoints is
unlimited theoratically.
SRAM
128 bytes internal direct access RAM (DATA)
128 bytes internal indirect access RAM (IDATA)
1024 bytes internal extended RAM (internal XDATA)
Clock
Internal high precise R/C clock (IRC, range from 4MHz to 36MHz), adjustable while ISP and can be divided to
lower frequency by user software, 100KHz for instance.
Error:±0.3% (at the temperature 25℃)
-1.38%~+1.42% temperature drift (at the temperature range of -40°C to +85°C)
-0.88%~+1.05% temperature drift (at the temperature range of -20℃ to 65℃)
Internal 32KHz low speed IRC with large error
External 4MHz~33MHz oscillator or external clock
The three clock sources above can be selected freely by used code.
Reset
Hardware reset
Power-on reset. Measured voltage value is 1.69V~1.82V. (Effective when the chip does not enable the
low voltage reset function)
The power-on reset voltage is a voltage range consisting of an upper limit voltage and a lower limit voltage.
When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage of the power-on reset,
the chip is in reset state. When the voltage rises from 0V to the upper threshold voltage of power-on reset,
the chip is released from the reset state.
Reset by reset pin. The default function of P5.4 is I/O port. P5.4 pin can be set as the reset pin while ISP
download. (Note: When the P5.4 pin is set as the reset pin, the reset level is low.)
Watch dog timer reset
Low voltage detection reset. 4 low voltage detection levels are provided, 2.2V (Measured as 1.90V~2.04V),
2.4V (Measured as 2.30V~2.50V), V2.7 (Measured as 2.61V~2.82V), V3.0 (Measured as 2.90V~3.13V).
Each level of low-voltage detection voltage is a voltage range consisting of an upper limit voltage and a
lower limit voltage. When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage
of low-voltage detection, the low-voltage detection takes effect. When the voltage rises from 0V to the
upper threshold voltage, the low voltage detection becomes effective.
Software reset
Writing the reset trigger register using software
Interrupts
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -4-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
16 interrupt sources: INT0(Supports rising edge and falling edge interrupt), INT1(Supports rising edge and
falling edge interrupt), INT2(Supports falling edge interrupt only), INT3(Supports falling edge interrupt only),
INT4(Supports falling edge interrupt only), timer0, timer1, timer2, UART1, UART2, ADC, LVD, SPI, I2C,
comparator, PCA/CCP/PWM
4 interrupt priority levels
Interrupts that can awaken the CPU in clock stop mode: INT0 (P3.2), INT1 (P3.3), INT2 (P3.6), INT3 (P3.7),
INT4 (P3.0), T0 (P3.4) ), T1(P3.5), T2(P1.2), RXD(P3.0/P3.6/P1.6), RXD2(P1.4), CCP0(P1.1/P3.5), CCP1
(P1.0/P3.6), CCP2 (P3.7), I2C_SDA (P1.4/P3.3) and comparator interrupt, low-voltage detection interrupt,
power-down wake-up timer.
Digital peripherals
3 16-bit timers: timer0, timer1, timer2, where the mode 3 of timer 0 has the Non Maskable Interrupt (NMI in
short) function. Mode 0 of timer 0 and timer 1 is 16-bit Auto-reload mode.
2 high speed UARTs: UART1, UART2, whose baudrate clock may be as fast as FOSC/4
3 groups of PCAs: CCP0, CCP1, CCP2, which can be used as capture, high speed output and 6-bits, 7-bits, 8-bits
or 10-bits PWM.
SPI: Master mode, slave mode or master/slave automatic switch mode are supported.
I2C: Master mode or slave mode are supported.
Analog peripherals
15 channels (channel 0 to channel 14) ultra-high speed ADC which supports 10-bit precision analog-to-digital
conversion, the speed can be as fast as 500K(500,000 conversions per second).
ADC channel 15 is used to test the internal reference voltage. (The default internal reference voltage is 1.19V
when the chip is shipped)
Comparator. A set of comparators (the positive terminal of the comparator can select the CMP+ and all ADC
input ports, so the comparator can be used as a multi-channel comparator for time division multiplexing).
DAC. 3 groups of PCAs can be used as DAC.
GPIO
Up to 18 GPIOs: P1.0~P1.7, P3.0~P3.7, P5.4~P5.5
4 modes for all GPIOs: quasi_bidirectional mode, push-pull outputmode, open drain mode, high-impedance input
mode
Except for P3.0 and P3.1, all other I/O ports are in high-impedance state after power-on. User must set the
I/O ports mode before using them. In addition, each I/O can independently enable the internal 4K pull-up
resistor.
Package
TSSOP20, QFN20 (3mm*3mm), SOP20, DIP20, SOP16, DIP16
2.1.2 Pinouts
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -5-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
T2/ECI/SS/ADC2/P1.2 1 20 P1.1/ADC1/TxD2/CCP0
T2CLKO/MOSI/ADC3/P1.3 2 19 P1.0/ADC0/RxD2/CCP1
I2CSDA/MISO/ADC4/P1.4 3 18 P3.7/INT3/TxD_2/CCP2_2/CCP2/CMP+
TSSOP20
I2CSCL/SCLK/ADC5/P1.5 4 17 P3.6/ADC14/INT2/RxD_2/CCP1_2/CMP-
XTALO/MCLKO_2/RxD_3/ADC6/P1.6 5 16 P3.5/ADC13/T1/T0CLKO/CCP0_2/SS_4
XTALI/TxD_3/ADC7/P1.7 6 15 P3.4/ADC12/T0/T1CLKO/ECI_2/CMPO/MOSI_4
MCLKO/RST/P5.4 7 14 P3.3/ADC11/INT1/MISO_4/I2CSDA_4
VCC/AVCC/VREF+ 8 13 P3.2/ADC10/INT0/SCLK_4/I2CSCL_4
P5.5 9 12 P3.1/ADC9/TxD
GND/AGND 10 11 P3.0/ADC8/RxD/INT4
RxD2/CCP1/ADC0/P1.0 1 16 P3.7/INT3/TxD_2/CCP2/CCP2_2CMP+
TxD2/CCP0/ADC1/P1.1 2 15 P3.6/ADC14/INT2/RxD_2/CCP1_2/CMP-
XTALO/MCLKO_2/RxD_3/ADC6/P1.6 3 14 P3.5/ADC13/T1/T0CLKO/CCP0_2/SS_4
XTALI/TxD_3/ADC7/P1.7 4 13 P3.4/ADC12/T0/T1CLKO/ECI_2/CMPO/MOSI_4
MCLKO/RST/P5.4
SOP16
5 12 P3.3/ADC11/INT1/MISO_4/I2CSDA_4
VCC/AVCC/VREF+ 6 11 P3.2/ADC10/INT0/SCLK_4/I2CSCL_4
P5.5 7 10 P3.1/ADC9/TxD
GND/AGND 8 9 P3.0/ADC8/RxD/INT4
P3.4/ADC12/T0/T1CLKO/ECI_2/MOSI_4/CMPO
P3.6/ADC14/INT2/RxD_2/CCP1_2/CMP-
P3.5/ADC13/T1/T0CLKO/CCP0_2/SS_4
P3.7/INT3/TxD_2/CCP2/CCP2_2/CMP+
P3.3/ADC11/INT1/MISO_4/I2CSDA_4
15
14
13
12
11
CCP1/RxD2/ADC0/P1.0 16 10 P3.2/ADC10/INT0/SCLK_4/I2CSCL_4
I2CSDA/MISO/ADC4/P1.4 17 9 P3.1/ADC9/TxD
T2CLKO/MOSI/ADC3/P1.3 18 QFN20 8 P3.0/ADC8/RxD/INT4
T2/ECI/SS/ADC2/P1.2 19 7 GND/AGND
CCP0/TxD2/ADC1/P1.1 20 6 P5.5
1
2
3
4
5
I2CSCL/SCLK/ADC5/P1.5
XTALO/MCLKO_2/RxD_3/ADC6/P1.6
XTALI/TxD_3/ADC7/P1.7
MCLKO/RST/P5.4
VCC/AVCC/VREF+
Vcc
Connect P3.0
to PC P3.1
Gnd
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -7-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -8-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Pin number
TSSOP20
QFN20
SOP16 name type description
DIP20 DIP16
P3.3 I/O Standard IO port
INT1 I External interrupt 1
14 11 12 ADC11 I ADC analog input 11
SDA_4 I/O Data of I2C
MISO_4 I/O Master Iutput/Slave Onput of SPI
P3.4 I/O Standard IO port
T0 I Timer0 external input
T1CLKO O Clock out of timer 1
15 12 13 ADC12 I ADC analog input 12
ECI_2 I External pulse input of PCA
CMPO O Comparator output
MOSI_4 I/O Master Output/Slave Input of SPI
P3.5 I/O Standard IO port
T1 I Timer1 external input
T0CLKO O Clock out of timer 0
ADC13 I ADC analog input 13
16 13 14
Capture of external signal/High-speed
CCP0_2 I/O
Pulse output of PCA
Slave selection of SPI (it is output with
SS_4 I
regard to master)
P3.6 I/O Standard IO port
INT2 I External interrupt 2
RxD_2 I Serial input of UART1
17 14 15 ADC14 I ADC analog input 14
Capture of external signal/High-speed
CCP1_2 I/O
Pulse output of PCA
CMP- I Comparator negative input
P3.7 I/O Standard IO port
INT3 I External interrupt 3
TxD_2 O Serial output of UART 1
Capture of external signal/High-speed
18 15 16 CCP2 I/O
Pulse output of PCA
Capture of external signal/High-speed
CCP2_2 I/O
Pulse output of PCA
CMP+ I Comparator positive input
P1.0 I/O Standard IO port
RxD2 I Serial input of UART2
19 16 1 ADC0 I ADC analog input 0
Capture of external signal/High-speed
CCP1 I/O
Pulse output of PCA
P1.1 I/O Standard IO port
TxD2 O Serial output of UART 2
20 20 2 ADC1 I ADC analog input 1
Capture of external signal/High-speed
CCP0 I/O
Pulse output of PCA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 -9-
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Internal high reliable reset circuit with 4-level optional reset threshold voltage
PCA/CCP/PWM (can be used as external interrupt and can wake-up CPU)
16-bit advanced PWM timer Complementary symmetrical dead-time
Package
15-channels high speed ADC (8 PWMs can be used as 8 DACs)
Online debugging
Watch-dog Timer
MCU model
SPI
I2 C
DFN8<3mm*3mm>
(
)
SOP8
STC8G1K08 1.9-5.5 8K 256 1K 2 4K 6 1 Y Y Y 2 - - - Y - Y Y Y Y Y Y Y Y Y Y √ √
Available
STC8G1K12 1.9-5.5 12K 256 1K 2 IAP 6 1 Y Y Y 2 - - - Y - Y Y Y Y Y Y Y Y Y Y
Note: The above unit prices are for orders of quantity of 10K and above. If the quantity is small, an additional RMB
0.1 per piece will be required. When the total amount of the order reaches or exceeds 3,000 yuan, it can be shipped free of
charge, otherwise the customer will have to bear the freight. Retail sale starts at 10 pieces.
Core
Ultra-high speed 8051 core with single clock per machine cycle, which is called 1T and is about 12 times faster
than traditional 8051
Fully compatible instruction set with traditional 8051
11 interrupt sources and 4 interrupt priority levels
Online debugging is supported
Operating voltage
1.9V~5.5V
Built-in LDO
Operating temperature
-40℃~85℃
Flash memory
Up to 17K bytes of Flash memory to be used to store user code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 10 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Configurable size EEPROM, 512 bytes single page erased, can be repeatedly erased more than 100 thousand
times.
In-System-Programming, ISP in short, can be used to update the application code, no need for special
programmer.
Online debugging with single chip is supported, and no special emulator is needed. The number of breakpoints is
unlimited theoratically.
SRAM
128 bytes internal direct access RAM (DATA)
128 bytes internal indirect access RAM (IDATA)
1024 bytes internal extended RAM (internal XDATA)
Clock
Internal high precise R/C clock (IRC, range from 4MHz to 36MHz), adjustable while ISP and can be divided to
lower frequency by user software, 100KHz for instance.
Error:±0.3% (at the temperature 25℃)
-1.38%~+1.42% temperature drift (at the temperature range of -40°C to +85°C)
-0.88%~+1.05% temperature drift (at the temperature range of -20℃ to 65℃)
Internal 32KHz low speed IRC with large error
Reset
Hardware reset
Power-on reset. Measured voltage value is 1.69V~1.82V. (Effective when the chip does not enable the
low voltage reset function)
The power-on reset voltage is a voltage range consisting of an upper limit voltage and a lower limit voltage.
When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage of the power-on reset,
the chip is in a reset state; when the voltage rises from 0V to the upper threshold voltage of power-on reset,
the chip is released from the reset state.
Reset by reset pin. The default function of P5.4 is the I/O port. The P5.4 pin can be set as the reset pin
while ISP download. (Note: When the P5.4 pin is set as the reset pin, the reset level is low.)
Watch dog timer reset
Low voltage detection reset. 4 low voltage detection levels are provided, 2.2V (Measured as 1.90V~2.04V),
2.4V (Measured as 2.30V~2.50V), V2.7 (Measured as 2.61V~2.82V), V3.0 (Measured as 2.90V~3.13V).
Each level of low-voltage detection voltage is a voltage range consisting of an upper limit voltage and a
lower limit voltage. When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage
of low-voltage detection, the low-voltage detection takes effect. When the voltage rises from 0V to the
upper threshold voltage, the low voltage detection becomes effective.
Software reset
Writing the reset trigger register using software
Interrupts
11 interrupt sources: INT0(Supports rising edge and falling edge interrupt), INT1(Supports rising edge and
falling edge interrupt), INT2(Supports falling edge interrupt only), INT3(Supports falling edge interrupt only),
INT4(Supports falling edge interrupt only), timer0, timer1, UART1, LVD, SPI, I2C
4 interrupt priority levels
Interrupts that can awaken the CPU in clock stop mode: INT0 (P3.2), INT1 (P3.3), INT2 (P3.6), INT3 (P3.7),
INT4 (P3.0), T0 (P3.4), T1(P3.5), RXD(P3.0/P3.2/P5.4), I2C_SDA (P3.3/P5.5) and low-voltage detection
interrupt, power-down wake-up timer.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 11 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Digital peripherals
2 16-bit timers: timer0, timer1, where the mode 3 of timer0 has the Non Maskable Interrupt (NMI in short)
function. Mode 0 of timer0 and timer1 is 16-bit Auto-reload mode.
1 high speed UART: UART1, whose baudrate clock source may be fast as FOSC/4
SPI: Master mode, slave mode or master/slave automatic switch mode are supported.
I2C: Master mode or slave mode are supported.
MDU16: Hardware 16-bit Multiplier and Divider which supports 32-bit divided by 16-bit, 16-bit divided
by 16-bit, 16-bit by 16-bit, data shift, and data normalization operations.
GPIO
Up to 6 GPIOs: P3.0~P3.3, P5.4~P5.5
4 modes for all GPIOs: quasi_bidirectional mode, push-pull outputmode, open drain mode, high-impedance input
mode
Except for P3.0 and P3.1, all other I/O ports are in high-impedance state after power-on. User must set the
I/O ports mode before using them. In addition, each I/O can independently enable the internal 4K pull-up
resistor.
Package
SOP8, DFN8 (3mm*3mm)
2.2.2 Pinouts
MCLKO/RST/SCL_2/MOSI/RxD_3/T1CLKO/T0/INT2/P5.4 1 8 P3.3/TxD_2/INT1/MISO/SDA
VCC 2 7 P3.2/RxD_2/INT0/SCLK/SCL
SDA_2/SS/TxD_3/T0CLKO/T1/INT3/P5.5 3
SOP8 6 P3.1/TxD
GND 4 5 P3.0/RxD/INT4
Vcc
Connect P3.0
to PC P3.1
Gnd
the ISP download. Therefore, please be sure to use the booster USB cable for ISP download.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 13 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 14 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Internal high reliable reset circuit with 4-level optional reset threshold voltage
PCA/CCP/PWM (can be used as external interrupt and can wake-up CPU)
16-bit advanced PWM timer Complementary symmetrical dead-time
Package
6-channels high speed ADCs (8 PWMs can be used as 8 DACs)
Online debugging
Watch-dog Timer
MCU model
DFN8<3mm*3mm>
(
)
SOP8
STC8G1K08A 1.9-5.5 8K 256 1K 2 4K 6 1 Y Y Y 2 - - 3 Y 10bit Y Y Y Y Y Y Y Y Y Y √ √ √
Available
STC8G1K12A 1.9-5.5 12K 256 1K 2 IAP 6 1 Y Y Y 2 - - 3 Y 10bit Y Y Y Y Y Y Y Y Y Y
Note: The above unit prices are for orders of quantity of 10K and above. If the quantity is small, an additional RMB
0.1 per piece will be required. When the total amount of the order reaches or exceeds 3,000 yuan, it can be shipped free of
charge, otherwise the customer will have to bear the freight. Retail sale starts at 10 pieces.
Core
Ultra-high speed 8051 Core with single clock per machine cycle, which is called 1T and the speed is about 12
times faster than traditional 8051
Fully compatible instruction set with traditional 8051
13 interrupt sources and 4 interrupt priority levels
Online debugging is supported
Operating voltage
1.9V~5.5V
Built-in LDO
Operating temperature
-40℃~85℃
Flash memory
Up to 17K bytes of Flash memory to be used to store user code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 15 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Configurable size EEPROM, 512bytes single page erased, can be repeatedly erased more than 100 thousand
times.
In-System-Programming, ISP in short, can be used to update the application code, no need for special
programmer.
Online debugging with single chip is supported, and no special emulator is needed. The number of breakpoints is
unlimited theoratically.
SRAM
128 bytes internal direct access RAM (DATA)
128 bytes internal indirect access RAM (IDATA)
1024 bytes internal extended RAM (internal XDATA)
Clock
Internal high precise R/C clock (IRC, range from 4MHz to 36MHz), adjustable while ISP and can be divided to
lower frequency by user software, 100KHz for instance.
Error:±0.3% (at the temperature 25℃)
-1.38%~+1.42% temperature drift (at the temperature range of -40°C to +85°C)
-0.88%~+1.05% temperature drift (at the temperature range of -20℃ to 65℃)
Internal 32KHz low speed IRC with large error
Reset
Hardware reset
Power-on reset. Measured voltage value is 1.69V~1.82V. (Effective when the chip does not enable the
low voltage reset function)
The power-on reset voltage is a voltage range consisting of an upper limit voltage and a lower limit voltage.
When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage of the power-on reset,
the chip is in a reset state; when the voltage rises from 0V to the upper threshold voltage of power-on reset,
the chip is released from the reset state.
Reset by reset pin. The default function of P5.4 is I/O port. The P5.4 pin can be set as the reset pin while
ISP download. (Note: When the P5.4 pin is set as the reset pin, the reset level is low.)
Watch dog timer reset
Low voltage detection reset. 4 low voltage detection levels are provided, 2.2V (Measured as 1.90V~2.04V),
2.4V (Measured as 2.30V~2.50V), V2.7 (Measured as 2.61V~2.82V), V3.0 (Measured as 2.90V~3.13V).
Each level of low-voltage detection voltage is a voltage range consisting of an upper limit voltage and a
lower limit voltage. When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage
of low-voltage detection, the low-voltage detection takes effect. When the voltage rises from 0V to the
upper threshold voltage, the low voltage detection becomes effective.
Software reset
Writing the reset trigger register using software
Interrupts
13 interrupt sources: INT0(Supports rising edge and falling edge interrupt), INT1(Supports rising edge and
falling edge interrupt), INT2(Supports falling edge interrupt only), INT3(Supports falling edge interrupt only),
INT4(Supports falling edge interrupt only), timer0, timer1, UART1, ADC, LVD, SPI, I2C, PCA/CCP/PWM
4 interrupt priority levels
Interrupts that can awaken the CPU in clock stop mode: INT0 (P3.2), INT1 (P3.3), INT2 (P3.6), INT3 (P3.7),
INT4 (P3.0), T0 (P3.4), T1(P3.5), RXD(P3.0/P3.2/P1.6/P5.4), CCP0(P3.2/P3.1), CCP1 (P3.3), CCP2 (P5.4/P5.5),
I2C_SDA (P3.3/P5.5) and low-voltage detection interrupt, power-down wake-up timer.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 16 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Digital peripherals
2 16-bit timers: timer0, timer1, where the mode 3 of timer0 has the Non Maskable Interrupt (NMI in short)
function. Mode 0 of timer0 and timer1 is 16-bit Auto-reload mode.
1 high speed UART: UART1, whose baudrate clock may be fast as FOSC/4
3 groups of PCAs: CCP0, CCP1, CCP2, which can be used as capture, high speed output and 6-bits, 7-bits, 8-bits
or 10-bits PWM.
SPI: Master mode, slave mode or master/slave automatic switch mode are supported.
I2C: Master mode or slave mode are supported.
MDU16: Hardware 16-bit Multiplier and Divider which supports 32-bit divided by 16-bit, 16-bit divided
by 16-bit, 16-bit by 16-bit, data shift, and data normalization operations.
Analog peripherals
6 channels (channel 0 to channel 5) ultra-high speed ADC which supports 10-bit precision analog-to-digital
conversion, the speed can be as fast as 500K(500,000 conversions per second).
ADC channel 15 is used to test the internal reference voltage. (The default internal reference voltage is 1.19V
when the chip is shipped)
DAC. 3 groups of PCAs can be used as DAC.
GPIO
Up to 6 GPIOs: P3.0~P3.3, P5.4~P5.5
4 modes for all GPIOs: quasi_bidirectional mode, push-pull outputmode, open drain mode, high-impedance input
mode
Except for P3.0 and P3.1, all other I/O ports are in a high-impedance state after power-on. User must set
the I/O ports mode before using them. In addition, each I/O can independently enable the internal 4K pull-
up resistor.
Package
SOP8, DFN8 (3mm*3mm), DIP8
2.3.2 Pinouts
CCP2_2/CCP2/MCLKO/RST/SCL_2/MOSI/RxD_3/T1CLKO/T0/INT2/ADC4/P5.4 1 8 P3.3/ADC3/TxD_2/INT1/MISO/SDA/CCP1/CCP1_2/CCP1_3
VCC/AVCC 2 7 P3.2/ADC2/RxD_2/INT0/SCLK/SCL/CCP0/CCP0_3
ECI_2/ECI/CCP2_3/SDA_2/SS/TxD_3/T0CLKO/T1/INT3/ADC5/P5.5 3
SOP8 6 P3.1/ADC1/TxD/CCP0_2/ECI_3
GND/AGND 4 5 P3.0/ADC0/RxD/INT4
Vcc
Connect P3.0
to PC P3.1
Gnd
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 indicator is on).
5. Start ISP download.
Note: It has been found that when using the USB cable for ISP download, if the USB cable is too thin
and the voltage drop on the USB cable is too large, this will result in insufficient power supply during
the ISP download. Therefore, please be sure to use the booster USB cable for ISP download.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 18 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Pin number
SOP8
DFN8
name type description
DIP8
P3.2 I/O Standard IO port
INT0 I External interrupt 0
SCLK I/O Serial Clock of SPI
SCL I/O Serial Clock line of I2C
7
RxD_2 I Serial input of UART1
ADC2 I ADC analog input 2
CCP0 I/O Capture of external signal/High-speed Pulse output of PCA
CCP0_3 I/O Capture of external signal/High-speed Pulse output of PCA
P3.3 I/O Standard IO port
INT1 I External interrupt 1
MISO I/O Master Iutput/Slave Onput of SPI
SDA I/O Serial data line of I2C
8 TxD_2 O Serial output of UART 1
ADC3 I ADC analog input 3
CCP1 I/O Capture of external signal/High-speed Pulse output of PCA
CCP1_2 I/O Capture of external signal/High-speed Pulse output of PCA
CCP1_3 I/O Capture of external signal/High-speed Pulse output of PCA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 19 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Internal high reliable reset circuit with 4-level optional reset threshold voltage
PCA/CCP/PWM (can be used as external interrupt and can wake-up CPU)
16-bit advanced PWM timer Complementary symmetrical dead-time
Package
15 channels high speed ADC (All PWMs can be used as DACs)
Online debugging
Watch-dog Timer
MCU model
SPI
I2 C
QFN48<6mm*6mm>
QFN32<4mm*4mm>
(
LQFP48
LQFP32
)
Available
STC8G2K48S4 1.9-5.5 48K 256 2K 2 32K 45 4 Y Y Y 5 - 45 3 Y 10bit Y Y Y Y Y Y Y Y Y Y Y √ √ √
STC8G2K60S4 1.9-5.5 60K 256 2K 2 4K 45 4 Y Y Y 5 - 45 3 Y 10bit Y Y Y Y Y Y Y Y Y Y Y √ √ √
Note: The above unit prices are for orders of quantity of 10K and above. If the quantity is small, an additional RMB
0.1 per piece will be required. When the total amount of the order reaches or exceeds 3,000 yuan, it can be shipped free of
charge, otherwise the customer will have to bear the freight. Retail sale starts at 10 pieces.
If you need to choose a 48-pin chip, it is recommended to choose LQFP48 package, QFN48 needs to be ordered in
advance.
Core
Ultra-high speed 8051 Core with single clock per machine cycle, which is called 1T and the speed is about 12
times faster than traditional 8051
Fully compatible instruction set with traditional 8051
29 interrupt sources and 4 interrupt priority levels
Online debugging is supported
Operating voltage
1.9V~5.5V
Built-in LDO
Operating temperature
-40℃~85℃
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 20 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Flash memory
Up to 64K bytes of Flash memory to be used to store user code
Configurable size EEPROM, 512bytes single page erased, can be repeatedly erased more than 100 thousand
times.
In-System-Programming, ISP in short, can be used to update the application code, no need for special
programmer.
Online debugging with single chip is supported, and no special emulator is needed. The number of breakpoints is
unlimited theoratically.
SRAM
128 bytes internal direct access RAM (DATA)
128 bytes internal indirect access RAM (IDATA)
2048 bytes internal extended RAM (internal XDATA)
Clock
Internal high precise R/C clock (IRC, range from 4MHz to 36MHz), adjustable while ISP and can be divided to
lower frequency by user software, 100KHz for instance.
Error:±0.3% (at the temperature 25℃)
-1.38%~+1.42% temperature drift (at the temperature range of -40°C to +85°C)
-0.88%~+1.05% temperature drift (at the temperature range of -20℃ to 65℃)
Internal 32KHz low speed IRC with large error
External 4MHz~33MHz oscillator or external clock
Reset
Hardware reset
Power-on reset. Measured voltage value is 1.69V~1.82V. (Effective when the chip does not enable the
low voltage reset function)
The power-on reset voltage is a voltage range consisting of an upper limit voltage and a lower limit voltage.
When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage of the power-on reset,
the chip is in a reset state; when the voltage rises from 0V to the upper threshold voltage of power-on reset,
the chip is released from the reset state.
Reset by reset pin. The default function of P5.4 is the I/O port. The P5.4 pin can be set as the reset pin
while ISP download. (Note: When the P5.4 pin is set as the reset pin, the reset level is low.)
Watch dog timer reset
Low voltage detection reset. 4 low voltage detection levels are provided, 2.2V (Measured as 1.90V~2.04V),
2.4V (Measured as 2.30V~2.50V), V2.7 (Measured as 2.61V~2.82V), V3.0 (Measured as 2.90V~3.13V).
Each level of low-voltage detection voltage is a voltage range consisting of an upper limit voltage and a
lower limit voltage. When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage
of low-voltage detection, the low-voltage detection takes effect. When the voltage rises from 0V to the
upper threshold voltage, the low voltage detection becomes effective.
Software reset
Writing the reset trigger register using software
Interrupts
29 interrupt sources: INT0(Supports rising edge and falling edge interrupt), INT1(Supports rising edge and
falling edge interrupt), INT2(Supports falling edge interrupt only), INT3(Supports falling edge interrupt only),
INT4(Supports falling edge interrupt only), timer0, timer1, timer2, timer3, timer4, UART1, UART2, UART3,
UART4, ADC, LVD, SPI, I2C, comparator, PCA/CCP/PWM, enhanced PWM0, enhanced PWM1, enhanced
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 21 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM2, enhanced PWM3, enhanced PWM4, enhanced PWM5, enhanced PWM0 fault detection, enhanced
PWM2 fault detection, enhanced PWM4 fault detection.
4 interrupt priority levels
Interrupts that can awaken the CPU in clock stop mode: INT0 (P3.2), INT1 (P3.3), INT2 (P3.6), INT3 (P3.7),
INT4 (P3.0), T0(P3.4), T1(P3.5), T2(P1.2), T3(P0.4), T4(P0.6), RXD(P3.0/P3.6/P1.6/P4.3), RXD2(P1.4/P4.6),
RXD3(P0.0/P5.0), RXD4(P0.2/P5.2), CCP0(P1.1/P3.5/P2.5), CCP1(P1.0/P3.6/P2.6), CCP2(P3.7/P2.7),
I2C_SDA (P1.4/P2.4/P3.3) and comparator interrupt, low-voltage detection interrupt, power-down wake-up
timer.
Digital peripherals
5 16-bit timers: timer0, timer1, timer2, timer3, timer4, where the mode 3 of timer0 has the Non Maskable
Interrupt (NMI in short) function. Mode 0 of timer0 and timer1 is 16-bit Auto-reload mode.
4 high speed uarts: uart1, uart2, uart3, uart4, whose baudrate clock source may be fast as FOSC/4
3 groups of PCAs: CCP0, CCP1, CCP2, which can be used as capture, high speed output and 6-bits, 7-bits, 8-bits
or 10-bits PWM.
45 groups of 15-bit enhanced PWMs, which can realize control signals with dead time, and support external fault
detection function. In addition, there are 3 groups of traditional PCA/CCP/PWMs can be used as PWM.
SPI: Master mode, slave mode or master/slave automatic switch mode are supported.
I2C: Master mode or slave mode are supported.
MDU16: Hardware 16-bit Multiplier and Divider which supports 32-bit divided by 16-bit, 16-bit divided
by 16-bit, 16-bit by 16-bit, data shift, and data normalization operations.
Analog peripherals
15 channels (channel 0 to channel 14) ultra-high speed ADC which supports 10-bit precision analog-to-digital
conversion, the speed can be as fast as 500K(500,000 conversions per second).
ADC channel 15 is used to test the internal reference voltage. (The default internal reference voltage is 1.19V
when the chip is shipped)
Comparator. A set of comparators (the positive terminal of the comparator can select the CMP+ and all ADC
input ports, so the comparator can be used as a multi-channel comparator for time division multiplexing).
DAC. 3 groups of PCAs can be used as DACs. 45-channel enhanced PWMs can be used as 45-channel DACs.
GPIO
Up to 45 GPIOs: P0.0~P0.7, P1.0~P1.7, P2.0~P2.7, P3.0~P3.7, P4.0~P4.7, P5.0~P5.4
4 modes for all GPIOs: quasi_bidirectional mode, push-pull outputmode, open drain mode, high-impedance input
mode
Except for P3.0 and P3.1, all other I/O ports are in a high-impedance state after power-on. User must set
the I/O ports mode before using them. In addition, each I/O can independently enable the internal 4K pull-
up resistor.
Package
LQFP48, QFN48, LQFP32(Not available at present)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 22 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2.4.2 Pinouts
P3.5/PWM35/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
P3.7/PWM37/INT3/TxD_2/CMP+/CCP2_2/CCP2
P3.6/PWM36/INT2/RxD_2/CMP-/CCP1_2
P4.1/PWM41/MISO_3/CMPO_2
P4.3/PWM43/RxD_4/SCLK_3
P2.3/PWM23/A11/MOSI_2
P4.4/PWM44/RD/TxD_4
P2.2/PWM22/A10/SS_2
P5.1/PWM51/TxD3_2
P4.2/PWM42/WR
P2.1/PWM21/A9
P2.0/PWM20/A8
36
35
34
33
32
31
30
29
28
27
26
25
MISO_2/I2CSDA_2/ECI_3/A12/PWM24/P2.4 37 24 P5.0/PWM50/RxD3_2
SCLK_2/I2CSCL_2/CCP0_3/A13/PWM25/P2.5 38 23 P3.4/PWM34/T0/T1CLKO/ECI_2/MOSI_4/CMPO
CCP1_3/A14/PWM26/P2.6 39 22 P3.3/PWM33/INT1/MISO_4/I2CSDA_4
CCP2_3/A15/PWM27/P2.7 40 21 P3.2/PWM32/INT0/SCLK_4/I2CSCL_4
ALE/PWM45/P4.5 41 20 P3.1/PWM31/TxD
RxD2_2/PWM46/P4.6 42 LQFP48 19 P3.0/PWM30/RxD/INT4
RxD3/AD0/ADC8/PWM00/P0.0 43 QFN48 18 P4.0/PWM40/MOSI_3
TxD3/AD1/ADC9/PWM01/P0.1 44 17 Gnd/AGnd
RxD4/AD2/ADC10/PWM02/P0.2 45 16 Vref+
TxD4/AD3/ADC11/PWM03/P0.3 46 15 Vcc/AVcc
T3/AD4/ADC12/PWM04/P0.4 47 14 P5.4/PWM54/RST/MCLKO/SS_3
RxD4_2/PWM52/P5.2 48 13 P1.7/PWM17/ADC7/TxD_3/XTALI
1
2
3
4
5
6
7
8
9
10
11
12
TxD4_2/PWM53/P5.3
T3CLKO/AD5/ADC13/PWM05/P0.5
PWMFLT2/T4/AD6/ADC14/PWM06/P0.6
PWMFLT3/T4CLKO/AD7/PWM07/P0.7
RxD2/CCP1/ADC0/PWM10/P1.0
TxD2/CCP0/ADC1/PWM11/P1.1
TxD2_2/PWM47/P4.7
T2/SS/ECI/ADC2/PWM12/P1.2
T2CLKO/MOSI/ADC3/PWM13/P1.3
I2CSDA/MISO/ADC4/PWM14/P1.4
I2CSCL/SCLK/ADC5/PWM15/P1.5
XTALO/MCLKO_2/RxD_3/ADC6/PWM16/P1.6
Vcc
Connect P3.0
to PC P3.1
Gnd
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 23 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
RxD3/AD0/ADC8/PWM00/P0.0 1 40 P4.5/PWM45/ALE
TxD3/AD1/ADC9/PWM01/P0.1 2 39 P2.7/PWM27/A15/CCP2_3
RxD4/AD2/ADC10/PWM02/P0.2 3 38 P2.6/PWM26/A14/CCP1_3
TxD4/AD3/ADC11/PWM03/P0.3 4 37 P2.5/PWM25/A13/CCP0_3/I2CSCL_2/SCLK_2
T3/AD4/ADC12/PWM04/P0.4 5 36 P2.4/PWM24/A12/ECI_3/I2CSDA_2/MISO_2
T3CLKO/AD5/ADC13/PWM05/P0.5 6 35 P2.3/PWM23/A11/MOSI_2
PWMFLT2/T4/AD6/ADC14/PWM06/P0.6 7 34 P2.2/PWM22/A10/SS_2
PWMFLT3/T4CLKO/AD7/PWM07/P0.7 8 33 P2.1/PWM21/A9
RxD2/CCP1/ADC0/PWM10/P1.0 9 32 P2.0/PWM20/A8
PDIP40
TxD2/CCP0/ADC1/PWM11/P1.1 10 31 P4.4/PWM44/RD/TxD_4
T2/SS/ECI/ADC2/PWM12/P1.2 11 30 P4.2/PWM42/WR
T2CLKO/MOSI/ADC3/PWM13/P1.3 12 29 P4.1/PWM41/MISO_3/CMPO_2
I2CSDA/MISO/ADC4/PWM14/P1.4 13 28 P3.7/PWM37/INT3/TxD_2/CMP+/CCP2_2/CCP2
I2CSCL/SCLK/ADC5/PWM15/P1.5 14 27 P3.6/PWM36/INT2/RxD_2/CMP-/CCP1_2
XTALO/MCLKO_2/RxD_3/ADC6/PWM16/P1.6 15 26 P3.5/PWM35/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
XTALI/TxD_3/ADC7/PWM17/P1.7 16 25 P3.4/PWM34/T0/T1CLKO/ECI_2/MOSI_4/CMPO
SS_3/MCLKO/RST/PWM54/P5.4 17 24 P3.3/PWM33/INT1/MISO_4/I2CSDA_4
Vcc/AVcc 18 23 P3.2/PWM32/INT0/SCLK_4/I2CSCL_4
ADC_VRef+ 19 22 P3.1/PWM31/TxD
Gnd/AGnd 20 21 P3.0/PWM30/RxD/INT4
P3.5/PWM35/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
P3.4/PWM34/T0/T1CLKO/ECI_2/MOSI_4/CMPO
P3.7/PWM37/INT3/TxD_2/CMP+/CCP2_2/CCP2
P3.6/PWM36/INT2/RxD_2/CMP-/CCP1_2
P2.3/PWM23/A11/MOSI_2
P2.2/PWM22/A10/SS_2
P2.1/PWM21/A9
P2.0/PWM20/A8
24
23
22
21
20
19
18
17
MISO_2/I2CSDA_2/ECI_3/A12/PWM24/P2.4 25 16 P3.3/PWM33/INT1/MISO_4/I2CSDA_4
SCLK_2/I2CSCL_2/CCP0_3/A13/PWM25/P2.5 26 15 P3.2/PWM32/INT0/SCLK_4/I2CSCL_4
CCP1_3/A14/PWM26/P2.6 27 14 P3.1/PWM31/TxD
CCP2_3/A15/PWM27/P2.7 28 LQFP32 13 P3.0/PWM30/RxD/INT4
RxD3/AD0/ADC8/PWM00/P0.0 29 12 Gnd/AGnd
TxD3/AD1/ADC9/PWM01/P0.1 30 QFN32 11 Vref+
RxD4/AD2/ADC10/PWM02/P0.2 31 10 Vcc/AVcc
TxD4/AD3/ADC11/PWM03/P0.3 32 9 P5.4/PWM54/RST/MCLKO/SS_3
1
2
3
4
5
6
7
8
RxD2/CCP1/ADC0/PWM10/P1.0
TxD2/CCP0/ADC1/PWM11/P1.1
T2/SS/ECI/ADC2/PWM12/P1.2
T2CLKO/MOSI/ADC3/PWM13/P1.3
I2CSDA/MISO/ADC4/PWM14/P1.4
I2CSCL/SCLK/ADC5/PWM15/P1.5
XTALO/MCLKO_2/RxD_3/ADC6/PWM16/P1.6
XTALI/TxD_3/ADC7/PWM17/P1.7
Note:
1. ADC's external reference power supply pin ADC_VRef+ must not be floating, it must be connected to an
external reference power supply or directly connected to Vcc.
2. If USB download is not required, P3.0/P3.1/P3.2 cannot be at low level at the same time when the chip is
reset.
indicator is off).
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 indicator is on).
5. Start ISP download.
Note: It has been found that when using the USB cable for ISP download, if the USB cable is too thin
and the voltage drop on the USB cable is too large, this will result in insufficient power supply during
the ISP download. Therefore, please be sure to use the booster USB cable for ISP download.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 26 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Pin number
LQFP48
name type description
P1.5 I/O Standard IO port
PWM15 O Enhanced PWM output
11 ADC5 I ADC analog input 5
SCLK I/O Serial Clock of SPI
SCL I/O Serial Clock line of I2C
P1.6 I/O Standard IO port
PWM16 O Enhanced PWM output
ADC6 I ADC analog input 6
12
RxD_3 I Serial input of UART1
MCLKO_2 O Master clock output
XTALO O Connect to external oscillator
P1.7 I/O Standard IO port
PWM17 O Enhanced PWM output
13 ADC7 I ADC analog input 7
TxD_3 O Serial output of UART 1
XTALI I Connect to external oscillator
P5.4 I/O Standard IO port
PWM54 O Enhanced PWM output
14 RST I Reset pin
MCLKO O Master clock output
SS_3 I Slave selection of SPI (it is output with regard to master)
Vcc VCC Power Supply
15
AVcc VCC ADC Power Supply
16 Vref+ I Reference voltage pin of ADC
Gnd GND Ground
17
AGnd GND ADC Ground
P4.0 I/O Standard IO port
18 PWM40 O Enhanced PWM output
MOSI_3 I/O Master Output/Slave Input of SPI
P3.0 I/O Standard IO port
PWM30 O Enhanced PWM output
19
RxD I Serial input of UART1
INT4 I External interrupt 4
P3.1 I/O Standard IO port
20 PWM31 O Enhanced PWM output
TxD O Serial output of UART 1
P3.2 I/O Standard IO port
PWM32 O Enhanced PWM output
21 INT0 I External interrupt 0
SCLK_4 I/O Serial Clock of SPI
SCL_4 I/O Serial Clock line of I2C
P3.3 I/O Standard IO port
PWM33 O Enhanced PWM output
22 INT1 I External interrupt 1
MISO_4 I/O Master Iutput/Slave Onput of SPI
SDA_4 I/O Serial data line of I2C
P3.4 I/O Standard IO port
PWM34 O Enhanced PWM output
T0 I Timer0 external input
23 T1CLKO O Clock out of timer 1
ECI_2 I External pulse input of PCA
MOSI_4 I/O Master Output/Slave Input of SPI
CMPO O Comparator output
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 27 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Pin number
LQFP48
name type description
P5.0 I/O Standard IO port
24 PWM50 O Enhanced PWM output
RxD3_2 I Serial input of UART3
P5.1 I/O Standard IO port
25 PWM51 O Enhanced PWM output
TxD3_2 O Serial output of UART 3
P3.5 I/O Standard IO port
PWM35 O Enhanced PWM output
T1 I Timer1 external input
26 T0CLKO O Clock out of timer 0
SS_4 I Slave selection of SPI (it is output with regard to master)
CCP0_2 I/O Capture of external signal/High-speed Pulse output of PCA
PWMFLT I Enhanced PWM fault detection
P3.6 I/O Standard IO port
PWM36 O Enhanced PWM output
INT2 I External interrupt 2
27
RxD_2 I Serial input of UART1
CMP- I Comparator negative input
CCP1_2 I/O Capture of external signal/High-speed Pulse output of PCA
P3.7 I/O Standard IO port
PWM37 O Enhanced PWM output
INT3 I External interrupt 3
28 TxD_2 O Serial output of UART 1
CMP+ I Comparator positive input
CCP2 I/O Capture of external signal/High-speed Pulse output of PCA
CCP2_2 I/O Capture of external signal/High-speed Pulse output of PCA
P4.1 I/O Standard IO port
PWM41 O Enhanced PWM output
29
MISO_3 I/O Master Iutput/Slave Onput of SPI
CMPO_2 O Comparator output
P4.2 I/O Standard IO port
30 PWM42 O Enhanced PWM output
WR O Write signal of external bus
P4.3 I/O Standard IO port
PWM43 O Enhanced PWM output
31
RxD_4 I Serial input of UART1
SCLK_3 I/O Serial Clock of SPI
P4.4 I/O Standard IO port
PWM44 O Enhanced PWM output
32
RD O Read signal of external bus
TxD_4 O Serial output of UART 1
P2.0 I/O Standard IO port
33 PWM20 O Enhanced PWM output
A8 I Address bus
P2.1 I/O Standard IO port
34 PWM21 O Enhanced PWM output
A9 I Address bus
P2.2 I/O Standard IO port
PWM22 O Enhanced PWM output
35
A10 I Address bus
SS_2 I Slave selection of SPI (it is output with regard to master)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 28 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Pin number
LQFP48
name type description
P2.3 I/O Standard IO port
PWM23 O Enhanced PWM output
36 A11 I Address bus
MOSI_2 I/O Master Output/Slave Input of SPI
CCP0_2 I/O Capture of external signal/High-speed Pulse output of PCA
P2.4 I/O Standard IO port
PWM24 O Enhanced PWM output
A12 I Address bus
37
ECI_3 I External pulse input of PCA
SDA_2 I/O Serial data line of I2C
MISO_2 I/O Master Iutput/Slave Onput of SPI
P2.5 I/O Standard IO port
PWM25 O Enhanced PWM output
A13 I Address bus
38
CCP0_3 I/O Capture of external signal/High-speed Pulse output of PCA
SCL_2 I/O Serial Clock line of I2C
SCLK_2 I/O Serial Clock of SPI
P2.6 I/O Standard IO port
PWM26 O Enhanced PWM output
39
A14 I Address bus
CCP1_3 I/O Capture of external signal/High-speed Pulse output of PCA
P2.7 I/O Standard IO port
PWM27 O Enhanced PWM output
40
A15 I Address bus
CCP2_3 I/O Capture of external signal/High-speed Pulse output of PCA
P4.5 I/O Standard IO port
41 PWM45 O Enhanced PWM output
ALE O Address Latch Enable signal
P4.6 I/O Standard IO port
42 PWM46 O Enhanced PWM output
RxD2_2 I Serial input of UART2
P0.0 I/O Standard IO port
PWM00 O Enhanced PWM output
43 ADC8 I ADC analog input 8
AD0 I Address/data bus
RxD3 I Serial input of UART3
P0.1 I/O Standard IO port
PWM01 O Enhanced PWM output
44 ADC9 I ADC analog input 9
AD1 I Address/data bus
TxD3 O Serial output of UART 3
P0.2 I/O Standard IO port
PWM02 O Enhanced PWM output
45 ADC10 I ADC analog input 10
AD2 I Address/data bus
RxD4 I Serial input of UART4
P0.3 I/O Standard IO port
PWM03 O Enhanced PWM output
46 ADC11 I ADC analog input 11
AD3 I Address/data bus
TxD4 O Serial output of UART 4
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 29 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Pin number
LQFP48
name type description
P0.4 I/O Standard IO port
PWM04 O Enhanced PWM output
47 ADC12 I ADC analog input 12
AD4 I Address/data bus
T3 I Timer3 external input
P5.2 I/O Standard IO port
48 PWM52 O Enhanced PWM output
RxD4_2 I Serial input of UART4
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 30 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
do not have.
Internal high reliable reset circuit with 4-level optional reset threshold voltage
PCA/CCP/PWM (can be used as external interrupt and can wake-up CPU)
16-bit advanced PWM timer Complementary symmetrical dead-time
Package
Comparator (May be used as ADC to detect external power-down)
15-channels high speed ADC (All PWMs can be used as DACs)
Online debugging
Watch-dog Timer
MCU model
SPI
I2 C
QFN48<6mm*6mm>
(
LQFP48
)
Note: The above unit prices are for orders of quantity of 10K and above. If the quantity is small, an additional RMB
0.1 per piece will be required. When the total amount of the order reaches or exceeds 3,000 yuan, it can be shipped free of
charge, otherwise the customer will have to bear the freight. Retail sale starts at 10 pieces.
Core
Ultra-high speed 8051 Core with single clock per machine cycle, which is called 1T and the speed is about 12
times faster than traditional 8051
Fully compatible instruction set with traditional 8051
27 interrupt sources and 4 interrupt priority levels
Online debugging is supported
Operating voltage
1.9V~5.5V
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 31 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Built-in LDO
Operating temperature
-40℃~85℃
Flash memory
Up to 64Kbytes of Flash memory to be used to store user code
Configurable size EEPROM, 512bytes single page erased, can be repeatedly erased more than 100 thousand
times.
In-System-Programming, ISP in short, can be used to update the application code, no need for special
programmer.
Online debugging with single chip is supported, and no special emulator is needed. The number of breakpoints is
unlimited theoratically.
SRAM
128 bytes internal direct access RAM (DATA)
128 bytes internal indirect access RAM (IDATA)
2048 bytes internal extended RAM (internal XDATA)
Clock
Internal high precise R/C clock (IRC, range from 4MHz to 36MHz), adjustable while ISP and can be divided to
lower frequency by user software, 100KHz for instance.
Error:±0.3% (at the temperature 25℃)
-1.38%~+1.42% temperature drift (at the temperature range of -40°C to +85°C)
-0.88%~+1.05% temperature drift (at the temperature range of -20℃ to 65℃)
Internal 32KHz low speed IRC with large error
External 4MHz~33MHz oscillator or external clock
Reset
Hardware reset
Power-on reset. Measured voltage value is 1.69V~1.82V. (Effective when the chip does not enable the
low voltage reset function)
The power-on reset voltage is a voltage range consisting of an upper limit voltage and a lower limit voltage.
When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage of the power-on reset,
the chip is in a reset state; when the voltage rises from 0V to the upper threshold voltage of power-on reset,
the chip is released from the reset state.
Reset by reset pin. The default function of P5.4 is the I/O port. The P5.4 pin can be set as the reset pin
while ISP download. (Note: When the P5.4 pin is set as the reset pin, the reset level is low.)
Watch dog timer reset
Low voltage detection reset. 4 low voltage detection levels are provided, 2.2V (Measured as 1.90V~2.04V),
2.4V (Measured as 2.30V~2.50V), V2.7 (Measured as 2.61V~2.82V), V3.0 (Measured as 2.90V~3.13V).
Each level of low-voltage detection voltage is a voltage range consisting of an upper limit voltage and a
lower limit voltage. When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage
of low-voltage detection, the low-voltage detection takes effect. When the voltage rises from 0V to the
upper threshold voltage, the low voltage detection becomes effective.
Software reset
Writing the reset trigger register using software
Interrupts
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 32 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
27 interrupt sources: INT0(Supports rising edge and falling edge interrupt), INT1(Supports rising edge and
falling edge interrupt), INT2(Supports falling edge interrupt only), INT3(Supports falling edge interrupt only),
INT4(Supports falling edge interrupt only), timer0, timer1, timer2, timer3, timer4, UART1, UART2, ADC, LVD,
SPI, I2C, comparator, PCA/CCP/PWM, enhanced PWM2, enhanced PWM2 fault detection.
4 interrupt priority levels
Interrupts that can awaken the CPU in clock stop mode: INT0 (P3.2), INT1 (P3.3), INT2 (P3.6), INT3 (P3.7),
INT4 (P3.0), T0 (P3.4), T1(P3.5), T2(P1.2), T3(P0.4), T4(P0.6), RXD(P3.0/P3.6/P1.6/P4.3), RXD2(P1.4/P4.6),
CCP0(P1.1/P3.5/P2.5), CCP1(P1.0/P3.6/P2.6), CCP2 (P3.7/P2.7), I2C_SDA (P1.4/P2.4/P3.3) and comparator
interrupt, low-voltage detection interrupt, power-down wake-up timer.
Digital peripherals
5 16-bit timers: timer0, timer1, timer2, timer3, timer4, where the mode 3 of timer0 has the Non Maskable
Interrupt (NMI in short) function. Mode 0 of timer0 and timer1 is 16-bit Auto-reload mode.
2 high speed UARTs: UART1, UART2, whose baudrate clock source may be fast as FOSC/4
3 groups of 16-bit PCAs: CCP0, CCP1, CCP2, which can be used as capture, high speed output and 6-bits, 7-bits,
8-bits or 10-bits PWM.
8 groups of 15-bit enhanced PWMs, which can realize control signals with dead-time, and support external fault
detection function. In addition, there are 3 groups of traditional PCA / CCP / PWM can be used as PWM.
SPI: Master mode, slave mode or master/slave automatic switch mode are supported.
I2C: Master mode or slave mode are supported.
MDU16: Hardware 16-bit Multiplier and Divider which supports 32-bit divided by 16-bit, 16-bit divided
by 16-bit, 16-bit by 16-bit, data shift, and data normalization operations.
Analog peripherals
15 channels (channel 0 to channel 14) ultra-high speed ADC which supports 10-bit precision analog-to-digital
conversion.
ADC channel 15 is used to test the internal reference voltage. (The default internal reference voltage is 1.19V
when the chip is shipped)
Comparator. A set of comparators (the positive terminal of the comparator can select the CMP+ and all ADC
input ports, so the comparator can be used as a multi-channel comparator for time division multiplexing).
DAC. 3 groups of PCAs can be used as DACs. 8 channels enhanced PWMs can be used as DACs.
GPIO
Up to 45 GPIOs: P0.0~P0.7, P1.0~P1.7, P2.0~P2.7, P3.0~P3.7, P4.0~P4.7, P5.0~P5.4
4 modes for all GPIOs: quasi_bidirectional mode, push-pull outputmode, open drain mode, high-impedance input
mode
Except for P3.0 and P3.1, all other I/O ports are in a high-impedance state after power-on. User must set
the I/O ports mode before using them. In addition, each I/O can independently enable the internal 4K pull-
up resistor.
Package
LQFP48, QFN48
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 33 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2.5.2 Pinouts
P3.5/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
P3.7/INT3/TxD_2/CMP+/CCP2_2/CCP2
P3.6/INT2/RxD_2/CMP-/CCP1_2
P2.3/PWM23/A11/MOSI_2
P2.2/PWM22/A10/SS_2
P4.1/MISO_3/CMPO_2
P4.3/RxD_4/SCLK_3
P2.1/PWM21/A9
P2.0/PWM20/A8
P4.4/RD/TxD_4
P4.2/WR
P5.1
36
35
34
33
32
31
30
29
28
27
26
25
MISO_2/I2CSDA_2/ECI_3/A12/PWM24/P2.4 37 24 P5.0/
SCLK_2/I2CSCL_2/CCP0_3/A13/PWM25/P2.5 38 23 P3.4/T0/T1CLKO/ECI_2/MOSI_4/CMPO
CCP1_3/A14/PWM26/P2.6 39 22 P3.3/INT1/MISO_4/I2CSDA_4
CCP2_3/A15/PWM27/P2.7 40 21 P3.2/INT0/SCLK_4/I2CSCL_4
ALE/P4.5 41 20 P3.1/TxD
RxD2_2/P4.6 42 LQFP48 19 P3.0/RxD/INT4
AD0/ADC8/P0.0 43 QFN48 18 P4.0/MOSI_3
AD1/ADC9/P0.1 44 17 Gnd/AGnd
AD2/ADC10/P0.2 45 16 Vref+
AD3/ADC11/P0.3 46 15 Vcc/AVcc
T3/AD4/ADC12/P0.4 47 14 P5.4/RST/MCLKO/SS_3
P5.2 48 13 P1.7/ADC7/TxD_3/XTALI
1
2
3
4
5
6
7
8
9
10
11
12
P5.3
T3CLKO/AD5/ADC13/P0.5
PWMFLT2/T4/AD6/ADC14/P0.6
PWMFLT3/T4CLKO/AD7/P0.7
RxD2/CCP1/ADC0/P1.0
TxD2/CCP0/ADC1/P1.1
TxD2_2/P4.7
T2/SS/ECI/ADC2/P1.2
T2CLKO/MOSI/ADC3/P1.3
I2CSDA/MISO/ADC4/P1.4
I2CSCL/SCLK/ADC5/P1.5
XTALO/MCLKO_2/RxD_3/ADC6/P1.6
Note:
1. ADC's external reference power supply pin ADC_VRef+ must not be floating, it must be connected to an
external reference power supply or directly connected to Vcc.
2. If USB download is not required, P3.0/P3.1/P3.2 cannot be at low level at the same time when the chip is
reset.
Vcc
Connect P3.0
to PC P3.1
Gnd
Note: It has been found that when using the USB cable for ISP download, if the USB cable is too thin
and the voltage drop on the USB cable is too large, this will result in insufficient power supply during
the ISP download. Therefore, please be sure to use the booster USB cable for ISP download.
AD0/ADC8/P0.0 1 40 P4.5/ALE
AD1/ADC9/P0.1 2 39 P2.7/PWM27/A15/CCP2_3
AD2/ADC10/P0.2 3 38 P2.6/PWM26/A14/CCP1_3
AD3/ADC11/P0.3 4 37 P2.5/PWM25/A13/CCP0_3/I2CSCL_2/SCLK_2
T3/AD4/ADC12/P0.4 5 36 P2.4/PWM24/A12/ECI_3/I2CSDA_2/MISO_2
T3CLKO/AD5/ADC13/P0.5 6 35 P2.3/PWM23/A11/MOSI_2
PWMFLT2/T4/AD6/ADC14/P0.6 7 34 P2.2/PWM22/A10/SS_2
PWMFLT3/T4CLKO/AD7/P0.7 8 33 P2.1/PWM21/A9
RxD2/CCP1/ADC0/P1.0 9 32 P2.0/PWM20/A8
PDIP40
TxD2/CCP0/ADC1/P1.1 10 31 P4.4/RD/TxD_4
T2/SS/ECI/ADC2/P1.2 11 30 P4.2/WR
T2CLKO/MOSI/ADC3/P1.3 12 29 P4.1/MISO_3/CMPO_2
I2CSDA/MISO/ADC4/P1.4 13 28 P3.7/INT3/TxD_2/CMP+/CCP2_2/CCP2
I2CSCL/SCLK/ADC5/P1.5 14 27 P3.6/INT2/RxD_2/CMP-/CCP1_2
XTALO/MCLKO_2/RxD_3/ADC6/P1.6 15 26 P3.5/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
XTALI/TxD_3/ADC7/P1.7 16 25 P3.4/T0/T1CLKO/ECI_2/MOSI_4/CMPO
SS_3/MCLKO/RST/P5.4 17 24 P3.3/INT1/MISO_4/I2CSDA_4
Vcc/AVcc 18 23 P3.2/INT0/SCLK_4/I2CSCL_4
ADC_VRef+ 19 22 P3.1/TxD
Gnd/AGnd 20 21 P3.0/RxD/INT4
Pin number
LQFP48
name type description
P3.5 I/O Standard IO port
T1 I Timer1 external input
T0CLKO O Clock out of timer 0
26
SS_4 I Slave selection of SPI (it is output with regard to master)
CCP0_2 I/O Capture of external signal/High-speed Pulse output of PCA
PWMFLT I Enhanced PWM fault detection
P3.6 I/O Standard IO port
INT2 I External interrupt 2
27 RxD_2 I Serial input of UART1
CMP- I Comparator negative input
CCP1_2 I/O Capture of external signal/High-speed Pulse output of PCA
P3.7 I/O Standard IO port
INT3 I External interrupt 3
TxD_2 O Serial output of UART 1
28
CMP+ I Comparator positive input
CCP2 I/O Capture of external signal/High-speed Pulse output of PCA
CCP2_2 I/O Capture of external signal/High-speed Pulse output of PCA
P4.1 I/O Standard IO port
29 MISO_3 I/O Master Iutput/Slave Onput of SPI
CMPO_2 O Comparator output
P4.2 I/O Standard IO port
30
WR O Write signal of external bus
P4.3 I/O Standard IO port
31 RxD_4 I Serial input of UART1
SCLK_3 I/O Serial Clock of SPI
P4.4 I/O Standard IO port
32 RD O Read signal of external bus
TxD_4 O Serial output of UART 1
P2.0 I/O Standard IO port
33 PWM20 O Enhanced PWM output
A8 I Address bus
P2.1 I/O Standard IO port
34 PWM21 O Enhanced PWM output
A9 I Address bus
P2.2 I/O Standard IO port
PWM22 O Enhanced PWM output
35
A10 I Address bus
SS_2 I Slave selection of SPI (it is output with regard to master)
P2.3 I/O Standard IO port
PWM23 O Enhanced PWM output
36 A11 I Address bus
MOSI_2 I/O Master Output/Slave Input of SPI
CCP0_2 I/O Capture of external signal/High-speed Pulse output of PCA
P2.4 I/O Standard IO port
PWM24 O Enhanced PWM output
A12 I Address bus
37
ECI_3 I External pulse input of PCA
SDA_2 I/O Serial data line of I2C
MISO_2 I/O Master Iutput/Slave Onput of SPI
P2.5 I/O Standard IO port
38
PWM25 O Enhanced PWM output
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 37 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 38 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Internal high reliable reset circuit with 4 level optional reset threshold voltage
PCA/CCP/PWM (can be used as external interrupt and can wake-up CPU)
Package
Comparator (May be used as ADC to detect external power-down)
15-channels high speed ADC (3 PWMs can be used as 3 DACs)
Online debugging
Watch-dog Timer
MCU model
LED driver
Touch key
SPI
I2 C
QFN20 (3mm*3mm)
(
TSSOP20
SOP16
)
Examples
STC8G1K17T 1.9-5.5 17K 256 1K 2 IAP 16 1 Y Y Y Y 3 3 Y 10bie Y Y Y Y Y Y Y Y Y - - √
Note: The above unit prices are for orders of quantity of 10K and above. If the quantity is small, an additional RMB
0.1 per piece will be required. When the total amount of the order reaches or exceeds 3,000 yuan, it can be shipped free of
charge, otherwise the customer will have to bear the freight. Retail sale starts at 10 pieces.
Core
Ultra-high speed 8051 Core with single clock per machine cycle, which is called 1T and the speed is about 12
times faster than traditional 8051
Fully compatible instruction set with traditional 8051
16 interrupt sources and 4 interrupt priority levels
Online debugging is supported
Operating voltage
1.9V~5.5V
Built-in LDO
Operating temperature
-40℃~85℃
Flash memory
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 39 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SRAM
128 bytes internal direct access RAM (DATA)
128 bytes internal indirect access RAM (IDATA)
1024 bytes internal extended RAM (internal XDATA)
Clock
Internal high precise R/C clock (IRC, range from 4MHz to 36MHz), adjustable while ISP and can be divided to
lower frequency by user software, 100KHz for instance.
Error:±0.3% (at the temperature 25℃)
-1.38%~+1.42% temperature drift (at the temperature range of -40°C to +85°C)
-0.88%~+1.05% temperature drift (at the temperature range of -20℃ to 65℃)
Internal 32KHz low speed IRC with large error
External 4MHz~33MHz oscillator or external clock
The three clock sources above can be selected freely by used code.
Reset
Hardware reset
Power-on reset. Measured voltage value is 1.69V~1.82V. (Effective when the chip does not enable the
low voltage reset function)
The power-on reset voltage is a voltage range consisting of an upper limit voltage and a lower limit voltage.
When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage of the power-on reset,
the chip is in a reset state; when the voltage rises from 0V to the upper threshold voltage of power-on reset,
the chip is released from the reset state.
Reset by reset pin. The default function of P5.4 is the I/O port. The P5.4 pin can be set as the reset pin
while ISP download. (Note: When the P5.4 pin is set as the reset pin, the reset level is low.)
Watch dog timer reset
Low voltage detection reset. 4 low voltage detection levels are provided, 2.2V (Measured as 1.90V~2.04V),
2.4V (Measured as 2.30V~2.50V), V2.7 (Measured as 2.61V~2.82V), V3.0 (Measured as 2.90V~3.13V).
Each level of low-voltage detection voltage is a voltage range consisting of an upper limit voltage and a
lower limit voltage. When the operating voltage drops from 5V / 3.3V to the lower limit threshold voltage
of low-voltage detection, the low-voltage detection takes effect. When the voltage rises from 0V to the
upper threshold voltage, the low voltage detection becomes effective.
Software reset
Writing the reset trigger register using software
Interrupts
16 interrupt sources: INT0(Supports rising edge and falling edge interrupt), INT1(Supports rising edge and
falling edge interrupt), INT2(Supports falling edge interrupt only), INT3(Supports falling edge interrupt only),
INT4(Supports falling edge interrupt only), timer0, timer1, timer2, UART1, ADC, LVD, SPI, I2C, comparator,
PCA/CCP/PWM, touch key
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 40 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Digital peripherals
3 16-bit timers: timer0, timer1, timer2, where the mode 3 of timer0 has the Non Maskable Interrupt (NMI in
short) function. Mode 0 of timer0 and timer1 is 16-bit Auto-reload mode.
1 high speed UART: UART1, whose baudrate clock source may be fast as FOSC/4
3 groups of 16-bit PCAs: CCP0, CCP1, CCP2, which can be used as capture, high speed output and 6-bits, 7-bits,
8-bits or 10-bits PWM.
SPI: Master mode, slave mode or master/slave automatic switch mode are supported.
I2C: Master mode or slave mode are supported.
Analog peripherals
15 channels (channel 0 to channel 14) ultra-high speed ADC which supports 10-bit precision analog-to-digital
conversion.
ADC channel 15 is used to test the internal reference voltage. (The default internal reference voltage is 1.19V
when the chip is shipped)
Comparator. A set of comparators (the positive terminal of the comparator can select the CMP+ and all ADC
input ports, so the comparator can be used as a multi-channel comparator for time division multiplexing).
Touch key: The microcontroller supports up to 16 touch keys. Each touch key can be independently enabled. The
internal reference voltage is adjustable in 4 levels. Charge and discharge time settings and internal working
frequency settings are flexible. The touch key supports wake-up from low-power mode.
LED driver: The microcontroller can drive up to 128 (8 * 8 * 2) LEDs, support common negative mode,
common positive mode and common negative/common positive mode, and support 8 levels of gray
adjustment (brightness adjustment).
DAC. 3 groups of PCAs can be used as DACs.
GPIO
Up to 16 GPIOs: P1.0~P1.1, P1.3~P1.7, P3.0~P3.7, P5.4
4 modes for all GPIOs: quasi_bidirectional mode, push-pull outputmode, open drain mode, high-impedance input
mode
Except for P3.0 and P3.1, all other I/O ports are in a high-impedance state after power-on. User must set
the I/O ports mode before using them. In addition, each I/O can independently enable the internal 4K pull-
up resistor.
Package
TSSOP20, QFN20 (3mm*3mm)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 41 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2.6.2 Pinouts
COM4/TK4/CCP1_3/X32O/I2CSDA/MISO/ADC4/P1.4 1 20 P1.1/ADC1/CCP0/TK1/COM1
COM5/TK5/CCP2_3/X32I/I2CSCL/SCLK/ADC5/P1.5 2 19 P1.0/ADC0/CCP1/TK0/COM0
COM6/TK6/XTALO/MCLKO_2/RxD_3/ADC6/P1.6 3 18 P3.7/INT3/TxD_2/CCP2_2/CCP2/CMP+/TK15/SEG7
TSSOP20
COM7/TK7/XTALI/TxD_3/ADC7/P1.7 4 17 P3.6/ADC14/INT2/RxD_2/CCP1_2/CMP-/TK14/SEG6
COM3/TK3/CCP0_3/ECI/T2CLKO/MOSI/ADC3/P1.3 5 16 P3.5/ADC13/T1/T0CLKO/CCP0_2/SS_4/TK13/SEG5
TK_CAP 6 15 P3.4/ADC12/T0/T1CLKO/ECI_2/CMPO/MOSI_4/TK12/SEG4
COM2/TK2/ECI_3/T2/SS/MCLKO/RST/ADC2/P5.4 7 14 P3.3/ADC11/INT1/MISO_4/I2CSDA_4/TK11/SEG3
VCC/AVCC 8 13 P3.2/ADC10/INT0/SCLK_4/I2CSCL_4/TK10/SEG2
VREF+ 9 12 P3.1/ADC9/TxD/TK9/SEG1
GND/AGND 10 11 P3.0/ADC8/RxD/INT4/TK8/SEG0
Note:
1. ADC's external reference power supply pin ADC_VRef+ must not be floating, it must be connected to an
external reference power supply or directly connected to Vcc.
2. If USB download is not required, P3.0/P3.1/P3.2 cannot be at low level at the same time when the chip is
reset.
Vcc
Connect P3.0
to PC P3.1
Gnd
Pin number
TSSOP20 QFN20
name type description
P1.7 I/O Standard IO port
ADC7 I ADC analog input 7
TxD_3 O Serial output of UART 1
4
XTALI I Connect to external oscillator
TK7 I Touch key
COM7 O LED dirver
P1.3 I/O Standard IO port
ADC3 I ADC analog input 3
T2CLKO O Clock out of timer 2
MOSI I/O Master Output/Slave Input of SPI
5
ECI I External pulse input of PCA
CCP0_3 I/O Capture of external signal/High-speed Pulse output of PCA
TK3 I Touch key
COM3 O LED dirver
6 TK_CAP I External capacitor for touch key
P5.4 I/O Standard IO port
ADC2 I ADC analog input 2
RST I Reset pin
MCLKO O Master clock output
7 SS I/O SPI slave selection
T2 I Timer2 external input
ECI_3 I External pulse input of PCA
TK2 I Touch key
COM2 O LED dirver
VCC VCC Power Supply
8
AVCC VCC Power Supply for ADC
9 VREF+ I Reference voltage pin of ADC
GND GND Ground
10
AGND GND ADC Ground
P3.0 I/O Standard IO port
RxD I Serial input of UART1
ADC8 I ADC analog input 8
11
INT4 I External interrupt 4
TK8 I Touch key
SEG0 O LED dirver
P3.1 I/O Standard IO port
12 TxD O Serial output of UART 1
ADC9 I ADC analog input 9
TK9 I Touch key
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 43 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 45 -
Availa
Main product supply information ble
- 46 -
2.7 STC15H family (Traditional STC15 series to enhance the
wafers is tight, the STC8G2K64S4 series wafers are used to produce the above special models. If you need to purchase the
Note: Because the performance of the traditional STC15F2K series needs to be improved, and the current supply of
Development adviser: +86-13922805190
LQFP32
√ √ √
√ √ √
PDIP40
Package
LQFP44
LQFP48
Y
Support software USBdownload directly
Y
Y
Support RS485 download
Y
Password can be set for next update
Y
Program encrypted transmission (Anti-blocking)
Y
Clock output and Reset
Y
Internal high presision Clock (adjustbal under 36MHz)
Y
Internal high reliable reset circuit with 4-level optional reset threshold voltage
Y
Technical support: +86-13922809991
Watch-dog Timer
performance of special models)
Y
Internal LVD interrupt (can wake-up CPU)
Y
Comparator (May be used as ADC to detect external power-down)
Y 10bit Y
Y 10bit Y
15-channels high speed ADC (All PWMs can be used as DACs)
3
42
42
15-bit enhanced PWM (with dead-time control)
16-bit advanced PWM timer Complementary symmetrical dead-time
-
Timers/Counters (T0-T4 Pin can wake-up CPU)
5
I2 C
SPI
Y
Features and Price
Y
UARTs which may wake-up CPU
4
2 16K 42
2 IAP 42
Maximum I/O Lines
Selection and price EEPROM 100 thousand times) (Byte)
(
)
Operating voltage V
2.7.1
MCU model
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2.7.2 Pinouts
P3.5/PWM35/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
P3.7/PWM37/INT3/TxD_2/CMP+/CCP2_2/CCP2
P3.6/PWM36/INT2/RxD_2/CMP-/CCP1_2
P4.1/PWM41/MISO_3/CMPO_2
P4.3/PWM43/RxD_4/SCLK_3
P2.3/PWM23/A11/MOSI_2
P4.4/PWM44/RD/TxD_4
P2.2/PWM22/A10/SS_2
P4.2/PWM42/WR
P2.1/PWM21/A9
P2.0/PWM20/A8
33
32
31
30
29
28
27
26
25
24
23
MISO_2/I2CSDA_2/ECI_3/A12/PWM24/P2.4 34 22 P3.4/PWM34/T0/T1CLKO/ECI_2/MOSI_4/CMPO
SCLK_2/I2CSCL_2/CCP0_3/A13/PWM25/P2.5 35 21 P3.3/PWM33/INT1/MISO_4/I2CSDA_4
CCP1_3/A14/PWM26/P2.6 36 20 P3.2/PWM32/INT0/SCLK_4/I2CSCL_4
CCP2_3/A15/PWM27/P2.7 37 19 P3.1/PWM31/TxD
ALE/PWM45/P4.5 38 18 P3.0/PWM30/RxD/INT4
RxD2_2/PWM46/P4.6 39
STC15H2K64S4 17 P4.0/PWM40/MOSI_3
RxD3/AD0/ADC8/PWM00/P0.0 40 LQFP44 16 Gnd/AGnd
MCU-VCC
TxD3/AD1/ADC9/PWM01/P0.1 41 15 P5.2/PWM52/RxD4_2
RxD4/AD2/ADC10/PWM02/P0.2 42 14 Vcc/Avcc/ADC_VRef+
TxD4/AD3/ADC11/PWM03/P0.3 43 13 P5.4/PWM54/RST/MCLKO/SS_3 22u 0.1u
T3/AD4/ADC12/PWM04/P0.4 44 12 P1.7/PWM17/ADC7/TxD_3/XTALI
1
2
3
4
5
6
7
8
9
10
11
T3CLKO/AD5/ADC13/PWM05/P0.5
PWMFLT2/T4/AD6/ADC14/PWM06/P0.6
PWMFLT3/T4CLKO/AD7/PWM07/P0.7
RxD2/CCP1/ADC0/PWM10/P1.0
TxD2/CCP0/ADC1/PWM11/P1.1
TxD2_2/PWM47/P4.7
T2/SS/ECI/ADC2/PWM12/P1.2
T2CLKO/MOSI/ADC3/PWM13/P1.3
I2CSDA/MISO/ADC4/PWM14/P1.4
I2CSCL/SCLK/ADC5/PWM15/P1.5
XTALO/MCLKO_2/RxD_3/ADC6/PWM16/P1.6
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 47 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
RxD3/AD0/ADC8/PWM00/P0.0 1 40 P4.5/PWM45/ALE
TxD3/AD1/ADC9/PWM01/P0.1 2 39 P2.7/PWM27/A15/CCP2_3
RxD4/AD2/ADC10/PWM02/P0.2 3 38 P2.6/PWM26/A14/CCP1_3
TxD4/AD3/ADC11/PWM03/P0.3 4 37 P2.5/PWM25/A13/CCP0_3/I2CSCL_2/SCLK_2
T3/AD4/ADC12/PWM04/P0.4 5 36 P2.4/PWM24/A12/ECI_3/I2CSDA_2/MISO_2
T3CLKO/AD5/ADC13/PWM05/P0.5 6 35 P2.3/PWM23/A11/MOSI_2
STC15H2K64S4
PWMFLT2/T4/AD6/ADC14/PWM06/P0.6 7 34 P2.2/PWM22/A10/SS_2
PWMFLT3/T4CLKO/AD7/PWM07/P0.7 8 33 P2.1/PWM21/A9
RxD2/CCP1/ADC0/PWM10/P1.0 9 32 P2.0/PWM20/A8
PDIP40
TxD2/CCP0/ADC1/PWM11/P1.1 10 31 P4.4/PWM44/RD/TxD_4
T2/SS/ECI/ADC2/PWM12/P1.2 11 30 P4.2/PWM42/WR
T2CLKO/MOSI/ADC3/PWM13/P1.3 12 29 P4.1/PWM41/MISO_3/CMPO_2
I2CSDA/MISO/ADC4/PWM14/P1.4 13 28 P3.7/PWM37/INT3/TxD_2/CMP+/CCP2_2/CCP2
MCU-VCC I2CSCL/SCLK/ADC5/PWM15/P1.5 14 27 P3.6/PWM36/INT2/RxD_2/CMP-/CCP1_2
XTALO/MCLKO_2/RxD_3/ADC6/PWM16/P1.6 15 26 P3.5/PWM35/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
XTALI/TxD_3/ADC7/PWM17/P1.7 16 25 P3.4/PWM34/T0/T1CLKO/ECI_2/MOSI_4/CMPO
SS_3/MCLKO/RST/PWM54/P5.4 17 24 P3.3/PWM33/INT1/MISO_4/I2CSDA_4
22u 0.1u Vcc/Avcc/ADC_Vref+ 18 23 P3.2/PWM32/INT0/SCLK_4/I2CSCL_4
RxD4_2/PWM52/P5.2 19 22 P3.1/PWM31/TxD
Gnd/AGnd 20 21 P3.0/PWM30/RxD/INT4
P3.5/PWM35/T1/T0CLKO/SS_4/CCP0_2/PWMFLT
P3.4/PWM34/T0/T1CLKO/ECI_2/MOSI_4/CMPO
P3.7/PWM37/INT3/TxD_2/CMP+/CCP2_2/CCP2
P3.6/PWM36/INT2/RxD_2/CMP-/CCP1_2
P2.3/PWM23/A11/MOSI_2
P2.2/PWM22/A10/SS_2
P2.1/PWM21/A9
P2.0/PWM20/A8
24
23
22
21
20
19
18
17
MISO_2/I2CSDA_2/ECI_3/A12/PWM24/P2.4 25 16 P3.3/PWM33/INT1/MISO_4/I2CSDA_4
SCLK_2/I2CSCL_2/CCP0_3/A13/PWM25/P2.5 26 15 P3.2/PWM32/INT0/SCLK_4/I2CSCL_4
CCP1_3/A14/PWM26/P2.6 27 14 P3.1/PWM31/TxD
CCP2_3/A15/PWM27/P2.7 28 STC15H2K64S4 13 P3.0/PWM30/RxD/INT4
RxD3/AD0/ADC8/PWM00/P0.0 29 LQFP32 12 Gnd/AGnd
TxD3/AD1/ADC9/PWM01/P0.1 30 11 P5.2/PWM52/RxD4_2 MCU-VCC
RxD4/AD2/ADC10/PWM02/P0.2 31 10 Vcc/Avcc/ADC_VRef+
TxD4/AD3/ADC11/PWM03/P0.3 32 9 P5.4/PWM54/RST/MCLKO/SS_3 22u 0.1u
1
2
3
4
5
6
7
8
RxD2/CCP1/ADC0/PWM10/P1.0
TxD2/CCP0/ADC1/PWM11/P1.1
T2/SS/ECI/ADC2/PWM12/P1.2
T2CLKO/MOSI/ADC3/PWM13/P1.3
I2CSDA/MISO/ADC4/PWM14/P1.4
I2CSCL/SCLK/ADC5/PWM15/P1.5
XTALO/MCLKO_2/RxD_3/ADC6/PWM16/P1.6
XTALI/TxD_3/ADC7/PWM17/P1.7
Note:
If USB download is not required, P3.0/P3.1/P3.2 cannot be at low level at the same time when the chip is reset.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 48 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 50 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 51 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 53 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 54 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SJMP $
END
C language code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 55 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 56 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 57 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 58 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 59 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 60 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 61 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 62 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SJMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 63 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
CLKOCR = 0x04; //HIRC/4 output via MCLKO/P5.4
// CLKOCR = 0x84; //HIRC/4 output via MCLKO_2/P1.6
P_SW2 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
MOV A,#04H ;HIRC/4 output via MCLKO/P5.4
; MOV A,#84H ;HIRC/4 output via MCLKO_2/P1.6
MOV DPTR,#CLKOCR
MOVX @DPTR,A
MOV P_SW2,#00H
SJMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 65 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
4 Package Dimensions
4.1 SOP8 Package mechanical data
R1
A3
A2
R
A
?
L2
A1
L
b(0.40mm)
L1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 66 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
K 0.275REF
e(0.5mm)
E2
R 0.125 - -
4
R
A
A1
A3
The back metal sheet (substrate) of STC's existing DFN8 packaged chip is not grounded inside the chip. It can
be grounded or not grounded on the user's PCB board, which will not affect the performance of the chip.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 67 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
R1
A3
A2
R
A
?
L2
A1
L
b(0.40mm)
L1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 68 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
R1
A3
A2
R
A
?
L2
A1
L
b(0.24mm)
L1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 69 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
L
1
e(0.4mm)
E2
D2 R
4
11
A
C2 A1
b(0.20mm) C1
A3
The back metal sheet (substrate) of STC's existing QFN20 packaged chip is not grounded inside the chip. It can
be grounded or not grounded on the user's PCB board, which will not affect the performance of the chip.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 70 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
e(0.8mm) b(0.3mm)
R1
A2
R
A
A3
?
A1
L
b
b1
L1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 71 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
K
27 32
A
A1
1
A3
R
e(0.4mm)
E2
D2
17
C2
b(0.20mm) 12
C1
The back metal sheet (substrate) of STC's existing QFN32 packaged chip is not grounded inside the chip. It can
be grounded or not grounded on the user's PCB board, which will not affect the performance of the chip.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 72 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
e (0.5mm) b
R1
A3
A2
R2
A
L2
A1
L
b
b1
L1
c c1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 73 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
13 24
K
39 48
A
A1
1
A3
35
R
e(0.4mm)
E2
D2
25 12
24 b(0.20mm) 13
The back metal sheet (substrate) of STC's existing QFN48 packaged chip is not grounded inside the chip. It can
be grounded or not grounded on the user's PCB board, which will not affect the performance of the chip.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 74 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
D (12mm) A
A2
D1 (10mm)
48 33 A3
49 32
64 17
1 16
A1
e (0.5mm) b
?2
General size ?1
mm R1
SYMBOL MIN TYP MAX R2
A - - 1.60
A1 0.05 - 0.15 ?3
?
A2 1.35 1.40 1.45 L2
A3 0.59 0.64 0.69 L1
b 0.18 - 0.27 L
b1 0.17 0.20 0.23
c 0.13 - 0.18
S
c1 0.12 0.127 0.134
D 11.80 12.00 12.20
D1 9.90 10.00 10.10
E 11.80 12.00 12.20
E1 9.90 10.00 10.10
e 0.50BSC b
L 0.45 0.60 0.75
L1 1.00REF b1
L2 0.25BSC
R1 0.08 - -
R2 0.08 - 0.20
c c1
S 0.20 - -
? 0° 3.5° 7°
?1 0° - -
(A-A Section view)
?2 11° 12° 13°
?3 11° 12° 13°
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 75 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
16 33
17 32
A
A1
A3
K
51 64
L
1
47
R
D2
E2
e(0.4mm)
33 16
32 b(0.20mm) 17
The back metal sheet (substrate) of STC's existing QFN64 packaged chip is not grounded inside the chip. It can
be grounded or not grounded on the user's PCB board, which will not affect the performance of the chip.
STC 8x xK 08
Flash size
12: 12Kbytes
08: 8Kbytes
SRAM size
1K: 1Kbytes
Sub-series
8G: STC8G series
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 76 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SP3232/
SP232/
0.1u MAX3232/
MAX232
System power
0.1u
(Can be powered from USB) 1 16 10u 1
C1+ VCC
1 20 0.1u 2 15 6
P1.2 P1.1 V+ GND
2 19 3 14 2
P1.3 P1.0 C1- T1OUT
3 18 4 13 7
P1.4 P3.7 C2+ R1IN
Vin 4 17 5 12 3
P1.5 P3.6 C2- R1OUT
5 16 6 11 8
P1.6 P3.5 0.1u V- T1IN
Power On 6 15 7 10 4
P1.7 P3.4 T2OUT T2IN
7 14 8 9 9
P5.4 P3.3 0.1u R2IN R2OUT
Vcc 8 13 5
VCC P3.2
9 12
P5.5 P3.1
10 11
47u C? GND P3.0 100R
STC8G1K08
When MAX232 and
1N5819
target chip are powered
on at the same time,
47u Tantalum capacitor
System clock<=10MHz System clock>10MHz resistors and diodes can
22u Tantalum capacitor
be omitted
10u Tantalum capacitor C? 104(0.1uF) 103(0.01uF)
0.1u Tantalum capacitor
SP3232/
SP232/
0.1u MAX3232/
MAX232
System power
0.1u
(Can be powered from USB) 1 16 10u 1
C1+ VCC
1 20 0.1u 2 15 6
P1.2 P1.1 V+ GND
2 19 3 14 2
P1.3 P1.0 C1- T1OUT
3 18 4 13 7
P1.4 P3.7 C2+ R1IN
Vin 4 17 5 12 3
P1.5 P3.6 C2- R1OUT
5 16 6 11 8
P1.6 P3.5 0.1u V- T1IN
Power On 6 15 7 10 4
P1.7 P3.4 T2OUT T2IN
7 14 8 9 9
P5.4 P3.3 0.1u R2IN R2OUT
Vcc 8 13 5
VCC P3.2
9 12
VREF P3.1
10 11
47u C? GND P3.0 100R
STC8xx
When MAX232 and
1N5819
target chip are
47u Tantalum capacitor powered on at the
22u Tantalum capacitor System clock<=10MHz System clock>10MHz same time, resistors
10u Tantalum capacitor and diodes can be
0.1u Tantalum capacitor C? 104(0.1uF) 103(0.01uF) omitted
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 77 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8xx
When MAX232 and
1N5819 target chip are
powered on at the
47u Tantalum capacitor same time, resistors
22u Tantalum capacitor System clock<=10MHz System clock>10MHz and diodes can be
10u Tantalum capacitor C? 104(0.1uF) 103(0.01uF) omitted
0.1u Tantalum capacitor
System power
Vcc 0.1u 10u 0.1u
(Can be powered from USB)
USB +5V
Vin 1 8
1N5819 GND VO33
2 7 1
P3.0 TXD VBUS +5V
Power On
3 6 2
IO_VDD DM D-
4 5 3
P3.1 RXD DP D+
Vcc 4
VCC 100R GND
PL2303-GL
SOP8
47u C? GND
STC8Gxx
Connect to
computer/PC
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 79 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
5.1.6 Use U8-Mini tool to download, support ISP online and offline
download, and also support emulation
1 20
P1.2 P1.1
2 19
P1.3 P1.0
3 18
P1.4 P3.7
4 17
P1.5 P3.6
5 16
P1.6 P3.5
6 15
P1.7 P3.4
7 14
P5.4 P3.3
8 13
VCC P3.2
9 12
P5.5 P3.1
10 11
47u 104 GND P3.0
STC8G1K08
Connect
to
computer
/PC
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 80 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
5.1.7 Download using U8W tool, support ISP online and offline
download, and also support emulation
1 20
P1.2 P1.1
2 19
P1.3 P1.0
3 18
P1.4 P3.7
4 17
P1.5 P3.6
5 16
P1.6 P3.5
6 15 The chip can be placed on this green locking
P1.7 P3.4
7 14
8
P5.4 P3.3
13 seat directly for ISP programming, or be
VCC P3.2
9
P5.5 P3.1
12 downloaded using lead as the connection
10 11 method on the left.
47u 104 GND P3.0
STC8G1K08
Connect
to
computer
/PC
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 81 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
5.1.8 ISP Download using Simulate USB directly, only supports ISP
download, does not support emulation
Note: 1. When using USB download, connect P3.2 to GND for normal download.
2. If USB download is not required, P3.0/P3.1/P3.2 cannot be at low level at the same time when the chip
is reset, otherwise the chip will always be in USB download mode without running user code.
USB-Micro
D- 2
(Can be powered from USB) D+ 3
4
10K 5
Vin
300R
Power On
Vcc
VCC P3.2 22R
P3.1
47u C? GND P3.0
22R
STC8Gxx 1N4729-3.6V
zener protection diode
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 82 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SS8550
External power input Target chip power
2K
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 83 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
When the microcontroller enters Power-down mode, the clock controller will shut down all clock sources.
MCLKO_S
0 P5.4
MCLKODIV[6:0]
internal high-precision IRC 00 1 P1.6
MCKSEL[1:0]
Related registers
Bit Address and Symbol Reset
Symbol Description Address
B7 B6 B5 B4 B3 B2 B1 B0 value
CKSEL Clock selection register FE00H - MCKSEL[1:0] xxxx,xx00
CLKDIV Clock Division Register FE01H 0000,0100
Internal high speed Oscillator control
HIRCCR FE02H ENIRC24M - - - - - - IRC24MST 1xxx,xxx0
register
XOSCCR External Oscillator control register FE03H ENXOSC XITYPE - - - - - XOSCST 00xx,xxx0
IRC32KCR Internal 32KHz Oscillator control register FE04H ENIRC32K - - - - - - IRC32KST 0xxx,xxx0
MCLKOCR Master clock output control register FE05H MCLKO_S MCLKODIV[6:0] 0000,0000
Note: After the user program is reset, the system will automatically set the initial value of this register according
to the frequency division coefficient required for the operating frequency set during the last ISP download.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 85 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
after the oscillator frequency stabilizes. When the user program needs to switch the clock to external
crystal oscillator, ENXOSC must be set at first to enable the oscillator and then keep polling the oscillator
stable flag XOSCST until the flag changes to 1.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 86 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Related registers
Bit Address and Symbol Reset
Symbol Description Address
B7 B6 B5 B4 B3 B2 B1 B0 value
IRCBAND IRC band selection register 9DH - - - - - - - SEL 0000,00nn
LIRTRIM IRC frequency trim register 9EH - - - - - - LIRTRIM[1:0] 0000,00nn
IRTRIM IRC frequency adjustment register 9FH IRTRIM[7:0] nnnn,nnnn
CLKDIV Clock Divide Register FE01H CLKDIV[7:0] 0000,0100
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 87 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 88 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Then select the internal IRC as the clock source in the code and use the CLKDIV register to divide by 8.
C language code
// Operating frequency for test is 24MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 89 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
CKSEL = 0x00; // Select internal IRC (default)
CLKDIV = 0x08; // Clock divided by 8
P_SW2 = 0x00;
IRTRIM++; // Fine-tune the IRC frequency up to 3 ‰ (pay attention to judging the boundary)
// IRTRIM--; // Fine-tune the IRC frequency down to 3 ‰ (pay attention to judging the boundary)
while (1);
}
Assembly code
; Operating frequency for test is 24MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 90 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV P_SW2,#80H
MOV A,#00H ; Select internal IRC
MOV DPTR,#CKSEL
MOVX @DPTR,A
MOV A,#08H ; Clock divided by 8
MOV DPTR,#CLKDIV
MOVX @DPTR,A
MOV P_SW2,#00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 91 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
When software reset occurs, all the registers values are reset to the initial value except that the clock-
related registers remain unchanged. Software reset does not re-read all hardware options. Software reset mainly
includes,
Write SWRST bit in IAP_CONTR register to trigger reset
Related registers
Bit Address and Symbol Reset
Symbol Description Address
B7 B6 B5 B4 B3 B2 B1 B0 value
WDT_CONTR Watchdog control register C1H WDT_FLAG - EN_WDT CLR_WDT IDL_WDT WDT_PS[2:0] 0x00,0000
IAP_CONTR IAP Control Register C7H IAPEN SWBS SWRST CMD_FAIL - 0000,xxxx
RSTCFG Reset Configuration Registe FFH - ENLVR - P54RST - - LVDS[1:0] 0000,0000
In systems that require high reliability, such as industrial control/automotive electronics/aerospace, etc., in
order to prevent "the system is interfered under abnormal conditions, the MCU/CPU program runs away,
causing the system to work abnormally for a long time", usually the watch-dog-timer is introduced. If
MCU/CPU does not access the watchdog as required within the specified time, it is considered that the
MCU/CPU is in an abnormal state, and the watchdog will force the MCU/CPU to reset, so that the system
restarts to execute the user program from the beginning.
The watchdog reset of the STC8 series is one of the hardware resets in the hot start reset. The STC8 series
MCUs introduce this function, which makes the reliable design of MCU system more convenient and concise.
After the STC8 series watchdog reset state is over, the system will start from the ISP monitoring program area,
which has nothing to do with the SWBS of the IAP_CONTR register before the watchdog reset. (Note: This is
different from the STC15 series MCU)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 92 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
again to turn it off. The software only needs to write 1 to the EN_WDT bit to start the watchdog. If you
need the hardware to start the watchdog, you need to perform the settings as shown in the figure below
when downloading from the ISP:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 93 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Writting 60H to the IAP control register can achieve the effect of cold start of the microcontroller.
Symbol Address B7 B6 B5 B4 B3 B2 B1 B0
IAP_CONTR C7H IAPEN SWBS SWRST CMD_FAIL -
SWBS: Software boot selection bit
0: The microcontroller executes the code from user program space (main flash memory) after the software
reset. The data in the user data space remains unchanged.
1: The microcontroller executes the code from ISP space after the software reset. The data in the user data
space is initialized.
SWRST: Software reset trigger bit.
0: No operation
1: Trigger software reset.
Vcc
10K
301R
P5.4-RST
10uF
Optional
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 94 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Vcc
10uF
301R
Traditional 8051reset pin
10K Optional
The picture above shows the high-level reset circuit of the traditional 8051. The reset of STC8G is low-level
reset, which is different from the traditional reset circuit.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 95 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C1
20p~47p
P1.6/XTALO
4~36MHz MCU
P1.7/XTALI
20p~47p
C2
Note: The two capacitors C1 and C2 must not be saved. Without these two capacitors, the crystal
oscillator may not be able to oscillate. In addition, even if the crystal oscillator can start oscillating, the
MCU will increase the power consumption of 5-8mA.
P1.6/XTALO
4~36MHz MCU
P1.7/XTALI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 96 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
1: Make the microcontroller entering power-down mode. CPU and all peripherals stop working. It is
cleared by hardware automatically after the microcontroller wakes up.
IDL: IDLE mode control bit
0: No operation.
1: Make the microcontroller entering IDLE mode. CPU stops working and all peripherals keep working. It
is cleared by hardware automatically after the microcontroller wakes up.
Note: Although both the LVD and the comparator can wake up the clock stop mode, it is not recommended to
start the LVD and the comparator in the clock stop power saving mode, otherwise the hardware system will
automatically start the internal 1.19V high-precision reference source. This high-precision reference source has
a corresponding anti-temperature drift and adjustment circuit, which will increase the power consumption of
about 300uA. After the MCU enters the clock stop mode, it only consumes about 0.4uA at the 3.3V operating
voltage. So tt is not recommended to turn on the LVD and the comparator in the clock stop mode. If you really
need to use it, it is recommended to turn on the power-down wake-up timer. The power-down wake-up timer
will only increase the power consumption of about 1.4uA. This power consumption is generally acceptable for
the system. Let the power-down wake-up timer wake up the MCU every 5 seconds. And after wake-up, the
external battery voltage can be detected by LVD, comparator, and ADC. The detection will take about 1ms and
then enter the clock stop/power saving mode again, so that the average current increase is less than 1uA, and the
overall power consumption is about 2.8uA (0.4uA + 1.4uA + luA).
Power-down mode can be woke up by one of the following interrupts, INT0(P3.2), INT1(P3.3),
INT2(P3.6), INT3(P3.7), INT4(P3.0), T0(P3.4), T1(P3.5), T2(P1.2), T3(P0.4), T4(P0.6),
RXD(P3.0/P3.6/P1.6/P4.3), RXD2(P1.0/P4.6), RXD3(P0.0/P5.0), RXD4(P0.2/P5.2), CCP0(P1.1/P3.5/P2.5),
CCP1(P1.0/P3.6/P2.6), CCP2(P3.7/P2.7), I2C_SDA(P1.4/P2.4/P3.3), comparator, LVD and power-down wake-
up timer.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 97 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 98 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
CKSEL = 0x00; //Select internal IRC (default)
P_SW2 = 0x00;
/*
P_SW2 = 0x80;
XOSCCR = 0xc0; //Start external crystal
while (!(XOSCCR & 1)); //Waiting for the clock to stabilize
CLKDIV = 0x00; //Clock is not divided
CKSEL = 0x01; //Select external crystal
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 99 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P_SW2 = 0x00;
*/
/*
P_SW2 = 0x80;
IRC32KCR = 0x80; //Start internal 32KHz IRC
while (!(IRC32KCR & 1)); //Waiting for the clock to stabilize
CLKDIV = 0x00; //Clock is not divided
CKSEL = 0x03; //Select internal 32KHz
P_SW2 = 0x00;
*/
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 100 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
; MOV P_SW2,#80H
; MOV A,#0C0H ;Start external crystal
; MOV DPTR,#XOSCCR
; MOVX @DPTR,A
; MOVX A,@DPTR
; JNB ACC.0,$-1 ;Waiting for the clock to stabilize
; CLR A ;Clock is not divided
; MOV DPTR,#CLKDIV
MOVX @DPTR,A
; MOV A,#01H ;Select external crystal
; MOV DPTR,#CKSEL
; MOVX @DPTR,A
; MOV P_SW2,#00H
; MOV P_SW2,#80H
; MOV A,#80H ;Start internal 32KHz IRC
; MOV DPTR,#IRC32KCR
; MOVX @DPTR,A
; MOVX A,@DPTR
; JNB ACC.0,$-1 ;Waiting for the clock to stabilize
; CLR A ;Clock is not divided
; MOV DPTR,#CLKDIV
; MOVX @DPTR,A
; MOV A,#03H ;Select internal 32KHz
; MOV DPTR,#CKSEL
; MOVX @DPTR,A
; MOV P_SW2,#00H
JMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
// MCLKOCR = 0x01; //Main clock output to P5.4
// MCLKOCR = 0x02; //Divide the main clock by 2 and output to P5.4
MCLKOCR = 0x04; //Divide the main clock by 4 and output to P5.4
// MCLKOCR = 0x84; //Divide the main clock by 4 and output to P1.6
P_SW2 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 102 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV P_SW2,#80H
; MOV A,#01H ;Main clock output to P5.4
; MOV A,#02H ;Divide the main clock by 2 and output to P5.4
MOV A,#04H ;Divide the main clock by 4 and output to P5.4
; MOV A,#84H ;Divide the main clock by 4 and output to P1.6
MOV DPTR,#MCLKOCR
MOVX @DPTR,A
MOV P_SW2,#00H
JMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 103 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
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
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 104 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 105 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1)
{
if (!P32 && !P33)
{
IAP_CONTR |= 0x60; //Reset to ISP when P3.2 and P3.3 are both 0
}
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB P3.2
SETB P3.3
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 106 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LOOP:
JB P3.2,LOOP
JB P3.3,LOOP
MOV IAP_CONTR,#60H ;Reset to ISP when P3.2 and P3.3 are both 0
JMP $
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 107 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0033H
LJMP LVDISR
ORG 0100H
LVDISR:
ANL PCON,#NOT LVDF ;Clear interrupt flag
CPL P3.2 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 108 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 109 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT0ISR
ORG 0100H
INT0ISR:
CPL P3.4 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 110 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 111 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
EA = 1;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 112 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT0ISR
ORG 0013H
LJMP INT1ISR
ORG 0053H
LJMP INT2ISR
ORG 005BH
LJMP INT3ISR
ORG 0083H
LJMP INT4ISR
ORG 0100H
INT0ISR:
CPL P1.0 ;Test port
RETI
INT1ISR:
CPL P1.0 ;Test port
RETI
INT2ISR:
CPL P1.0 ;Test port
RETI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 113 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
INT3ISR:
CPL P1.0 ;Test port
RETI
INT4ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
CLR IT0 ;Enable INT0 rising edge and falling edge interrupts
; SETB IT0 ;Enable INT0 falling edge interrupt
SETB EX0 ;Enable INT0 interrupt
CLR IT1 ;Enable INT1 rising edge and falling edge interrupts
; SETB IT1 ;Enable INT1 falling edge interrupt
SETB EX1 ;Enable INT1 interrupt
SETB EA
END
C language code
// Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 114 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 115 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
TMOD = 0x00;
TL0 = 0x66; //65536-11.0592M/12/1000
TH0 = 0xfc;
TR0 = 1; //Start timer
ET0 = 1; //Enable timer interrupt
EA = 1;
while (1)
{
P11 = ~P11;
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 116 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
ORG 001BH
LJMP TM1ISR
ORG 0063H
LJMP TM2ISR
ORG 009BH
LJMP TM3ISR
ORG 00A3H
LJMP TM4ISR
ORG 0100H
TM0ISR:
CPL P1.0 ;Test port
RETI
TM1ISR:
CPL P1.0 ;Test port
RETI
TM2ISR:
CPL P1.0 ;Test port
RETI
TM3ISR:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 117 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV TMOD,#00H
MOV TL0,#66H ;65536-11.0592M/12/1000
MOV TH0,#0FCH
SETB TR0 ;Start timer
SETB ET0 ;Enable timer interrupt
SETB EA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 118 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 119 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1)
{
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART1ISR
ORG 0043H
LJMP UART2ISR
ORG 008BH
LJMP UART3ISR
ORG 0093H
LJMP UART4ISR
ORG 0100H
UART1ISR:
RETI
UART2ISR:
RETI
UART3ISR:
RETI
UART4ISR:
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 121 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
6.7.10 Wake up MCU from Power Saving Mode using I2C SDA pin
I2C STRT
SCL
SDA
(output)
MCU is woke up
at this time.
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1)
{
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00C3H
LJMP I2CISR
ORG 0100H
I2CISR:
PUSH ACC
PUSH DPH
PUSH DPL
ORL PSW2,#80H
MOV DPTR,#I2CSLST
MOVX A,@DPTR
ANL A,#NOT 40H
MOVX @DPTR,A
POP DPL
POP DPH
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 124 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
NOP
NOP
LOOP:
CPL P1.1
JMP LOOP
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 125 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
_nop_();
_nop_();
PCON = 0x02; //MCU enters power down mode
_nop_();
_nop_();
_nop_();
_nop_();
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LOOP:
NOP
NOP
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 126 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1)
{
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0033H
LJMP LVDISR
ORG 0100H
LVDISR:
ANL PCON,#NOT LVDF ;Clear interrupt flag
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 129 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 130 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CCON = 0x00;
CMOD = 0x08; //PCA clock is the system clock
CCAPM0 = 0x31; //Enable CCP0 edge wake-up function
CCAPM1 = 0x31; //Enable CCP1 edge wake-up function
CCAPM2 = 0x31; //Enable CCP2 edge wake-up function
while (1)
{
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
ANL CCON,#NOT 8FH ;Clear interrupt flag
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CCON,#00H
MOV CMOD,#08H ;PCA clock is the system clock
MOV CCAPM0,#31H ;Enable CCP0 edge wake-up function
MOV CCAPM1,#31H ;Enable CCP1 edge wake-up function
MOV CCAPM2,#31H ;Enable CCP2 edge wake-up function
SETB CR ;Start PCA timer
SETB EA
LOOP:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 132 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CPL P1.1
JMP LOOP
END
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 133 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CMPCR2 = 0x00;
CMPCR1 = 0x80; //Enable comparator module
CMPCR1 |= 0x30; //Enable edge interrupt of comparator
CMPCR1 &= ~0x08; //P3.6 is CMP + input pin
CMPCR1 |= 0x04; //P3.7 is CMP- input pin
CMPCR1 |= 0x02; //Enable Comparator output
EA = 1;
while (1)
{
P11 = ~P11;
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00ABH
LJMP CMPISR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 134 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
CMPISR:
ANL CMPCR1,#NOT 40H ;Clear interrupt flag
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CMPCR2,#00H
MOV CMPCR1,#80H ;Enable comparator module
ORL CMPCR1,#30H ;Enable edge interrupt of comparator
ANL CMPCR1,#NOT 08H ;P3.6 is CMP + input pin
ORL CMPCR1,#04H ;P3.7 is CMP- input pin
ORL CMPCR1,#02H ;Enable Comparator output
SETB EA
LOOP:
CPL P1.1
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 135 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
// Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void delay()
{
int i;
void main()
{
unsigned char power;
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 136 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
power = 0x0f;
RSTCFG = LVD3V0;
delay();
PCON &= ~LVDF;
delay();
if (PCON & LVDF)
{
power >>= 1;
RSTCFG = LVD2V7;
delay();
PCON &= ~LVDF;
delay();
if (PCON & LVDF)
{
power >>= 1;
RSTCFG = LVD2V4;
delay();
PCON &= ~LVDF;
delay();
if (PCON & LVDF)
{
power >>= 1;
RSTCFG = LVD2V2;
delay();
PCON &= ~LVDF;
delay();
if (PCON & LVDF)
{
power >>= 1;
}
}
}
}
RSTCFG = LVD3V0;
P2 = ~power; // P2.3 ~ P2.0 are used to display battery level
}
}
Assembly code
; Operating frequency for test is 11.0592MHz
ORG 0000H
JMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV RSTCFG,#LVD3V0
CALL DELAY
ANL PCON,#NOT LVDF
CALL DELAY
MOV A,PCON
ANL A,#LVDF
JZ SKIP
MOV A,B
CLR C
RRC A
MOV B,A
MOV RSTCFG,#LVD2V7
CALL DELAY
ANL PCON,#NOT LVDF
CALL DELAY
MOV A,PCON
ANL A,#LVDF
JZ SKIP
MOV A,B
CLR C
RRC A
MOV B,A
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 138 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV RSTCFG,#LVD2V4
CALL DELAY
ANL PCON,#NOT LVDF
CALL DELAY
MOV A,PCON
ANL A,#LVDF
JZ SKIP
MOV A,B
CLR C
RRC A
MOV B,A
MOV RSTCFG,#LVD2V2
CALL DELAY
ANL PCON,#NOT LVDF
CALL DELAY
MOV A,PCON
ANL A,#LVDF
JZ SKIP
MOV A,B
CLR C
RRC A
MOV B,A
SKIP:
MOV A,B
CPL A
MOV P2,A ; P2.3 ~ P2.0 are used to display battery level
JMP LOOP
DELAY:
MOV R0,#100
NEXT:
NOP
NOP
NOP
NOP
DJNZ R0,NEXT
RET
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 139 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
7 Memory
The STC8G 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 STC8G series of microcontrollers. The data memory inside
the STC8G series of microcontrollers is physically and logically separated into two address spaces: 256 bytes of
internal RAM and internal extended RAM. The addresses of the high 128 bytes of internal RAM and special
function registers (SFRs) overlap. They can be accessed through different addressing modes in actual use.
2FFFH
12K
…
001BH
0013H Interrupt vectors
000BH
0003H
0000H Entry address after program reset
64K bytes of Flash program memory is integrated in STC8G2K64S4 family, STC8G2K64S2 family,
STC15H2K64S4 family of microcontrollers.
FFFFH
64K
…
001BH
0013H Interrupt vectors
000BH
0003H
0000H Entry address after program reset
After the microcontroller resets, the content of the Program Counter (PC) is 0000H, and the CPU begins to
execute program from 0000H of Program Memory. The entry addresses of interrupt service routines, which are
also called interrupt vectors, are also located in the program memory. Each interrupt has a fixed entry address in
Program Memory. When an interrupt occurs and gets response, the microcontroller will automatically jump to
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 140 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
its corresponding interrupt entry address to execute the service routine. The entry address of the interrupt
service routine for the external interrupt 0 (INT0) is 0003H, the entry address for the timer / counter 0 (TIMER0)
interrupt service routine is 000BH, and the entry address for the interrupt service routine for the external
interrupt 1 (INT1) is 0013H. The counter/counter 1 (TIMER1) interrupt service routine's entry address is
001BH. More interrupt service routine entry address (interrupt vector), please refer to interrupt chapter.
The interval of adjacent interrupt entry addresses is only 8 bytes, which is not enough to save the complete
interrupt service routine in general, so an unconditional jump instruction is stored in the the interrupt vector to
jump to the space where the real interrupt service routine is stored, then execute interrupt service routine.
All STC8G series of microcontrollers integrate Flash data memory (EEPROM). The EEPROM is read or
written in byte, and is erased in page of 512-bytes. It can be repeatedly programmed and erased over 100,000
times, which improves the flexibility and convenience of use.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 141 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
80H 80H
7FH Direct
addressing
30H
Bit-addressable 2FH
20H space
Register bank, 18H Register bank 3 1FH
selected by RS0 10H Register bank 2 17H
and RS1 in PSW 08H Register bank 1 0FH
00H Register bank 0 07H
The Lower 128 bytes of RAM are also called as general-purpose RAM space. The general-purpose RAM
space can be divided into working register banks space, bit addressable space, user RAM space and stack space.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 142 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Total of 32 bytes of working register bank space, 00H to 1FH, are divided into 4 groups. Each group is called a
register bank, which contains 8 8-bit working registers. All the numbers in different register bank are R0
through R7, but they belong to different Physical space. By using the working register registers, the operation
speed can be increased. R0 ~ R7 are commonly used registers. Four bank sare provided because one bank is
often not enough. The combination of RS1 and RS0 in the PSW register determines the working register bank
currently used, see the introduction of PSW register below.
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. There are totally 128 bits in this space,
whose logic bit addresses are 00H to 7FH. From the appearance, bit addresses and the internal Lower 128 bytes
RAM addresses are the same as 00H to 7FH, but in fact, they are essentially different: bit address points to a bit,
and the byte address points to a byte unit. They are distinguished by using different instructions in programs.
The addresses 30H to FFH in the internal RAM are the user RAM and stack space. An 8-bit stack pointer,
SP in short is used to point to the stack space. On reset, SP is 07H, which is R7 of register bank 0. Therefore, the
initial value of SP should be set in the user initialisation codes. You would better to set the initial value of SP at
80H or higher.
SP is an 8-bit dedicated register. It indicates the top of the stack in the internal RAM. On reset, SP is
initialized to 07H, which makes the stack space begin from 08H. The addresses 08H to 1FH are also the
addresses of working register bank 1 through 3. It is better to change the SP value to a value of 80H or more if
these spaces are used in user application. The stack of STC8G series of microcontrollers grows upward, which
means that when a datum is pushed into the stack, the content of SP will increase.
In assembly language, the on-chip extended RAM is accessed through the MOVX instruction,
MOVX A,@DPTR
MOVX @DPTR,A
MOVX A,@Ri
MOVX @Ri,A
In C language, xdata / pdata can be used to declare the storage type, such as,
unsigned char xdata i;
unsigned int pdata j;
Note that pdata is the lower 256 bytes of xdata. After declaring a variable as the pdata type in C program,
the compiler will automatically allocate the variables in the 0000H to 00FFH of XDATA and use MOVX @ Ri,
A and MOVX A @ Ri to access.
The control bit EXTRAM located in AUXR register is used to control the access of on-chip extended
RAM can be used or not.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 144 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The timing of reading and writing external extended RAM is shown in the figure below:
P4.5 (ALE)
P4.4 (RD)
P4.5 (ALE)
P4.2 (WR)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 146 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The addresses of these parameters in the Flash program memory (ROM) are as follows:
Addresses
STC8G1K04-
STC8G1K08-8Pin STC8G1K12-8Pin STC8G1K17-8Pin Parameter
Parameters 8Pin
STC8G1K08A STC8G1K12A STC8G1K17A Description
STC8G1K04A
STC8G1K08 STC8G1K12 STC8G1K17
STC8G1K04
STC8G1K08T STC8G1K12T STC8G1K17T
STC8G1K04T
global unique ID 0FF9H~0FFFH 1FF9H~1FFFH 2FF9H~2FFFH 43F9H~43FFH 7 bytes
internal 1.19V reference voltage 0FF7H~0FF8H 1FF7H~1FF8H 2FF7H~2FF8H 43F7H~43F8H mV (high byte first)
frequency of the 32K power-down
0FF5H~0FF6H 1FF5H~1FF6H 2FF5H~2FF6H 43F5H~43F6H Hz (high byte first)
wake-up timer
parameters of 22.1184MHz IRC 0FF4H 1FF4H 2FF4H 43F4H -
parameters of 24MHz IRC 0FF3H 1FF3H 2FF3H 43F3H -
parameters of 20MHz IRC 0FF2H 1FF3H 2FF2H 43F2H
parameters of 27MHz IRC 0FF1H 1FF1H 2FF1H 43F1H
parameters of 30MHz IRC 0FF0H 1FF0H 2FF0H 43F0H
parameters of 33.1776MHz IRC 0FEFH 1FEFH 2FEFH 43EFH
Valid for the firmware
parameters of 35MHz IRC 0FEEH 1FEEH 2FEEH 43EEH
version 7.3.12U or
parameters of 36.864MHz IRC 0FEDH 1FEDH 2FEDH 43EDH
above
Reserved 0FECH 1FECH 2FECH 43ECH
Reserved 0FEBH 1FEBH 2FEBH 43EBH
VRTRIM parameters of 20MHz 0FEAH 1FEAH 2FEAH 43EAH
VRTRIM parameters of 35MHz 0FE9H 1FE9H 2FE9H 43E9H
Addresses
Parameter
Parameters STC8G2K16S2 STC8G2K32S2 STC8G2K48S2 STC8G2K60S2 STC8G2K64S2
Description
STC8G2K16S4 STC8G2K32S4 STC8G2K48S4 STC8G2K60S4 STC8G2K64S4
STC15H2K16S4 STC15H2K32S4 STC15H2K48S4 STC15H2K60S4 STC15H2K64S4
global unique ID 3FF9H~3FFFH 7FF9H~7FFFH 0BFF9H~0BFFFH 0EFF9H~0EFFFH 0FDF9H~0FDFFH 7 bytes
internal 1.19V mV (high byte
3FF7H~3FF8H 7FF7H~7FF8H 0BFF7H~0BFF8H 0EFF7H~0EFF8H 0FDF7H~0FDF8H
reference voltage first)
frequency of the 32K
Hz (high byte
power-down wake-up 3FF5H~3FF6H 7FF5H~7FF6H 0BFF5H~0BFF6H 0EFF5H~0EFF6H 0FDF5H~0FDF6H
first)
timer
parameters of
3FF4H 7FF4H 0BFF4H 0EFF4H 0FDF4H -
22.1184MHz IRC
parameters of 24MHz
3FF3H 7FF3H 0BFF3H 0EFF3H 0FDF3H -
IRC
parameters of 20MHz
3FF2H 7FF2H BFF2H EFF2H FDF2H
IRC
parameters of 27MHz
3FF1H 7FF1H BFF1H EFF1H FDF1H
IRC
parameters of 30MHz
3FF0H 7FF0H BFF0H EFF0H FDF0H
IRC
parameters of
3FEFH 7FEFH BFEFH EFEFH FDEFH
33.1776MHz IRC
Valid for the
parameters of 35MHz
3FEEH 7FEEH BFEEH EFEEH FDEEH firmware version
IRC
7.3.12U or above
parameters of
3FEDH 7FEDH BFEDH EFEDH FDEDH
36.864MHz IRC
Reserved 3FECH 7FECH BFECH EFECH FDECH
Reserved 3FEBH 7FEBH BFEBH EFEBH FDEBH
VRTRIM parameters of
3FEAH 7FEAH BFEAH EFEAH FDEAH
20MHz
VRTRIM parameters of
3FE9H 7FE9H BFE9H EFE9H FDE9H
35MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 147 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The addresses of these parameters in the data memory (RAM) are as follows:
Special Note
1. Since the parameters in RAM may be modified, it is generally not recommended to used. Especially, it is strongly
recommended to read ID data in FLASH program memory (ROM) when you use ID for encryption.
3. By default, only the global unique ID is in the Flash program memory (ROM), and the internal reference voltage
value, the frequency of the 32K power-down wake-up timer, and the IRC parameters are not available. You need
to select the option in the following figure when downloading by ISP, and then the options shown are available.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 148 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
int *BGV;
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
busy = 0;
}
while (busy);
busy = 1;
SBUF = dat;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 150 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
UART_ISR:
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
UARTISR_EXIT:
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#BGV
CLR A
MOVC A,@A+DPTR ;Read the high byte of the internal reference voltage
LCALL UART_SEND
MOV A,#1
MOVC A,@A+DPTR ;Read the low byte of the internal reference voltage
LCALL UART_SEND
LOOP:
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 151 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
int *BGV;
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
busy = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 152 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (busy);
busy = 1;
SBUF = dat;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 153 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
UARTISR_EXIT:
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV R0,#BGV
MOV A,@R0 ;Read the high byte of the internal 1.19V reference voltage
LCALL UART_SEND
INC R0
MOV A,@R0 ;Read the low byte of the internal 1.19V reference voltage
LCALL UART_SEND
LOOP:
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 154 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char *ID;
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
busy = 0;
}
SBUF = dat;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
char i;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 156 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
UART_ISR:
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
UARTISR_EXIT:
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#ID
MOV R1,#7
NEXT: CLR A
MOVC A,@A+DPTR
LCALL UART_SEND
INC DPTR
DJNZ R1,NEXT
LOOP:
JMP LOOP
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 157 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char *ID;
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
busy = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 158 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
char i;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 159 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
UARTISR_EXIT:
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV R0,#ID
MOV R1,#7
NEXT: MOV A,@R0
LCALL UART_SEND
INC R0
DJNZ R1,NEXT
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 160 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LOOP:
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
int *F32K;
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 161 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
UARTISR_EXIT:
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#F32K
CLR A
MOVC A,@A+DPTR ;Read high byte of 32K frequency
LCALL UART_SEND
INC DPTR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 163 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CLR A
MOVC A,@A+DPTR ;Read low byte of 32K frequency
LCALL UART_SEND
LOOP:
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
int *F32K;
void UartInit()
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 164 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
UARTISR_EXIT:
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV R0,#F32K
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 166 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LOOP:
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
// //Select 20MHz
// P_SW2=0x80;
// CLKDIV=0x04;
// IRTRIM= T20M_ROMADDR;
// VRTRIM= VRT20M_ROMADDR;
// IRCBAND=0x00;
// CLKDIV=0x00;
// //Select 22.1184MHz
// P_SW2=0x80;
// CLKDIV=0x04;
// IRTRIM= T22M_ROMADDR;
// VRTRIM= VRT20M_ROMADDR;
// IRCBAND=0x00;
// CLKDIV=0x00;
//Select 24MHz
P_SW2=0x80;
CLKDIV=0x04;
IRTRIM= T24M_ROMADDR;
VRTRIM= VRT20M_ROMADDR;
IRCBAND=0x00;
CLKDIV=0x00;
// //Select 27MHz
// P_SW2=0x80;
// CLKDIV=0x04;
// IRTRIM= T27M_ROMADDR;
// VRTRIM= VRT35M_ROMADDR;
// IRCBAND=0x00;
// CLKDIV=0x00;
// //Select 30MHz
// P_SW2=0x80;
// CLKDIV=0x04;
// IRTRIM= T30M_ROMADDR;
// VRTRIM= VRT35M_ROMADDR;
// IRCBAND=0x01;
// CLKDIV=0x00;
// //Select 33.1776MHz
// P_SW2=0x80;
// CLKDIV=0x04;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 168 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
// IRTRIM= T33M_ROMADDR;
// VRTRIM= VRT35M_ROMADDR;
// IRCBAND=0x01;
// CLKDIV=0x00;
// //Select 35MHz
// P_SW2=0x80;
// CLKDIV=0x04;
// IRTRIM= T35M_ROMADDR;
// VRTRIM= VRT35M_ROMADDR;
// IRCBAND=0x01;
// CLKDIV=0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 169 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
; ;Select 20MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T20M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT20M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#00H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
; ;Select 22.1184MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T22M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT20M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#00H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
;Select 24MHz
MOV P_SW2,#80H
MOV A,#4
MOV DPTR,#CLKDIV
MOV DPTR,#T24M_ROMADDR
CLR A
MOVC A,@A+DPTR
MOV IRTRIM,A
MOV DPTR,#VRT20M_ROMADDR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 170 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CLR A
MOVC A,@A+DPTR
MOV VRTRIM,A
MOV IRCBAND,#00H
MOV A,#0
MOV DPTR,#CLKDIV
MOV P_SW2,#00H
; ;Select 27MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T27M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT35M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#01H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
; ;Select 30MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T30M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT35M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#01H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
; ;Select 33.1776MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T33M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT35M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#01H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 171 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
; ;Select 35MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T35M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT35M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#01H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
; ;Select 36.864MHz
; MOV P_SW2,#80H
; MOV A,#4
; MOV DPTR,#CLKDIV
; MOV DPTR,#T36M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV IRTRIM,A
; MOV DPTR,#VRT35M_ROMADDR
; CLR A
; MOVC A,@A+DPTR
; MOV VRTRIM,A
; MOV IRCBAND,#01H
; MOV A,#0
; MOV DPTR,#CLKDIV
; MOV P_SW2,#00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
char *IRC22M;
char *IRC24M;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
CLKDIV = 0; //No division to main clock
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
MOV A,#0 ;No division to main clock
MOV DPTR,#CLKDIV
MOVX @DPTR,A
MOV P_SW2,#00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 174 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 175 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 176 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 177 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 178 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 179 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 180 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 181 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 182 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Note: Bit addressing can only be carried out if the register address is divisible by 8, while the bit addressing is
not available if the register address is not divisible by 8.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 183 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 184 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AG
IAP_DATA IAP Flash Data Register C2H 1111,1111
IAP_ADDRH IAP Flash Address High Byte C3H 0000,0000
IAP_ADDRL IAP Flash Address Low Byte C4H 0000,0000
IAP_CMD IAP Flash Command Register C5H - - - - - - CMD[1:0] xxxx,xx00
IAP_TRIG IAP Flash Trigger register C6H 0000,0000
IAP_CONTR IAP Control Register C7H IAPEN SWBS SWRST CMD_FAIL - - - - 0000,xxxx
P5 Port 5 C8H - - P55 P54 P53 P52 P51 P50 xx11,1111
P5M1 Port 5 mode register 1 C9H - - P55M1 P54M1 P53M1 P52M1 P51M1 P50M1 xx11,1111
P5M0 Port 5 mode register 0 CAH - - P55M0 P54M0 P53M0 P52M0 P51M0 P50M0 xx00,0000
SPSTAT SPI Status register CDH SPIF WCOL - - - - - - 00xx,xxxx
SPCTL SPI Control Register CEH SSIG SPEN DORD MSTR CPOL CPHA SPR[1:0] 0000,0100
SPDAT SPI Data Register CFH 0000,0000
PSW Program Status Word Register D0H CY AC F0 RS1 RS0 OV - P 0000,00x0
Timer4 and Timer 3 Control
T4T3M D1H T4R T4_C/T T4x12 T4CLKO T3R T3_C/T T3x12 T3CLKO 0000,0000
Register
T4H Timer 4 high byte register D2H 0000,0000
T4L Timer 4 low byte register D3H 0000,0000
T3H Timer 3 high byte register D4H 0000,0000
T3L Timer 3 low byte register D5H 0000,0000
T2H Timer 2 high byte register D6H 0000,0000
T2L Timer 2 low byte register D7H 0000,0000
CCON PCA Control Register D8H CF CR - - - CCF2 CCF1 CCF0 00xx,x000
CMOD PCA Mode Register D9H CIDL - - - CPS[2:0] ECF 0xxx,0000
CCAPM0 PCA 0 Mode Control Register DAH - ECOM0 CCAPP0 CCAPN0 MAT0 TOG0 PWM0 ECCF0 x000,0000
CCAPM1 PCA 1 Mode Control Register DBH - ECOM1 CCAPP1 CCAPN1 MAT1 TOG1 PWM1 ECCF1 x000,0000
CCAPM2 PCA 2 Mode Control Register DCH - ECOM2 CCAPP2 CCAPN2 MAT2 TOG2 PWM2 ECCF2 x000,0000
ADCCFG ADC Configuration Register DEH - - RESFMT - SPEED[3:0] xx0x,0000
3nd Interrupt Priority register PPWM4F
IP3 DFH D
PPWM5 PPWM4 PPWM3 PPWM2 PPWM1 PS4 PS3 0000,0000
low byte
ACC Accumulator E0H 0000,0000
DPS DPTR Selection Register E3H ID1 ID0 TSL AU1 AU0 - - SEL 0000,0xx0
DPL1 2nd Data pointer low byte E4H 0000,0000
DPH1 2nd Data pointer high byte E5H 0000,0000
CMPCR1 Comparator Control Register 1 E6H CMPEN CMPIF PIE NIE PIS NIS CMPOE CMPRES 0000,0000
INVCM
CMPCR2 Comparator Control Register 2 E7H DISFLT LCDTY[5:0] 0000,0000
PO
CL PCA Counter Low Byte E9H 0000,0000
PCA 0 Capture Register Low
CCAP0L EAH 0000,0000
Byte
PCA 1 Capture Register Low
CCAP1L EBH 0000,0000
Byte
PCA 2 Capture Register Low
CCAP2L ECH 0000,0000
Byte
3nd Interrupt Priority Register PPWM4F
IP3H EEH DH
PPWM5H PPWM4H PPWM3H PPWM2H PPWM1H PS4H PS3H 0000,0000
High Byte
Extended External Interrupt Flag
AUXINTIF EFH - INT4IF INT3IF INT2IF - - - T2IF x000,xxx0
Register
B B register F0H 0000,0000
ENGLB
PWMSET PWM Set Register F1H PWMRST ENPWM5 ENPWM4 ENPWM3 ENPWM2 ENPWM1 ENPWM0 0000,0000
SET
PCA_PWM0 PCA0 PWM Mode Register F2H EBS0[1:0] XCCAP0H[1:0] XCCAP0L[1:0] EPC0H EPC0L 0000,0000
PCA_PWM1 PCA1 PWM Mode Register F3H EBS1[1:0] XCCAP1H[1:0] XCCAP1L[1:0] EPC1H EPC1L 0000,0000
PCA_PWM2 PCA2 PWM Mode Register F4H EBS2[1:0] XCCAP2H[1:0] XCCAP2L[1:0] EPC2H EPC2L 0000,0000
IAP Waiting Time Control
IAP_TPS F5H - - IAPTPS[5:0] xx00,0000
Register
PWM1CB EPWM1CB
PWMCFG01 PWM Configuration Register F6H IF I
FLTPS0 PWM1CEN PWM0CBIF EPWM0CBI ENPWM0TA PWM0CEN 0000,0000
PWM3CB EPWM3CB
PWMCFG23 PWM Configuration Register F7H IF I
FLTPS1 PWM3CEN PWM2CBIF EPWM2CBI ENPWM2TA PWM2CEN 0000,0000
CH PCA Counter High Byte F9H 0000,0000
PCA 0 Capture Register High
CCAP0H FAH 0000,0000
Byte
PCA 1 Capture Register High
CCAP1H FBH 0000,0000
Byte
PCA 2 Capture Register High
CCAP2H FCH 0000,0000
Byte
PWM5CB EPWM5CB
PWMCFG45 PWM Configuration Register FEH IF I
FLTPS2 PWM5CEN PWM4CBIF EPWM4CBI ENPWM4TA PWM4CEN 0000,0000
RSTCFG Reset Configuration Register FFH - ENLVR - P54RST - - LVDS[1:0] xnxn,xxnn
The following special function registers are extended SFRs whose logical addresses are in the XDATA area.
Before access them, the highest bit (EAXFR) of the P_SW2 (BAH) register needs to be set, and they can
accessed by using the MOVX A, @DPTR and MOVX @ DPTR, A instructions.
Bit Address and Symbol Reset
Symbol Description Address
B7 B6 B5 B4 B3 B2 B1 B0 value
CKSEL Clock Select Register FE00H - - - - - - MCKSEL[1:0] xxxx,xx00
CLKDIV Clock Divide Register FE01H 0000,0100
Internal high speed Oscillator
HIRCCR FE02H ENHIRC - - - - - - HIRCST 1xxx,xxx0
Control Register
External Oscillator Control
XOSCCR FE03H ENXOSC XITYPE - - - - - XOSCST 00xx,xxx0
Register
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 186 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 188 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 189 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 190 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 191 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM53CR PWM53 Control Register FCCCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM53 Level Holding Control
PWM53HLD FCCDH - - - - - - HLDH HLDL xxxx,xx00
Register
PWM54T1H PWM54T1 High Byte FCD0H - x000,0000
PWM54T1L PWM54T1 Low Byte FCD1H 0000,0000
PWM54T2H PWM54T2 High Byte FCD2H - x000,0000
PWM54T2L PWM54T2 Low Byte FCD3H 0000,0000
PWM54CR PWM54 Control Register FCD4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM54 Level Holding Control
PWM54HLD FCD5H - - - - - - HLDH HLDL xxxx,xx00
Register
PWM55T1H PWM55T1 High Byte FCD8H - x000,0000
PWM55T1L PWM55T1 Low Byte FCD9H 0000,0000
PWM55T2H PWM55T2 High Byte FCDAH - x000,0000
PWM55T2L PWM55T2 Low Byte FCDBH 0000,0000
PWM55CR PWM55 Control Register FCDCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM55 Level Holding Control
PWM55HLD FCDDH - - - - - - HLDH HLDL xxxx,xx00
Register
PWM56T1H PWM56T1 High Byte FCE0H - x000,0000
PWM56T1L PWM56T1 Low Byte FCE1H 0000,0000
PWM56T2H PWM56T2 High Byte FCE2H - x000,0000
PWM56T2L PWM56T2 Low Byte FCE3H 0000,0000
PWM56CR PWM56 Control Register FCE4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM56 Level Holding Control
PWM56HLD FCE5H - - - - - - HLDH HLDL xxxx,xx00
Register
PWM57T1H PWM57T1 High Byte FCE8H - x000,0000
PWM57T1L PWM57T1 Low Byte FCE9H 0000,0000
PWM57T2H PWM57T2 High Byte FCEAH - x000,0000
PWM57T2L PWM57T2 Low Byte FCEBH 0000,0000
PWM57CR PWM57 Control Register FCECH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM57 Level Holding Control
PWM57HLD FCEDH - - - - - - HLDH HLDL xxxx,xx00
Register
MD3 MDU Data Register FCF0H MD3[7:0] 0000,0000
MD2 MDU Data Register FCF1H MD2[7:0] 0000,0000
MD1 MDU Data Register FCF2H MD1[7:0] 0000,0000
MD0 MDU Data Register FCF3H MD0[7:0] 0000,0000
MD5 MDU Data Register FCF4H MD5[7:0] 0000,0000
MD4 MDU Data Register FCF5H MD4[7:0] 0000,0000
ARCON MDU Mode Control Register FCF6H MODE[2:0] SC[4:0] 0000,0000
OPCON MDU Operation Control Register FCF7H - MDOV - - - - RST ENOP 0000,0000
COMEN COM Enable Register FB00H C7EN C6EN C5EN C4EN C3EN C2EN C1EN C0EN 0000,0000
SEGENL SEG Enable Register FB01H S7EN S6EN S5EN S4EN S3EN S2EN S1EN S0EN 0000,0000
SEGENH SEG Enable Register FB02H S15EN S14EN S13EN S12EN S11EN S10EN S9EN S8EN 0000,0000
LEDCTRL LED Control Register FB03H LEDON - LEDMODE[1:0] - LEDDUTY[2:0] 0000,0000
LEDCKS LED Clock Divide Register FB04H 0000,0001
COM0_DA_L Common Anode Mode Disply FB10H 0000,0000
COM1_DA_L Common Anode Mode Disply FB11H 0000,0000
COM2_DA_L Common Anode Mode Disply FB12H 0000,0000
COM3_DA_L Common Anode Mode Disply FB13H 0000,0000
COM4_DA_L Common Anode Mode Disply FB14H 0000,0000
COM5_DA_L Common Anode Mode Disply FB15H 0000,0000
COM6_DA_L Common Anode Mode Disply FB16H 0000,0000
COM7_DA_L Common Anode Mode Disply FB17H 0000,0000
COM0_DA_H Common Cathode Mode Disply FB18H 0000,0000
COM1_DA_H Common Cathode Mode Disply FB19H 0000,0000
COM2_DA_H Common Cathode Mode Disply FB1AH 0000,0000
COM3_DA_H Common Cathode Mode Disply FB1BH 0000,0000
COM4_DA_H Common Cathode Mode Disply FB1CH 0000,0000
COM5_DA_H Common Cathode Mode Disply FB1DH 0000,0000
COM6_DA_H Common Cathode Mode Disply FB1EH 0000,0000
COM7_DA_H Common Cathode Mode Disply FB1FH 0000,0000
COM0_DC_L Common Anode Mode Disply FB20H 0000,0000
COM1_DC_L Common Anode Mode Disply FB21H 0000,0000
COM2_DC_L Common Anode Mode Disply FB22H 0000,0000
COM3_DC_L Common Anode Mode Disply FB23H 0000,0000
COM4_DC_L Common Anode Mode Disply FB24H 0000,0000
COM5_DC_L Common Anode Mode Disply FB25H 0000,0000
COM6_DC_L Common Anode Mode Disply FB26H 0000,0000
COM7_DC_L Common Anode Mode Disply FB27H 0000,0000
COM0_DC_H Common Cathode Mode Disply FB28H 0000,0000
COM1_DC_H Common Cathode Mode Disply FB29H 0000,0000
COM2_DC_H Common Cathode Mode Disply FB2AH 0000,0000
COM3_DC_H Common Cathode Mode Disply FB2BH 0000,0000
COM4_DC_H Common Cathode Mode Disply FB2CH 0000,0000
COM5_DC_H Common Cathode Mode Disply FB2DH 0000,0000
COM6_DC_H Common Cathode Mode Disply FB2EH 0000,0000
COM7_DC_H Common Cathode Mode Disply FB2FH 0000,0000
TSCHEN1 Touch Key Enable Register 1 FB40H TKEN7 TKEN6 TKEN5 TKEN4 TKEN3 TKEN2 TKEN1 TKEN0 0000,0000
TSCHEN2 Touch Key Enable Register 2 FB41H TKEN15 TKEN14 TKEN13 TKEN12 TKEN11 TKEN10 TKEN9 TKEN8 0000,0000
TSCFG1 Touch Key Configuration FB42H
- SCR[2:0] - DT[2:0] 0000,0000
Register 1
TSCFG2 Touch Key Configuration FB43H
- - - - - - TSVR[1:0] 0000,0000
Register 2
TSWUTC Touch Key Wakeup Control FB44H
0000,0000
Register
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 192 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
TSCTRL Touch Key Control Register FB45H TSGO SINGLE TSWAIT TSWUCS TSDCEN TSWUEN TSSAMP[1:0] 0000,0000
TSSTA1 Touch Key Status Register 1 FB46H LEDWK - - - TSWKCHN[3:0] 0000,0000
TSSTA2 Touch Key Status Register 2 FB47H TSIF TSDOV - - TSDNCHN[3:0] 0000,0000
TSRT Touch Key Time Control Register FB48H 0000,0000
TSDATH Touch Key Data High Byte FB49H 0000,0000
TSDATL Touch Key Data Low Byte FB4AH 0000,0000
TSTH00H Touch Key0 Threshold High Byte FB50H 0000,0000
TSTH00L Touch Key0 Threshold Low Byte FB51H 0000,0000
TSTH01H Touch Key1 Threshold High Byte FB52H 0000,0000
TSTH01L Touch Key1 Threshold Low Byte FB53H 0000,0000
TSTH02H Touch Key2 Threshold High Byte FB54H 0000,0000
TSTH02L Touch Key2 Threshold Low Byte FB55H 0000,0000
TSTH03H Touch Key3 Threshold High Byte FB56H 0000,0000
TSTH03L Touch Key3 Threshold Low Byte FB57H 0000,0000
TSTH04H Touch Key4 Threshold High Byte FB58H 0000,0000
TSTH04L Touch Key4 Threshold Low Byte FB59H 0000,0000
TSTH05H Touch Key5 Threshold High Byte FB5AH 0000,0000
TSTH05L Touch Key5 Threshold Low Byte FB5BH 0000,0000
TSTH06H Touch Key6 Threshold High Byte FB5CH 0000,0000
TSTH06L Touch Key6 Threshold Low Byte FB5DH 0000,0000
TSTH07H Touch Key7 Threshold High Byte FB5EH 0000,0000
TSTH07L Touch Key7 Threshold Low Byte FB5FH 0000,0000
TSTH08H Touch Key8 Threshold High Byte FB60H 0000,0000
TSTH08L Touch Key8 Threshold Low Byte FB61H 0000,0000
TSTH09H Touch Key9 Threshold High Byte FB62H 0000,0000
TSTH09L Touch Key9 Threshold Low Byte FB63H 0000,0000
TSTH10H Touch Key10 Threshold High FB64H
0000,0000
Byte
TSTH10L Touch Key10 Threshold Low FB65H
0000,0000
Byte
TSTH11H Touch Key11 Threshold High FB66H
0000,0000
Byte
TSTH11L Touch Key11 Threshold Low FB67H
0000,0000
Byte
TSTH12H Touch Key12 Threshold High FB68H
0000,0000
Byte
TSTH12L Touch Key12 Threshold Low FB69H
0000,0000
Byte
TSTH13H Touch Key13 Threshold High FB6AH
0000,0000
Byte
TSTH13L Touch Key13 Threshold Low FB6BH
0000,0000
Byte
TSTH14H Touch Key14 Threshold High FB6CH
0000,0000
Byte
TSTH14L Touch Key14 Threshold Low FB6DH
0000,0000
Byte
TSTH15H Touch Key15 Threshold High FB6EH
0000,0000
Byte
Touch Key15 Threshold Low
TSTH15L FB6FH 0000,0000
Byte
Note: The meaning of the initial value of the special function register
0: The initial value is 0.
1: The initial value is l.
n: The initial value is related to the hardware options during ISP download.
x: This bit does not exist, and the initial value is uncertain.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 193 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
9 I/O Ports
Product line Max I/O lines
STC8G1K08family 18
STC8G1K08-8Pin family 6
STC8G1K08A family 6
STC8G2K64S4 family 45
STC8G2K64S2 family 45
STC8G1K08T family 16
STC15H2K64S4 family 42
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.
Note: All I/O ports except for P3.0 and P3.1 are in high-impedance input state after
power-on. You must set the I/O port mode before using it.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 194 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 195 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Note: When an I/0 port is selected as the ADC input channel, the PxMO/PxM1 register must be set to set
the I/0 port mode to input mode. In addition, if the MCU still needs to enable the ADC channel after
entering the power-down mode/clock stop mode, you need to set the PxIE register to turn off the digital
input to ensure that there will be no additional power consumption
P0DR FE28H P07DR P06DR P05DR P04DR P03DR P02DR P01DR P00DR
P1DR FE29H P17DR P16DR P15DR P14DR P13DR P12DR P11DR P10DR
P2DR FE2AH P27DR P26DR P25DR P24DR P23DR P22DR P21DR P20DR
P3DR FE2BH P37DR P36DR P35DR P34DR P33DR P32DR P31DR P30DR
P4DR FE2CH P47DR P46DR P45DR P44DR P43DR P42DR P41DR P40DR
P5DR FE2DH - - P55DR P54DR P53DR P52DR P51DR P50DR
Drive capability control bit:
0: Enhanced drive ability
1: General drive ability
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 197 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Taking Port 0 as an example, two registers, P0M0 and P0M1, are used to configure Port 0, as shown in the
following figure:
P0M0 7 6 5 4 3 2 1 0
P0M1 7 6 5 4 3 2 1 0
The combination of bit 0 of P0M0 and bit 0 of P0M1 is used to configure the mode of P0.0.
The combination of bit 1 of P0M0 and bit 1 of P0M1 is used to configure the mode of P0.1.
All other I/O lines configuration method is similar.
The combination of PnM0 and PnM1 to configure the I/O ports mode is as following.
Note: n = 0,1,2,3,4,5,6,7
Note:
Although each I/0 pin can withstand a 20mA sink current in weak pull-up (quasi-bidirectional)/strong push-pull
output/open-drain mode (current-limiting resistance is still required, such as 1K, 560Ω, 472Ω, etc.), it can output a
current of 20mA in the strong push-pull output mode, (current limiting resistor should also be added), the working
current of the whole chip is recommended not to exceed 70mA, that is, the current flowing in from Vcc is
recommended not to exceed 70mA, and the current flowing from Gnd is recommended not to exceed 70mA, the
overall inflow/outflow current is recommended not to exceed 70mA. (For STC8G1K08A series and STC8GIK08-
8Pin series, the working current of the entire chip is recommended not to exceed 35mA, that is, the current flowing in
from Vcc is recommended not to exceed 35mA, the current flowing from Gnd is recommended not to exceed 35mA,
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 198 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Input Data
interference suppression
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 199 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
VCC
Strong
Port
Port latch data Pin
Input Data
interference suppression
Port
Input data Pin
interference suppression
The open drain port has a Schmitt trigger input and an interference suppression circuit.
Port
Pin
Port latch data
Input data
interference suppression
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 200 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 201 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00; //Set P0.0 ~ P0.7 as bidirectional port mode
P0M1 = 0x00;
P1M0 = 0xff; //Set P1.0 ~ P1.7 as push-pull output mode
P1M1 = 0x00;
P2M0 = 0x00; //Set P2.0 ~ P2.7 as high impedance input mode
P2M1 = 0xff;
P3M0 = 0xff; //Set P3.0 ~ P3.7 as open-drain mode
P3M1 = 0xff;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 203 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 204 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SETB P0.0 ;Enable the internal weak pull-up resistor before reading
the port
NOP ;Wait for two clocks
NOP
MOV C,P0.0 ;Read port status
JMP $
END
VCC VCC
R1
R3
10K(3.3K~10K)
I/O Pin
R2
15K (3.3K~15K)
For pull-up control, it is recommended to add a pull-up resistor R1 (3.3K ~ 10K). If pull-up resistor R1
(3.3K ~ 10K) is not connected, it is recommended that the value of R2 be above 15K, or use strong push-pull output
mode.
1K
I/O Pin VCC
For push-pull (strong pull-up ) I/O, you can drive the light-emitting diode with pull current mode.
1K
I/O Pin
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 205 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
3.3V
10K
5V 330Ω 3.3V
microcontroller device
I/O Pin I/O Pin
When STC's 3V microcontroller is connected to a 5V device and the corresponding I/O port is used as an input,
an isolation diode can be connected in series to the I/O port to isolate the high voltage part in order to prevent the 3V
microcontroller from bearing 5V. When the external signal voltage is higher than the microcontroller operating
voltage, the isolation diode will cutoff, the state of the read I/O port is high because the I/O port is pulled up to a high
level internally. When the external signal voltage is low, the isolation diode will turn on and the I/O port is clamped at
0.7V. The microcontroller reads I/O port low status as the voltage is less than 0.8V.
Microcontroller External
I/O Pin input
signal
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.
5V
10K
I/O Pin
5V
device
I/O Pin
2K
Now you can connect a pull-down resistor (1K, 2K or 3K) to the I/O port of STC microcontroller. The I/O port
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 206 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
of the microcontroller is internal weak pull-up (quasi-bidirectional)/high-level output when the microcontroller is
powered on reset. It cannot be pulled high because the internal pull-up capability is limited and the external pull-
down resistor is small. Therefore the I/O port is externally low when power is reset. If you want to drive this I/O port
to a high level, you can set this I/O port in strong push-pull output mode, under this circumstance, the I/O port drive
current can reach 20mA, so the port can be definitely driven high.
Greater than
470Ω(Optional)
I/O Pin
10K
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 207 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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. In fact, many small projects, such as a large
number of small appliances, do not need to display a lot of segment codes. There are usually four 8 colons with
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 208 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
a decimal point or clock: ":", so if you use the IO port to scan and display directly, it will reduce costs and work
more reliably.
However, this solution is not suitable for driving too many segments (occupying too many IOs), and it is
not suitable for very low power consumption occasions (driving will have hundreds of uA current).
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. The content will be displayed if the voltage across the LCD is higher than this
threshold, and the content will not be displayed if the voltage is lower than this threshold. There are usually 3
parameters in LCD: working voltage, DUTY (corresponding to COM number) and BIAS (ie bias,
corresponding threshold). For example, ‘3.0V, 1/4 DUTY, 1/3 BIAS’ means that the LCD display voltage is
3.0V, 4 COM, the threshold is about 1.5V. The content will be displayed if the voltage across a certain LCD
segment is 3.0V, and the content will not be displayed if the voltage is 1.0V. However, the LCD's response to the
driving voltage is not very sensitive. For example, the display may be faint if the voltage is 2V. This is usually
called a ‘ghost image’. Therefore, it is necessary to ensure that the voltage is larger than the threshold value if
you want to display something, and the voltage is smaller than the threshold value if you do not display
anything.
Note: The LCD should be driven by AC, and DC voltage cannot be applied to the two ends of the LCD.
Otherwise, it will be damaged for a long time DC applying. The average voltage of the driving voltage applied
to the LCD must be 0. Time-sharing is used to LCD. At any time, if one COM scan is valid, the other COM is
invalid.
The scheme circuit for driving ‘1/4Duty, 1/ 2BIAS, 3V’ is shown in Figure 1. The scanning principle of
LCD is shown in Figure 3. The MCU works at 3.0V or 3.3V. Each COM is connected with a 20K resistor in
series to a capacitor C1 aiming to obtain the midpoint voltage of 1/2VDD after RC filtering. When it is the turn
of a COM scan, the connected IO is set to push-pull output mode, and the remaining COMs are set to high
impedance. If the SEG connected to this COM is not used to display, the SEG output is in phase with the COM,
and if it is not used to display, it is inverted. After scanning is finished, the I/O corresponding to this COM is set
to high impedance. Each COM is connected to the 1/2VDD voltage on the capacitor C1 through a 20K resistor.
The SEG outputs high or low level according to whether it is used to display or not. The voltage applied to the
LCD segment is +-VDD when displayed, and +-1/2VDD when not displayed, which can ensure that the average
DC voltage across the LCD is 0.
The circuit for driving the ‘1/4Duty, 1/3BIAS, 3V’ is shown in Figure 4. The scanning principle of LCD is
shown in Figure 5. The MCU works at 5V. The IOs connected to SEG output 1.5V and 3.5V through the resistor
divider. The IOs connected to COM output 0.5V, 2.5V (at high impedance), 4.5V. The common point of the
voltage-dividing resistor is connected to a capacitor C1 to abtain a mid-point voltage of 1/2VDD after RC
filtering. When it is the turn of a certain COM scan, the IO is set to push-pull output mode. If the SEG
connected to this COM is not used to display, the SEG output is in phase with COM, and if it is used to display,
it is inverted. After scanning is finished, the I/O corresponding to this COM is set to high impedance. This COM
is connected to a 2.5V voltage through a 47K resistor. The SEG outputs high or low level according to whether
it is used to display or not. The voltage applied to the LCD is +-3.0V when displayed, and +-1.0V when not
displaying, which can meet the LCD scanning requirements.
When sleep of power saving is required, all IOs used to dirve COMs and SEGs output low level, and the
extra current will not appear in LCD drive part.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 209 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 210 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 211 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 212 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 213 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In addition, macros are used to display, extinguish, or flash colons or decimal points.
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.
;************************************************************
P0M1 DATA 0x93
P0M0 DATA 0x94
P1M1 DATA 0x91
P1M0 DATA 0x92
P2M1 DATA 0x95
P2M0 DATA 0x96
P3M1 DATA 0xB1
P3M0 DATA 0xB2
P4M1 DATA 0xB3
P4M0 DATA 0xB4
P5M1 DATA 0xC9
P5M0 DATA 0xC
P6M1 DATA 0xCB
P6M0 DATA 0xCC
P7M1 DATA 0xE1
P7M0 DATA 0xE2
AUXR DATA 0x8E
INT_CLKO DATA 0x8F
IE2 DATA 0xAF
P4 DATA 0xC0
T2H DATA 0xD6
T2L DATA 0xD7
;************************************************************
DIS_BLACK EQU 010H
DIS_ EQU 011H
DIS_A EQU 00AH
DIS_B EQU 00BH
DIS_C EQU 00CH
DIS_D EQU 00DH
DIS_E EQU 00EH
DIS_F EQU 00FH
;************************************************************
ORG 0000H
LJMP F_Main
ORG 000BH
LJMP F_Timer0_Interrupt
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 215 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
;************************************************************
ORG 0100H
F_Main:
CLR A
MOV P3M1, A ;Set as a quasi-bidirectional port
MOV P3M0, A
MOV P5M1, A ;Set as a quasi-bidirectional port
MOV P5M0, A
;************************************************************
MOV R2, #8
MOV R0, #LCD_buff
L_ClearLcdRam:
MOV @R0, #0
INC R0
DJNZ R2, L_ClearLcdRam
LCALL F_Timer0_init
SETB EA
;************************************************************
L_Main_Loop:
JNB B_2ms, L_Main_Loop ;2ms beat
CLR B_2ms
INC cnt_500ms
MOV A, cnt_500ms
CJNE A, #250, L_Main_Loop
;reach to 500ms
MOV cnt_500ms, #0;
CPL B_Second
JNB B_Second, L_Main_Loop
INC second
MOV A, second
CJNE A, #60, L_Main_Load
MOV second, #0 ; reach to 1 minute
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 216 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
INC minute
MOV A, minute
CJNE A, #60, L_Main_Load
MOV minute, #0;
INC hour
MOV A, hour
CJNE A, #24, L_Main_Load
MOV hour, #0 ;reach to 24 hours
L_Main_Load:
LCALL F_LoadRTC ;Display time
LJMP L_Main_Loop
;************************************************************
F_Timer0_init:
CLR TR0 ; Stop counting
ANL TMOD, #0f0H
SETB ET0 ; Enable interrupt
ORL TMOD, #0 ; Working mode 0: 16-bit auto-reload
ANL INT_CLKO, #NOT 0x01 ; Does not output clock
ORL AUXR, #0x80 ; 1T mode
MOV TH0, #HIGH (-22118) ; 2ms
MOV TL0, #LOW (-22118) ;
SETB TR0 ; Start operation
RET
;************************************************************
F_Timer0_Interrupt: ;Timer0 1ms interrupt function
PUSH PSW ;push PSW into stack
PUSH ACC ;push ACC into stack
PUSH AR0
PUSH AR7
PUSH DPH
PUSH DPL
LCALL F_LCD_scan
SETB B_2ms
POP DPL
POP DPH
POP AR7
POP AR0
POP ACC ;pop ACC from stack
POP PSW ;pop PSW from stack
RETI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 217 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
DIV AB
MOV R7, B
LCALL F_LCD_load ;R6 is the number, which is 1~6, R7 is the number to be
displayed
RET
;************************************************************
T_COM:
DB 008H, 004H, 002H, 001H
F_LCD_scan:
MOV A, scan_index ;j = scan_index >> 1;
CLR C
RRC A
MOV R7, A ;R7 = j
ADD A, #LCD_buff
MOV R0, A ;R0 = LCD_buff[j]
ORL P2M1, #00fH ;All COM outputs are high impedance, and COM ’ s
voltage is the midpoint
ANL P2M0, #0f0H
MOV A, scan_index
JNB ACC.0, L_LCD_Scan2 ;if(scan_index & 1) // Reverse scan
MOV A, @R0 ;P1 = ~LCD_buff[j];
CPL A
MOV P1, A
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 218 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
L_LCD_Scan3:
MOV DPTR, #T_COM ;A COM is set as push-pull output mode
MOV A, R7
MOVC A, @A+DPTR
ORL P2M0, A
CPL A
ANL P2M1, A
L_QuitLcdScan:
RET
;****************** Load display functions for numbers 1 to 6, and the algorithm is simple ***************************
F_LCD_load: ;R6 is the number, which is 1~6, R7 is the number to be
displayed
MOV DPTR, #T_Display ;i = t_display[dat];
MOV A, R7
MOVC A, @A+DPTR
MOV B, A ;the number to be displayed
MOV A, R6
CJNE A, #1, L_NotLoadChar1
MOV R0, #LCD_buff
MOV A, @R0
MOV C, B.3 ;D
MOV ACC.6, C
MOV @R0, A
INC R0
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 219 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV A, @R0
MOV C, B.2 ;C
MOV ACC.6, C
MOV C, B.4 ;E
MOV ACC.7, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.1 ;B
MOV ACC.6, C
MOV C, B.6 ;G
MOV ACC.7, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.0 ;A
MOV ACC.6, C
MOV C, B.5 ;F
MOV ACC.7, C
MOV @R0, A
RET
L_NotLoadChar1:
CJNE A, #2, L_NotLoadChar2
MOV R0,#LCD_buff
MOV A, @R0
MOV C, B.3 ;D
MOV ACC.4, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.2 ;C
MOV ACC.4, C
MOV C, B.4 ;E
MOV ACC.5, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.1 ;B
MOV ACC.4, C
MOV C, B.6 ;G
MOV ACC.5, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.0 ;A
MOV ACC.4, C
MOV C, B.5 ;F
MOV ACC.5, C
MOV @R0, A
RET
L_NotLoadChar2:
CJNE A, #3, L_NotLoadChar3
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 220 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV R0,#LCD_buff
MOV A, @R0
MOV C, B.3 ;D
MOV ACC.2, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.2 ;C
MOV ACC.2, C
MOV C, B.4 ;E
MOV ACC.3, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.1 ;B
MOV ACC.2, C
MOV C, B.6 ;G
MOV ACC.3, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.0 ;A
MOV ACC.2, C
MOV C, B.5 ;F
MOV ACC.3, C
MOV @R0, A
RET
L_NotLoadChar3:
CJNE A, #4, L_NotLoadChar4
MOV R0,#LCD_buff
MOV A, @R0
MOV C, B.3 ;D
MOV ACC.0, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.2 ;C
MOV ACC.0, C
MOV C, B.4 ;E
MOV ACC.1, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.1 ;B
MOV ACC.0, C
MOV C, B.6 ;G
MOV ACC.1, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.0 ;A
MOV ACC.0, C
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 221 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV C, B.5 ;F
MOV ACC.1, C
MOV @R0, A
RET
L_NotLoadChar4:
CJNE A, #5, L_NotLoadChar5
MOV R0,#LCD_buff+4
MOV A, @R0
MOV C, B.3 ;D
MOV ACC.6, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.2 ;C
MOV ACC.6, C
MOV C, B.4 ;E
MOV ACC.7, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.1 ;B
MOV ACC.6, C
MOV C, B.6 ;G
MOV ACC.7, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.0 ;A
MOV ACC.6, C
MOV C, B.5 ;F
MOV ACC.7, C
MOV @R0, A
RET
L_NotLoadChar5:
CJNE A, #6, L_NotLoadChar6
MOV R0,#LCD_buff+4
MOV A, @R0
MOV C, B.3 ;D
MOV ACC.4, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.2 ;C
MOV ACC.4, C
MOV C, B.4 ;E
MOV ACC.5, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.1 ;B
MOV ACC.4, C
MOV C, B.6 ;G
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 222 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV ACC.5, C
MOV @R0, A
INC R0
MOV A, @R0
MOV C, B.0 ;A
MOV ACC.4, C
MOV C, B.5 ;F
MOV ACC.5, C
MOV @R0, A
RET
L_NotLoadChar6:
RET
END
C language code
/*****************Function description******************
STC15 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.
P3.2 is connected to ground via a switch to enter sleep or wake up.
******************************************/
#include "reg51.h"
#include "intrins.h"
/********************main function**************************/
void main(void)
{
u8 i;
AUXR = 0x80;
TMOD = 0x00;
TL0 = (65536 - (MAIN_Fosc / 500));
TH0 = (65536 - (MAIN_Fosc / 500)) >> 8;
TR0 = 1;
ET0 = 1;
EA = 1;
while (1)
{
PCON |= 0x01; //Enter Idle mode, wake up and exit by Timer0 2ms
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 224 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
_nop_();
_nop_();
_nop_();
B_Second = ~B_Second;
if(B_Second)
{
if(++second >= 60) //reach to 1 minute
{
second = 0;
if(++minute >= 60) //reach to 1 hour
{
minute = 0;
if(++hour >= 24) hour = 0; //reach to 24 hours
}
}
LoadRTC(); //Display time
}
}
TR0 = 0; //关闭定时器
IE0 = 0; //外中断 0 标志位
EX0 = 1; //INT0 Enable
IT0 = 1; //INT0 下降沿中断
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 225 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
/********************delay function**************************/
void delay_ms(u8 ms)
{
unsigned int i;
do{
i = MAIN_Fosc / 13000;
while(--i); //14T per loop
}while(--ms);
}
j = scan_index >> 1;
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] & 0xf0;
}
P2n_push_pull(T_COM[j]); //A COM is set as push-pull output mode
if(++scan_index >= 8) scan_index = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 226 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
k = 0;
if(i & 0x08) k |= 0x40; //D
*p = (*p & T_LCD_mask4[n]) | (k>>2*n);
p++;
k = 0;
if(i & 0x04) k |= 0x40; //C
if(i & 0x10) k |= 0x80; //E
*p = (*p & T_LCD_mask[n]) | (k>>2*n);
p++;
k = 0;
if(i & 0x02) k |= 0x40; //B
if(i & 0x40) k |= 0x80; //G
*p = (*p & T_LCD_mask[n]) | (k>>2*n);
p++;
k = 0;
if(i & 0x01) k |= 0x40; //A
if(i & 0x20) k |= 0x80; //F
*p = (*p & T_LCD_mask[n]) | (k>>2*n);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 227 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCD_load(6,second%10);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 228 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
10 Instruction Set
Mnemonic Description Bytes Cycle
ADD A,Rn Add register to Accumulator 1 1
ADD A,direct Add ditect byte to Accumulator 2 1
ADD A,@Ri Add indirect RAM to Accumulator 1 1
ADD A,#data Add immediate data to Accumulator 2 1
ADDC A,Rn Add register to Accumulator with Carry 1 1
ADDC A,direct Add ditect byte to Accumulator with Carry 2 1
ADDC A,@Ri Add indirect RAM to Accumulator with Carry 1 1
ADDC A,#data Add immediate data to Accumulator with Carry 2 1
SUBB A,Rn Subtract Register from Accumulator with borrow 1 1
SUBB A,direct Subtract direct byte from Accumulator with borrow 2 1
SUBB A,@Ri Subtract indirect RAM from Accumulator with borrow 1 1
SUBB A,#data Substract immediate data from Accumulator with borrow 2 1
INC A Increment Accumulator 1 1
INC Rn Increment register 1 1
INC direct Increment direct byte 2 1
INC @Ri Increment indirect RAM 1 1
DEC A Decrement Accumulator 1 1
DEC Rn Decrement Register 1 1
DEC direct Decrement direct byte 2 1
DEC @Ri Decrement indirect RAM 1 1
INC DPTR Increment Data Pointer 1 1
MUL AB Multiply A & B, high byte of result is in B, low byte in A 1 2
DIV AB Divde A by B, quotient is in A, remainder is in B. 1 6
DA A Decimal Adjust Accumulator 1 3
ANL A,Rn AND Register to Accumulator 1 1
ANL A,direct AND direct btye to Accumulator 2 1
ANL A,@Ri AND indirect RAM to Accumulator 1 1
ANL A,#data AND immediate data to Accumulator 2 1
ANL direct,A AND Accumulator to direct byte 2 1
ANL direct,#data AND immediate data to direct byte 3 1
ORL A,Rn OR register to Accumulator 1 1
ORL A,direct OR direct byte to Accumulator 2 1
ORL A,@Ri OR indirect RAM to Accumulator 1 1
ORL A,#data OR immediate data to Accumulator 2 1
ORL direct,A OR Accumulator to direct byte 2 1
ORL direct,#data OR immediate data to direct byte 3 1
XRL A,Rn Exclusive-OR register to Accumulator 1 1
XRL A,direct Exclusive-OR direct byte to Accumulator 2 1
XRL A,@Ri Exclusive-OR indirect RAM to Accumulator 1 1
XRL A,#data Exclusive-OR immediate data to Accumulator 2 1
XRL direct,A Exclusive-OR Accumulator to direct byte 2 1
XRL direct,#data Exclusive-OR immediate data to direct byte 3 1
CLR A Clear Accumulator 1 1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 229 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 230 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 231 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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. After the emergency processing is completed, the CPU returns to the
place where it was interrupted and continues the original work. This process is called interrupt. The componet
that implements this function is called the interrupt system. The request source that makes the CPU interrupt to
suspend the current work is called the interrupt source. Microcontroller interrupt system generally allows
multiple interrupt sources. When several interrupt sources simultaneously require the CPU to handle the
requests, the CPU should response the interrupt source which has the highest priority. The CPU handle the
interrupt requests according to the priority of interrupt sources. The most urgent incidents have the highest
priority. Each interrupt source has a priority level. The CPU always responds the highest priority interrupt
request.
Another interrupt source request with a higher priority takes place while the CPU is processing an interrupt
source request, that is, the CPU is executing the corresponding interrupt service routine, if the CPU can suspend
the original interrupt service routine, and deal with the higher priority interrupt request source, and then return
to the original low-level interrupt service routine after processing finished, this process is called interrupt
nesting. Such an interrupt system is called a multi-level interrupt system, whereas an interrupt system without
interrupt nesting is called a single-level interrupt system.
The corresponding interrupt request can be masked by turning off the general enable bit (EA / IE.7) or the
corresponding interrupt enable bit. The CPU can be enabled to respond to the corresponding interrupt request by
turning on the corresponding interrupt enable bit. Every interrupt source can be set or reset independently by
software to interrupt enabled or disabled state. The priority of some interrupts can be set by software. Higher
priority interrupt requests can interrupt lower priority interrupts, whereas lower priority interrupt requests can
not interrupt higher priority interrupts. When two interrupts with the same priority ocuur simultaneously, the
inquiry order determines which interrupt the system responds firstly.
Capture interrupt
√ √ √ √ √ √
(CCP/PCA/PWM)
UART2 interrupt (UART2) √ √ √ √
SPI interrupt (SPI) √ √ √ √ √ √ √
External interrupt 2 (INT2) √ √ √ √ √ √ √
External interrupt 3 (INT3) √ √ √ √ √ √ √
Timer 2 interrrupt (Timer2) √ √ √ √ √
External interrupt 4 (INT4) √ √ √ √ √ √ √
UART3 interrupt (UART3) √ √
UART4 interrupt (UART4) √ √
Timer 3 interrrupt (Timer3) √ √ √
Timer 4 interrrupt (Timer4) √ √ √
Comparator interrupt
√ √ √ √ √
(CMP)
Enhenced PWM0 interrupt √ √ √
PWM0 fault detection
√ √ √
interrupt (PWM0FD)
I2C interrupt √ √ √ √ √ √ √
Touch Key interrupt √
Enhenced PWM1 interrupt √ √ √
Enhenced PWM2 interrupt √ √ √
Enhenced PWM3 interrupt √ √ √
Enhenced PWM4 interrupt √ √ √
Enhenced PWM5 interrupt √ √ √
PWM2 fault detection
√ √ √
interrupt (PWM2FD)
PWM4 fault detection
√ √ √
interrupt (PWM4FD)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 233 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
EX4 EA PX4/PX4H 0
1
INT4 INT4IF 2
Priority is fixed at the 3
S3RI ES3 EA lowest priority
UART3 0
S3TI Priority is fixed at the
S4RI ES4 EA lowest priority
UART4 Priority is fixed at the
0
S4TI
ET3 EA lowest priority
Timer3 T3IF 0
Priority is fixed at the
ET4 EA
lowest priority
Timer4 T4IF 0
PIE
EA PCMP/PCMPH 0
1
CMP CMPIF 2
3
NIE
ECBI
CBIF
EC0I
C0IF
EC0T1SI
EC0T2SI
EC1I
C1IF
EC1T1SI
EC1T2SI
EC2I
C2IF
EC2T1SI
EC2T2SI EA 0
EC3I PPWM/PPWMH 1
PWM C3IF
EC3T1SI 2
EC3T2SI 3
EC4I
C4IF
EC4T1SI
EC4T2SI
EC5I
C5IF
EC5T1SI
EC5T2SI
EC6I
C6IF
EC6T1SI
EC6T2SI
EC7I
C7IF
EC7T1SI
EC7T2SI
EFDI EA PPWMFD/PPWMFDH 0
1
PWMFD FDIF 2
3
EMSI
MSIF
ESTAI
STAIF
ESTOI PI2C/PI2CH 0
1
I2C STOIF 2
3
ERXI
RXIF
ETXI
TXIF
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 234 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 235 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 236 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 237 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 238 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM22CR PWM22 Control Register FFC4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM23CR PWM23 Control Register FFCCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM24CR PWM24 Control Register FFD4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM25CR PWM25 Control Register FFDCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM26CR PWM26 Control Register FFE4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM27CR PWM27 Control Register FFECH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM3IF PWM3 Interrupt Flag Register FC05H C7IF C6IF C5IF C4IF C3IF C2IF C1IF C0IF 0000,0000
PWM3 Fault Detection Control
PWM3FDCR FC06H INVCMP INVIO ENFD FLTFLIO - FDCMP FDIO FDIF 0000,0000
Register
PWM30CR PWM30 Control Register FC14H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM31CR PWM31 Control Register FC1CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM32CR PWM32 Control Register FC24H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM33CR PWM33 Control Register FC2CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM34CR PWM34 Control Register FC34H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM35CR PWM35 Control Register FC3CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM36CR PWM36 Control Register FC44H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM37CR PWM37 Control Register FC4CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM4IF PWM4 Interrupt Flag Register FC55H C7IF C6IF C5IF C4IF C3IF C2IF C1IF C0IF 0000,0000
PWM4 Fault Detection Control
PWM4FDCR FC56H INVCMP INVIO ENFD FLTFLIO EFDI FDCMP FDIO FDIF 0000,0000
Register
PWM40CR PWM40 Control Register FC64H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM41CR PWM41 Control Register FC6CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM42CR PWM42 Control Register FC74H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM43CR PWM43 Control Register FC7CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM44CR PWM44 Control Register FC84H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM45CR PWM45 Control Register FC8CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM46CR PWM46 Control Register FC94H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM47CR PWM47 Control Register FC9CH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM5IF PWM5 Interrupt Flag Register FCA5H C7IF C6IF C5IF C4IF C3IF C2IF C1IF C0IF 0000,0000
PWM5 Fault Detection Control
PWM5FDCR FCA6H INVCMP INVIO ENFD FLTFLIO - FDCMP FDIO FDIF 0000,0000
Register
PWM50CR PWM50 Control Register FCB4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM51CR PWM51 Control Register FCBCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM52CR PWM52 Control Register FCC4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM53CR PWM53 Control Register FCCCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM54CR PWM54 Control Register FCD4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM55CR PWM55 Control Register FCDCH ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM56CR PWM56 Control Register FCE4H ENO INI - - ENI ENT2I ENT1I 00xx,x000
PWM57CR PWM57 Control Register FCECH ENO INI - - ENI ENT2I ENT1I 00xx,x000
TSSTA2 Touch Key Status Register 2 FB47H TSIF TSDOV - - TSDNCHN[3:0] 00xx,0000
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 240 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 242 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 243 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Notice:
STC15 series added 16-bit reload timer in the early adopting 0.35um process 1T 8051, which is the important
change in the 8051 world. Due to the high producing cost, the interrupt request flag registers of 16-bit reload
timer 2/3/4 are not designed for users to access. There are only internally hidden flag bits. The method provided
to the user software to clear the internal hidden flag bits is: when the user software disables the timer 2/3/4
interrupt, the hardware automatically clears the timer 2/3/4 internal hidden the interrupt request flag bit.
For product consistency, the STC8A/STC8F and subsequent STC8G/STC8H/STC8C/STC12H series who use
0.18um technology have added interrupt request flag registers that can be accessed by users of timer 2/3/4, but
the function of the hidden interrupt request flags being cleared by hardware automatically in timer 2/3/4 when
their interrupts are prohibited is still reserved. So do not arbitrarily disable the timer 2/3/4 interrupt when the
timer 2/3/4 does not stop counting, otherwise, the hidden interrupt request flags that actually work will be
cleared. It is possible that after the counter overflows, and the hidden interrupt request flag is set to 1, it is
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 244 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 245 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM0CBIF: Enhanced PWM0 counter interrupt request flag, which must be cleared by software.
PWM1CBIF: Enhanced PWM1 counter interrupt request flag, which must be cleared by software.
PWM2CBIF: Enhanced PWM2 counter interrupt request flag, which must be cleared by software.
PWM3CBIF: Enhanced PWM3 counter interrupt request flag, which must be cleared by software.
PWM4CBIF: Enhanced PWM4 counter interrupt request flag, which must be cleared by software.
PWM5CBIF: Enhanced PWM5 counter interrupt request flag, which must be cleared by software.
FDIF: PWM fault detection interrupt request flag, which must be cleared by software.
All other interrupts except INT2, INT3, Timer 2, Timer 3, and Timer 4 have 4-level interrupt priority levels that
can be set.
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT0ISR
ORG 0100H
INT0ISR:
JB INT0,RISING ;Judging rising and falling edges
CPL P1.0 ;Test port
RETI
RISING:
CPL P1.1 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
CLR IT0 ;Enable INT0 rising edge and falling edge interrupts
SETB EX0 ;Enable INT0 interrupt
SETB EA
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 251 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 252 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT0ISR
ORG 0100H
INT0ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0013H
LJMP INT1ISR
ORG 0100H
INT1ISR:
JB INT1,RISING ;Judging rising and falling edges
CPL P1.0 ;Test port
RETI
RISING:
CPL P1.1 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
CLR IT1 ;Enable INT1 rising edge and falling edge interrupts
SETB EX1 ;Enable INT1 interrupt
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0013H
LJMP INT1ISR
ORG 0100H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 256 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
INT1ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0053H
LJMP INT2ISR
ORG 0100H
INT2ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 258 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 259 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 005BH
LJMP INT3ISR
ORG 0100H
INT3ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 260 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 261 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0083H
LJMP INT4ISR
ORG 0100H
INT4ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 262 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
TMOD = 0x00;
TL0 = 0x66; //65536-11.0592M/12/1000
TH0 = 0xfc;
TR0 = 1; //Start timer
ET0 = 1; //Enable timer0 interrupt
EA = 1;
while (1);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 263 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
ORG 0100H
TM0ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV TMOD,#00H
MOV TL0,#66H ;65536-11.0592M/12/1000
MOV TH0,#0FCH
SETB TR0 ;Start timer
SETB ET0 ;Enable timer0 interrupt
SETB EA
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 264 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
TMOD = 0x00;
TL1 = 0x66; //65536-11.0592M/12/1000
TH1 = 0xfc;
TR1 = 1; //Start timer
ET1 = 1; //Enable timer1 interrupt
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 265 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP TM1ISR
ORG 0100H
TM1ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV TMOD,#00H
MOV TL1,#66H ;65536-11.0592M/12/1000
MOV TH1,#0FCH
SETB TR1 ;Start timer
SETB ET1 ;Enable timer1 interrupt
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0063H
LJMP TM2ISR
ORG 0100H
TM2ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 268 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 269 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 009BH
LJMP TM3ISR
ORG 0100H
TM3ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 270 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 271 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00A3H
LJMP TM4ISR
ORG 0100H
TM4ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 272 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
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
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART1ISR
ORG 0100H
UART1ISR:
JNB TI,CHECKRI
CLR TI ;Clear interrupt flag
CPL P1.0 ;Test port
CHECKRI:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 274 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB RI,ISREXIT
CLR RI ;Clear interrupt flag
CPL P1.1 ;Test port
ISREXIT:
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV SCON,#50H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#15H ;Start timer
SETB ES ;Enable UART1 interrupt
SETB EA
MOV SBUF,#5AH ; Send test data
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
S2CON = 0x10;
T2L = 0xe8; //65536-11059200/115200/4=0FFE8H
T2H = 0xff;
AUXR = 0x14; //Start timer
IE2 = ES2; //Enable UART2 interrupt
EA = 1;
S2BUF = 0x5a; // Send test data
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0043H
LJMP UART2ISR
ORG 0100H
UART2ISR:
PUSH ACC
PUSH PSW
MOV A,S2CON
JNB ACC.1,CHECKRI
ANL S2CON,#NOT 02H ;Clear interrupt flag
CPL P1.2 ;Test port
CHECKRI:
MOV A,S2CON
JNB ACC.0,ISREXIT
ANL S2CON,#NOT 01H ;Clear interrupt flag
CPL P1.3 ;Test port
ISREXIT:
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV S2CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H ;Start timer
MOV IE2,#ES2 ;Enable UART2 interrupt
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 277 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SETB EA
MOV S2BUF,#5AH ; Send test data
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 278 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
S3CON = 0x10;
T2L = 0xe8; //65536-11059200/115200/4=0FFE8H
T2H = 0xff;
AUXR = 0x14; //Start timer
IE2 = ES3; //Enable UART3 interrupt
EA = 1;
S3BUF = 0x5a; //Send test data
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 008BH
LJMP UART3ISR
ORG 0100H
UART3ISR:
PUSH ACC
PUSH PSW
MOV A,S3CON
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 279 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB ACC.1,CHECKRI
ANL S3CON,#NOT 02H ;Clear interrupt flag
CPL P1.2 ;Test port
CHECKRI:
MOV A,S3CON
JNB ACC.0,ISREXIT
ANL S3CON,#NOT 01H ;Clear interrupt flag
CPL P1.3 ;Test port
ISREXIT:
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV S3CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H ;Start timer
MOV IE2,#ES3 ;Enable UART3 interrupt
SETB EA
MOV S3BUF,#5AH ;Send test data
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
S4CON = 0x10;
T2L = 0xe8; //65536-11059200/115200/4=0FFE8H
T2H = 0xff;
AUXR = 0x14; //Start timer
IE2 = ES4; //Enable UART4 interrupt
EA = 1;
S4BUF = 0x5a; //Send test data
while (1);
}
Assembly code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 281 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0093H
LJMP UART4ISR
ORG 0100H
UART4ISR:
PUSH ACC
PUSH PSW
MOV A,S4CON
JNB ACC.1,CHECKRI
ANL S4CON,#NOT 02H ;Clear interrupt flag
CPL P1.2 ;Test port
CHECKRI:
MOV A,S4CON
JNB ACC.0,ISREXIT
ANL S4CON,#NOT 01H ;Clear interrupt flag
CPL P1.3 ;Test port
ISREXIT:
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 282 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV S4CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H ;Start timer
MOV IE2,#ES4 ;Enable UART4 interrupt
SETB EA
MOV S4BUF,#5AH ;Send test data
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 283 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
ADCCFG = 0x00;
ADC_CONTR = 0xc0; //Enable and start the ADC module
EADC = 1; //Enable ADC interrupt
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 002BH
LJMP ADCISR
ORG 0100H
ADCISR:
ANL ADC_CONTR,#NOT 20H ;Clear interrupt flag
MOV P0,ADC_RES ;Test port
MOV P2,ADC_RESL ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 284 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV ADCCFG,#00H
MOV ADC_CONTR,#0C0H ;Enable and start the ADC module
SETB EADC ;Enable ADC interrupt
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 285 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0033H
LJMP LVDISR
ORG 0100H
LVDISR:
ANL PCON,#NOT LVDF ;Clear interrupt flag
CPL P1.0 ;Test port
RETI
MAIN:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 286 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CCON = 0x00;
CMOD = 0x09; //PCA clock is the system clock, enable PCA timing
interrupt
CR = 1; //Start PCA timer
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
CH 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 DATA 0DCH
CCAP2L DATA 0ECH
CCAP2H DATA 0FCH
PCA_PWM2 DATA 0F4H
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
JNB CF,ISREXIT
CLR CF ;Clear interrupt flag
CPL P1.0 ;Test port
ISREXIT:
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CCON,#00H
MOV CMOD,#09H ;PCA clock is the system clock, enable PCA timing
interrupt
SETB CR ;Start PCA timer
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 289 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 290 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 004BH
LJMP SPIISR
ORG 0100H
SPIISR:
MOV SPSTAT,#0C0H ;Clear interrupt flag
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 291 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 292 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CMPCR2 = 0x00;
CMPCR1 = 0x80; //Enable comparator module
CMPCR1 |= 0x30; //Enable edge interrupt of comparator
CMPCR1 &= ~0x08; //P3.6 is CMP + input pin
CMPCR1 |= 0x04; //P3.7 is CMP- input pin
CMPCR1 |= 0x02; //Enable Comparator output
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00ABH
LJMP CMPISR
ORG 0100H
CMPISR:
ANL CMPCR1,#NOT 40H ;Clear interrupt flag
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CMPCR2,#00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 293 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 294 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
PWM0CKS = 0x0f; //PWM0 clock is system clock/16.
PWM0CH = 0x01; //Set the PWM0 period to 256 PWM0 clocks
PWM0CL = 0x00;
P_SW2 = 0x00;
PWMCFG01 = 0x05; //Start PWM0 module and enable PWM0 counter interrupt
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00B3H
LJMP PWM0ISR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 295 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
PWM0ISR:
PUSH ACC
PUSH PSW
MOV A,PWMCFG01
JNB ACC.3,ISREXIT
ANL PWMCFG01,#NOT 08H ;Clear interrupt flag
CPL P1.0 ;Test port
ISREXIT:
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
MOV A,#0FH
MOV DPTR,#PWM0CKS
MOVX @DPTR,A ;PWM0 clock is system clock/16.
MOV A,#01H
MOV DPTR,#PWM0CH ;Set the PWM0 period to 256 PWM0 clocks
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM0CL
MOVX @DPTR,A
MOV P_SW2,#00H
MOV PWMCFG01,#05H ;Start PWM0 module and enable PWM0 counter interrupt
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 296 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
I2CCFG = 0xc0; //Enable I2C master mode
I2CMSCR = 0x80; //Enable I2C interrupt;
P_SW2 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 297 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
EA = 1;
P_SW2 = 0x80;
I2CMSCR = 0x81; //Send start command
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00C3H
LJMP I2CISR
ORG 0100H
I2CISR:
PUSH ACC
PUSH DPL
PUSH DPH
PUSH P_SW2
MOV P_SW2,#80H
MOV DPTR,#I2CMSST
MOVX A,@DPTR
ANL A,#NOT 40H ;Clear interrupt flag
MOVX @DPTR,A
CPL P1.0 ;Test port
POP P_SW2
POP DPH
POP DPL
POP ACC
RETI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 298 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
MOV A,#0C0H ;Enable I2C master mode
MOV DPTR,#I2CCFG
MOVX @DPTR,A
MOV A,#80H ;Enable I2C interrupt
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
MOV P_SW2,#00H
SETB EA
MOV P_SW2,#80H
MOV A,#081H ;Send start command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
MOV P_SW2,#00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 299 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
12 Timers/Counters
Product line Number of timers
STC8G1K08 family 3
STC8G1K08-8Pin family 2
STC8G1K08A family 2
STC8G2K64S4 family 5
STC8G2K64S2 family 5
STC8G1K08T family 3
STC15H2K64S4 family 5
Five 16-bit Timers/Counters are integrated in STC8G 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. For T2, the ‘timer’ or ‘counter’ function is selected by
the control bit T2_C/T in the special function register AUXR. For T3, the ‘timer’ or ‘counter’ function is
selected by the control bit T3_C/T in the special function register T4T3M. For T4, the ‘timer’ or ‘counter’
function is selected by the control bit T4_C/T in the special function register T4T3M. The core of the
timer/counter is a up counter, the essence of which is counting pulses. The only difference of ‘timer’ mode and
‘counter’ mode is the different counting pulses sources. If the counting pulse is from the system clock, the
timer/counter runs in the timing mode, it counts once every 12 clocks or one clock. If the counting pulse is from
the microcontroller external pins, the timer/counter runs in counting mode, it counts once every pulse.
When T0, T1 and T2 are operating in ‘timer’ mode, T0x12, T1x12 and T2x12 in AUXR register are used
to determine the clocks of T0, T1 and T2 are system clock/12 or system clock/1. When T3 and T4 are operating
in ‘timer’ mode, T3x12 and T4x12 in the T4T3M register determine the clocks of T3 and T4 are system
clock/12 or system clock/1. When the timer/counters are operating in ‘counter’ mode, the frequency of the
external pulse is not divided.
T0 has four operating modes which are selected by bit-pairs (M1, M0) in TMOD. The four modes are
mode 0 (16-bit auto-reload mode), mode 1 (16-bit non-auto-reload mode), mode 2 (8-bit auto-reload mode) and
mode 3 (16-bit auto-reload mode whose interrupt can not be disabled). And for T1, all modes except mode 3 are
the same as T0. The mode 3 of T1 is invalid and stops counting. For T2, T3 and T4, there is only one mode, 16-
bit auto-reload mode. Besides being used as timer/counters, T2, T3 and T4 can also be as the baud-rate
generators of UARTs and programmable clock outputs.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 300 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 301 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 302 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AUXR.7/T0x12=0
÷12
SYSclk TF0 Interrupt
C/T=0
Toggle
÷1 AUXR.7/T0x12=1 TH0 TL0
T0CLKO
(8bits) (8bits)
P3.5
C/T=1 control
T0 Pin
T0CLKO
TR0
RL_TH0 RL_TL0
GATE (8bits) (8bits)
INT0
When GATE=0 (TMOD.3), the timer will count if TR0=1. When GATE=1, it is allowed to control timer0
by external input INT0, so that pulse width measurement can be realized. TR0 is the control bit in the TCON
register. For the specific function description of each bit of the TCON register, see the introduction of the TCON
register in the previous section.
When C/T=0, the multiplexer is connected to the frequency division output of the system clock. T0 counts
the internal system clock, and works in timing mode. When C/T=1, the multiplexer is connected to the external
pulse input P3.4/T0, and T0 works in counting mode.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 303 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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. The rate of T0 is determined by T0x12 in the
special function register AUXR. If T0x12=0, T0 works in 12T mode, and if T0x12=1, T0 works in 1T mode.
Timer0 has two hidden registers RL_TH0 and RL_TL0. RL_TH0 and TH0 share the same address, and
RL_TL0 and TL0 share the same address. When TR0=0, that is, when Timer/Counter0 is disabled, the content
written to TL0 will be written to RL_TL0 at the same time, and the content written to TH0 will also be written
to RL_TH0 at the same time. When TR0=1, that is, when Timer/Counter0 is allowed to work, writing content to
TL0 is not actually written to the current register TL0, but written to the hidden register RL_TL0, and writing
content to TH0 is actually also it is not written into the current register TH0, but into the hidden register
RL_TH0, which can cleverly realize the 16-bit reload timer. When reading the contents of TH0 and TL0, the
contents be read are the contents of TH0 and TL0, not the contents of RL_TH0 and RL_TL0.
When Timer0 is working in mode 0 (TMOD[1:0]/[M1,M0]=00B), the overflow of [TH0,TL0] not only sets
TF0, but also automatically reloads the contents of [RL_TH0,RL_TL0] to [TH0,TL0].
If T0CLKO/INT_CLKO.0=1, the P3.5/T1 pin is configured as timer 0's clock output T0CLKO. The output
clock frequency is T0 overflow rate/2.
If C/T=1, the timer/counter 0 counts the external pulse input (P3.4/T0), then:
the output clock frequency = (T0_Pin_CLK) / (65536-[RL_TH0, RL_TL0])/2
In this mode, Timer/Counter 0 works in 16-bit non-reloadable mode, as shown in the figure below.
AUXR.7/T0x12=0
÷12
SYSclk TF0 Interrupt
C/T=0
Toggle
÷1 AUXR.7/T0x12=1 TH0 TL0
T0CLKO
(8bits) (8bits)
P3.5
C/T=1 control
T0 Pin
T0CLKO
TR0
GATE
INT0
In this mode, Timer/Counter 0 is configured as a 16-bit non-reloadable mode, which is composed of 8 bits
of TL0 and 8 bits of TH0. The 8-bit overflow of TL0 carries over to TH0, and the overflow of TH0 counts the
overflow flag TF0 in TCON.
When GATE=0 (TMOD.3), the timer will count if TR0=1. When GATE=1, it is allowed to control timer 0
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 304 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
by external input INT0, so that pulse width measurement can be realized. TR0 is the control bit in the TCON
register. For the specific function description of each bit of the TCON register, see the introduction of the TCON
register in the previous section.
When C/T=0, the multiplexer is connected to the frequency division output of the system clock, T0 counts
the internal system clock, and works in timing mode. When C/T=1, the multiplexer is connected to the external
pulse input 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. The rate of T0 is determined by T0x12 in the
special function register AUXR. If T0x12=0, T0 works in 12T mode, and if T0x12=1, T0 works in 1T mode.
AUXR.7/T0x12=0
÷12
SYSclk TF0 Interrupt
C/T=0
Toggle
÷1 AUXR.7/T0x12=1 TL0
T0CLKO
(8bits)
P3.5
C/T=1 control
T0 Pin
T0CLKO
TR0
TH0
GATE (8bits)
INT0
The overflow of TL0 not only sets TF0, but also reloads the content of TH0 into TL0. The content of TH0
is preset by software, and its content remains unchanged during reloading.
When T0CLKO/INT_CLKO.0=1, the P3.5/T1 pin is configured as timer 0's clock output T0CLKO. The
output clock frequency is T0 overflow rate/2.
If C/T=1, the timer/counter T0 counts the external pulse input (P3.4/T0), then:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 305 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AUXR.7/T0x12=0
÷12
SYSclk TF0 Interrupt
C/T=0
Toggle
÷1 AUXR.7/T0x12=1 TH0 TL0
T0CLKO
(8bits) (8bits)
P3.5
C/T=1 control
T0 Pin
T0CLKO
TR0
RL_TH0 RL_TL0
GATE (8bits) (8bits)
INT0
Note: When Timer/Counter 0 works in mode 3 (16-bit auto-reload mode with non-maskable interrupt), it is
not necessary to enable EA/IE.7 (total interrupt enable bit), only ET0/IE.1 is required. (Timer/counter 0
interrupt enable bit) can turn on the timer/counter 0 interrupt. The timer/counter 0 interrupt in this mode has
nothing to do with the total interrupt enable bit EA. Once the timer/counter 0 interrupt in this mode is enabled,
the timer/counter 0 interrupt priority is the highest, and it cannot be interrupted by any other interrupt (no matter
it is lower than the timer/counter 0 interrupt priority). After the interrupt in this mode is enabled, it is neither
controlled by EA/IE.7 nor controlled by ET0. Clearing EA nor ET0 can not disable this interrupt.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 306 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AUXR.6/T1x12=0
÷12
SYSclk TF1 Interrupt
C/T=0
Toggle
÷1 AUXR.6/T1x12=1 TH1 TL1
T1CLKO
(8bits) (8bits)
P3.4
C/T=1 control
T1 Pin
T1CLKO
TR1
RL_TH1 RL_TL1
GATE (8bits) (8bits)
INT1
When GATE=0 (TMOD.7), the timer will count if TR1=1. When GATE=1, it is allowed to control timer1
by external input INT1, so that pulse width measurement can be realized. TR1 is the control bit in the TCON
register. For the specific function description of each bit of the TCON register, see the introduction of the TCON
register in the previous section.
When C/T=0, the multiplexer is connected to the frequency division output of the system clock. T1 counts
the internal system clock, and works in timing mode. When C/T=1, the multiplexer is connected to the external
pulse input 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. The rate of T1 is determined by T1x12 in the
special function register AUXR. If T1x12=0, T1 works in 12T mode, and if T1x12=1, T1 works in 1T mode.
Timer1 has two hidden registers RL_TH1 and RL_TL1. RL_TH1 and TH1 share the same address, and
RL_TL1 and TL1 share the same address. When TR1=0, that is, when Timer/Counter1 is disabled, the content
written to TL1 will be written to RL_TL1 at the same time, and the content written to TH1 will also be written
to RL_TH1 at the same time. When TR1=1, that is, when Timer/Counter1 starts to work, writing content to TL1
is not actually written to the current register TL1, but written to the hidden register RL_TL1, and writing
content to TH1 is actually also it is not written into the current register TH1, but into the hidden register
RL_TH1, which can cleverly realize the 16-bit reload timer. When reading the contents of TH1 and TL1, the
contents be read are the contents of TH1 and TL1, not the contents of RL_TH1 and RL_TL1.
When Timer1 is working in mode 0 (TMOD[5:4]/[M1,M0]=00B), the overflow of [TH1,TL1] not only sets
TF1, but also automatically reloads the contents of [RL_TH1,RL_TL1] to [TH1,TL1].
If T1CLKO/INT_CLKO.1=1, the P3.4/T1 pin is configured as timer 1's clock output T1CLKO. The output
clock frequency is T1 overflow rate/2.
If C/T=1, the timer/counter 1 counts the external pulse input (P3.5/T1), then:
the output clock frequency = (T1_Pin_CLK) / (65536-[RL_TH1, RL_TL1])/2
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 307 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AUXR.6/T1x12=0
÷12
SYSclk TF1 Interrupt
C/T=0
Toggle
÷1 AUXR.6/T1x12=1 TH1 TL1
T1CLKO
(8bits) (8bits)
P3.4
C/T=1 control
T1 Pin
T1CLKO
TR1
GATE
INT1
In this mode, Timer/Counter 1 is configured as a 16-bit non-reloadable mode, which is composed of 8 bits
of TL1 and 8 bits of TH1. The 8-bit overflow of TL1 carries over to TH1, and the overflow of TH1 counts the
overflow flag TF1 in TCON.
When GATE=0 (TMOD.7), the timer will count if TR1=1. When GATE=1, it is allowed to control timer 1
by external input INT1, so that pulse width measurement can be realized. TR1 is the control bit in the TCON
register. For the specific function description of each bit of the TCON register, see the introduction of the TCON
register in the previous section.
When C/T=0, the multiplexer is connected to the frequency division output of the system clock, T1 counts
the internal system clock, and works in timing mode. When C/T=1, the multiplexer is connected to the external
pulse input 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. The rate of T1 is determined by T1x12 in the
special function register AUXR. If T1x12=0, T1 works in 12T mode, and if T1x12=1, T1 works in 1T mode.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 308 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AUXR.6/T1x12=0
÷12
SYSclk TF1 Interrupt
C/T=0
Toggle
÷1 AUXR.6/T1x12=1 TL1
T1CLKO
(8bits)
P3.4
C/T=1 control
T1 Pin
T1CLKO
TR1
TH1
GATE (8bits)
INT1
The overflow of TL1 not only sets TF1, but also reloads the content of TH1 into TL1. The content of TH1
is preset by software, and its content remains unchanged during reloading.
When T1CLKO/INT_CLKO.1=1, the P3.4/T0 pin is configured as timer 1's clock output T1CLKO. The
output clock frequency is T1 overflow rate/2.
If C/T=1, the timer/counter T1 counts the external pulse input (P3.5/T1), then:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 309 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
256 – TH0
Mode 2 1T Period =
SYSclk
(auto-reloadable)
(8-bit auto-reloadable
256 – TH0
mode) 12T Period = ×12 (auto-reloadable)
SYSclk
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 310 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
256 – TH1
Mode 2 1T Period =
SYSclk
(auto-reloadable)
(8-bit auto-reloadable
256 – TH1
mode) 12T Period = ×12 (auto-reloadable)
SYSclk
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 311 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
AUXR.2/T2x12=0
÷12
SYSclk TM2PS T2IF Interrupt
T2_C/T=0
When T2_C/T=0, the multiplexer is connected to the frequency division output of the system clock, T2
counts the internal system clock, and works in timing mode. When T2_C/T=1, the multiplexer is connected to
the external pulse input 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. The rate of T2 is determined by T2x12 in the
special function register AUXR. If T2x12=0, T2 works in 12T mode, and if T2x12=1, T1 works in 1T mode.
Timer2 has two hidden registers RL_T2H and RL_T2L. RL_T2H and T2H share the same address, and
RL_T2L and T2L share the same address. When T2R=0, that is, when Timer/Counter2 is disabled, the content
written to T2L will be written to RL_T2L at the same time, and the content written to T2H will also be written
to RL_T2H at the same time. When T2R=1, that is, when Timer/Counter2 starts to work, writing content to T2L
is not actually written to the current register T2L, but written to the hidden register RL_T2L, and writing
content to T2H is actually also it is not written into the current register T2H, but into the hidden register
RL_T2H, which can cleverly realize the 16-bit reload timer. When reading the contents of T2H and T2L, the
contents be read are the contents of T2H and T2L, not the contents of RL_T2H and RL_T2L.
The overflow of [T2H, T2L] not only sets the interrupt request flag (T2IF), which causes the CPU to
switch to the timer 2 interrupt routine, but also automatically reloads the contents of [RL_T2H, RL_T2L] into
[T2H, T2L].
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 312 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 313 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
T3 operates in 16-bit auto-reload mode. T3L and T3H combine into a 16-bit register with T3L as the low byte
and T3H as the high byte. When the 16-bit counter [T3H, T3L] overflows, the system loads the reload
value in the internal 16-bit reload register into [T3H, T3L] automatically.
T4T3M.1/T3x12=0
÷12
SYSclk TM3PS T3IF Interrupt
T3_C/T=0
When T3_C/T=0, the multiplexer is connected to the frequency division output of the system clock, T3
counts the internal system clock, and works in timing mode. When T3_C/T=1, the multiplexer is connected to
the external pulse input 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. The rate of T3 is determined by T3x12 in the
special function register T4T3M. If T3x12=0, T3 works in 12T mode, and if T3x12=1, T3 works in 1T mode.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 314 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Timer3 has two hidden registers RL_T3H and RL_T3L. RL_T3H and T3H share the same address, and
RL_T3L and T3L share the same address. When T3R=0, that is, when Timer/Counter3 is disabled, the content
written to T3L will be written to RL_T3L at the same time, and the content written to T3H will also be written
to RL_T3H at the same time. When T3R=1, that is, when Timer/Counter3 starts to work, writing content to T3L
is not actually written to the current register T3L, but written to the hidden register RL_T3L, and writing
content to T3H is actually also it is not written into the current register T3H, but into the hidden register
RL_T3H, which can cleverly realize the 16-bit reload timer. When reading the contents of T3H and T3L, the
contents be read are the contents of T3H and T3L, not the contents of RL_T3H and RL_T3L.
The overflow of [T3H, T3L] not only sets the interrupt request flag (T3IF), which causes the CPU to
switch to the timer 3 interrupt routine, but also automatically reloads the contents of [RL_T3H, RL_T3L] into
[T3H, T3L].
T4T3M.5/T4x12=0
÷12
SYSclk TM4PS T4IF Interrupt
T4_C/T=0
T4R/T4T3M.7 is the control bit in the T4T3M register. For the specific function description of each bit of
the T4T3M register, see the introduction of the T4T3M register in the previous section.
When T4_C/T=0, the multiplexer is connected to the frequency division output of the system clock, T4
counts the internal system clock, and works in timing mode. When T4_C/T=1, the multiplexer is connected to
the external pulse input 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. The rate of T4 is determined by T4x12 in the
special function register T4T3M. If T4x12=0, T4 works in 12T mode, and if T4x12=1, T4 works in 1T mode.
Timer4 has two hidden registers RL_T4H and RL_T4L. RL_T4H and T4H share the same address, and
RL_T4L and T4L share the same address. When T4R=0, that is, when Timer/Counter4 is disabled, the content
written to T4L will be written to RL_T4L at the same time, and the content written to T4H will also be written
to RL_T4H at the same time. When T4R=1, that is, when Timer/Counter4 starts to work, writing content to T4L
is not actually written to the current register T4L, but written to the hidden register RL_T4L, and writing
content to T4H is actually also it is not written into the current register T4H, but into the hidden register
RL_T4H, which can cleverly realize the 16-bit reload timer. When reading the contents of T4H and T4L, the
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 315 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
contents be read are the contents of T4H and T4L, not the contents of RL_T4H and RL_T4L.
The overflow of [T4H, T4L] not only sets the interrupt request flag (T4IF), which causes the CPU to
switch to the timer 4 interrupt routine, but also automatically reloads the contents of [RL_T4H, RL_T4L] into
[T4H, T4L].
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 316 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 317 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
ORG 0100H
TM0ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 318 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 319 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
ORG 0100H
TM0ISR:
MOV TL0,#66H ;Reset parameters
MOV TH0,#0FCH
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 320 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
ORG 0100H
TM0ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 322 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
ORG 0100H
TM0ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 324 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TM0ISR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 325 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
TM0ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 326 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT0ISR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 327 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
INT0ISR:
MOV P0,TL0 ;TL0 is the low byte of the measured value
MOV P1,TH0 ;TH0 is the high byte of the measured value
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 329 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 330 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP TM1ISR
ORG 0100H
TM1ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
TH1 = 0xfc;
TR1 = 1; //Start timer
ET1 = 1; //Enable timer interrupt
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP TM1ISR
ORG 0100H
TM1ISR:
MOV TL1,#66H ;Reset parameters
MOV TH1,#0FCH
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 333 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 334 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP TM1ISR
ORG 0100H
TM1ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 335 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 336 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 001BH
LJMP TM1ISR
ORG 0100H
TM1ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 337 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 338 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0013H
LJMP INT1ISR
ORG 0100H
INT1ISR:
MOV P0,TL1 ;TL1 is the low byte of the measured value
MOV P1,TH1 ;TH1 is the high byte of the measured value
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 339 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 342 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
ES = 1;
EA = 1;
UartSENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
UartSEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 343 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0100H
UART_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,SBUF
INC WPTR
UARTISR_EXIT:
POP PSW
POP ACC
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
UART_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SENDEND
LCALL UART_SEND
INC DPTR
JMP UART_SENDSTR
SENDEND:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 344 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#STRING
LCALL UART_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
void UartInit()
{
SCON = 0x50;
TMOD = 0x20;
TL1 = BRT;
TH1 = BRT;
TR1 = 1;
AUXR = 0x40;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 346 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
ES = 1;
EA = 1;
UartSENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
UartSEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 347 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,SBUF
INC WPTR
UARTISR_EXIT:
POP PSW
POP ACC
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#20H
MOV TL1,#0FDH ;256-11059200/115200/32=0FDH
MOV TH1,#0FDH
SETB TR1
MOV AUXR,#40H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
UART_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SENDEND
LCALL UART_SEND
INC DPTR
JMP UART_SENDSTR
SENDEND:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 348 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#STRING
LCALL UART_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 350 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0063H
LJMP TM2ISR
ORG 0100H
TM2ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 351 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
T2L = 0xff;
T2H = 0xff;
AUXR = 0x18; //Set external counting mode and start timer
IE2 = ET2; //Enable timer interrupt
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0063H
LJMP TM2ISR
ORG 0100H
TM2ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV T2L,#0FFH
MOV T2H,#0FFH
MOV AUXR,#18H ;Set external counting mode and start timer
MOV IE2,#ET2 ;Enable timer interrupt
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 353 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 354 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 355 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
bit busy;
char wptr;
char rptr;
char buffer[16];
void UartInit()
{
SCON = 0x50;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x15;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 356 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P5M1 = 0x00;
UartInit();
ES = 1;
EA = 1;
UartSENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
UartSEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 357 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB RI,UARTISR_EXIT
CLR RI
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,SBUF
INC WPTR
UARTISR_EXIT:
POP PSW
POP ACC
RETI
UART_INIT:
MOV SCON,#50H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#15H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
UART_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SENDEND
LCALL UART_SEND
INC DPTR
JMP UART_SENDSTR
SENDEND:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#STRING
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 358 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 359 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void Uart2Init()
{
S2CON = 0x10;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart2Init();
IE2 = 0x01;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 360 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
EA = 1;
Uart2SENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
Uart2SEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0043H
LJMP UART2_ISR
ORG 0100H
UART2_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S2CON
JNB ACC.1,CHKRI
ANL S2CON,#NOT 02H
CLR BUSY
CHKRI:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 361 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB ACC.0,UART2ISR_EXIT
ANL S2CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S2BUF
INC WPTR
UART2ISR_EXIT:
POP PSW
POP ACC
RETI
UART2_INIT:
MOV S2CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART2_SEND:
JB BUSY,$
SETB BUSY
MOV S2BUF,A
RET
UART2_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND2END
LCALL UART2_SEND
INC DPTR
JMP UART2_SENDSTR
SEND2END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART2_INIT
MOV IE2,#01H
SETB EA
MOV DPTR,#STRING
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 362 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART2_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART2_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 363 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void Uart3Init()
{
S3CON = 0x10;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart3Init();
IE2 = 0x08;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 364 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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
ORG 0000H
LJMP MAIN
ORG 008BH
LJMP UART3_ISR
ORG 0100H
UART3_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S3CON
JNB ACC.1,CHKRI
ANL S3CON,#NOT 02H
CLR BUSY
CHKRI:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 365 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB ACC.0,UART3ISR_EXIT
ANL S3CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S3BUF
INC WPTR
UART3ISR_EXIT:
POP PSW
POP ACC
RETI
UART3_INIT:
MOV S3CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART3_SEND:
JB BUSY,$
SETB BUSY
MOV S3BUF,A
RET
UART3_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND3END
LCALL UART3_SEND
INC DPTR
JMP UART3_SENDSTR
SEND3END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART3_INIT
MOV IE2,#08H
SETB EA
MOV DPTR,#STRING
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 366 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART3_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART3_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 367 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void Uart4Init()
{
S4CON = 0x10;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart4Init();
IE2 = 0x10;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 368 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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
ORG 0000H
LJMP MAIN
ORG 0093H
LJMP UART4_ISR
ORG 0100H
UART4_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S4CON
JNB ACC.1,CHKRI
ANL S4CON,#NOT 02H
CLR BUSY
CHKRI:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 369 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JNB ACC.0,UART4ISR_EXIT
ANL S4CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S4BUF
INC WPTR
UART4ISR_EXIT:
POP PSW
POP ACC
RETI
UART4_INIT:
MOV S4CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART4_SEND:
JB BUSY,$
SETB BUSY
MOV S4BUF,A
RET
UART4_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND4END
LCALL UART4_SEND
INC DPTR
JMP UART4_SENDSTR
SEND4END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART4_INIT
MOV IE2,#10H
SETB EA
MOV DPTR,#STRING
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 370 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART4_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART4_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 009BH
LJMP TM3ISR
ORG 0100H
TM3ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 373 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 374 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
T4T3M DATA 0D1H
T4L DATA 0D3H
T4H DATA 0D2H
T3L DATA 0D5H
T3H DATA 0D4H
T2L DATA 0D7H
T2H DATA 0D6H
AUXR DATA 8EH
IE2 DATA 0AFH
ET2 EQU 04H
ET3 EQU 20H
ET4 EQU 40H
AUXINTIF DATA 0EFH
T2IF EQU 01H
T3IF EQU 02H
T4IF EQU 04H
ORG 0000H
LJMP MAIN
ORG 009BH
LJMP TM3ISR
ORG 0100H
TM3ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 375 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 376 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 377 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 378 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void Uart3Init()
{
S3CON = 0x50;
T3L = BRT;
T3H = BRT >> 8;
T4T3M = 0x0a;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart3Init();
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
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 379 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 008BH
LJMP UART3_ISR
ORG 0100H
UART3_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S3CON
JNB ACC.1,CHKRI
ANL S3CON,#NOT 02H
CLR BUSY
CHKRI:
JNB ACC.0,UART3ISR_EXIT
ANL S3CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S3BUF
INC WPTR
UART3ISR_EXIT:
POP PSW
POP ACC
RETI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 380 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
UART3_INIT:
MOV S3CON,#50H
MOV T3L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T3H,#0FFH
MOV T4T3M,#0AH
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART3_SEND:
JB BUSY,$
SETB BUSY
MOV S3BUF,A
RET
UART3_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND3END
LCALL UART3_SEND
INC DPTR
JMP UART3_SENDSTR
SEND3END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART3_INIT
MOV IE2,#08H
SETB EA
MOV DPTR,#STRING
LCALL UART3_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 381 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL UART3_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 382 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00A3H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 383 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LJMP TM4ISR
ORG 0100H
TM4ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 384 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00A3H
LJMP TM4ISR
ORG 0100H
TM4ISR:
CPL P1.0 ;Test port
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 386 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P3M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 387 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 388 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
bit busy;
char wptr;
char rptr;
char buffer[16];
void Uart4Init()
{
S4CON = 0x50;
T4L = BRT;
T4H = BRT >> 8;
T4T3M = 0xa0;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 389 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart4Init();
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
ORG 0000H
LJMP MAIN
ORG 0093H
LJMP UART4_ISR
ORG 0100H
UART4_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S4CON
JNB ACC.1,CHKRI
ANL S4CON,#NOT 02H
CLR BUSY
CHKRI:
JNB ACC.0,UART4ISR_EXIT
ANL S4CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S4BUF
INC WPTR
UART4ISR_EXIT:
POP PSW
POP ACC
RETI
UART4_INIT:
MOV S4CON,#50H
MOV T4L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T4H,#0FFH
MOV T4T3M,#0A0H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 391 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
UART4_SEND:
JB BUSY,$
SETB BUSY
MOV S4BUF,A
RET
UART4_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND4END
LCALL UART4_SEND
INC DPTR
JMP UART4_SENDSTR
SEND4END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART4_INIT
MOV IE2,#10H
SETB EA
MOV DPTR,#STRING
LCALL UART4_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART4_SEND
INC RPTR
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 392 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8G1K08 family 2
STC8G1K08-8Pin family 1
STC8G1K08A family 1
STC8G2K64S4 family 4
STC8G2K64S2 family 2
STC8G1K08T family 1
STC15H2K64S4 family 4
There are 4 full duplex asynchronous serial communication ports (UART in short) in STC8G 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.
There are 4 modes for UART1 of STC8G series of microcontrollers, the baud rates of two modes of them are
variable, and the baud rates of the other two modes are fixed. They can be chosen for different applications. There are
only two modes in UART2, UART3 and UART4, and their baud rates are variable. Different baud rates and different
modes can be set by software. It is flexible for the host to query the receiving or sending process, or use the interrupt
method.
All the pins of UART1, UART2, UART3 and UART4 can be switched amoung multiple groups of ports
using the pin switching function, so that a serial port can be multiplexed into severial serial ports in a time-
sharing manner.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 393 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
13.2 UART1
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
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 394 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Transmission process of mode 0: Transmission is initiated by any instruction that write data to SBUF. The 8-bit
datum is output from the RxD pin at the baud rate of SYSclk/12 or SYSclk/2 (determined by the UART_M0x6
divided by 12 or 2), from LSB to MSB. The TxD pin outputs the synchronous shift pulse signal. The interrupt flag TI
will be set when transmittion is completed. When the write signal is valid, the transmit control signal SEND is active
(high) one clock apart, allowing RxD to send data while allowing the TxD output the synchronous shift pulse. When a
frame (8 bits) of datum is sent, all control signals are reset to the original status, and only TI keeps high level and
keeps the interrupt request status. TI must be cleared by software before sending data again.
Receiving process of mode 0: Receiving is initiated by setting REN and the receive interrupt request flag RI=0.
After starting the receive process, RxD is the serial data input pin and TxD is the synchronous pulse output pin. The
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 395 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
serial receiving baud rate is SYSclk/12 or SYSclk/2 (determined by UART_M0x6 is 12 or 2). After receiving a frame
of datum (8 bits), the control signal is reset and the interrupt flag RI is set to 1, the interrupt requet status appears. RI
must be cleared by software for the next receiving data.
Write
SBUF
TxD
RxD D0 D1 D2 D3 D4 D5 D6 D7
TI
RI
Write
REN=1, RI=0
SCON
TxD
RxD D0 D1 D2 D3 D4 D5 D6 D7
TI
RI
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.
The baud rates of UART1 mode 0 are shown in the following table, where SYSclk is the system operating
frequency:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 396 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Transmission process of mode 1: TxD is used as data output pin when transmitting a datum. Transmission is
initiated by writing SBUF. "1" is also written into the 9th bit of transmission shift register by the writing "SBUF"
signal, and the TX control unit is notified to start sending. The shift register shifts the data right to TxD to send, and
shifts "0" in the left to supplement. When the highest bit of data is shifted to the output of the shift register, it is
followed by the 9th bit "1", and all bits to the left of it are "0". This state causes the TX control unit to make the last
shift output, and then disables the transmission signal "SEND" to complete the transmission of a frame and sets TI,
and requests interrupt processing to CPU.
Receiving process of mode 1: After the software sets the reception enable flag REN, i.e. REN = 1, the receiver
will detect the RxD pin signal. The receiver is ready to receive data when a "1" → "0" falling edge is detected at RxD
pin, and 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. The received datum is valid only if the following two conditions are met:
·RI=0;
·SM2=0 or the stop bit received is 1.
The datum received is loaded into SBUF, the stop bit is loaded into RB8, RI flag is set to request interrupt to
CPU. If the two conditions can not be met at the same time, the received data is invalid and is discarded. Regardless
of the conditions are met or not, the receiver will re-test RxD pin of the "1" → "0" edge, and continue to receive the
next frame. If the received datum is valid, the RI flag must be cleared by software in the interrupt service routine.
Usually, SM2 is set to "0" when serial port is operating in mode 1.
Write
SBUF
TI
Write
REN=1, RI=0
SCON
RI
The baud rate of UART1 is variable. It can be generated by T1 or T2. If the timer is in 1T mode (12x speed), the
corresponding baud rate is increased by 12 times.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 397 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The baud rate of UART1 mode 1 is calculated as follows, where SYSclk is the system operating frequency.
1T
T1 mode 0
12T
1T
T1 mode 2
12T
The reload value of the timers corresponding to the common frequency and the common baud rate are as
following.
T2 T1 mode 0 T1 mode 2
Frequency
Baud rate SMOD=1 1T mode
(MHz) 1T mode 12T mode 1T mode 12T mode
1T mode 12T mode 1T mode 12T mode
115200 FFE8H FFFEH FFE8H FFFEH FAH - FDH -
57600 FFD0H FFFCH FFD0H FFFCH F4H FFH FAH -
11.0592 38400 FFB8H FFFAH FFB8H FFFAH EEH - F7H -
19200 FF70H FFF4H FF70H FFF4H DCH FDH EEH -
9600 FEE0H FFE8H FEE0H FFE8H B8H FAH DCH FDH
115200 FFD8H - FFD8H - F6H - FBH -
57600 FFB0H - FFB0H - ECH - F6H -
18.432 38400 FF88H FFF6H FF88H FFF6H E2H - F1H -
19200 FF10H FFECH FF10H FFECH C4H FBH E2H -
9600 FE20H FFD8H FE20H FFD8H 88H F6H C4H FBH
115200 FFD0H FFFCH FFD0H FFFCH F4H FFH FAH -
57600 FFA0H FFF8H FFA0H FFF8H E8H FEH F4H FFH
22.1184 38400 FF70H FFF4H FF70H FFF4H DCH FDH EEH -
19200 FEE0H FFE8H FEE0H FFE8H B8H FAH DCH FDH
9600 FDC0H FFD0H FDC0H FFD0H 70H F4H B8H FAH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 398 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
frequency.
SMOD Baud rate calculation formula
Except that the source of the baud rate is slightly different, and the 9th bit of the shift register supplied by TB8
while being sent is different, the functional and structure of mode 2 and mode 1 are basically the same, the receiving /
sending operation and timing of mode 2 and mode 1are also basically the same.
After the receiver receives a frame of information, the following conditions must be met at the same time.
·RI=0
·SM2=0 or SM2=1 and the 9th bit received RB8=1.
Only when the two conditions above are met at the same time, the data received in shift register is loaded into
SBUF and RB8. The RI flag is set to 1, and the interrupt is requested to CPU. If one of the above conditions is not
met, the data received in the shift register is invalid and is discarded, and RI is not set. Regardless of the above
conditions are met or not, the receiver begins to detect the RxD pin hopping information again to receive the next
frame of information. In mode 2, the received stop bit is not related to SBUF, RB8 and RI.
It provides for the convenience of multi-machine communication by setting SM2, TB8 of SCON and
communication protocol using the software.
Write
SBUF
TI
Write
REN=1,RI=0
SCON
RI
structure of mode 3 and mode 1 are basically the same, the receiving / sending operation and timing of mode 3 and
mode 1 are also basically the same.
After the receiver receives a frame of information, the following conditions must be met at the same time.
·RI=0
·SM2=0 or SM2=1 and the 9th bit received RB8=1.
Only when the two conditions above are met at the same time, the data received in shift register is loaded into
SBUF and RB8. The RI flag is set to 1, and the interrupt is requested to CPU. If one of the above conditions is not
met, the data received in the shift register is invalid and is discarded, and RI is not set. Regardless of the above
conditions are met or not, the receiver begins to detect the RxD pin hopping information again to receive the next
frame of information. In mode 3, the received stop bit is not related to SBUF, RB8 and RI.
It provides for the convenience of multi-machine communication by setting SM2, TB8 of SCON and
communication protocol using the software.
Write
SBUF
TI
Write
REN=1,RI=0
SCON
RI
The baud rate calculation formula of UART1 mode 3 is exactly the same as that of mode 1. Please refer to
the mode 1 baud rate calculation formula.
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. The address of the slave is set by the registers SADDR and
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 400 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SADEN. The hardware filters the slave address automatically. The hardware will generate a serial port interrupt
when the slave address information from the master matches the slave address set by the slave. Otherwise, the
hardware will discard the serial port data automatically without any interruption. When a number of slaves in
Idle mode are connected together, only the slave that matches the slave address will wake up from Idle mode.
Then the power consumption of the slave MCU reduces greatly. Constantly entering the serial port interrupt
which reduces the system execution efficiency can be avoided even if the slave is in normal operation.
To use the automatic address recognition feature of the serial port, mode 2 or mode 3 of the serial port of
the MCU that participates in communication is selected. Usually, the mode 3 with variable baud rate is selected
because the baud rate of mode 2 is fixed, and it is inconvenient to adjust. SM2 bit of slave in SCON is set to 1.
The 9th bit which is stored in RB8 is the address/data flag in mode 2 or 3. When the 9th bit is 1, it indicates the
previous 8-bit datum stored in SBUF is the address information. If SM2 is set to 1, the slave MCU will filter out
non-address data whose 9th bit is 0 automatically while the address data whose 9th bit is 1 in SBUF will
automatically be matched with the address set in SADDR and SADEN. If the address matches, RI will be set to
"1" and an interrupt will occur. Otherwise, the received data is discarded.
The slave address is set by two registers, SADDR and SADEN. SADDR is the slave address register,
where the slave address is stored. SADEN is the slave address mask register, which is used to set the ignore bit
in the address information. The setting method is as follows.
For example
SADDR = 11001010
SADEN = 10000001
Then the matched address is 1xxxxxx0
That is, as long as bit 0 is 0 and bit 7 is 1 in the address data sent by the master, the address can be matched
with the local address.
Another example
SADDR = 11001010
SADEN = 00001111
Then the matched address is xxxx1010
That is, as long as the low 4 bits are 1010 in the address data sent by the master, the address can be
matched with the local address. The high 4 bits can be any value and are ignored.
The Broadcast Address (FFH) can be used by the master to select all the slaves simultaneously for
communication.
13.3 UART2
13.3.1 UART2 control register (S2CON)
Symbol Address B7 B6 B5 B4 B3 B2 B1 B0
S2CON 9AH S2SM0 - S2SM2 S2REN S2TB8 S2RB8 S2TI S2RI
S2SM0: Serial port 2 mode select bit.
S2SM0 UART2 mode Function description
0 Mode 0 8-bit UART, whose baud-rate is variable
1 Mode 1 9-bit UART, whose baud-rate is variable
S2SM2: UART2 multi-machine communication control enable bit. In mode 1, if the S2SM2 bit is 1 and the
S2REN bit is 1, the receiver is in the address frame filter state. In this case, the received 9th bit (S2RB8)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 401 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
can be used to filter the address frame. If S2RB8 = 1, the frame is the address frame, address information
can enter S2BUF, S2RI becomes 1, and then address can be compared in the interrupt service routine. If
S2RB8 = 0, it indicates that the frame is not an address frame and should be discarded and keep S2RI =
0. In mode 1, if the S2SM2 bit is 0 and the S2REN bit is 1, the receiver is in the address frame filter
disabled state. Regardless of the received S2RB8 is 0 or 1, the information received can enter into the
S2BUF, and make S2RI = 1. Here, S2RB8 is usually used as check bit. Mode 0 is non-multi-machine
communication mode, where S2SM2 should be 0.
S2REN: Receive enable control bit.
0: disable UART2 receive data.
1: enable UART2 receive data.
S2TB8: S2TB8 is the 9th bit of datum to be sent when UART2 is in mode 1, which is usually used as a parity
check bit or an address frame / data frame flag. It can be set or cleared by software as required. In mode
0, this bit is not used.
S2RB8: S2RB8 is the 9th bit of datum recieved when UART2 is in mode 1, which is usually used as a parity
check bit or an address frame / data frame flag. It can be set or cleared by software as required. In mode
0, this bit is not used.
S2TI: Transmit interrupt request flag of UART2. S2TI is set by the hardware automatically at the beginning of
the stop bit transmittion and requests interrupts to the CPU. S2TI must be cleared by software after the
interrupt is responded.
S2RI: Receive interrupt request flag of UART2. S2RI is set by hardware automatically at the middle of stop bit
received, and requests the interrupt to the CPU. After the interrupt is responded, S2RI must be cleared by
software.
Write
S2BUF
S2TI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 402 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Write
S2REN=1, S2RI=0
S2CON
S2RI
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.
The baud rate of UART2 mode 0 is calculated as follows, where SYSclk is the system operating frequency.
Timer selected Speed of timer Baud rate calculation formula
1T
T2
12T
Write
S2BUF
S2TI
Write
S2REN=1,S2RI=0
S2CON
S2RI
The baud rate calculation formula of UART2 mode 1 is exactly the same as that of mode 0. Please refer to
the mode 0 baud rate calculation formula.
13.4 UART3
13.4.1 UART3 control register (S3CON)
Symbol Address B7 B6 B5 B4 B3 B2 B1 B0
S3CON ACH S3SM0 S3ST3 S3SM2 S3REN S3TB8 S3RB8 S3TI S3RI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 403 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Write
S3BUF
S3TI
Write
S3REN=1, S3RI=0
S3CON
S3RI
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.
The baud rate of UART3 mode 0 is calculated as follows, where SYSclk is the system operating frequency.
1T
T3
12T
Write
S3BUF
S3TI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 405 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Write
S3REN=1,S3RI=0
S3CON
S3RI
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.
13.5 UART4
13.5.1 UART4 control register (S4CON)
Symbol Address B7 B6 B5 B4 B3 B2 B1 B0
S4CON 84H S4SM0 S4ST4 S4SM2 S4REN S4TB8 S4RB8 S4TI S4RI
S4SM0: UART4 mode select bit.
S4SM0 UART4 mode Function description
0 Mode 0 8-bit UART, whose baud-rate is variable
1 Mode 1 9-bit UART, whose baud-rate is variable
S4ST4: UART4 baud rate generator select bit.
0: Select T2 as the baud-rate generator of UART4.
1: Select T4 as the baud-rate generator of UART4.
S4SM2: UART4 multi-machine communication control bit. In mode 1, if the S4SM2 bit is 1 and the S4REN bit
is 1, the receiver is in the address frame filter state. In this case, the received 9 th bit (S4RB8) can be used
to filter the address frame. If S4RB8 = 1, the frame is the address frame, address information can enter
S4BUF, S4RI becomes 1, and then address can be compared with the slave address in the interrupt
service routine. If S4RB8 = 0, it indicates that the frame is not an address frame and should be discarded
and keep S4RI = 0. In mode 1, if the S4SM2 bit is 0 and the S4REN bit is 1, the receiver is in the
address frame filter disabled state. Regardless of the received S4RB8 is 0 or 1, the information received
can enter into the S4BUF, and make S4RI = 1. Here, S4RB8 is usually used as parity check bit. Mode 0
is non-multi-machine communication mode, where S4SM2 should be 0.
S4REN: Receive enable control bit.
0: disable UART4 receive data.
1: enable UART4 receive data.
S4TB8: S4TB8 is the 9th bit of datum to be sent when UART4 is in mode 1, which is usually used as a parity
check bit or an address frame / data frame flag. It can be set or cleared by software as required. In mode
0, this bit is not used.
S4RB8: S4RB8 is the 9th bit of datum recieved when UART4 is in mode 1, which is usually used as a parity
check bit or an address frame / data frame flag. It can be set or cleared by software as required. In mode
0, this bit is not used.
S4TI: Transmit interrupt request flag of UART4. S4TI is set by the hardware automatically at the beginning of
the stop bit transmittion and requests interrupt to the CPU. S4TI must be cleared by software after the
interrupt is responded.
S4RI: Receive interrupt request flag of UART4. S4RI is set by hardware automatically at the middle of stop bit
the serial port received, and requests interrupt to the CPU. After the interrupt is responded, S4RI must be
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 406 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
cleared by software.
Write
S4BUF
S4TI
Write
S4REN=1, S4RI=0
S4CON
S4RI
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.
The baud rate of UART4 mode 0 is calculated as follows, where SYSclk is the system operating frequency.
Timer selected Speed of timer Baud rate calculation formula
1T
T2
12T
1T
T4
12T
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 407 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
11 bits: 1 start bit, 8 data bits (LSB first), 1 programmable bit (9th bit) and 1 stop bit. The baud rate is variable,
which can be set by the software as needed. TxD4 is the data transmitting pin, and RxD4 is the data receiving
pin, the serial port is a full duplex receiver/transmitter.
Write
S4BUF
S4TI
Write
S4REN=1,S4RI=0
S4CON
S4RI
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.
In 8-bit data mode, TI interrupt request is generated after the entire stop bit is transmitted, as shown in the
following figure:
Write
SBUF
TI
In 8-bit data mode, RI interrupt request is generated after half of the stop bit is received, as shown in the
following figure:
Write
REN=1, RI=0
SCON
RI
Receiving data (8-bit data)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 408 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In 9-bit data mode, TI interrupt request is generated after the entire 9th data bit is transmitted, as shown in
the following figure:
Write
SBUF
TI
Transmission data (9-bit data)
In 9-bit data mode, RI interrupt request is generated after receiving half of the 9th bit, as shown in the
following figure:
Write
REN=1,RI=0
SCON
RI
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 409 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
bit busy;
char wptr;
char rptr;
char buffer[16];
void UartInit()
{
SCON = 0x50;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x15;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 410 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
ES = 1;
EA = 1;
UartSENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
UartSEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
JNB TI,CHKRI
CLR TI
CLR BUSY
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 411 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,SBUF
INC WPTR
UARTISR_EXIT:
POP PSW
POP ACC
RETI
UART_INIT:
MOV SCON,#50H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#15H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
UART_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SENDEND
LCALL UART_SEND
INC DPTR
JMP UART_SENDSTR
SENDEND:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 412 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV DPTR,#STRING
LCALL UART_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
{
TI = 0;
busy = 0;
}
if (RI)
{
RI = 0;
buffer[wptr++] = SBUF;
wptr &= 0x0f;
}
}
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
ES = 1;
EA = 1;
UartSENDStr(“Uart Test !\r\n”);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 414 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
if (rptr != wptr)
{
UartSEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,SBUF
INC WPTR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 415 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
UARTISR_EXIT:
POP PSW
POP ACC
RETI
UART_INIT:
MOV SCON,#50H
MOV TMOD,#00H
MOV TL1,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV TH1,#0FFH
SETB TR1
MOV AUXR,#40H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
UART_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SENDEND
LCALL UART_SEND
INC DPTR
JMP UART_SENDSTR
SENDEND:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#STRING
LCALL UART_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 416 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
buffer[wptr++] = SBUF;
wptr &= 0x0f;
}
}
void UartInit()
{
SCON = 0x50;
TMOD = 0x20;
TL1 = BRT;
TH1 = BRT;
TR1 = 1;
AUXR = 0x40;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
ES = 1;
EA = 1;
UartSENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
UartSEND(buffer[rptr++]);
rptr &= 0x0f;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 418 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP UART_ISR
ORG 0100H
UART_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
JNB TI,CHKRI
CLR TI
CLR BUSY
CHKRI:
JNB RI,UARTISR_EXIT
CLR RI
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,SBUF
INC WPTR
UARTISR_EXIT:
POP PSW
POP ACC
RETI
UART_INIT:
MOV SCON,#50H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 419 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV TMOD,#20H
MOV TL1,#0FDH ;256-11059200/115200/32=0FDH
MOV TH1,#0FDH
SETB TR1
MOV AUXR,#40H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART_SEND:
JB BUSY,$
SETB BUSY
MOV SBUF,A
RET
UART_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SENDEND
LCALL UART_SEND
INC DPTR
JMP UART_SENDSTR
SENDEND:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
SETB ES
SETB EA
MOV DPTR,#STRING
LCALL UART_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART_SEND
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 420 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
}
}
void Uart2Init()
{
S2CON = 0x10;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart2Init();
IE2 = 0x01;
EA = 1;
Uart2SENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
Uart2SEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 422 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0043H
LJMP UART2_ISR
ORG 0100H
UART2_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S2CON
JNB ACC.1,CHKRI
ANL S2CON,#NOT 02H
CLR BUSY
CHKRI:
JNB ACC.0,UART2ISR_EXIT
ANL S2CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S2BUF
INC WPTR
UART2ISR_EXIT:
POP PSW
POP ACC
RETI
UART2_INIT:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 423 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV S2CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART2_SEND:
JB BUSY,$
SETB BUSY
MOV S2BUF,A
RET
UART2_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND2END
LCALL UART2_SEND
INC DPTR
JMP UART2_SENDSTR
SEND2END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART2_INIT
MOV IE2,#01H
SETB EA
MOV DPTR,#STRING
LCALL UART2_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART2_SEND
INC RPTR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 424 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
void Uart3Init()
{
S3CON = 0x10;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart3Init();
IE2 = 0x08;
EA = 1;
Uart3SENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
Uart3SEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 426 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 008BH
LJMP UART3_ISR
ORG 0100H
UART3_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S3CON
JNB ACC.1,CHKRI
ANL S3CON,#NOT 02H
CLR BUSY
CHKRI:
JNB ACC.0,UART3ISR_EXIT
ANL S3CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S3BUF
INC WPTR
UART3ISR_EXIT:
POP PSW
POP ACC
RETI
UART3_INIT:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 427 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV S3CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART3_SEND:
JB BUSY,$
SETB BUSY
MOV S3BUF,A
RET
UART3_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND3END
LCALL UART3_SEND
INC DPTR
JMP UART3_SENDSTR
SEND3END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART3_INIT
MOV IE2,#08H
SETB EA
MOV DPTR,#STRING
LCALL UART3_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART3_SEND
INC RPTR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 428 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
void Uart3Init()
{
S3CON = 0x50;
T3L = BRT;
T3H = BRT >> 8;
T4T3M = 0x0a;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart3Init();
IE2 = 0x08;
EA = 1;
Uart3SENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
{
Uart3SEND(buffer[rptr++]);
rptr &= 0x0f;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 430 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 008BH
LJMP UART3_ISR
ORG 0100H
UART3_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S3CON
JNB ACC.1,CHKRI
ANL S3CON,#NOT 02H
CLR BUSY
CHKRI:
JNB ACC.0,UART3ISR_EXIT
ANL S3CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 431 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV @R0,S3BUF
INC WPTR
UART3ISR_EXIT:
POP PSW
POP ACC
RETI
UART3_INIT:
MOV S3CON,#50H
MOV T3L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T3H,#0FFH
MOV T4T3M,#0AH
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART3_SEND:
JB BUSY,$
SETB BUSY
MOV S3BUF,A
RET
UART3_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND3END
LCALL UART3_SEND
INC DPTR
JMP UART3_SENDSTR
SEND3END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART3_INIT
MOV IE2,#08H
SETB EA
MOV DPTR,#STRING
LCALL UART3_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 432 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART3_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
busy = 0;
}
if (S4CON & 0x01)
{
S4CON &= ~0x01;
buffer[wptr++] = S4BUF;
wptr &= 0x0f;
}
}
void Uart4Init()
{
S4CON = 0x10;
T2L = BRT;
T2H = BRT >> 8;
AUXR = 0x14;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart4Init();
IE2 = 0x10;
EA = 1;
Uart4SENDStr(“Uart Test !\r\n”);
while (1)
{
if (rptr != wptr)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 434 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
Uart4SEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0093H
LJMP UART4_ISR
ORG 0100H
UART4_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S4CON
JNB ACC.1,CHKRI
ANL S4CON,#NOT 02H
CLR BUSY
CHKRI:
JNB ACC.0,UART4ISR_EXIT
ANL S4CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 435 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV @R0,S4BUF
INC WPTR
UART4ISR_EXIT:
POP PSW
POP ACC
RETI
UART4_INIT:
MOV S4CON,#10H
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#14H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART4_SEND:
JB BUSY,$
SETB BUSY
MOV S4BUF,A
RET
UART4_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND4END
LCALL UART4_SEND
INC DPTR
JMP UART4_SENDSTR
SEND4END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART4_INIT
MOV IE2,#10H
SETB EA
MOV DPTR,#STRING
LCALL UART4_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 436 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART4_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
char wptr;
char rptr;
char buffer[16];
{
if (S4CON & 0x02)
{
S4CON &= ~0x02;
busy = 0;
}
if (S4CON & 0x01)
{
S4CON &= ~0x01;
buffer[wptr++] = S4BUF;
wptr &= 0x0f;
}
}
void Uart4Init()
{
S4CON = 0x50;
T4L = BRT;
T4H = BRT >> 8;
T4T3M = 0xa0;
wptr = 0x00;
rptr = 0x00;
busy = 0;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Uart4Init();
IE2 = 0x10;
EA = 1;
Uart4SENDStr(“Uart Test !\r\n”);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 438 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
if (rptr != wptr)
{
Uart4SEND(buffer[rptr++]);
rptr &= 0x0f;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0093H
LJMP UART4_ISR
ORG 0100H
UART4_ISR:
PUSH ACC
PUSH PSW
MOV PSW,#08H
MOV A,S4CON
JNB ACC.1,CHKRI
ANL S4CON,#NOT 02H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 439 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CLR BUSY
CHKRI:
JNB ACC.0,UART4ISR_EXIT
ANL S4CON,#NOT 01H
MOV A,WPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV @R0,S4BUF
INC WPTR
UART4ISR_EXIT:
POP PSW
POP ACC
RETI
UART4_INIT:
MOV S4CON,#50H
MOV T4L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T4H,#0FFH
MOV T4T3M,#0A0H
CLR BUSY
MOV WPTR,#00H
MOV RPTR,#00H
RET
UART4_SEND:
JB BUSY,$
SETB BUSY
MOV S4BUF,A
RET
UART4_SENDSTR:
CLR A
MOVC A,@A+DPTR
JZ SEND4END
LCALL UART4_SEND
INC DPTR
JMP UART4_SENDSTR
SEND4END:
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART4_INIT
MOV IE2,#10H
SETB EA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 440 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV DPTR,#STRING
LCALL UART4_SENDSTR
LOOP:
MOV A,RPTR
XRL A,WPTR
ANL A,#0FH
JZ LOOP
MOV A,RPTR
ANL A,#0FH
ADD A,#BUFFER
MOV R0,A
MOV A,@R0
LCALL UART4_SEND
INC RPTR
JMP LOOP
END
C language code
//Operating frequency for test is 22.1184MHz
#include "reg51.h"
#include "intrins.h"
sfr P4 = 0xC0;
sfr P5 = 0xC8;
sfr P6 = 0xE8;
sfr P7 = 0xF8;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xB1;
sfr P3M0 = 0xB2;
sfr P4M1 = 0xB3;
sfr P4M0 = 0xB4;
sfr P5M1 = 0xC9;
sfr P5M0 = 0xCA;
sfr P6M1 = 0xCB;
sfr P6M0 = 0xCC;
sfr P7M1 = 0xE1;
sfr P7M0 = 0xE2;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 442 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#define Baudrate_Break (65536UL - (MAIN_Fosc / 4) / 6647UL) // Baud rate for sending dominant interval
signal
#define UART1_BUF_LENGTH 32
#define UART2_BUF_LENGTH 32
//========================================================================
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 443 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
UART1_config(1);
UART2_config(2);
EA = 1; //Enable global interrupt
SLP_N = 1;
while (1)
{
delay_ms(1);
if(RX1_TimeOut > 0)
{
if(--RX1_TimeOut == 0) //UART ends receiving if it is time out
{
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) // UART ends receiving if it is time out
{
if(RX2_Cnt > 0)
{
for (i=0; I < RX2_Cnt; i++) // End with stop character 0
{
UART1_TxByte(RX2_Buffer[i]); // The data received from the LIN bus is sent to UART1
}
}
RX2_Cnt = 0;
}
}
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 444 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
//========================================================================
// Function: void delay_ms(unsigned char ms)
// Description: delay function
// Parameters: ms, number of msto delay, 1~255ms. Automatically adapt to the master clock.
// Return: none.
// Version: VER1.0
// Date: 2013-4-1
// Note:
//========================================================================
void delay_ms(u8 ms)
{
u16 i;
do{
i = MAIN_Fosc / 13000;
while(--i); //14T per loop
}while(--ms);
}
//========================================================================
// Function: u8 Lin_CheckPID(u8 id)
// Description: ID code plus check code, converted into PID code
// Parameters: ID code
// Return: PID code
// Version: VER1.0
// Date: 2020-12-2
// Note:
//========================================================================
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 check code
// Parameters: data transmitted in data field
// Return: check code.
// Version: VER1.0
// Date: 2020-12-2
// Note:
//========================================================================
static u8 LINCalcChecksum(u8 *dat)
{
u16 sum = 0;
u8 i;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 445 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
//========================================================================
// Function: void Lin_SendBreak(void)
// Description: Send a dominant interval signal
// Parameters: none.
// Return: none.
// Version: VER1.0
// Date: 2020-12-2
// Note:
//========================================================================
void Lin_SendBreak(void)
{
SetTimer2Baudraye(Baudrate_Break);
UART2_TxByte(0);
SetTimer2Baudraye(Baudrate2);
}
//========================================================================
// Function: void Lin_Send(u8 *puts)
// Description: Send LIN bus message
// Parameters: The content of the data field to be sent
// Return: none.
// Version: VER1.0
// Date: 2020-12-2
// Note:
//========================================================================
void Lin_Send(u8 *puts)
{
u8 i;
Lin_SendBreak(); //Break
UART2_TxByte(0x55); //SYNC
UART2_TxByte(Lin_CheckPID(LIN_ID)); //LIN ID
for(i=0;i<8;i++)
{
UART2_TxByte(puts[i]);
}
UART2_TxByte(LINCalcChecksum(puts));
}
//========================================================================
// Function: void UART1_TxByte(u8 dat)
// Description: Send a byte
// Parameters: none
// Return: none
// Version: V1.0, 2014-6-30
//========================================================================
void UART1_TxByte(u8 dat)
{
SBUF = dat;
B_TX1_Busy = 1;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 446 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while(B_TX1_Busy);
}
//========================================================================
// Function: void UART2_TxByte(u8 dat)
// Description: Send a byte
// Parameters: none
// Return: none
// Version: V1.0, 2014-6-30
//========================================================================
void UART2_TxByte(u8 dat)
{
S2BUF = dat;
B_TX2_Busy = 1;
while(B_TX2_Busy);
}
//========================================================================
// Function: void PrintString1(u8 *puts)
// Description: Send string using UART1
// Parameters: puts: pointer of string
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
void PrintString1(u8 *puts)
{
for (; *puts != 0; puts++) // End with stop character 0
{
SBUF = *puts;
B_TX1_Busy = 1;
while(B_TX1_Busy);
}
}
//========================================================================
// Function: void PrintString1(u8 *puts)
// Description: Send string using UART2
// Parameters: puts: pointer of string
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
//void PrintString2(u8 *puts)
//{
// for (; *puts != 0; puts++) // End with stop character 0
// {
// S2BUF = *puts;
// B_TX2_Busy = 1;
// while(B_TX2_Busy);
// }
//}
//========================================================================
// Function: SetTimer2Baudraye(u16 dat)
// Description: Set Timer2 as a baud rate generator.
// Parameters: dat: Reload value of Timer2
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 447 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
void SetTimer2Baudraye(u16 dat)
{
AUXR &= ~(1<<4); //Timer stop
AUXR &= ~(1<<3); //Timer2 set As Timer
AUXR |= (1<<2); //Timer2 set as 1T mode
TH2 = dat / 256;
TL2 = dat % 256;
IE2 &= ~(1<<2); //Disable interrupt
AUXR |= (1<<4); //Timer run enable
}
//========================================================================
// Function: void UART1_config(u8 brt)
// Description: UART1 initial function
// Parameters: brt: Select baud rate, 2: Use Timer2 as baud rate generator, Other values: Use Timer1 as the baud rate generator.
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
void UART1_config(u8 brt)
{
/*********** Use Timer2 as baud rate generator *****************/
if(brt == 2)
{
AUXR |= 0x01; //S1 BRT Use Timer2;
SetTimer2Baudraye(Baudrate1);
}
SCON = (SCON & 0x3f) | 0x40; //UART1 mode: 0x00: Synchronous shift output,
// 0x40: 8 bits data, Variable baud rate,
// 0x80: 9 bits data, Fixed baud rate,
// 0xc0: 9 bits data, Variable baud rate
// PS = 1; // High priority interrupt
ES = 1; //Enable interrupt
REN = 1; //Enable recieving
P_SW1 &= 0x3f;
// P_SW1 |= 0x80; //UART1switch to: 0x00: P3.0 P3.1,
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 448 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
B_TX1_Busy = 0;
TX1_Cnt = 0;
RX1_Cnt = 0;
}
//========================================================================
// Function: void UART2_config(u8 brt)
// Description: UART2 initial function
// Parameters: brt: Select baud rate, 2: Use Timer2 as baud rate generator, Other values: invalid
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
void UART2_config(u8 brt)
{
if(brt == 2)
{
SetTimer2Baudraye(Baudrate2);
S2CON &= ~(1<<7); //8 bits data, 1 start bit, 1 stop bit, no check bit
IE2 |= 1; //Enable interrupt
S2CON |= (1<<4); //Enable recieving
P_SW2 &= ~0x01;
// P_SW2 |= 1; //UART2 switch to: 0: P1.0/P1.1, 1: P4.6/P4.7
B_TX2_Busy = 0;
TX2_Cnt = 0;
RX2_Cnt = 0;
}
}
//========================================================================
// Function: void UART1_int (void) interrupt UART1_VECTOR
// Description: UART1 interrupt function
// Parameters: none.
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
void UART1_int (void) interrupt 4
{
if(RI)
{
RI = 0;
if(RX1_Cnt >= UART1_BUF_LENGTH) RX1_Cnt = 0;
RX1_Buffer[RX1_Cnt] = SBUF;
RX1_Cnt++;
RX1_TimeOut = 5;
}
if(TI)
{
TI = 0;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 449 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
B_TX1_Busy = 0;
}
}
//========================================================================
// Function: void UART2_int (void) interrupt UART2_VECTOR
// Description: UART2 interrupt function
// Parameters: none.
// Return: none.
// Version: VER1.0
// Date: 2014-11-28
// Note:
//========================================================================
void UART2_int (void) interrupt 8
{
if((S2CON & 1) != 0)
{
S2CON &= ~1; //Clear Rx flag
if(RX2_Cnt >= UART2_BUF_LENGTH) RX2_Cnt = 0;
RX2_Buffer[RX2_Cnt] = S2BUF;
RX2_Cnt++;
RX2_TimeOut = 5;
}
if((S2CON & 2) != 0)
{
S2CON &= ~2; //Clear Tx flag
B_TX2_Busy = 0;
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 450 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8G1K08 family ●
STC8G1K08-8Pin family
STC8G1K08A family
STC8G2K64S4 family ●
STC8G2K64S2 family ●
STC8G1K08T family ●
STC15H2K64S4 family ●
A comparator is integrated in STC8G series of microcontrollers. The positive terminal of the comparator
can be P3.7 or ADC analog input and the negative can be P3.6 or the REFV voltage of the internal BandGap
after amplified. The application of multiple comparators can be realized through multiplexer and time division
multiplexing.
There are two stages programmable filterings inside the comparator: analog filtering and digital filtering.
Analog filtering can filter out glitches in the input signal, and digital filtering can wait for the input signal to
stabilize before making a comparison. The result of the comparison can be obtained directly by reading the
internal register bits or output the result of the comparator forward or reverse to the external port. Outputting the
comparison result to the external port can be used as the trigger signal of external events and the feedback signal
to expand the scope of application.
NIE
ADCIN includes ADC0, ADC1, ADC2, ADC3, ADC4, ADC5, ADC6, ADC7, ADC8, ADC9, ADC10,
ADC11, ADC12, ADC13, ADC14 and ADC15.
Note: When the positive pole of the comparator selects the ADC input channel, make sure to turn on the
ADC power control bit ADC_POWER and ADC channel selection bit ADC_CHS in the ADC_CONTR register.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 451 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Comparator
output
CMPRES
The number of
CPU clocks in
LCDTY[5:0]
Comparator
output
CMPRES
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 453 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 454 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P5M1 = 0x00;
CMPCR2 = 0x00;
CMPCR2 &= ~0x80; //Comparator forward output
// CMPCR2 |= 0x80; //Comparator inverted output
CMPCR2 &= ~0x40; //Disable 0.1us filtering
// CMPCR2 |= 0x40; //Enable 0.1us filtering
// CMPCR2 &= ~0x3f; //Output comparator result directly
CMPCR2 |= 0x10; //Output comparator result after 16 debounce clocks
CMPCR1 = 0x00;
CMPCR1 |= 0x30; //Enable edge interrupt of comparator
// CMPCR1 &= ~0x20; //Disable comparator rising edge interrupt
// CMPCR1 |= 0x20; //Enable comparator rising edge interrupt
// CMPCR1 &= ~0x10; //Disable comparator falling edge interrupt
// CMPCR1 |= 0x10; //Enable comparator falling edge interrupt
CMPCR1 &= ~0x08; //P3.7 is CMP+ input pin
// CMPCR1 |= 0x08; //ADC input pin is CMP+ input pin
// CMPCR1 &= ~0x04; //Internal reference voltage is CMP- input pin
CMPCR1 |= 0x04; //P3.6 is CMP- input pin
// CMPCR1 &= ~0x02; //Disable comparator output
CMPCR1 |= 0x02; //Enable Comparator output
CMPCR1 |= 0x80; //Enable comparator module
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00ABH
LJMP CMPISR
ORG 0100H
CMPISR:
PUSH ACC
ANL CMPCR1,#NOT 40H ;Clear interrupt flag
MOV A,CMPCR1
JB ACC.0,RSING
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 455 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
FALLING:
CPL P1.0 ;Falling edge interrupt test port
POP ACC
RETI
RSING:
CPL P1.1 ;Rising edge interrupt test port
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CMPCR2,#00H
ANL CMPCR2,#NOT 80H ;Comparator forward output
; ORL CMPCR2,#80H ;Comparator inverted output
ANL CMPCR2,#NOT 40H ;Disable 0.1us filtering
; ORL CMPCR2,#40H ;Enable 0.1us filtering
; ANL CMPCR2,#NOT 3FH ;Output comparator result directly
ORL CMPCR2,#10H ;Output comparator result after 16 debounce clocks
MOV CMPCR1,#00H
ORL CMPCR1,#30H ;Enable edge interrupt of comparator
; ANL CMPCR1,#NOT 20H ;Disable comparator rising edge interrupt
; ORL CMPCR1,#20H ;Enable comparator rising edge interrupt
; ANL CMPCR1,#NOT 10H ;Disable comparator falling edge interrupt
; ORL CMPCR1,#10H ;Enable comparator falling edge interrupt
ANL CMPCR1,#NOT 08H ;P3.7 is CMP+ input pin
; ORL CMPCR1,#08H ;ADC input pin is CMP+ input pin
; ANL CMPCR1,#NOT 04H ;Internal reference voltage is CMP- input pin
ORL CMPCR1,#04H ;P3.6 is CMP- input pin
; ANL CMPCR1,#NOT 02H ;Disable comparator output
ORL CMPCR1,#02H ;Enable Comparator output
ORL CMPCR1,#80H ;Enable comparator module
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 456 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CMPCR2 = 0x00;
CMPCR2 &= ~0x80; //Comparator forward output
// CMPCR2 |= 0x80; //Comparator inverted output
CMPCR2 &= ~0x40; //Disable 0.1us filtering
// CMPCR2 |= 0x40; //Enable 0.1us filtering
// CMPCR2 &= ~0x3f; //Output comparator result directly
CMPCR2 |= 0x10; //Output comparator result after 16 debounce clocks
CMPCR1 = 0x00;
CMPCR1 |= 0x30; //Enable edge interrupt of comparator
// CMPCR1 &= ~0x20; //Disable comparator rising edge interrupt
// CMPCR1 |= 0x20; //Enable comparator rising edge interrupt
// CMPCR1 &= ~0x10; //Disable comparator falling edge interrupt
// CMPCR1 |= 0x10; //Enable comparator falling edge interrupt
CMPCR1 &= ~0x08; //P3.7 is CMP+ input pin
// CMPCR1 |= 0x08; //ADC input pin is CMP+ input pin
// CMPCR1 &= ~0x04; //Internal reference voltage is CMP- input pin
CMPCR1 |= 0x04; //P3.6 is CMP- input pin
// CMPCR1 &= ~0x02; //Disable comparator output
CMPCR1 |= 0x02; //Enable Comparator output
CMPCR1 |= 0x80; //Enable comparator module
while (1)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 457 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
P10 = CMPCR1 & 0x01; //Read comparator comparison result
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CMPCR2,#00H
ANL CMPCR2,#NOT 80H ;Comparator forward output
; ORL CMPCR2,#80H ;Comparator inverted output
ANL CMPCR2,#NOT 40H ;Disable 0.1us filtering
; ORL CMPCR2,#40H ;Enable 0.1us filtering
; ANL CMPCR2,#NOT 3FH ;Output comparator result directly
ORL CMPCR2,#10H ;Output comparator result after 16 debounce clocks
MOV CMPCR1,#00H
ORL CMPCR1,#30H ;Enable edge interrupt of comparator
; ANL CMPCR1,#NOT 20H ;Disable comparator rising edge interrupt
; ORL CMPCR1,#20H ;Enable comparator rising edge interrupt
; ANL CMPCR1,#NOT 10H ;Disable comparator falling edge interrupt
; ORL CMPCR1,#10H ;Enable comparator falling edge interrupt
ANL CMPCR1,#NOT 08H ;P3.7 is CMP+ input pin
; ORL CMPCR1,#08H ;ADC input pin is CMP+ input pin
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 458 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LOOP:
MOV A,CMPCR1
MOV C,ACC.0
MOV P1.0,C ;Read comparator comparison result
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 459 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CMPCR2 = 0x00;
CMPCR1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 460 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV CMPCR2,#00H
MOV CMPCR1,#00H
LOOP:
JMP LOOP
END
R1
100K
1 20
P1.2 P1.1 or greater
2 19
P1.3 P1.0
3 18
P1.4 CMP+ / P3.7
4 17
P1.5 CMP- / P3.6
5 16
P1.6 P3.5
6 15 R2
P1.7 P3.4
7 14 ?
P5.4 P3.3
Vcc 8 13
7805 Vcc P3.2
9 12
P5.5 P3.1
10 11
Vin 470u 104 Gnd P3.0
STC8G1K08
In the figure above, the resistor R1 and R2 divide the front-end voltage of the voltage regulator 7805. The
divided voltage is used as the external input of the comparator CMP+ to compare with the internal reference
voltage.
When the AC power is at 220V, the DC voltage at the front end of the voltage regulator block 7805 is 11V,
and when the AC voltage drops to 160V, the DC voltage at the front end of the voltage regulator 7805 is 8.5V.
When the dc voltage at the front end of the voltage regulator 7805 is lower than or equal to 8.5V, the dc voltage
at the front end is divided by the resistors R1 and R2, and added to the comparator positive input terminal
CMP+. The input voltage at the CMP+ terminal is lower than the internal reference voltage. A comparator
interrupt can be generated at this time, so that there is sufficient time to save the data to the EEPROM during
power-down detection. When the DC voltage of the front end of the voltage regulator 7805 is higher than 8.5V,
the DC voltage input by the front end is divided by the resistors R1 and R2, and connected to the comparator
positive input terminal CMP+. The input voltage of the CMP+ terminal is higher than the internal reference
voltage. At this time, the CPU Can continue to work normally.
The internal reference voltage is the REPV of the internal BandGap after the amplified (the internal
reference voltage is adjusted to 1.19V when the chip is shipped from the factory). The specific value should be
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 461 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
obtained by reading the value occupied by the internal reference voltage in the internal RAM area or the Flash
program memory (ROM) area. For STC8 series, the storage address of the internal reference voltage value in
RAM and Flash program memory (ROM), please refer to "Chapter 7.3 Special Parameters in Memory".
R0
100K
STC8G1K08
In the figure above, the working voltage of the MCU can be approximately measured using the principle of
resistance voltage division. The I/O port of selected channel outputs low level, which is close to GND, and the
I/O port of unselected channel working in open-drain mode outputs high. Other channels are not affected.
The negative terminal of the comparator selects the internal reference voltage, and the positive terminal
selects the voltage value got from the voltage divided by a resistor as the input to the CMP+ pin.
In initialization, P1.5 ~ P1.0 ports are set to open-drain mode and output high. Firstly, P1.0 outputs a low
level. At this time, if the VCC voltage is lower than 2.5V, the comparison value of the comparator is 0.
Otherwise, if the VCC voltage is higher than 2.5V, the comparison value of the comparator is 1.
If you make sure that VCC is higher than 2.5V, then make the output of P1.0 high and the output of P1.1
low. At this time, if the VCC voltage is lower than 3.0V, the comparison value of the comparator is 0. Otherwise,
if the VCC voltage is higher than 3.0V, the comparison value of the comparator is 1.
If you make sure that VCC is higher than 3.0V, then make the output of P1.1 high and the output of P1.2
low. At this time, if the VCC voltage is lower than 3.5V, the comparison value of the comparator is 0. Otherwise,
if the VCC voltage is higher than 3.5V, the comparison value of the comparator is 1.
If you make sure that VCC is higher than 3.5V, then make the output of P1.2 high and the output of P1.3
low. At this time, if the VCC voltage is lower than 4.0V, the comparison value of the comparator is 0. Otherwise,
if the VCC voltage is higher than 4.0V, the comparison value of the comparator is 1.
If you make sure that VCC is higher than 4.0V, then make the output of P1.3 high and the output of P1.4
low. At this time, if the VCC voltage is lower than 4.5V, the comparison value of the comparator is 0. Otherwise,
if the VCC voltage is higher than 4.5V, the comparison value of the comparator is 1.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 462 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
If you make sure that VCC is higher than 4.5V, then make the output of P1.4 high and the output of P1.5
low. At this time, if the VCC voltage is lower than 5.0V, the comparison value of the comparator is 0. Otherwise,
if the VCC voltage is higher than 5.0V, the comparison value of the comparator is 1.
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void delay ()
{
char i;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
unsigned char v;
while (1)
{
v = 0x00; //Voltage <2.5V
P1 = 0xfe; //P1.0 outputs 0
delay();
if (!(CMPCR1 & 0x01)) goto ShowVol;
v = 0x01; //Voltage>2.5V
P1 = 0xfd; //P1.1 outputs 0
delay();
if (!(CMPCR1 & 0x01)) goto ShowVol;
v = 0x03; //Voltage>3.0V
P1 = 0xfb; //P1.2 outputs 0
delay();
if (!(CMPCR1 & 0x01)) goto ShowVol;
v = 0x07; //Voltage>3.5V
P1 = 0xf7; //P1.3 outputs 0
delay();
if (!(CMPCR1 & 0x01)) goto ShowVol;
v = 0x0f; //Voltage>4.0V
P1 = 0xef; //P1.4 outputs 0
delay();
if (!(CMPCR1 & 0x01)) goto ShowVol;
v = 0x1f; //Voltage>4.5V
P1 = 0xdf; //P1.5 outputs 0
delay();
if (!(CMPCR1 & 0x01)) goto ShowVol;
v = 0x3f; //Voltage>5.0V
ShowVol:
P1 = 0xff;
P0 = ~v;
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 464 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 465 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
DELAY:
MOV R0,#20
DJNZ R0,$
RET
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 466 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
15 IAP/EEPROM
Large capacity of internal EEPROM is integrated in STC8G 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. EEPROM can be divided into several sectors, each sector contains 512 bytes.
Note: The EEPROM write operation can only write 1 in the byte as 0. When the 0 in the byte needs to be
written as 1, the sector erase operation must be performed. The read/write operation of EEPROM is carried out
in units of 1 byte, while the erasing operation of EEPROM is carried out in units of 1 sector (512 bytes). During
the erasing operation, if there are data that need to be reserved in the target sector, these data must be read into
RAM for temporary storage in advance, and then the saved data and the data that need to be updated will be
written back to EEPROM/DATA-FLASH after erasing is completed.
When EEPROM is used, it is recommended that the data modified at the same time be stored in the same
sector, and data modified at different time be stored in different sectors, and not necessarily full. Data memory
is erased sector by sector.
EEPROM can be used to save some parameters which need to be modified in the application and need be
kept when power down takes place. In the user program, byte read / byte programming / sector erase can be
performed to the EEPROM. When the operating voltage is low, it is recommended not to carry out EEPROM
operation to avoid data loss.
Programming 1 byte: about 30~40us (the actual programming time is 6~7.5us, but the state
conversion time and the SETUP and HOLD time of various control signals need to be added)
The time required for EEPROM operation is automatically controlled by the hardware, and the user only
needs to set the IAP_TPS register correctly.
IAP_TPS = system operating frequency/1000000 (the decimal part is rounded to the nearest whole number)
For example, the operating frequency of the system is 12MHz, then IAP_TPS is set to 12.
Another example, the system operating frequency is 22.1184MHz, then IAP_TPS is set to 22.
Another example, the system operating frequency is 5.5296MHz, then IAP_TPS is set to 6.
Register
Note: For every EEPROM operation, 5AH should be written to IAP_TRIG firstly and then A5H to take
effect the corresponding command. After the trigger command has been written, the CPU is in IDLE state until
the corresponding IAP operation completes. And then the CPU will return to the normal state from the IDLE
and resume executing the CPU instructions.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 469 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
There are two ways to access the internal EEPROM of STC8G series microcontrollers: IAP mode and
MOVC mode. The IAP mode can perform reading, writing and erasing operations on the EEPROM. MOVC can
only perform reading operations on the EEPROM, cannot perform writing and erasing operations. Regardless of
whether IAP or MOVC is used to access the EEPROM, the correct target address must be set firstly. In IAP
mode, the target address is the same as the actual physical address of the EEPROM. Both of them are accessed
from address 0000H. However, when using MOVC instruction to read EEPROM data, the target address must
be the actual physical address of the EEPROM plus a program size offset. STC8G1K08 is used as an example to
describe the target address in detail as following.
0000h
ROM
1FFFh
0000h
0234h
EEPROM
0FFFh
STC8C1K08
The program space of STC8G1K08 is 8K bytes (0000h ~ 1FFFh), and the EEPROM space is 4K bytes
(0000h ~ 0FFFh). When you need to read, write, and erase the unit with EEPROM physical address 0234h, if
you use IAP to access, set the target address to 0234h, that is, IAP_ADDRH is set to 02h, IAP_ADDRL is set to
34h, and then the corresponding trigger command can be set and the 0234h can be operated correctly. However,
if the 0234h unit of the EEPROM is read by MOVC, the flash program memory (ROM) space must be added in
addition to 0234h. That is, the DPTR must be set to 2234h 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. For example, if the target address is set to 0234H, 0200H,
0300H or 03FFH when executing the erasing command, the final erasing operation is the same, and the 512
bytes of 0200H ~ 03FFH are erased.
The size and access address of the internal EEPROM are different for different models. The size and
address of EEPROM of each model are listed in the table below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 470 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Users can plan any EEPROM space in the entire FLASH space provided that the size does not exceed the
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 471 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
FLASH size according to their own needs. It should be noted that the EEPROM is always planned from the
back to the front.
For example, the size of FLASH in STC8G1K12 is 12K. If user wants to allocate 4K of it as EEPROM,
the physical address of EEPROM is the last 4K of 12K, and the physical address is 2000h ~ 2FFFh. Of course,
if the user uses IAP to access, the target address still starts from 0000h and ends at 0FFFh. When using MOVC
to read, the target address is in the range from 2000h to 2FFFh.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 472 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void IapIdle()
{
IAP_CONTR = 0; //Disable IAP function
IAP_CMD = 0; //Clear command register
IAP_TRIG = 0; //Clear trigger register
IAP_ADDRH = 0x80; //Set the address to a non-IAP area
IAP_ADDRL = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 473 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
return dat;
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
IapErase(0x0400);
P0 = IapRead(0x0400); //P0=0xff
IapProgram(0x0400, 0x12);
P1 = IapRead(0x0400); //P1=0x12
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 474 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
IAP_IDLE:
MOV IAP_CONTR,#0 ;Disable IAP function
MOV IAP_CMD,#0 ;Clear command register
MOV IAP_TRIG,#0 ;Clear trigger register
MOV IAP_ADDRH,#80H ;Set the address to a non-IAP area
MOV IAP_ADDRL,#0
RET
IAP_READ:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#1 ;Set IAP read command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
MOV IAP_TRIG,#0A5H ;Write trigger command (0xa5)
NOP
MOV A,IAP_DATA ;Read IAP data
LCALL IAP_IDLE ;Disable IAP function
RET
IAP_PROGRAM:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#2 ;Set IAP writing command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_DATA,A ;Write IAP data
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
MOV IAP_TRIG,#0A5H ;Write trigger command (0xa5)
NOP
LCALL IAP_IDLE ;Disable IAP function
RET
IAP_ERASE:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 475 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV DPTR,#0400H
LCALL IAP_ERASE
MOV DPTR,#0400H
LCALL IAP_READ
MOV P0,A ;P0=0FFH
MOV DPTR,#0400H
MOV A,#12H
LCALL IAP_PROGRAM
MOV DPTR,#0400H
LCALL IAP_READ
MOV P1,A ;P1=12H
SJMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 476 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void IapIdle()
{
IAP_CONTR = 0; //Disable IAP function
IAP_CMD = 0; //Clear command register
IAP_TRIG = 0; //Clear trigger register
IAP_ADDRH = 0x80; //Set the address to a non-IAP area
IAP_ADDRL = 0;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 477 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
IapErase(0x0400);
P0 = IapRead(0x0400); //P0=0xff
IapProgram(0x0400, 0x12);
P1 = IapRead(0x0400); //P1=0x12
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
IAP_IDLE:
MOV IAP_CONTR,#0 ;Disable IAP function
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 478 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
IAP_READ:
MOV A,#LOW IAP_OFFSET ;Using MOVC to read the EEPROM needs to add the
corresponding offset
ADD A,DPL
MOV DPL,A
MOV A,@HIGH IAP_OFFSET
ADDC A,DPH
MOV DPH,A
CLR A
MOVC A,@A+DPTR ;Read data using MOVC
RET
IAP_PROGRAM:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#2 ;Set IAP writing command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_DATA,A ;Write IAP data
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
MOV IAP_TRIG,#0A5H ;Write trigger command (0xa5)
NOP
LCALL IAP_IDLE ;Disable IAP function
RET
IAP_ERASE:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#3 ;Set IAP erasing command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
MOV IAP_TRIG,#0A5H ;Write trigger command (0xa5)
NOP
LCALL IAP_IDLE ;Disable IAP function
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV DPTR,#0400H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 479 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LCALL IAP_ERASE
MOV DPTR,#0400H
LCALL IAP_READ
MOV P0,A ;P0=0FFH
MOV DPTR,#0400H
MOV A,#12H
LCALL IAP_PROGRAM
MOV DPTR,#0400H
LCALL IAP_READ
MOV P1,A ;P1=12H
SJMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void UartInit()
{
SCON = 0x5a;
T2L = BRT;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 480 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void IapIdle()
{
IAP_CONTR = 0; //Disable IAP function
IAP_CMD = 0; //Clear command register
IAP_TRIG = 0; //Clear trigger register
IAP_ADDRH = 0x80; //Set the address to a non-IAP area
IAP_ADDRL = 0;
}
return dat;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 481 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
UartInit();
IapErase(0x0400);
UartSEND(IapRead(0x0400));
IapProgram(0x0400, 0x12);
UartSEND(IapRead(0x0400));
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 482 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
UART_INIT:
MOV SCON,#5AH
MOV T2L,#0E8H ;65536-11059200/115200/4=0FFE8H
MOV T2H,#0FFH
MOV AUXR,#15H
RET
UART_SEND:
JNB TI,$
CLR TI
MOV SBUF,A
RET
IAP_IDLE:
MOV IAP_CONTR,#0 ;Disable IAP function
MOV IAP_CMD,#0 ;Clear command register
MOV IAP_TRIG,#0 ;Clear trigger register
MOV IAP_ADDRH,#80H ;Set the address to a non-IAP area
MOV IAP_ADDRL,#0
RET
IAP_READ:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#1 ;Set IAP read command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
MOV IAP_TRIG,#0A5H ;Write trigger command (0xa5)
NOP
MOV A,IAP_DATA ;Read IAP data
LCALL IAP_IDLE ;Disable IAP function
RET
IAP_PROGRAM:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#2 ;Set IAP writing command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_DATA,A ;Write IAP data
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
MOV IAP_TRIG,#0A5H ;Write trigger command (0xa5)
NOP
LCALL IAP_IDLE ;Disable IAP function
RET
IAP_ERASE:
MOV IAP_CONTR,#80H ;Enable IAP
MOV IAP_TPS,#12 ;Set the erasing wait parameter of 12MHz
MOV IAP_CMD,#3 ;Set IAP erasing command
MOV IAP_ADDRL,DPL ;Set IAP low address
MOV IAP_ADDRH,DPH ;Set IAP high address
MOV IAP_TRIG,#5AH ;Write trigger command (0x5a)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 483 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LCALL UART_INIT
MOV DPTR,#0400H
LCALL IAP_ERASE
MOV DPTR,#0400H
LCALL IAP_READ
LCALL UART_SEND
MOV DPTR,#0400H
MOV A,#12H
LCALL IAP_PROGRAM
MOV DPTR,#0400H
LCALL IAP_READ
LCALL UART_SEND
SJMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 484 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
A 10-bit high-speed Analog to Digital Converter is integrated in STC8G series 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. The range of ADC clock frequency is SYSclk/2/1 ~ SYSclk/2/16.
The maximum speed of the STC8G series ADC is 800K for 12-bit ADC (800,000 ADC conversions per
second), and 500K for 10-bit ADC (500,000 ADC conversions per second).
There are two data formats for ADC conversion results: Align left and align right. It is convenient for user
program to read and reference.
Note: The 15th channel of the ADC can only be used to detect the internal reference voltage. The reference
voltage value is calibrated to 1.19V at the factory. Due to the manufacturing errors and measurement errors, the
actual internal reference voltage has about ±1% error compared to 1.19V. If you want to know the exact internal
reference voltage of each chip, you can connect the accurate reference voltage and then use the 15th channel of
the ADC to measure the calibration.
If the chip has ADC external reference power supply pin ADC_VRef+, it must not be floating, it must be
connected to an external reference power supply or directly connected to VCC.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 485 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ADC's internal sampling and holding capacitor. The internal potential can be equal to the external potential
if the time is sufficient.
ADC_START: ADC start bit. ADC conversion will start after write 1 to this bit. It is cleared automatically by
the hardware after A/D conversion completes.
0: no effect. Writing 0 to this bit will not stop the A/D conversion if the ADC has already started.
1: start the A/D conversion. It is cleared automatically by the hardware after A/D conversion completes.
ADC_FLAG: ADC conversion completement flag. It is set by the hardware after the ADC conversion
hasfinished, and requests interrupt to CPU. It must be cleared by software.
ADC_EPWMT: enable PWM synchronous trigger ADC function.
ADC_CHS[3:0]: ADC anolog channel selection bits.
(Note: PxM0/PxM1 registers of the I/O port selected as the ADC input channel must be set to set the I/O port
mode to high-impedance input mode. In addition, if the MCU enters the power-down mode/clock stop
mode, the ADC channel is still needed to be enabled, and the PxIE register is needed to set to close the
digital input channel to prevent the external analog input signal from fluctuating high and low which will
cause additional power consumption.)
(Note: The channels in red font in the table below represent that different series may be on different ports, and
red just means highlighting.)
(STC8G1K08/STC8G1K08T family)
ADC_CHS[3:0] ADC channel ADC_CHS[3:0] ADC channel
0000 P1.0/ADC0 1000 P3.0/ADC8
0001 P1.1/ADC1 1001 P3.1/ADC9
0010 P1.2/ADC2 1010 P3.2/ADC10
0011 P1.3/ADC3 1011 P3.3/ADC11
0100 P1.4/ADC4 1100 P3.4/ADC12
0101 P1.5/ADC5 1101 P3.5/ADC13
0110 P1.6/ADC6 1110 P3.6/ADC14
0111 P1.7/ADC7 1111 Test internal 1.19V
(STC8G2K64S4/STC8G2K64S2/STC15H2K64S4 family)
ADC_CHS[3:0] ADC channel ADC_CHS[3:0] ADC channel
0000 P1.0/ADC0 1000 P0.0/ADC8
0001 P1.1/ADC1 1001 P0.1/ADC9
0010 P1.2/ADC2 1010 P0.2/ADC10
0011 P1.3/ADC3 1011 P0.3/ADC11
0100 P1.4/ADC4 1100 P0.4/ADC12
0101 P1.5/ADC5 1101 P0.5/ADC13
0110 P1.6/ADC6 1110 P0.6/ADC14
0111 P1.7/ADC7 1111 Test internal 1.19V
(STC8G1K08A family)
ADC_CHS[3:0] ADC channel ADC_CHS[3:0] ADC channel
0000 P3.0/ADC0 1000 No such channel
0001 P3.1/ADC1 1001 No such channel
0010 P3.2/ADC2 1010 No such channel
0011 P3.3/ADC3 1011 No such channel
0100 P5.4/ADC4 1100 No such channel
0101 P5.5/ADC5 1101 No such channel
0110 No such channel 1110 No such channel
0111 No such channel 1111 Test internal 1.19V
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 486 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0
1: The conversion result aligns right. ADC_RES is used to save the upper 2 bits of the result and
ADC_RESL is used to save the lower 8 bits of the result. The format is as follows:
ADC_RES ADC_RESL
0 0 0 0 0 0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
00001 2
... ...
01010 11 (default)
... ...
11110 31
11111 32
Enabling signal
ADC_POWER
Start signal
ADC_START
Completed signal
ADC_FLAG
Notice:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 488 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 490 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SP3232/
SP232/
0.1u MAX3232/
MAX232
System power
0.1u
(Can be powered from USB) 1 16 10u 1
C1+ VCC
1 20 0.1u 2 15 6
P1.2 P1.1 V+ GND
2 19 3 14 2
P1.3 P1.0 C1- T1OUT
3 18 4 13 7
P1.4 P3.7 C2+ R1IN
Vin 4 17 5 12 3
P1.5 P3.6 C2- R1OUT
5 16 6 11 8
P1.6 P3.5 0.1u V- T1IN
Power On 6 15 7 10 4
P1.7 P3.4 T2OUT T2IN
7 14 8 9 9
P5.4 P3.3 0.1u R2IN R2OUT
Vcc 8 13 5
VCC P3.2
9 12
P5.5 P3.1
10 11
47u C? GND P3.0 100Ω
STC8G1K08
SP3232/
SP232/
0.1u MAX3232/
MAX232
System power
0.1u
(Can be powered from USB) 1 16 10u 1
C1+ VCC
1 20 0.1u 2 15 6
P1.2 P1.1 V+ GND
2 19 3 14 2
P1.3 P1.0 C1- T1OUT
3 18 4 13 7
P1.4 P3.7 C2+ R1IN
Vin 4 17 5 12 3
P1.5 P3.6 C2- R1OUT
5 16 6 11 8
P1.6 P3.5 0.1u V- T1IN
Power On 6 15 7 10 4
P1.7 P3.4 T2OUT T2IN
7 14 8 9 9
P5.4 P3.3 0.1u R2IN R2OUT
Vcc 8 13 5
VCC P3.2
9 12
VREF P3.1
10 11
47u C? GND P3.0 100Ω
STC8xx
1N5819
If the MAX232 and the
target chip are powered on
47u tantalum capacitor (package 3528) reference price<RMB ¥0.16 at the same time, resistors
System clock<=10MHz System clock>10MHz and diodes can be omitted.
22u monolithic capacitor (package 0603) reference price<RMB ¥0.038
10u monolithic capacitor (package 0603) reference price<RMB ¥0.028 C? 104(0.1uF) 103(0.01uF)
0.1u monolithic capacitor (package 0603) reference price<RMB ¥0.005
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 491 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SP3232/
SP232/
0.1u MAX3232/
MAX232
System power
0.1u
(Can be powered from USB) 1 16 10u 1
C1+ VCC
1 20 0.1u 2 15 6
P1.2 P1.1 V+ GND
2 19 3 14 2
P1.3 P1.0 C1- T1OUT
3 18 4 13 7
P1.4 P3.7 C2+ R1IN
Vin 4 17 5 12 3
P1.5 P3.6 C2- R1OUT
5 16 6 11 8
P1.6 P3.5 0.1u V- T1IN
Power On 6 15 7 10 4
P1.7 P3.4 T2OUT T2IN
7 14 8 9 9
P5.4 P3.3 0.1u R2IN R2OUT
Vcc 8 13 5
VCC P3.2
9 12
VREF P3.1
10 11
47u C? GND P3.0 100Ω
STC8xx
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 492 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 493 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
ADC_CONTR |= 0x40; //Start AD conversion
_nop_();
_nop_();
while (!(ADC_CONTR & 0x20)); //Query ADC completion flag
ADC_CONTR &= ~0x20; //Clear completion flag
P2 = ADC_RES; //Read ADC results
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 494 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOVX @DPTR,A
MOV P_SW2,#00H
MOV ADCCFG,#0FH ;Set the ADC clock to the system clock/2/16/16
MOV ADC_CONTR,#80H ;Enable ADC module
LOOP:
ORL ADC_CONTR,#40H ;Start AD conversion
NOP
NOP
MOV A,ADC_CONTR ;Query ADC completion flag
JNB ACC.5,$-2
ANL ADC_CONTR,#NOT 20H ;Clear completion flag
MOV P2,ADC_RES ;Read ADC results
SJMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 495 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 002BH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 496 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LJMP ADCISR
ORG 0100H
ADCISR:
ANL ADC_CONTR,#NOT 20H ;Clear completion flag
MOV P2,ADC_RES ;Read ADC results
ORL ADC_CONTR,#40H ;Continue AD conversion
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SJMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 497 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 498 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 499 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SJMP $
END
STC8G1K08
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void UartInit()
{
SCON = 0x50;
TMOD = 0x00;
TL1 = BRT;
TH1 = BRT >> 8;
TR1 = 1;
AUXR = 0x40;
busy = 0;
}
void ADCInit()
{
P_SW2 |= 0x80;
ADCTIM = 0x3f; // Set ADC internal timing
P_SW2 &= 0x7f;
int ADCRead()
{
int res;
return res;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 501 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
int res;
int vcc;
int i;
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
ES = 1;
EA = 1;
// ADCRead();
// ADCRead(); //Discard the first two data
res = 0;
for (i=0; i<8; i++)
{
res += ADCRead(); //Read data 8 times
}
res >>= 3; //take the average
vcc = (int)(4095L * *BGV / res); //Calculate VREF pin voltage, i.e. battery voltage
//Note that this voltage is in millivolts (mV)
UartSend(vcc >> 8); //Output voltage value to UART
UartSend(vcc);
while (1);
}
The above method uses the 15th channel of the ADC to reverse the external battery voltage. In the ADC
measurement range, the external measurement voltage of the ADC is directly proportional to the measurement
value of the ADC. Therefore, the 15th channel of the ADC can also be used to reverse the input voltage of the
external channel. Assuming that the internal reference signal source voltage has been obtained as BGV, The
ADC measurement value of the internal reference signal source is resbg, and the ADC measurement value of the
external channel input voltage is resx, then the external channel input voltage Vx = BGV / resbg * resx;
There are various solutions for non-contact keys. Capacitive-sensing keys are low-cost solutions.
Specialized ICs were used to implement capacitive-sensing keys many years ago. With the enhancement of
MCU functions and the practical experience of users, MCUs were used to implement capacitive-sensing keys
directly. The technology of capacitive sensing keys is mature. 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. The principles are the same. The second diagram is used.
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 503 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The following is the description of the circuit diagram. CP is the distributed capacitance of metal plate and
ground, CF is the finger capacitance, they are connected in parallel and connected with C1 to divide the input
300KHZ square wave. After being rectified by D1 and filtered by R2 and C2, the wave is sent to ADC. After pressing
the finger, the voltage sent to the ADC decreases, and the program can detect the key action.
C language code
//Operating frequency for testing is 24MHz
#include "reg51.h"
#include "intrins.h"
void main(void)
{
u8 i;
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 505 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P5M1 = 0x00;
delay_ms(50);
ET0 = 0; //Initialize Timer0 to output a 300KHz clock
TR0 = 0;
AUXR |= 0x80; //Timer0 set as 1T mode
AUXR2 |= 0x01; //Enable clock output
TMOD = 0; //Timer0 set as Timer, 16 bits Auto Reload.
TH0 = (u8)(Timer0_Reload >> 8);
TL0 = (u8)Timer0_Reload;
TR0 = 1;
ADC_init(); //ADC initialization
delay_ms(50); //Delay 50ms
for (i=0; i<TOUCH_CHANNEL; i++) // Initialize the 0-point, the previous value and the 0-point auto-tracking count
{
adc_prev[i] = 1023;
TouchZero[i] = 1023;
TouchZeroCnt[i] = 0;
}
cnt_250ms = 0;
while (1)
{
delay_ms(50); //Process key once every 50ms
ShowLED();
if (++cnt_250ms >= 5)
{
cnt_250ms = 0;
AutoZero(); //Process 0-point auto-tracking every 250ms
}
}
}
do
{
i = MAIN_Fosc / 13000;
while(--i) ;
} while(--ms);
}
void ADC_init(void)
{
P1M0 = 0x00; //8 channels ADC
P1M1 = 0xff;
ADC_CONTR = 0x80; //Enable ADC
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 506 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
adc[index] = 1023 - Get_ADC10bitResult(index); // Get ADC value, convert to press the key, ADC value increases
if(adc[index] < TouchZero[index]) return 0; // A value smaller than 0-point is considered a key release
delta = adc[index] - TouchZero[index];
if(delta >= 40) return 1; //Key pressed
if(delta <= 20) return 0; //Key released
return 2; // Keep the original state
}
void ShowLED(void)
{
u8 i;
i = check_adc(0);
if(i == 0) P_LED0 = 1; //Light off
if(i == 1) P_LED0 = 0; //Light on
i = check_adc(1);
if(i == 0) P_LED1 = 1; //Light off
if(i == 1) P_LED1 = 0; //Light on
i = check_adc(2);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 507 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for testing is 24MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 508 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
adc_prev EQU 40H ; Previous ADC value in 40H ~ 4FH, two bytes constitute a value
TouchZero EQU 50H ; ADC 0 value in 50H~5FH, two bytes constitute a value
TouchZeroCnt EQU 60H ; 0-point automatic tracking count in 60H~67H
cnt_250ms DATA 68H
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP,#0D0H
MOV P0M0,#00H
MOV P0M1,#00H
MOV P1M0,#00H
MOV P1M1,#00H
MOV P2M0,#00H
MOV P2M1,#00H
MOV P3M0,#00H
MOV P3M1,#00H
MOV P4M0,#00H
MOV P4M1,#00H
MOV P5M0,#00H
MOV P5M1,#00H
MOV R7,#50
LCALL F_delay_ms
CLR ET0 ;Initialize Timer0 to output a 300KHz clock
CLR TR0
ORL AUXR,#080H ;Timer0 set as 1T mode
ORL AUXR2,#01H ;Enable clock output
MOV TMOD,#0 ;Timer0 set as Timer,16 bits Auto Reload.
MOV TH0,#HIGH Reload
MOV TL0,#LOW Reload
SETB TR0
LCALL F_ADC_init
MOV R7,#50
LCALL F_delay_ms
MOV R0,#adc_prev ;Initialize the previous ADC value
L_Init_Loop1:
MOV @R0,#03H
INC R0
MOV @R0,#0FFH
INC R0
MOV A,R0
CJNE A,#(adc_prev + CHANNEL * 2),L_Init_Loop1
MOV R0,#TouchZero ;Initialize the ADC 0-point value
L_Init_Loop2:
MOV @R0,#03H
INC R0
MOV @R0,#0FFH
INC R0
MOV A,R0
CJNE A,#(TouchZero+CHANNEL * 2),L_Init_Loop2
MOV R0,#TouchZeroCnt ;Initialize the automatic tracking count value
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 509 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
L_Init_Loop3:
MOV @R0,#0
INC R0
MOV A,R0
CJNE A,#(TouchZeroCnt + CHANNEL),L_Init_Loop3
MOV cnt_250ms,#5
L_MainLoop:
MOV R7,#50 ;Delay 50ms
LCALL F_delay_ms
LCALL F_ShowLED ;Handle key value once
DJNZ cnt_250ms,L_MainLoop
MOV cnt_250ms,#5 ;Processing once 0-point automatic tracking value every 250ms
LCALL F_AutoZero ; Zero tracking
SJMP L_MainLoop
F_ADC_init:
MOV P1M0,#00H ;8 channels ADC
MOV P1M1,#0FFH
MOV ADC_CONTR,#080H ;Enable ADC
RET
F_Get_ADC10bitResult:
MOV ADC_RES,#0
MOV ADC_RESL,#0
MOV A,R7
ORL A,#0E8H ;Trigger ADC
MOV ADC_CONTR,A
NOP
NOP
NOP
NOP
L_10bitADC_Loop1:
MOV A,ADC_CONTR
JNB ACC.4,L_10bitADC_Loop1 ;Wait for the ADC conversion complement
MOV ADC_CONTR,#080H ;Clear flag
MOV A,ADC_RES
MOV B,#04H
MUL AB
MOV R7,A
MOV R6,B
MOV A,ADC_RESL
ANL A,#03H
ORL A,R7
MOV R7,A
RET
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 510 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV R7,A
MOV A,R5
ADD A,ACC
ADD A,#LOW (adc_prev+01H)
MOV R0,A
CLR C
MOV A,R7
SUBB A,@R0
MOV R3,A
MOV A,R6
DEC R0
SUBB A,@R0
MOV R2,A
CLR F0 ;按下
JNB ACC.7,L_AutoZero_1
SETB F0
CLR C
CLR A
SUBB A,R3
MOV R3,A
MOV A,R3
CLR A
SUBB A,R2
MOV R2,A
L_AutoZero_1:
CLR C ;Calculate [R2 R3] - #20,if(k >= 20)
MOV A,R3
SUBB A,#20
MOV A,R2
SUBB A,#00H
JC L_AutoZero_2 ;[R2 R3] ,20, Jump
MOV A,#LOW (TouchZeroCnt) ; If the change is large, clear the counter TouchZeroCnt[i] =
0;
ADD A,R5
MOV R0,A
MOV @R0,#0
JNB F0,L_AutoZero_3
MOV A,R5
ADD A,ACC
ADD A,#LOW (TouchZero)
MOV R0,A
MOV @R0,6
INC R0
MOV @R0,7
SJMP L_AutoZero_3
L_AutoZero_2: ; If the change is relatively small, then creep, track 0-point automatically
; Continuously detect small changes 20 times/4 = 5 seconds.
MOV A,#LOW (TouchZeroCnt)
ADD A,R5
MOV R0,A
INC @R0
MOV A,@R0
CLR C
SUBB A,#20
JC L_AutoZero_3 ;if(TouchZeroCnt[i] < 20), jump
MOV @R0,#0 ;TouchZeroCnt[i]= 0;
MOV A,R5 ; Use slowly changing values as 0 points
ADD A,ACC
ADD A,#LOW (adc_prev)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 511 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV R0,A
MOV A,@R0
MOV R2,A
INC R0
MOV A,@R0
MOV R3,A
MOV A,R5
ADD A,ACC
ADD A,#LOW (TouchZero)
MOV R0,A
MOV @R0,2
INC R0
MOV @R0,3
L_AutoZero_3: ; Save the sampled value adc_prev[i] = j;
MOV A,R5
ADD A,ACC
ADD A,#LOW (adc_prev)
MOV R0,A
MOV @R0,6
INC R0
MOV @R0,7
INC R5
MOV A,R5
XRL A,#08H
JZ $ + 5H
LJMP L_AutoZero_Loop
RET
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 512 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV A,R6
DEC R1
SUBB A,@R1
JNC L_check_adc_1
MOV R7,#00H
RET
L_check_adc_1:
MOV A,R4
ADD A,ACC
ADD A,#LOW (TouchZero+01H)
MOV R1,A
MOV A,R4
ADD A,ACC
ADD A,#LOW (adc+01H)
MOV R0,A
CLR C
MOV A,@R0
SUBB A,@R1
MOV R7,A
DEC R0
MOV A,@R0
DEC R1
SUBB A,@R1
MOV R6,A
CLR C
MOV A,R7
SUBB A,#40
MOV A,R6
SUBB A,#00H
JC L_check_adc_2 ;if(delta < 40), jump
MOV R7,#1 ;if(delta >= 40) return 1; //Key pressed, return 1
RET
L_check_adc_2:
SETB C
MOV A,R7
SUBB A,#20
MOV A,R6
SUBB A,#00H
JNC L_check_adc_3
MOV R7,#0
RET
L_check_adc_3:
MOV R7,#2
RET
F_ShowLED:
MOV R7,#0
LCALL F_check_adc
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck0
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED0,C
L_QuitCheck0:
MOV R7,#1
LCALL F_check_adc
MOV A,R7
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 513 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ANL A,#0FEH
JNZ L_QuitCheck1
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED1,C
L_QuitCheck1:
MOV R7,#2
LCALL F_check_adc
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck2
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED2,C
L_QuitCheck2:
MOV R7,#3
LCALL F_check_adc
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck3
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED3,C
L_QuitCheck3:
MOV R7,#4
LCALL F_check_adc
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck4
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED4,C
L_QuitCheck4:
MOV R7,#5
LCALL F_check_adc
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck5
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED5,C
L_QuitCheck5:
MOV R7,#6
LCALL F_check_adc
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck6
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED6,C
L_QuitCheck6:
MOV R7,#7
LCALL F_check_adc
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 514 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV A,R7
ANL A,#0FEH
JNZ L_QuitCheck7
MOV A,R7
MOV C,ACC.0
CPL C
MOV P_LED7,C
L_QuitCheck7:
RET
F_delay_ms:
PUSH 3
PUSH 4
L_delay_ms_1:
MOV R3,#HIGH (Fosc_KHZ / 13)
MOV R4,#LOW (Fosc_KHZ / 13)
L_delay_ms_2:
MOV A,R4
DEC R4
JNZ L_delay_ms_3
DEC R3
L_delay_ms_3:
DEC A
ORL A,R3
JNZ L_delay_ms_2
DJNZ R7,L_delay_ms_1
POP 4
POP 3
RET
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 515 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
10K
Test-OUT
0~+5V,
Which can be connected
10K
directly to the MCU ADC
Test-IN port
-5V~+5V
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 516 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
10K
Vcc Vcc
R1 10K
Vcc R1
10K R1 10K
Vin Vo Vo Vo
i2
R2 10K
Vin R2
R R2 10K
Vin
Formula 1: Vo = Vin + i2 * R2
In the analog-to-digital conversion measurement of the microcontroller, the measured voltage is required
to be greater than 0 and less than VCC. If the measured voltage is less than 0V, an addition circuit can be
used to increase the measured voltage to above 0V. At this time, there are certain requirements for the
variation range of the measured voltage:
Substituting the above conditions into formula 4, the following formula 2 can be obtained
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 517 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
17 Application of PCA/CCP/PWM
STC8G1K08 family ●
STC8G1K08-8Pin family
STC8G1K08A family ●
STC8G2K64S4 family ●
STC8G2K64S2 family ●
STC8G1K08T family ●
STC15H2K64S4 family ●
Three groups of programmable counter array (PCA/CCP/PWM) modules are integrated in STC8G 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 three groups of PCA modules are connected. The
structure of PCA counter is as follows:
PCA0
PCA1
SYSclk/12 000 PCA2
SYSclk/2 001
T0 overflow 010
SYSclk/6 110
SYSclk/8 111
CCON CF CR - - - CF2 CF1 CF0
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 518 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 519 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
interrupt
6/7/8/10 bit PWM mode, rising and falling
- 1 1 1 0 0 1 1
edge interrup
- 0 1 0 0 0 0 x 16 bit rising edge capture mode
- 0 0 1 0 0 0 x 16 bit falling edge capture mode
- 0 1 1 0 0 0 x 16 bit rising and falling edge capture mode
- 1 0 0 1 0 0 x 16 bit software timer mode
- 1 0 0 1 1 0 x 16 bit high speed pulse output mode
The structure of the PCA module working in capture mode is shown in the following figure.
CH CL
PCA
interrupt
CCAPnH CCAPnL
CCP0
CCP1
CCP2
CCP3
0 0 0 0 0
The structure of PCA module working in software timer mode is shown in the following figure.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 521 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Write Then
CCAPnL write CCON CF CR - - CF3 CF2 CF1 CF0
firstly CCAPnH
0 1 CH CL
enable matched
PCA
16 bit comparator
interrupt
0 0 0 1 0 0
The structure of PCA module working in high-speed pulse output mode is shown below.
Write Then
CCAPnL write CCON CF CR - - CF3 CF2 CF1 CF0
firstly CCAPnH
0 1 CH CL PCA
interrupt
enable matched
16 bit comparator
CCPn
ECOMn=0, stop comparison CCAPnH CCAPnL
ECOMn=1, continue comparison
0 0 0 1 1 0
Pulse width modulation is a technique that uses a program to control the duty ratio, cycle and phase of a
waveform. It is widely used in applications such as three-phase motor driving and D/A conversion. The PCA
modules of the STC8G series of microcontrollers can be configured to operate in 8-bit, 7-bit, 6-bit or 10-bit
PWM mode by setting corresponding PCA_PWMn registers. To enable the PWM function of the PCA module,
the PWMn and ECOMn bits of the module register CCAPMn must be set.
When EBSn [1:0] in the PCA_PWMn register is set to 00, PCAn operates in 8-bit PWM mode, where {0,
CL [7: 0]} is compared with the capture registers {EPCnL, CCAPnL [7: 0]}. When PCA modules are operating
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 522 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
in 8-bit PWM mode, the output frequencies of them are the same because all the modules share a single PCA
counter. The output duty ratio of each module is set using the registers {EPCnL, CCAPnL [7: 0]}. The output is
low when the value of {0, CL [7: 0]} is less than {EPCnL, CCAPnL [7: 0]}, and the output is high when the
value of {0, CL [7: 0]} is equal to or greater than {EPCnL , CCAPnL [7: 0]}. When CL [7: 0] overflows from
FF to 00, the contents of {EPCnH, CCAPnH [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]}
enable
9-bit comparator CCPn
{0,CL[7:0]} >= {EPCnL,CCAPnL[7:0]}
0 CL[7:0]
CL overflow Output 1
When EBSn [1:0] in the PCA_PWMn register is set to 01, the PCAn operates in 7-bit PWM mode, where
{0, CL [6: 0]} is compared with the capture registers {EPCnL, CCAPnL [6: 0]}. When PCA modules are
operating in 7-bit PWM mode, the output frequencies of them are the same because all the modules share a
single PCA counter. The output duty ratio of each module is set using the registers {EPCnL, CCAPnL [6: 0]}.
The output is low when the value of {0, CL [6: 0]} is less than {EPCnL, CCAPnL [6: 0]}, and the output is high
when the value of {0, CL [6: 0]} is equal to or greater than {EPCnL , CCAPnL [6: 0]}. When CL [6: 0]
overflows from 7F to 00, the contents of {EPCnH, CCAPnH [6: 0]} are reloaded into {EPCnL, CCAPnL [6: 0]}.
This makes it possible to update the PWM without interference.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 523 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The structure of PCA module working in 7-bit PWM mode is shown below.
EPCnH CCAPnH[6:0]
reload
Output 0
EPCnL CCAPnL[6:0]
{0,CL[6:0]}<{EPCnL,CCAPnL[6:0]}
enable
8-bit comparator CCPn
{0,CL[6:0]}>={EPCnL,CCAPnL[6:0]}
0 CL[6:0]
CL overflow Output 1
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] }. When PCA modules are operating
in 6-bit PWM mode, the output frequencies of them are the same because all the modules share a single PCA
counter. The output duty ratio of each module is set using the registers {EPCnL, CCAPnL [5: 0]}. The output is
low when the value of {0, CL [5: 0]} is less than {EPCnL, CCAPnL [5: 0]}, and the output is high when the
value of {0, CL [5: 0]} is equal to or greater than {EPCnL , CCAPnL [5: 0]}. When CL [5: 0] overflows from
3F to 00, the contents of {EPCnH, CCAPnH [5: 0]} are reloaded into {EPCnL, CCAPnL [5: 0]}. This makes it
possible to update the PWM without interference.
The structure of PCA module working in 6-bit PWM mode is shown below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 524 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
EPCnH CCAPnH[5:0]
reload
Output 0
EPCnL CCAPnL[5:0]
{0,CL[5:0]}<{EPCnL,CCAPnL[5:0]}
enable
7-bit comparator CCPn
{0,CL[5:0]}>={EPCnL,CCAPnL[5:0]}
0 CL[5:0]
Output 1
CL overflow
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. The output duty ratio of each module is set using the registers {EPCnL,
XCCAPnL[1:0],CCAPnL[7:0]}. The output is low when the value of {CH[1:0],CL[7:0]} is less than
{EPCnL,XCCAPnL[1:0],CCAPnL[7:0]}, and the output is high when the value of {CH[1:0],CL[7:0]} is equal
to or greater than {EPCnL,XCCAPnL[1:0],CCAPnL[7:0]}. When {CH[1:0],CL[7:0]} overflows from 3FF to
00, the contents of {EPCnH,XCCAPnH[1:0],CCAPnH[7:0]} are reloaded into {EPCnL,XCCAPnL[1:0],
CCAPnL[7:0]}. This makes it possible to update the PWM without interference.
The structure of PCA module working in 10-bit PWM mode is shown below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 525 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
0 CH[1:0] CL[7:0]
Output 1
CL overflow
If PCA_PWMn &= 0xC0 and CCAPnH = 0x00, PWM fixed output high.
If PCA_PWMn |= 0x3F and CCAPnH = 0xFF, PWM fixed output low.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 526 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 527 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 528 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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; //PCA 0 outputs 6-bit PWM
CCAP0L = 0x20; //PWM duty cycle is 50%[(40H-20H)/40H]
CCAP0H = 0x20;
//--7 bit PWM--
CCAPM1 = 0x42; //PCA 1 is in PWM mode
PCA_PWM1 = 0x40; //PCA 1 outputs 7-bit PWM
CCAP1L = 0x20; //PWM duty cycle is 75%[(80H-20H)/80H]
CCAP1H = 0x20;
//--8 bit PWM--
// CCAPM2 = 0x42; //PCA 2 is in PWM mode
// PCA_PWM2 = 0x00; //PCA 2 outputs 8-bit PWM
// CCAP2L = 0x20; //PWM duty cycle is 87.5%[(100H-20H)/100H]
// CCAP2H = 0x20;
//--10 bit PWM--
CCAPM2 = 0x42; //PCA 2 is in PWM mode
PCA_PWM2 = 0x00; //PCA 2 outputs 10-bit PWM
CCAP2L = 0x20; // PWM duty cycle is 96.875%[(400H-20H)/400H]
CCAP2H = 0x20;
CR = 1; //Start PCA timer
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CCON,#00H
MOV CMOD,#08H ;PCA clock is the system clock
MOV CL,#00H
MOV CH,#0H
;--6 bit PWM--
MOV CCAPM0,#42H ;PCA 0 is in PWM mode
MOV PCA_PWM0,#80H ;PCA 0 outputs 6-bit PWM
MOV CCAP0L,#20H ;PWM duty cycle is 50%[(40H-20H)/40H]
MOV CCAP0H,#20H
;--7 bit PWM--
MOV CCAPM1,#42H ;PCA 1 is in PWM mode
MOV PCA_PWM1,#40H ;PCA 1 outputs 7-bit PWM
MOV CCAP1L,#20H ;PWM duty cycle is 75%[(80H-20H)/80H]
MOV CCAP1H,#20H
;--8 bit PWM--
; MOV CCAPM2,#42H ;PCA 2 is in PWM mode
; MOV PCA_PWM2,#00H ;PCA 2 outputs 8-bit PWM
; MOV CCAP2L,#20H ;PWM duty cycle is 87.5%[(100H-20H)/100H]
; MOV CCAP2H,#20H
;--10 bit PWM--
MOV CCAPM2,#42H ;PCA 2 is in PWM mode
MOV PCA_PWM2,#0C0H ;PCA 2 outputs 10-bit PWM
MOV CCAP2L,#20H ;PWM duty cycle is 96.875%[(400H-20H)/400H]
MOV CCAP2H,#20H
SETB CR ;Start PCA timer
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 530 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
{
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;
((unsigned char *)&count1)[0] = 0;
length = count1 - count0; //length saved is the captured pulse width
}
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
CF BIT CCON.7
CR BIT CCON.6
CCF2 BIT CCON.2
CCF1 BIT CCON.1
CCF0 BIT CCON.0
CMOD DATA 0D9H
CL DATA 0E9H
CH 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 DATA 0DCH
CCAP2L DATA 0ECH
CCAP2H DATA 0FCH
PCA_PWM2 DATA 0F4H
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
PUSH ACC
PUSH PSW
JNB CF,CHECKCCF0
CLR CF ;Clear interrupt flag
INC CNT ; PCA Timing overflow times+1
CHECKCCF0:
JNB CCF0,ISREXIT
CLR CCF0
MOV COUNT0,COUNT1 ;Back up the last captured value
MOV COUNT0+1,COUNT1+1
MOV COUNT0+2,COUNT1+2
MOV COUNT1,CNT ;Save the current captured value
MOV COUNT1+1,CCAP0H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 533 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV COUNT1+2,CCAP0L
CLR C ;Calculate two captures’ differences
MOV A,COUNT1+2
SUBB A,COUNT0+2
MOV LENGTH+2,A
MOV A,COUNT1+1
SUBB A,COUNT0+1
MOV LENGTH+1,A
MOV A,COUNT1
SUBB A,COUNT0
MOV LENGTH,A ;LENGTH saved is the captured pulse width
ISREXIT:
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
CLR A
MOV CNT,A ;User variable initialization
MOV COUNT0,A
MOV COUNT0+1,A
MOV COUNT0+2,A
MOV COUNT1,A
MOV COUNT1+1,A
MOV COUNT1+2,A
MOV LENGTH,A
MOV LENGTH+1,A
MOV LENGTH+2,A
MOV CCON,#00H
MOV CMOD,#09H ;PCA clock is the system clock, enable PCA timing
interrupt
MOV CL,#00H
MOV CH,#0H
MOV CCAPM0,#11H ;PCA module 0 is 16-bit capture mode (falling edge capture)
; MOV CCAPM0,#21H ;PCA module 0 is 16-bit capture mode (rising edge capture)
; MOV CCAPM0,#31H ;PCA module 0 is 16-bit capture mode (falling and rising edge capture)
MOV CCAP0L,#00H
MOV CCAP0H,#00H
SETB CR ;Start PCA timer
SETB EA
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 534 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 535 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
value += T50HZ;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CCON = 0x00;
CMOD = 0x00; //PCA clock is the system clock/12
CL = 0x00;
CH = 0x00;
CCAPM0 = 0x49; //PCA module 0 is 16-bit timer mode
value = T50HZ;
CCAP0L = value;
CCAP0H = value >> 8;
value += T50HZ;
CR = 1; //Start PCA timer
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
PUSH ACC
PUSH PSW
CLR CCF0
MOV A,CCAP0L
ADD A,#LOW T50HZ
MOV CCAP0L,A
MOV A,CCAP0H
ADDC A,#HIGH T50HZ
MOV CCAP0H,A
CPL P1.0 ;Test port, flashing frequency is 50Hz
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CCON,#00H
MOV CMOD,#00H ;PCA clock is the system clock/12
MOV CL,#00H
MOV CH,#0H
MOV CCAPM0,#49H ;PCA module 0 is 16-bit timer mode
MOV CCAP0L,#LOW T50HZ
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 537 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
17.4.4 PCA realizes 16-bit software timing (ECI external clock mode)
Note: The external clock frequency cannot be higher than 1/2 of the system frequency.
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 538 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CCON = 0x00;
CMOD = 0x06; // The PCA clock is an external clock input from the ECI
port
CL = 0x00;
CH = 0x00;
CCAPM0 = 0x49; // PCA module 0 is 16-bit timer mode
value = T50HZ;
CCAP0L = value;
CCAP0H = value >> 8;
value += T50HZ;
CR = 1; // Start the PCA timer
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
PUSH ACC
PUSH PSW
CLR CCF0
MOV A,CCAP0L
ADD A,#LOW T50HZ
MOV CCAP0L,A
MOV A,CCAP0H
ADDC A,#HIGH T50HZ
MOV CCAP0H,A
CPL P1.0 ; Test port, flashing frequency is 50Hz
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 540 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV CCON,#00H
MOV CMOD,#06H ; The PCA clock is an external clock input from the ECI
port
MOV CL,#00H
MOV CH,#0H
MOV CCAPM0,#49H ; PCA module 0 is 16-bit timer mode
MOV CCAP0L,#LOW T50HZ
MOV CCAP0H,#HIGH T50HZ
SETB CR ; Start the PCA timer
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CCON = 0x00;
CMOD = 0x08; //PCA clock is the system clock
CL = 0x00;
CH = 0x00;
CCAPM0 = 0x4d; //PCA module 0 is 16-bit timer mode, and enable pulse output
value = T38K4HZ;
CCAP0L = value;
CCAP0H = value >> 8;
value += T38K4HZ;
CR = 1; //Start PCA timer
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
PUSH ACC
PUSH PSW
CLR CCF0
MOV A,CCAP0L
ADD A,#LOW T38K4HZ
MOV CCAP0L,A
MOV A,CCAP0H
ADDC A,#HIGH T38K4HZ
MOV CCAP0H,A
POP PSW
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 543 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV CCON,#00H
MOV CMOD,#08H ;PCA clock is the system clock
MOV CL,#00H
MOV CH,#0H
MOV CCAPM0,#4DH ;PCA module 0 is 16-bit timer mode, and enable pulse
output
MOV CCAP0L,#LOW T38K4HZ
MOV CCAP0H,#HIGH T38K4HZ
SETB CR ;Start PCA timer
SETB EA
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
CCON = 0x00;
CMOD = 0x08; //PCA clock is the system clock
CL = 0x00;
CH = 0x00;
CCAPM0 = 0x11; //Extend external port CCP0 as a falling edge interrupt
port
// CCAPM0 = 0x21; //Extend external port CCP0 as a rising edge interrupt port
// CCAPM0 = 0x31; //Extend external port CCP0 as a rising and falling edge interrupt port
CCAP0L = 0;
CCAP0H = 0;
CR = 1; //Start PCA timer
EA = 1;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 003BH
LJMP PCAISR
ORG 0100H
PCAISR:
CLR CCF0
CPL P1.0
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV CCON,#00H
MOV CMOD,#08H ;PCA clock is the system clock
MOV CL,#00H
MOV CH,#0H
MOV CCAPM0,#11H ;Extend external port CCP0 as a falling edge interrupt port
; MOV CCAPM0,#21H ;Extend external port CCP0 as a rising edge interrupt port
; MOV CCAPM0,#31H ;Extend external port CCP0 as a rising and falling edge interrupt port
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 546 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV CCAP0L,#0
MOV CCAP0H,#0
SETB CR ;Start PCA timer
SETB EA
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 547 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8G1K08 family
STC8G1K08-8Pin family
STC8G1K08A family
STC8G2K64S4 family ●
STC8G2K64S2 family ●
STC8G1K08T family
STC15H2K64S4 family ●
(When an interrupt with an interrupt number greater than 31 is used in a C program, an error will
be reported when compiled in Keil. For the solution, please refer to Appendix.)
6 groups of individually 8-channel enhanced PWM waveform generators are integrated in some STC8G
series microcontrollers. Each group can set the period separately, and has 8 independent channels. Because the
P5 port lacks the 3 pins P5.5/P5.6/P5.7, the STC8G2K64S4 series can output up to 45 channels of PWM.
Group 0 has 8 channels, PWM00~PWM07, which use PWM0CH/PWM0CL to set the period value;
Group 1 has 8 channels, PWM10~PWM17, which use PWM1CH/PWM1CL to set the period value;
Group 2 has 8 channels, PWM20~PWM27, which use PWM2CH/PWM2CL to set the period value;
Group 3 has 8 channels, PWM30~PWM37, which use PWM3CH/PWM3CL to set the period value;
Group 4 has 8 channels, PWM40~PWM47, which use PWM4CH/PWM4CL to set the period value;
Group 5 has 5 channels, PWM50~PWM54, which use PWM5CH/PWM5CL to set the period value.
The STC8G2K64S2 series microcontrollers integrate a group (P2 port) enhanced PWM waveform
generator. The P2 group can generate 8 independent PWMs, so the STC8G2K64S2 series can output up to 8
PWMs. PWM20~PWM27, using PWM2CH/PWM2CL to set the period value.
The clock source of PWM can be selected. There is a 15-bit PWM counter in the PWM waveform
generator which is used for 8 channel PWMs. The initial level of each PWM can be set. In addition, two
counters T1 and T2 are designed in the PWM waveform generator to control the waveform hopping for each
PWM. The width of high and low level of each PWM can be set very flexibly, so that the PWM duty ratio and
PWM output delay can be controlled. Because the 8 PWMs are independent and the initial state of each PWM
can be set, any two of them can be used together to achieve special applications such as complementary
symmetrical output and dead band control. Note: Enhanced PWM only has output function. If you need to
measure pulse width, please use the PCA/CCP/PWM function of this series microcontroller. The enhanced
PWM waveform generators also feature the ability to monitor external abnormal events, such as external port
P3.5/0.6/0.7 abnormal level and the abnormal comparator results. It can be used to shutdown PWM outputs
immediately. The PWM waveform generator can also be associated with ADC. Any point in the PWM cycle can
be set to trigger the ADC conversion event.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 548 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Compatible with traditional 8051 PCA/CCP/PWM: It can output PWM waveforms, capture external input
signals and output high-speed pulses. It can output 6-bit/7-bit/8-bit/10-bit PWM waveform externally. The
frequency of the 6-bit PWM waveform is the PCA module clock source frequency/64. The frequency of the 7-
bit PWM waveform is the PCA module clock source frequency/128. The frequency of the 8-bit PWM waveform
is the PCA module clock source frequency/256. The frequency of the 10-bit PWM waveform is the PCA module
clock source frequency/1024. For the external input signal capture, you can capture the rising edge, the falling
edge or the rising edge and the falling edge at the same time.
15-bit enhanced PWM of STC8G series: It can only output PWM waveform externally, without input
capture function. The frequency and duty cycle of PWM output can be set arbitrarily. Through software
intervention, multiple complementary/symmetrical with dead-time PWM waveforms can be realized. There are
external abnormality detection function and real-time trigger ADC conversion function.
The 16-bit advanced PWM timer of the STC8H series: 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. It can capture the
external signal for the rising edge, the falling edge or the rising edge and the falling edge at the same time.
When measuring the external waveform, the period value and the duty ratio value of the waveform can be
measured at the same time. There are quadrature encoding function, external anomaly detection function and
real-time trigger ADC conversion function.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 549 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 550 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 551 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 552 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
0: disable PWM2
1: enable PWM2
ENPWM1: PWM1 enable bit (including PWM10~PWM17).
0: disable PWM1
1: enable PWM1
ENPWM0: PWM0 enable bit (including PWM00~PWM07).
0: disable PWM0
1: enable PWM0
PWMnCBIF: The interrupt flag bit of PWMn when the PWMn counter returns to zero (n=0~5).
When the 15-bit PWMn counter overflows and returns to zero, this bit is set by hardware automatically and
an interrupt is requested to CPU. This flag bit needs to be cleared by software.
EPWMnCBI: PWMn counter returns to zero interrupt enable bit. (n= 0 ~5)
0: disable PWMn counter returns to zero interrupt (PWMnCBIF is still set by hardware)
1: enable PWMn counter returns to zero interrupt
PWMnCEN: PWMn waveform generator starts counting control bit. (n= 0~5)
0: PWMn stops counting
1: PWMn starts counting
Important note about the PWMnCEN control bit:
O
nce PWMnCEN is enabled, the internal PWMn counter will start counting immediately and compare
the counting value with the value of T1/T2. So PWMnCEN must be enabled after all other PWM
settings (including T1 / T2 settings, initial level setting, PWM fault detection setting and PWM
interrupt setting) are completed.
D
uring the PWMn counter counting, when the PWMnCEN control bit is turned off, the PWMn counting
will stop immediately. When the PWMnCEN control bit is enabled again, the PWMn counting will
start counting from 0 again without remembering the count value before the PWMn stopped counting.
EPWMnTA: Whether the PWMn is associated with the ADC or not. (n=0,2,4)
0: PWMn is not associated with the ADC.
1: PWMn is associated with the ADC. A/D conversion is enabled to be triggered at a certain point in the
PWMn cycle. PWMnTADCHand PWMnTADCL are used to set the counter value..
(Note: The ADC_POWER and ADC_EPWMT bits in the ADC_CONTR register need to be set at the
same time to enable the PWM triger function. PWM only sets ADC_START to 1 automatically.
Only PWM0, PWM2 and PWM4 can trigger the ADC.)
FLTPS0、FLTPS1、FLTPS2: External fault detection pin selection control bit
PWM2 PWM4
PWM0/PWM1/PWM3/PWM5
FLTPS2 FLTPS1 FLTPS0 external fault detection external fault detection
external fault detection pin
pin pin
0 0 0 PWMFLT(P3.5) PWMFLT(P3.5) PWMFLT(P3.5)
0 0 1 PWMFLT(P3.5) PWMFLT2(P0.6) PWMFLT3(P0.7)
0 1 0 PWMFLT(P3.5) PWMFLT3(P0.7) PWMFLT2(P0.6)
0 1 1 PWMFLT2(P0.6) PWMFLT2(P0.6) PWMFLT2(P0.6)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 554 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 555 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
It is set automatically by the hardware when a PWMn fault occurs. If EFDI=1, the program will jump to
the corresponding interrupt entry to execute interrupt service routine. It should be cleared by software.
(Note: Only PWM0, PWM2 and PWM4 will be interrupted. PWM1, PWM3, PWM5 have fault detection
function, but do not enter the interrupt service routine.)
different frequency.
Clock source selection
PWM output frequency calculation formula
(SELT2)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 557 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM06T2L FF43H
PWM07T1H FF48H -
PWM07T1L FF49H
PWM07T2H FF4AH -
PWM07T2L FF4BH
PWM10T1H FF60H -
PWM10T1L FF61H
PWM10T2H FF62H -
PWM10T2L FF63H
PWM11T1H FF68H -
PWM11T1L FF69H
PWM11T2H FF6AH -
PWM11T2L FF6BH
PWM12T1H FF70H -
PWM12T1L FF71H
PWM12T2H FF72H -
PWM12T2L FF73H
PWM13T1H FF78H -
PWM13T1L FF79H
PWM13T2H FF7AH -
PWM13T2L FF7BH
PWM14T1H FF80H -
PWM14T1L FF81H
PWM14T2H FF82H -
PWM14T2L FF83H
PWM15T1H FF88H -
PWM15T1L FF89H
PWM15T2H FF8AH -
PWM15T2L FF8BH
PWM16T1H FF90H -
PWM16T1L FF91H
PWM16T2H FF92H -
PWM16T2L FF93H
PWM17T1H FF98H -
PWM17T1L FF99H
PWM17T2H FF9AH -
PWM17T2L FF9BH
PWM20T1H FFB0H -
PWM20T1L FFB1H
PWM20T2H FFB2H -
PWM20T2L FFB3H
PWM21T1H FFB8H -
PWM21T1L FFB9H
PWM21T2H FFBAH -
PWM21T2L FFBBH
PWM22T1H FFC0H -
PWM22T1L FFC1H
PWM22T2H FFC2H -
PWM22T2L FFC3H
PWM23T1H FFC8H -
PWM23T1L FFC9H
PWM23T2H FFCAH -
PWM23T2L FFCBH
PWM24T1H FFD0H -
PWM24T1L FFD1H
PWM24T2H FFD2H -
PWM24T2L FFD3H
PWM25T1H FFD8H -
PWM25T1L FFD9H
PWM25T2H FFDAH -
PWM25T2L FFDBH
PWM26T1H FFE0H -
PWM26T1L FFE1H
PWM26T2H FFE2H -
PWM26T2L FFE3H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 558 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM27T1H FFE8H -
PWM27T1L FFE9H
PWM27T2H FFEAH -
PWM27T2L FFEBH
PWM30T1H FC10H -
PWM30T1L FC11H
PWM30T2H FC12H -
PWM30T2L FC13H
PWM31T1H FC18H -
PWM31T1L FC19H
PWM31T2H FC1AH -
PWM31T2L FC1BH
PWM32T1H FC20H -
PWM32T1L FC21H
PWM32T2H FC22H -
PWM32T2L FC23H
PWM33T1H FC28H -
PWM33T1L FC29H
PWM33T2H FC2AH -
PWM33T2L FC2BH
PWM34T1H FC30H -
PWM34T1L FC31H
PWM34T2H FC32H -
PWM34T2L FC33H
PWM35T1H FC38H -
PWM35T1L FC39H
PWM35T2H FC3AH -
PWM35T2L FC3BH
PWM36T1H FC40H -
PWM36T1L FC41H
PWM36T2H FC42H -
PWM36T2L FC43H
PWM37T1H FC48H -
PWM37T1L FC49H
PWM37T2H FC4AH -
PWM37T2L FC4BH
PWM40T1H FC60H -
PWM40T1L FC61H
PWM40T2H FC62H -
PWM40T2L FC63H
PWM41T1H FC68H -
PWM41T1L FC69H
PWM41T2H FC6AH -
PWM41T2L FC6BH
PWM42T1H FC70H -
PWM42T1L FC71H
PWM42T2H FC72H -
PWM42T2L FC73H
PWM43T1H FC78H -
PWM43T1L FC79H
PWM43T2H FC7AH -
PWM43T2L FC7BH
PWM44T1H FC80H -
PWM44T1L FC81H
PWM44T2H FC82H -
PWM44T2L FC83H
PWM45T1H FC88H -
PWM45T1L FC89H
PWM45T2H FC8AH -
PWM45T2L FC8BH
PWM46T1H FC90H -
PWM46T1L FC91H
PWM46T2H FC92H -
PWM46T2L FC93H
PWM47T1H FC98H -
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 559 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWM47T1L FC99H
PWM47T2H FC9AH -
PWM47T2L FC9BH
PWM50T1H FCB0H -
PWM50T1L FCB1H
PWM50T2H FCB2H -
PWM50T2L FCB3H
PWM51T1H FCB8H -
PWM51T1L FCB9H
PWM51T2H FCBAH -
PWM51T2L FCBBH
PWM52T1H FCC0H -
PWM52T1L FCC1H
PWM52T2H FCC2H -
PWM52T2L FCC3H
PWM53T1H FCC8H -
PWM53T1L FCC9H
PWM53T2H FCCAH -
PWM53T2L FCCBH
PWM54T1H FCD0H -
PWM54T1L FCD1H
PWM54T2H FCD2H -
PWM54T2L FCD3H
PWM55T1H FCD8H -
PWM55T1L FCD9H
PWM55T2H FCDAH -
PWM55T2L FCDBH
PWM56T1H FCE0H -
PWM56T1L FCE1H
PWM56T2H FCE2H -
PWM56T2L FCE3H
PWM57T1H FCE8H -
PWM57T1L FCE9H
PWM57T2H FCEAH -
PWM57T2L FCEBH
PWMniT1H: The upper 7 bits of T1 counter value of channel i of PWMn. (n= 0~5 and i= 0~7)
PWMniT1L: The lower 8 bits of T1 counter value of channel i of PWMn. (n= 0~5 and i= 0~7)
PWMniT2H: The upper 7 bits of T2 counter value of channel i of PWMn. (n= 0~5 and i= 0~7)
PWMniT2L: The lower 8 bits of T2counter value of channel i of PWMn. (n= 0~5 and i= 0~7)
{PWMniT1H, PWMniT1L} and {PWMniT2H, PWMniT2L} of every channel of every PWMn are combined
into two 15-bit registers, which are used to control the two flip points of the PWM output waveform in
every PWM cycle of each PWM. During the counting cycle of PWMn, the output of PWM will be low
level when the internal counting value of PWMn is equal to the value of T1 set by{PWMniT1H,
PWMniT1L}. And the output of the PWM will be high level when the internal counting value of PWM is
queal to the value of the T2 set by {PWMnT2H, PWMnT2L}.
Note: When the values of {PWMniT1H, PWMniT1L} and {PWMniT2H, PWMniT2L} are set equal, and if the
internal count value of PWM is equal to the set value of T1 / T2, it will output low level.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 561 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 562 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 563 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P2M1 = 0x00;
P3M0 = 0x00;
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;
PWM0CKS = 0x00; //The clock of PWM0 is the system clock
PWM0C = 0x1000; //Set the PWM0 cycle to 1000H PWM clocks
PWM00T1= 0x0100; //At the count value of 100H, the PWM00 channel outputs low level.
PWM00T2= 0x0500; //At the count value of 500H, the PWM00 channel outputs high level.
PWM00CR= 0x80; //enable PWM00 output
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV PWMSET,#01H ;Enable PWM0 module (The configuration is effective only after the
module is enabled.)
MOV P_SW2,#80H
CLR A
MOV DPTR,#PWM0CKS
MOVX @DPTR,A ;The clock of PWM0 is the system clock
MOV A,#10H
MOV DPTR,#PWM0CH ;Set the PWM0 cycle to 1000H PWM clocks
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM0CL
MOVX @DPTR,A
MOV A,#01H
MOV DPTR,#PWM00T1H ;At the count value of 100H, the PWM00 channel outputs low level.
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T1L
MOVX @DPTR,A
MOV A,#05H
MOV DPTR,#PWM00T2H ;At the count value of 500H, the PWM00 channel outputs high level.
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T2L
MOVX @DPTR,A
MOV A,#80H
MOV DPTR,#PWM00CR ;enable PWM00 output
MOVX @DPTR,A
MOV P_SW2,#00H
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 565 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 566 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
PWM0CKS = 0x00; //The clock of PWM0 is the system clock
PWM0C = 0x0800; //Set the PWM0 cycle to 0800H PWM clocks
PWM00T1= 0x0100; //At the count value of 100H, PWM00 outputs low level.
PWM00T2= 0x0700; //At the count value of 700H, PWM00 outputs high level.
PWM01T2= 0x0080; //At the count value of 0080H, PWM01 outputs high level.
PWM01T1= 0x0780; //At the count value of 0780H, PWM01 outputs low level.
PWM00CR= 0x80; //enable PWM00 output
PWM01CR= 0x80; //enable PWM01 output
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 567 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
CLR A
MOV DPTR,#PWM0CKS
MOVX @DPTR,A ;The clock of PWM0 is the system clock
MOV A,#08H
MOV DPTR,#PWM0CH ;Set the PWM0 cycle to 0800H PWM clocks
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM0CL
MOVX @DPTR,A
MOV A,#01H
MOV DPTR,#PWM00T1H ;At the count value of 0100H, PWM00 outputs low level.
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T1L
MOVX @DPTR,A
MOV A,#07H
MOV DPTR,#PWM00T2H ;At the count value of 0700H, PWM00 outputs high level.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 568 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T2L
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM01T2H ;At the count value of 0080H, PWM01 outputs high level.
MOVX @DPTR,A
MOV A,#80H
MOV DPTR,#PWM01T2L
MOVX @DPTR,A
MOV A,#07H
MOV DPTR,#PWM01T1H ;At the count value of 0780H, PWM01 outputs low level.
MOVX @DPTR,A
MOV A,#80H
MOV DPTR,#PWM01T1L
MOVX @DPTR,A
MOV A,#080H
MOV DPTR,#PWM00CR ;enable PWM00 output
MOVX @DPTR,A
MOV A,#80H
MOV DPTR,#PWM01CR ;enable PWM01 output
MOVX @DPTR,A
MOV P_SW2,#00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 570 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
PWM0CKS = 0x00; // The clock of PWM0 is the system clock
PWM0C = CYCLE; //Set PWM0 period
PWM00T1= 0x0000;
PWM00T2= 0x0001;
PWM00CR= 0x80; //enable PWM00 output
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00B3H
LJMP PWM0ISR
ORG 0100H
PWM0ISR:
PUSH ACC
PUSH PSW
PUSH DPL
PUSH DPH
PUSH P_SW2
MOV P_SW2,#80H
MOV A,PWMCFG01
JNB ACC.3,ISREXIT
ANL PWMCFG01,#NOT 08H ;Clear interrupt flag
JNB DIR,PWMDN
PWMUP:
MOV A,VALL
ADD A,#1
MOV VALL,A
MOV A,VALH
ADDC A,#0
MOV VALH,A
CJNE A,#HIGH CYCLE,SETPWM
MOV A,VALL
CJNE A,#LOW CYCLE,SETPWM
CLR DIR
JMP SETPWM
PWMDN:
MOV A,VALL
ADD A,#0FFH
MOV VALL,A
MOV A,VALH
ADDC A,#0FFH
MOV VALH,A
JNZ SETPWM
MOV A,VALL
CJNE A,#1,SETPWM
SETB DIR
SETPWM:
MOV A,VALH
MOV DPTR,#PWM00T2H
MOVX @DPTR,A
MOV A,VALL
MOV DPTR,#PWM00T2L
MOVX @DPTR,A
ISREXIT:
POP P_SW2
POP DPH
POP DPL
POP PSW
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 572 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB DIR
MOV VALH,#00H
MOV VALL,#01H
MOV P_SW2,#80H
CLR A
MOV DPTR,#PWM0CKS
MOVX @DPTR,A ;The clock of PWM0 is the system clock
MOV A,#HIGH CYCLE
MOV DPTR,#PWM0CH ;Set PWM0 period
MOVX @DPTR,A
MOV A,#LOW CYCLE
MOV DPTR,#PWM0CL
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T1H
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T1L
MOVX @DPTR,A
MOV A,VALH
MOV DPTR,#PWM00T2H
MOVX @DPTR,A
MOV A,VALL
MOV DPTR,#PWM00T2L
MOVX @DPTR,A
MOV A,#80H
MOV DPTR,#PWM00CR ;enable PWM00 output
MOVX @DPTR,A
MOV P_SW2,#00H
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 573 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 574 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void delay()
{
int i;
for (i=0; i<100; i++);
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
PWM0CKS = 0x00; // The clock of PWM0 is the system clock
PWM0C = 0x1000; // Set the period of PWM0 to 1000H PWM clocks
PWM00T1= 0x0100; // When the count value is 100H, the PWM00 channel outputs low level
PWM00T2= 0x0500; // When the count value is 500H, the PWM00 channel outputs high level
PWM0TADC = 0x0200; // Set ADC trigger point
PWM00CR= 0x80; //Enable PWM00 output
P_SW2 = 0x00;
PWMCFG01 = 0x07; // Start the PWM0 module and enable the PWM0 interrupt and ADC trigger
EA = 1;
while (1);
}
Assembly code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 575 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 002BH
LJMP ADCISR
ORG 00B3H
LJMP PWM0ISR
ORG 0100H
ADCISR:
ANL ADC_CONTR,#NOT ADC_FLAG
RETI
PWM0ISR:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 576 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PUSH ACC
MOV A,PWMCFG01
JNB ACC.3,ISREXIT
ANL PWMCFG01,#NOT 08H
ISREXIT:
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
CLR A
MOV DPTR,#PWM0CKS
MOVX @DPTR,A ; The clock of PWM0 is the system clock
MOV A,#10H
MOV DPTR,#PWM0CH ; Set the period of PWM0 to 1000H PWM clocks
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM0CL
MOVX @DPTR,A
MOV A,#01H
MOV DPTR,#PWM00T1H ; When the count value is 100H, the PWM00 channel
outputs low level
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T1L
MOVX @DPTR,A
MOV A,#05H
MOV DPTR,#PWM00T2H ; When the count value is 500H, the PWM00 channel
outputs high level
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM00T2L
MOVX @DPTR,A
MOV A,#02H
MOV DPTR,#PWM0TADCH ; Set ADC trigger point
MOVX @DPTR,A
MOV A,#00H
MOV DPTR,#PWM0TADCL
MOVX @DPTR,A
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 577 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV A,#80H
MOV DPTR,#PWM00CR ; Enable PWM00 output
MOVX @DPTR,A
MOV P_SW2,#00H
MOV PWMCFG01,#07H ; Start the PWM0 module and enable the PWM0 interrupt
and ADC trigger
SETB EA
JMP $
END
C language code
//Operating frequency for test is 24MHz
#include "reg51.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 578 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void PWM2_config(void);
void main(void)
{
PWM2_config();
while (1);
}
//========================================================================
// Function: void PWM2_config(void)
// Description: PWM configure function
// Parameters: none.
// Return: none.
// Version: VER1.0
// Date: 2020-5-17
// Note:
//========================================================================
void PWM2_config(void)
{
EAXSFR(); // Access the macros in the XFR. header file.
PWMCFG23 &= 0xf0;
PWMSET |= ENPWM2; //Enable P2(P2.0~P2.7) as PWM
PWM2CKS = CKS_1T; //Select PWM2 clock, CKS_TIMER2, CKS_1T ~ CKS_16T
PWM2C = 480; //Set PWM2 period = PWM2C + 1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 579 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
PWMCFG23 |= PWM2CEN; //Starts counter, PWM output begins, initialize the last
executed statement
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 580 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Method 2: PWM00T2 sets the output high level moment (generally sets it to 0)
PWM00T1 sets the output low level time, and PWM00T1-PWM00T2 is the output high level time.
If the value of PWM00T1 is set larger than the period value, the low level will not be output, and 100% duty
cycle will be output.
C language code
//Operating frequency for test is 24MHz
#include "reg51.h"
#include "intrins.h"
sfr P6 = 0xE8;
sfr P7 = 0xF8;
void main()
{
P0M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 582 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Period = 0x1000;
DirFlag = 0;
PWMSET = 0x01; // Enable the PWM0 module (must enable the following
settings of the module to be effective)
P_SW2 = 0x80; // Enable XFR access
PWM0CKS = 0x00; // PWM0 clock is the system clock
PWM00T1= 0x0000; // When the count value is 00H, the PWM00 channel
outputs low level
PWM00CR= 0x80; // Enable PWM00 output
EA = 1;
while (1)
{
delay_ms(10);
PeriodSet(Period); // Set period and duty
PWMCFG01 = 0x05; // Start the PWM0 module, enable the counter zero
interrupt
if(DirFlag)
{
Period++; // Cycle increment
if(Period >= 0x1000)
{
DirFlag = 0;
}
}
else
{
Period--; // Cycle decreasement
if(Period <= 0x0100)
{
DirFlag = 1;
}
}
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 583 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Counter = 0;
PWMCFG01 = 0x00;
}
else
{
PWMCFG01 &= ~0x08; // Clear flag
}
}
}
//========================================================================
// Function: void PeriodSet(unsigned int period)
// Description: PWM period setting function.
// Parameters: period, The number of periods to set.
// Return: none.
// Version: VER1.0
// Date: 2021-08-23
// Note:
//========================================================================
void PeriodSet(unsigned int period)
{
PWM0C = period; // Set the period of PWM0 to period PWM clocks
PWM00T2= (period>>1); // When the count value is Period/2, the PWM00 channel
outputs high level
}
//========================================================================
// Function: void delay_ms(unsigned char ms)
// Description: delay function
// Parameters: ms, number of ms to delay, Here only support 1~255ms. Automatically adapt to the main clock.
// Return: none.
// Version: VER1.0
// Date: 2021-01-05
// Note:
//========================================================================
void delay_ms(unsigned char ms)
{
unsigned int i;
do{
i = MAIN_Fosc / 10000;
while(--i);
}while(--ms);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 584 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8G1K08 family ●
STC8G1K08-8Pin family ●
STC8G1K08A family ●
STC8G2K64S4 family ●
STC8G2K64S2 family ●
STC8G1K08T family ●
STC15H2K64S4 family ●
A high-speed serial communication interface, SPI, is integrated in STC8G series of microcontrollers. SPI is
a full-duplex high-speed synchronous communication bus. SPI interface integrated in the STC8G series of
microcontrollers offers two operation modes: master mode and slave mode.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 586 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Master settings: SSIG set to 1, MSTR set to 1, fixed to be master mode. The master can use any port to
connect the slave SS pin, pull down the slave SS pin to enable the slave.
Slave settings: SSIG is set to 0, SS pin as the chip select signal of the slave.
Master Slave
MISO MISO
MOSI MOSI
SCLK SCLK
GPIO SS
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 587 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Device 1 Device 2
MISO MISO
MOSI MOSI
SCLK SCLK
SS SS
Master Slaves
MISO MISO
MOSI MOSI
SCLK SCLK
GPIO SS
GPIO
MISO
MOSI
SCLK
SS
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 588 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
When CPHA = 0, SSIG must be 0 (i.e. SS pin can not be ignored). The SS pin must be pulled low before
each serial byte begins transfer and must be reset to high after the transfer completes. The SPDAT register can
not be written while the SS pin is low, otherwise a write collision error will occur. Operation with CPHA = 0
and SSIG = 1 is undefined.
When CPHA = 1, SSIG may be set to 1 (i.e. the SS pin can be ignored). If SSIG = 0, the SS pin may
remain active low (i.e., stay low all the way) for consecutive transfers. This method is suitable for fixed single
master single slave system.
In SPI, transfers are always initiated by the master. If the SPI is enabled (SPEN = 1) and selected as the
master, the master will initiate SPI clock generator and data transfer by writing to SPI data register, SPDAT. The
data will appear on the MOSI pin a half to one SPI bit-time later after the data is written to SPDAT. The data
written to the SPDAT register of the master is shifted out from the MOSI pin and sent to the MOSI pin of the
slave. And, at the same time the data in SPDAT register of the selected slave is shifted out on MISO pin to the
MISO pin of the master.
After one byte has been transmitted, the SPI clock generator is stopped, the transfer completion flag (SPIF)
is set, and an SPI interrupt is generated if the SPI interrupt is enabled. The two shift registers for the master and
slave CPUs 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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 589 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
device as an SPI slave and send data to it. To avoid bus contention, the SPI system clears the slave's MSTR,
forces MOSI and SCLK to be input mode, and MISO changes to output mode. The SPIF flag in SPSTAT is set,
and if the SPI interrupt is enabled, an SPI interrupt will occur.
The user software must always detect the MSTR bit. If this bit is cleared by a slave selection action and the
user wants to continue using the SPI as a master, the MSTR bit must be set again, otherwise it will remain in
slave mode.
Write Collision
The SPI is single buffered in the transmition process and double buffered in receiving process. New data
for transmission can not be written to the shift register until the previous transmission is complete. The WCOL
bit will be set to indicate that a data write collision error has occurred when the data register SPDAT is written
during transmission. In this case, the data currently being transmitted will continue to be transmitted, and the
newly written data will be lost.
A write collision condition on the master is rare when write collision detection is performed on a master or
slave because the master has full control of the data transfer. However, a write collision may occur on the slave
because the slave can not control it when the master initiates the transfer.
When receiving data, the received data is transferred to a parallel read data buffer, which will release the
shift register for the next data reception. However, the received data must be read from the data register before
the next character is completely shifted in. Otherwise, the previous received data will be lost.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 590 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
1 2 3 4 5 6 7 8
SCLK (CPOL=0)
SCLK (CPOL=1)
Sample at the leading edge
DORD=0 MSB 6 5 4 3 2 1 LSB
MOSI (input) DORD=1 LSB 1 2 3 4 5 6 MSB
Change data at the trailing edge
MISO (output) DORD=0
DORD=1
MSB
LSB
6
1
5
2
4
3
3
4
2
5
1
6
LSB
MSB
The falling edge triggers the slave to send the 1st bit of data Invalid data
SS (If SSIG=0)
1 2 3 4 5 6 7 8
SCLK (CPOL=0)
SCLK (CPOL=1)
Sample at the trailing edge
DORD=0 MSB 6 5 4 3 2 1 LSB
MOSI (input) DORD=1 LSB 1 2 3 4 5 6 MSB
Drive at the leading edge
MISO (output) DORD=0
DORD=1
MSB
LSB
6
1
5
2
4
3
3
4
2
5
1
6
LSB
MSB
Invalid data
SS (If SSIG=0)
1 2 3 4 5 6 7 8
SCLK (CPOL=0)
SCLK (CPOL=1)
Change data at the trailing edge
MOSI (output) DORD=0
DORD=1
MSB
LSB
6
1
5
2
4
3
3
4
2
5
1
6
LSB
MSB
Sample at the leading edge
MISO (input) DORD=0
DORD=1
MSB
LSB
6
1
5
2
4
3
3
4
2
5
1
6
LSB
MSB
SS (If SSIG=0)
SPI master transfer format with CPHA=0
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 591 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
1 2 3 4 5 6 7 8
SCLK (CPOL=0)
SCLK (CPOL=1)
Sample at the trailing edge
MOSI (output) DORD=0
DORD=1
MSB
LSB
6
1
5
2
4
3
3
4
2
5
1
6
LSB
MSB
Drive at the leading edge
MISO (input) DORD=0
DORD=1
MSB
LSB
6
1
5
2
4
3
3
4
2
5
1
6
LSB
MSB
SS (If SSIG=0)
SPI master transfer format with CPHA=1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 592 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
sbit SS = P1^0;
sbit LED = P1^1;
bit busy;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 593 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
LED = 1;
SS = 1;
busy = 0;
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
ORG 0000H
LJMP MAIN
ORG 004BH
LJMP SPIISR
ORG 0100H
SPIISR:
MOV SPSTAT,#0C0H ;Clear interrupt flag
SETB SS ;Pull up the SS pin of the slave
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 594 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CLR BUSY
CPL LED
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB LED
SETB SS
CLR BUSY
LOOP:
JB BUSY,$
SETB BUSY
CLR SS ;Pull down the slave SS pin
MOV SPDAT,#5AH ;Send test data
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 595 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 004BH
LJMP SPIISR
ORG 0100H
SPIISR:
MOV SPSTAT,#0C0H ;Clear interrupt flag
MOV SPDAT,SPDAT ;Transmit the received data back to the master
CPL LED
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 597 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "intrins.h"
sbit SS = P1^0;
sbit LED = P1^1;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
LED = 1;
SS = 1;
while (1)
{
SS = 0; //Pull down the slave SS pin
SPDAT = 0x5a; //Send test data
while (!(SPSTAT & 0x80)); //Query completion flag
SPSTAT = 0xc0; //Clear interrupt flag
SS = 1; //Pull up the SS pin of the slave
LED = !LED; //Test port
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 598 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SS BIT P1.0
LED BIT P1.1
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB LED
SETB SS
LOOP:
CLR SS ;Pull down the slave SS pin
MOV SPDAT,#5AH ;Send test data
MOV A,SPSTAT ;Query completion flag
JNB ACC.7,$-2
MOV SPSTAT,#0C0H ;Clear interrupt flag
SETB SS
CPL LED
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 599 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 600 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
while (!(SPSTAT & 0x80)); //Query completion flag
SPSTAT = 0xc0; //Clear interrupt flag
SPDAT = SPDAT; //Transmit the received data back to the master
LED = !LED; //Test port
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
LOOP:
MOV A,SPSTAT ;Query completion flag
JNB ACC.7,$-2
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 601 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
sbit SS = P1^0;
sbit LED = P1^1;
sbit KEY = P0^0;
void main()
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 602 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
LED = 1;
KEY = 1;
SS = 1;
while (1)
{
if (!KEY) //Wait for the key to trigger
{
SPCTL = 0x50; //Enable SPI master mode
SS = 0; //Pull down the slave SS pin
SPDAT = 0x5a; //Send test data
while (!KEY); //Wait for the keys to be released
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
SS BIT P1.0
LED BIT P1.1
KEY BIT P0.0
ORG 0000H
LJMP MAIN
ORG 004BH
LJMP SPIISR
ORG 0100H
SPIISR:
PUSH ACC
MOV SPSTAT,#0C0H ;Clear interrupt flag
MOV A,SPCTL
JB ACC.4,MASTER
SLAVE:
MOV SPDAT,SPDAT ;Transmit the received data back to the master
JMP ISREXIT
MASTER:
SETB SS ;Pull up the SS pin of the slave
MOV SPCTL,#40H ;Reset to slave and standby
ISREXIT:
CPL LED
POP ACC
RETI
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
SETB SS
SETB LED
SETB KEY
LOOP:
JB KEY,LOOP ;Wait for the key to trigger
MOV SPCTL,#50H ;Enable SPI master mode
CLR SS ;Pull down the slave SS pin
MOV SPDAT,#5AH ;Send test data
JNB KEY,$ ;Wait for the keys to be released
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 604 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
sbit SS = P1^0;
sbit LED = P1^1;
sbit KEY = P0^0;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
LED = 1;
KEY = 1;
SS = 1;
while (1)
{
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 605 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Assembly code
;Operating frequency for test is 11.0592MHz
SS BIT P1.0
LED BIT P1.1
KEY BIT P0.0
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 606 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SETB SS
SETB LED
SETB KEY
LOOP:
JB KEY,SKIP ;Wait for the key to trigger
MOV SPCTL,#50H ;Enable SPI master mode
CLR SS ;Pull down the slave SS pin
MOV SPDAT,#5AH ;Send test data
JNB KEY,$ ;Wait for the keys to be released
SKIP:
MOV A,SPSTAT
JNB ACC.7,LOOP
MOV SPSTAT,#0C0H ;Clear interrupt flag
MOV A,SPCTL
JB ACC.4,MASTER
SLAVE:
MOV SPDAT,SPDAT ;Transmit the received data back to the master
CPL LED
JMP LOOP
MASTER:
SETB SS ;Pull up the SS pin of the slave
MOV SPCTL,#40H ;Reset to slave and standby
CPL LED
JMP LOOP
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 607 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
20 I2C Bus
STC8G1K08 family ●
STC8G1K08-8Pin family ●
STC8G1K08A family ●
STC8G2K64S4 family ●
STC8G2K64S2 family ●
STC8G1K08T family ●
STC15H2K64S4 family ●
An I2C serial bus controller is integrated in the STC8G series of microcontrollers. I2C is a high-speed
synchronous communication bus, which uses SCL (clock line) and SDA (data line) to carry out two-wire
synchronous communication. For the port allocation of SCL and SDA, STC8G series of microcontrollers
provide pin switch mode that can switch SCL and SDA to different I/O ports. Therefor, it is convenience to use
a set of I2C as multiple sets of I2C buses through time sharing.
Compared with the standard I2C protocol, the following two mechanisms are ignored:
No timeout detection when the clock signal (SCL) stays at low level.
The I2C bus of the STC8G series of microcontrollers offer two modes of operation: master mode (SCL is
the output port, which is used to transmit synchronous clock signal) and slave mode (SCL is the input port,
which is used to receive the synchronous clock signal).
STC innovation: When the I2C 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 I2C transmission speed,
the first packet of data after the MCU wakes up is generally incorrect.)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 608 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SCL
SDA
TSSTA TSSTO THCKL
Fixed to 1 clock
THSTA THSTO THCKH
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 609 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SCL
SDA
(output)
SCL
SDA
D7 D6 D5 D4 D3 D2 D1 D0
(output)
SCL
SDA
ACK
(input)
SCL
SDA
D7 D6 D5 D4 D3 D2 D1 D0
(input)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 610 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SCL
SDA
ACK
(output)
SCL
SDA
(output)
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.
This command is a combination of command 0010 and command 0011. After writing this command,
the controller will execute these two commands in sequence.
1011: Receive data command + send ACK (0) command.
This command is a combination of command 0100 and command 0101. After writing this command,
the controller will execute these two commands in sequence.
Note: The response signal returned by this command is fixed as ACK (0) and is not affected by the
MSACKO bit.
1100: Receive data command + send NAK (1) command.
This command is a combination of command 0100 and command 0101. After writing this command,
the controller will execute these two commands in sequence.
Note: The response signal returned by this command is fixed to NAK (1), and is not affected by the
MSACKO bit.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 611 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 612 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SCL
SDA
(input)
STAIF is
set to 1
here
RXIF: interrupt request bit after 1-byte datum is received in slave mode. After the I2C controller in slave mode
receives a 1-byte datum, this bit is set by hardware automatically at the falling edge of the 8th clock and
will request interrupt to CPU. The RXIF bit must be cleared by software after the interrupt is responded.
The time point of RXIF being set is shown in the figure below:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 613 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SCL
SDA
D7 D6 D5 D4 D3 D2 D1 D0 ACK
(input)
TXIF: interrupt request bit after 1-byte datum transmission is completed in slave mode. After the I2C 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 9th clock and requests an interrupt to CPU. TXIF
bit must be cleared by software after the interrupt is responded. The time point of TXIF being set is shown
below:
SCL
SDA
D7 D6 D5 D4 D3 D2 D1 D0 ACK
(output)
STOIF: interrupt request bit after STOP signal is received in slave mode. After the I2C controller in slave mode
receives the STOP signal, this bit is set by hardware automatically and requests interrupt to CPU. The
STOIF bit must be cleared by software after the interrupt is serviced. The time point of STOIF being set is
shown below:
SCL
SDA
(input)
SDA
A6 A5 A4 A3 A2 A1 A0 R/W ACK
(input)
SCL
SDA D7 D6 D5 D4 D3 D2 D1 D0 ACK
R/W
I2CSLADR
A7 A6 A5 A4 A3 A2 A1 1
register
MA
SCL
SDA D7 D6 D5 D4 D3 D2 D1 D0 ACK
R/W
I2CSLADR
A7 A6 A5 A4 A3 A2 A1 0
register
MA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 615 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
bit busy;
void Start()
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 616 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
busy = 1;
I2CMSCR = 0x81; //Send START command
while (busy);
}
void RecvACK()
{
busy = 1;
I2CMSCR = 0x83; //Send read ACK command
while (busy);
}
char RecvData()
{
busy = 1;
I2CMSCR = 0x84; //Send RECV command
while (busy);
return I2CRXD;
}
void SendACK()
{
I2CMSST = 0x00; //Setup the ACK signal
busy = 1;
I2CMSCR = 0x85; //Send ACK command
while (busy);
}
void SendNAK()
{
I2CMSST = 0x01; //Setup the NAK signal
busy = 1;
I2CMSCR = 0x85; //Send ACK command
while (busy);
}
void Stop()
{
busy = 1;
I2CMSCR = 0x86; //Send STOP command
while (busy);
}
void Delay()
{
int i;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 617 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
_nop_();
_nop_();
_nop_();
}
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
P_SW2 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 618 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00C3H
LJMP I2CISR
ORG 0100H
I2CISR:
PUSH ACC
PUSH DPL
PUSH DPH
POP DPH
POP DPL
POP ACC
RETI
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 619 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
START:
SETB BUSY
MOV A,#10000001B ;Send START command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDDATA:
MOV DPTR,#I2CTXD ;Write data to the data buffer
MOVX @DPTR,A
SETB BUSY
MOV A,#10000010B ;Send a SEND command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVACK:
SETB BUSY
MOV A,#10000011B ;Send read ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVDATA:
SETB BUSY
MOV A,#10000100B ;Send RECV command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
CALL WAIT
MOV DPTR,#I2CRXD ;Read data from the data buffer
MOVX A,@DPTR
RET
SENDACK:
MOV A,#00000000B ;Setup the ACK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
SETB BUSY
MOV A,#10000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDNAK:
MOV A,#00000001B ;Setup the NAK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
SETB BUSY
MOV A,#10000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
STOP:
SETB BUSY
MOV A,#10000110B ;Send STOP command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
WAIT:
JB BUSY,$ ;Wait for the command to be sent
RET
DELAY:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 620 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV R0,#0
MOV R1,#0
DELAY1:
NOP
NOP
NOP
NOP
DJNZ R1,DELAY1
DJNZ R0,DELAY1
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 621 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CALL RECVACK
MOV A,#000H ;Send storage address high byte
CALL SENDDATA
CALL RECVACK
MOV A,#000H ;Send storage address low byte
CALL SENDDATA
CALL RECVACK
CALL START ;Send start command
MOV A,#0A1H ;Send device address + read command
CALL SENDDATA
CALL RECVACK
CALL RECVDATA ;Read data 1
MOV P0,A
CALL SENDACK
CALL RECVDATA ;Read data 2
MOV P2,A
CALL SENDNAK
CALL STOP ;Send stop command
JMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 622 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void Wait()
{
while (!(I2CMSST & 0x40));
I2CMSST &= ~0x40;
}
void Start()
{
I2CMSCR = 0x01; //Send START command
Wait();
}
void RecvACK()
{
I2CMSCR = 0x03; //Send read ACK command
Wait();
}
char RecvData()
{
I2CMSCR = 0x04; //Send RECV command
Wait();
return I2CRXD;
}
void SendACK()
{
I2CMSST = 0x00; //Setup the ACK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void SendNAK()
{
I2CMSST = 0x01; //Setup the NAK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void Stop()
{
I2CMSCR = 0x06; //Send STOP command
Wait();
}
void Delay()
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 623 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
int i;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 624 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
START:
MOV A,#00000001B ;Send START command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDDATA:
MOV DPTR,#I2CTXD ;Write data to the data buffer
MOVX @DPTR,A
MOV A,#00000010B ;Send a SEND command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVACK:
MOV A,#00000011B ;Send read ACK command
MOV DPTR,#I2CMSCR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 625 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOVX @DPTR,A
JMP WAIT
RECVDATA:
MOV A,#00000100B ;Send RECV command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
CALL WAIT
MOV DPTR,#I2CRXD ;Read data from the data buffer
MOVX A,@DPTR
RET
SENDACK:
MOV A,#00000000B ;Setup the ACK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
MOV A,#00000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDNAK:
MOV A,#00000001B ;Setup the NAK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
MOV A,#00000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
STOP:
MOV A,#00000110B ;Send STOP command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
WAIT:
MOV DPTR,#I2CMSST ;Clear interrupt flag
MOVX A,@DPTR
JNB ACC.6,WAIT
ANL A,#NOT 40H
MOVX @DPTR,A
RET
DELAY:
MOV R0,#0
MOV R1,#0
DELAY1:
NOP
NOP
NOP
NOP
DJNZ R1,DELAY1
DJNZ R0,DELAY1
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 626 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV P_SW2,#80H
JMP $
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 627 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void Wait()
{
while (!(I2CMSST & 0x40));
I2CMSST &= ~0x40;
}
void Start()
{
I2CMSCR = 0x01; //Send START command
Wait();
}
void RecvACK()
{
I2CMSCR = 0x03; //Send read ACK command
Wait();
}
char RecvData()
{
I2CMSCR = 0x04; //Send RECV command
Wait();
return I2CRXD;
}
void SendACK()
{
I2CMSST = 0x00; //Setup the ACK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void SendNAK()
{
I2CMSST = 0x01; //Setup the NAK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void Stop()
{
I2CMSCR = 0x06; //Send STOP command
Wait();
}
void Delay()
{
int i;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 629 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
while (1)
{
Start(); //Send start command
SendData(0xa2); //Send device address + write command
RecvACK();
SendData(0x02); //Send storage address
RecvACK();
Start(); //Send start command
SendData(0xa3); //Send device address + read command
RecvACK();
P0 = RecvData(); //Read second value
SendACK();
P2 = RecvData(); //Read minute value
SendACK();
P3 = RecvData(); //Read hour value
SendNAK();
Stop(); //Send stop command
Delay();
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 630 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
START:
MOV A,#00000001B ;Send START command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDDATA:
MOV DPTR,#I2CTXD ;Write data to the data buffer
MOVX @DPTR,A
MOV A,#00000010B ;Send a SEND command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVACK:
MOV A,#00000011B ;Send read ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVDATA:
MOV A,#00000100B ;Send RECV command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
CALL WAIT
MOV DPTR,#I2CRXD ;Read data from the data buffer
MOVX A,@DPTR
RET
SENDACK:
MOV A,#00000000B ;Setup the ACK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
MOV A,#00000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDNAK:
MOV A,#00000001B ;Setup the NAK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
MOV A,#00000101B ;Send ACK command
MOV DPTR,#I2CMSCR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 631 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOVX @DPTR,A
JMP WAIT
STOP:
MOV A,#00000110B ;Send STOP command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
WAIT:
MOV DPTR,#I2CMSST ;Clear interrupt flag
MOVX A,@DPTR
JNB ACC.6,WAIT
ANL A,#NOT 40H
MOVX @DPTR,A
RET
DELAY:
MOV R0,#0
MOV R1,#0
DELAY1:
NOP
NOP
NOP
NOP
DJNZ R1,DELAY1
DJNZ R0,DELAY1
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 632 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CALL SENDDATA
CALL RECVACK
MOV A,#00H ;Set minute value
CALL SENDDATA
CALL RECVACK
MOV A,#12H ;Set hour value
CALL SENDDATA
CALL RECVACK
CALL STOP ;Send stop command
LOOP:
CALL START ;Send start command
MOV A,#0A2H ;Send device address + write command
CALL SENDDATA
CALL RECVACK
MOV A,#002H ;Send storage address
CALL SENDDATA
CALL RECVACK
CALL START ;Send start command
MOV A,#0A3H ;Send device address + read command
CALL SENDDATA
CALL RECVACK
CALL RECVDATA ;Read second value
MOV P0,A
CALL SENDACK
CALL RECVDATA ;Read minute value
MOV P2,A
CALL SENDACK
CALL RECVDATA ;Read hour value
MOV P3,A
CALL SENDNAK
CALL STOP ;Send stop command
CALL DELAY
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 634 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
_pop_(P_SW2);
}
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 00C3H
LJMP I2CISR
ORG 0100H
I2CISR:
PUSH ACC
PUSH PSW
PUSH DPL
PUSH DPH
MOV DPTR,#I2CSLST ;Detect slave status
MOVX A,@DPTR
JB ACC.6,STARTIF
JB ACC.5,RXIF
JB ACC.4,TXIF
JB ACC.3,STOPIF
ISREXIT:
POP DPH
POP DPL
POP PSW
POP ACC
RETI
STARTIF:
ANL A,#NOT 40H ;Handle the START event
MOVX @DPTR,A
JMP ISREXIT
RXIF:
ANL A,#NOT 20H ;Handle the RECV event
MOVX @DPTR,A
MOV DPTR,#I2CRXD
MOVX A,@DPTR
JBC ISDA,RXDA
JBC ISMA,RXMA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 636 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 637 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
;If the host needs to write data, it must send 5AH (0101_1010B)
;If the host needs to read data, it must send 5BH (0101_1011B)
MOV DPTR,#I2CSLADR
MOVX @DPTR,A
MOV A,#00000000B
MOV DPTR,#I2CSLST
MOVX @DPTR,A
MOV A,#01111000B ;Enable interrupt of slave mode
MOV DPTR,#I2CSLCR
MOVX @DPTR,A
SETB EA
SJMP $
END
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
while (1)
{
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; //Handle the RECV event(RECV MEMORY ADDR)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 639 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
addr = I2CRXD;
I2CTXD = buffer[addr];
}
else
{
buffer[addr++] = I2CRXD; //Handle the RECV event(RECV DATA)
}
}
else if (I2CSLST & 0x10)
{
I2CSLST &= ~0x10; //Handle the SEND event
if (I2CSLST & 0x02)
{
I2CTXD = 0xff; //Stop receiving data when receiving NAK
}
else
{
I2CTXD = buffer[++addr]; //Continue reading data when receiving ACK
}
}
else if (I2CSLST & 0x08)
{
I2CSLST &= ~0x08; //Handle the STOP event
isda = 1;
isma = 1;
}
}
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
LOOP:
MOV DPTR,#I2CSLST ;Detect slave status
MOVX A,@DPTR
JB ACC.6,STARTIF
JB ACC.5,RXIF
JB ACC.4,TXIF
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 641 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JB ACC.3,STOPIF
JMP LOOP
STARTIF:
ANL A,#NOT 40H ;Handle the START event
MOVX @DPTR,A
JMP LOOP
RXIF:
ANL A,#NOT 20H ;Handle the RECV event
MOVX @DPTR,A
MOV DPTR,#I2CRXD
MOVX A,@DPTR
JBC ISDA,RXDA
JBC ISMA,RXMA
MOV R0,ADDR ;Handle the RECV event(RECV DATA)
MOVX @R0,A
INC ADDR
JMP LOOP
RXDA:
JMP LOOP ;Handle the RECV event(RECV DEVICE ADDR)
RXMA:
MOV ADDR,A ;Handle the RECV event(RECV MEMORY ADDR)
MOV R0,A
MOVX A,@R0
MOV DPTR,#I2CTXD
MOVX @DPTR,A
JMP LOOP
TXIF:
ANL A,#NOT 10H ;Handle the SEND event
MOVX @DPTR,A
JB ACC.1,RXNAK
INC ADDR
MOV R0,ADDR
MOVX A,@R0
MOV DPTR,#I2CTXD
MOVX @DPTR,A
JMP LOOP
RXNAK:
MOVX A,#0FFH
MOV DPTR,#I2CTXD
MOVX @DPTR,A
JMP LOOP
STOPIF:
ANL A,#NOT 08H ;Handle the STOP event
MOVX @DPTR,A
SETB ISDA
SETB ISMA
JMP LOOP
END
C language code
//Operating frequency for test is 11.0592MHz
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 642 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
void Wait()
{
while (!(I2CMSST & 0x40));
I2CMSST &= ~0x40;
}
void Start()
{
I2CMSCR = 0x01; //Send START command
Wait();
}
void RecvACK()
{
I2CMSCR = 0x03; //Send read ACK command
Wait();
}
char RecvData()
{
I2CMSCR = 0x04; //Send RECV command
Wait();
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 643 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
return I2CRXD;
}
void SendACK()
{
I2CMSST = 0x00; //Setup the ACK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void SendNAK()
{
I2CMSST = 0x01; //Setup the NAK signal
I2CMSCR = 0x05; //Send ACK command
Wait();
}
void Stop()
{
I2CMSCR = 0x06; //Send STOP command
Wait();
}
void Delay()
{
int i;
void main()
{
P0M0 = 0x00;
P0M1 = 0x00;
P1M0 = 0x00;
P1M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
P3M0 = 0x00;
P3M1 = 0x00;
P4M0 = 0x00;
P4M1 = 0x00;
P5M0 = 0x00;
P5M1 = 0x00;
P_SW2 = 0x80;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 644 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
P_SW2 = 0x00;
while (1);
}
Assembly code
;Operating frequency for test is 11.0592MHz
ORG 0000H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 645 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
LJMP MAIN
ORG 0100H
START:
MOV A,#00000001B ;Send START command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDDATA:
MOV DPTR,#I2CTXD ;Write data to the data buffer
MOVX @DPTR,A
MOV A,#00000010B ;Send a SEND command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVACK:
MOV A,#00000011B ;Send read ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
RECVDATA:
MOV A,#00000100B ;Send RECV command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
CALL WAIT
MOV DPTR,#I2CRXD ;Read data from the data buffer
MOVX A,@DPTR
RET
SENDACK:
MOV A,#00000000B ;Setup the ACK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
MOV A,#00000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
SENDNAK:
MOV A,#00000001B ;Setup the NAK signal
MOV DPTR,#I2CMSST
MOVX @DPTR,A
MOV A,#00000101B ;Send ACK command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
STOP:
MOV A,#00000110B ;Send STOP command
MOV DPTR,#I2CMSCR
MOVX @DPTR,A
JMP WAIT
WAIT:
MOV DPTR,#I2CMSST ;Clear interrupt flag
MOVX A,@DPTR
JNB ACC.6,WAIT
ANL A,#NOT 40H
MOVX @DPTR,A
RET
DELAY:
MOV R0,#0
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 646 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV R1,#0
DELAY1:
NOP
NOP
NOP
NOP
DJNZ R1,DELAY1
DJNZ R0,DELAY1
RET
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
MOV P_SW2,#80H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 647 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
JMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 648 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8G1K08 family
STC8G1K08-8Pin family
STC8G1K08A family
STC8G2K64S4 family
STC8G2K64S2 family
STC8G1K08T family ●
STC15H2K64S4 family
A touch key controller or touch sensor unit (TSU in short) is integrated in the STC8G series of
microcontrollers, which can connect up to 16 keys. It can detect the small capacitance changes caused by a
finger touching the key electrode and quantify the capacitance as a 16-bit number. In principle, the TSU module
is similar to a 16-bit ADC. The only difference is that the ADC detects and quantifies the simulated voltage or
current, while the TSU detects and quantifies the capacitor. For touch-key sensing, a fixed capacitor of about
10nF to 47nF needs to be added for application as a reference. If the temperature of the environment changes
rapidly and intensely, a low-temperature drift capacitor should be used to maintain the TSU output data no too
much change, so as to avoid software misjudgment.
A description of continuous sensing of a certain key is shown in the following figure. The counter output
value is near 2572 if there is no finger touch. The counter output becomes near 2443 if there is a finger touch.
The difference of counter output value with or without finger touch is about 5%.
Counter value
No touch
2572
2443
Finger touch
0 Time
The TSU module can connect up to 16 keys. Each touch key port can be independently enabled through the
two 8-bit registers TSCHEN1 and TSCHEN2. The I/O port not used as touch key function can still maintain its
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 649 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
original GPIO or special functions such as LED driver. The frequency of the switched capacitor circuit is
selected through SCR [2: 0]. It is recommended not to exceed 12.5MHz to avoid large errors. There are four
reference voltage segments of the internal comparator of the TSU module for choosing, which is selected
through TSVR [1:0]. Changing the reference voltage will change the touch sensing time and sensitivity.
The touch key scan can be configured to scan continuously or to stop after one round of the enabled key.
This function is controlled by the SINGLE bit. The configuration register TSSAMP [1: 0] allows the TSU
module to scan four times continuously to one channel to sample and calculate the average value of the data. To
do this has the effect of hardware filtering. The WAIT bit allows the TSU module to enter the wait mode when
the TSIF flag is 1. TSU will continue to perform key scans until the software clears the WAIT bit to 0, which
helps the heavy CPU to have enough time to process other things. The value of the external capacitor Cref is
recommended to be in the range of 10nF to 47nF. The time from the initial value of Cref discharging to zero
must be sufficient. This can be adjusted flexibly through DT [2: 0].
When a key scan is completed, the output value of the 16-bit counter will be written to TSDATAH and
TSDATAL. The flag bit TSIF is set to 1 by hardware, and the scanned touch channel number will be written to
TSDNCHN [3: 0]. If the module's external interrupt controller is enabled, TSIF can request interrupt to the CPU.
The software may read the TSDNCHN [3: 0] register content to determine which touch channel requested the
TSIF interrupt. You can get the status of the TSU module being scanned and the number of keys being scanned
in real time by reading TSWKCHN [ 3: 0] and TSGO using software. If the 16-bit counter overflows, the
TSDOV flag will be set to 1 by hardware.
The TSU module can use I/O port in time-sharing multiplexing with the LED driver circuit. It is necessary
to enable the LED driving circuit together and time-multiplex the I/O port when the content of the TSRT
register is not zero, which means that TSGO enables TSU.Therefore, the relevant registers of the TSU module
and the LED driving circuit must be configured in order firstly before TSGO is enabled. In TSU / LED time-
sharing multi-tasking mode, in order to maintain the fixed frame rate of the LED, if the time allocated to the key
scan has arrived but the key being scanned has not been completed, the incomplete key will be rescaned to start
a new key scan.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 650 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
TSWKCHN[2]
TSWKCHN[0]
TSWKCHN[3]
TSWKCHN[1]
TSDNCHN[2]
TSDNCHN[0]
TSDNCHN[3]
TSDNCHN[1]
TSCFG2
LEDWK
TSDOV
TSVR[0]
TSVR[1]
TSIF
TSCHEN1 TSCHEN2
Auto-Scan
Logic
System clock
TSTHHx TSTHLx
Key0
Key1 8 bits 8 bits
Capacitance to
AMUX
TSWUTC
TSWUCS
TSWUEN
TSRT
TSDCEN
TSWAIT
SINGLE
SCR[2]
SCR[1]
SCR[0]
TSGO
TSPD
DT[0]
DT[2]
DT[1]
TSCFG1 TSCTRL
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 651 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2. Set the TSRT content to 0x00, which means that the LED driver time-sharing multi-tasking function is
not enabled.
3. Configure the switching frequency SCR [2: 0] and discharge time DT [2: 0] according to the value of
Cref and the touch key capacitor, and select the internal comparator reference voltage TSVR [1: 0]
according to the required scan time and sensitivity.
4. Configure the SINGLE bit to determine whether the scan is stopped automatically or continuously.
Configure TSSAMP [1: 0] to allow a channel to be resampled up to four times. If the CPU task is heavy,
configure TSWAIT to use the TSIF status to delay scanning of the next channel.
5. Configure TSDCEN to enable internal digital comparison function if necessary.
6. Set TSGO=1 to start the touch key scanning. You can read TSWKCHN [3: 0] to know which channel is
currently being scanned using software. After finish scanning a channel, the hardware will set TSIF to 1,
and the completed channel number will be written into TSDNCHN [3: 0]. If an overflow occurs, TSOV
will also be set to 1. You should read these registers to decide what to do next in your software. TSIF and
TSOV can only be set by hardware and cleared by software.
7. If SINGLE = 1, the hardware will clear TSGO automatically and end scanning after one round of
scanning, otherwise TSGO will remain at 1 and continue the new scanning.
8. If you want to stop the touch key scanning, you can set TSGO to 0 at any time. If you want to reduce
power consumption, you must set TSPD to 1.
DT[2:0]: Configure the initial discharge time of Cref inside the touch key controller to ground
DT[2:0] discharge time
000 125 system clocks
001 250 system clocks
010 500 system clocks
011 1000 system clocks
100 2000 system clocks
101 2500 system clocks
110 5000 system clocks
111 7500 system clocks
TSCV[1:0]: Configure the reference voltage inside the touch key controller
TSCV[1:0] reference voltage
00 1/4 AVCC
01 1/2 AVCC
10 5/8 AVCC
11 3/4 AVCC
F32K
Wake-up frequency =
32 * 8 * TSWUTC[7:0]
Note: If the wake-up frequency is set too fast, the wake-up time is not enough to complete a round of key
scan, and the touch key controller will scan continuously and cannot enter the power saving mode.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 654 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
writing 1 to TSIF in software clears TSIF to 0, and writing 0 to TSIF in software has no effect.
If TSWAIT = 1 and TSIF is 1, the TSU is in the pause and wait state. The next key scan will be
continued after the CPU is busy finished and clears the TSIF to 0.
TSDOV: Key scan data overflow flag (cleared by writing 1 using software)
0: The key scan data does not overflow, the scan data is less than or equal to 0xFFFF.
1: The key scan data overflows, and the scan data is greater than 0xFFFF. At this time, extreme software
configurations (such as TSVR) or system hardware must be adjusted to avoid overflow. TSDOV can
only be set to 1 by hardware. It is cleared by software writing 1 to it. There is no effect on it if software
writing 0 to it.
TSDNCHN [3:0]: Touch channel completion status
TSDNCHN [3:0] Touch channel completion status
0000 Scanning of touch channel 0 is completed
0001 Scanning of touch channel 1 is completed
0010 Scanning of touch channel 2 is completed
0011 Scanning of touch channel 3 is completed
0100 Scanning of touch channel 4 is completed
0101 Scanning of touch channel 5 is completed
0110 Scanning of touch channel 6 is completed
0111 Scanning of touch channel 7 is completed
1000 Scanning of touch channel 8 is completed
1001 Scanning of touch channel 9 is completed
1010 Scanning of touch channel 10 is completed
1011 Scanning of touch channel 11 is completed
1100 Scanning of touch channel 12 is completed
1101 Scanning of touch channel 13 is completed
1110 Scanning of touch channel 14 is completed
1111 Scanning of touch channel 15 is completed
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 657 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
R?
1 20
P1.4 P1.1
VCC 2 19
P1.5 P1.0
3 18
P1.6 P3.7
4 17
P1.7 P3.6
5 16
P1.3 P3.5
6 15
TK_CAP P3.4
7 14
P5.4 P3.3
8 13
VCC P3.2
9 12
10u 104 VREF P3.1
10 11
C? GND P3.0
STC8G1K08T
Note: In the reference circuit diagram, C? is the sensitivity adjustment capacitor for touch keys, and
R? is the ESD protection resistor. In PCB layout, C? and R? must be as close as possible to the
IC pins.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 658 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
22 LED Driver
Product LED
STC8G1K08 family
STC8G1K08-8Pin family
STC8G1K08A family
STC8G2K64S4 family
STC8G2K64S2 family
STC8G1K08T family ●
STC15H2K64S4 family
The LED driver circuit includes a timing controller, 8 COM output pins and 8 SEGMENT output pins.
Each pin has a corresponding register enable bit, which can independently control whether the pin is enabled or
not. Pins that are not enabled can be used as pins for GPIO or other functions.
The LED driver supports three modes: common cathode, common anode, common cathode / common
anode. At the same time, it can select 1/8 ~ 8/8 duty/cycle to adjust the gray scale. So only software is needed to
adjust the LED and digital LED brightness.
After power-on reset, the enable bit LEDON is 0 and the LED driver is turned off. Set LEDON to 1 to
enable the LED driver. If LEDMODE= 00, the driver works in the common cathode mode. At this time, the
selected COM outputs a low level, the selected SEGMENTs to light LED output high level. Therefore, the
forward bias of the LED between the two points of SEGMENT and COM turns on and lights up. Similarly, if
LEDMODE = 01, the driver works in the common anode mode. At this time, the selected COM outputs a high
level, and the selected SEGMENTs to light the LED output low level. The forward bias of the LED lights up. If
LEDMODE = 10, the driver works in the common cathode / common anode time-sharing drive mode. The
COM level is low and high-level time-sharing. The principle of LED lighting is the same as common cathod
and common anode.
In the common cathode mode and the common anode mode, the display RAM address is independent. The
location of display RAM address in the common cathode / common anode time-sharing mode is also read
independently.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 659 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2
LEDMODE 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
Bit processing
LEDDUTY
3
SEGMENT DATA COM DATA
8 8
From GPIO controller From GPIO controller
8 8
SEGEN
MUX COMEN MUX
PAD PAD
SYSclk
LED working frequency =
160 * LEDCKS[7:0]
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 661 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
If the value of the register LEDCKS is set too large, it will cause the LED to flicker. Generally, if the LED
refresh frequency is greater than or equal to 75Hz, there will be no obvious flicker.
SYSclk
suggested value: ≥ 75Hz
160 * 8 * NCOM * LEDCKS[7:0]
For example, if the operating frequency of the microcontroller is 11.0592MHz, the working mode of the LED is
common cathode/common anode mode, COMEN is set to 0FFH, even if there are 8 COMs, 11059200/160/8/16
/ LEDCKS ≥ 75, LEDCKS ≤ 7.2, so LEDCKS is recommended to be set to 7.
1
LED wOrking period (TLED) =
LED working frequency
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 662 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SEG0
D00 D10
SEG1
D01 D11 LED RAM 1 : ON 0: OFF
COM0 COM1
Tn = one TLED cycle SEGx state mapping to LED RAM : 1: High , 0 : Hi-Z
COMx state : active : Low, inactive : Hi-Z
LED clock
D01 OFF D11 OFF D01 OFF D11 OFF D01 OFF
SEG1
Note : LED duty control : change SEGx low pulse width to adjust LED brightness.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 663 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SEG0
D00 D10
SEG1
D01 D11 LED RAM 1 : ON 0: OFF
COM0 COM1
Tn = one TLED cycle SEGx state mapping to LED RAM : 1: Low , 0 : Hi-Z
COMx state : active : High, inactive : Hi-Z
LED clock
D01 OFF D11 OFF D01 OFF D11 OFF D01 OFF
SEG1
Note : LED duty control : change SEGx low pulse width to adjust LED brightness.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 664 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SEG0
D00A D10A D00C D10C
SEG1
D01A D11A D01C D11C
SEG2
D02A D12A D02C D12C
SEG3
D03A D13A D03C D13C
COM1
COM0
Tn = one TLED cycle SEGx state mapping to LED RAM : 1: Low , 0 : Hi-Z
COMx state : active : High, inactive : Hi-Z
LED clock
D01A OFF D01C OFF D01A OFF D11C OFF D01A OFF
SEG1
Note : LED duty control : change SEGx low pulse width to adjust LED brightness.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 665 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
COM0
active state “Low” is determined by LED controller
COM1
COM2
Unfinished channel is terminated due to time-over
TSU reworks on last unfinished channel
Cref
Steps:
1. Select the touch key channel to be scanned. The registers are TSCHEN1 and TSCHEN2.
2. Configure switching frequency SCR [2: 0], discharge time DT [2: 0] and select internal comparator
reference voltage TSVR [1: 0].
3. Configure TSSAMP [1: 0] to determine the number of repeated scans of the same channel. If the CPU
task is heavy, configure TSWAIT to use the TSIF state to delay the next channel scan.
4. If necessary, configure TSDCEN to enable the internal digital comparison function.
5. Set the TSRT content. If the TSRT content is not 0x00, the LED driver time sharing multitasking
function is not enabled.
6. Configure the SEGEN and COMEN registers.
7. Configure LEDCKS to determine the time length of each COM action. This needs to be considered
with the TKRT register to calculate the LED refresh rate.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 666 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
8. Configure LEDMODE [1: 0] and LEDDUTY according to the operating mode and brightness of the
LED required.
9. Write data to the data registers COMx_DC and COM_DA of the LED.
10. Set TSGO=1, the touch key controller starts scanning.
a) You can read TSWKCHN [3: 0] using software to know which channel is currently being
scanned. After a channel is scanned, the hardware will set TSIF to 1 and the completed
channel number will be written into TSDNCHN [3: 0]. If an overflow occurs, TSOV will also
be set to 1. Software should read these registers to decide what to do next. TSIF and TSOV
can only be set by hardware and cleared by software.
b) When switching to the LED working time, the LEDWK bit is read as 1, which is used to
determine whether the touch key controller is working or the LED driver is working.
c) Software continuously updates LED data register according to actual needs.
11. If you want to terminate the touch key and LED time-sharing multi-tasking mode, you need to write
TSGO = 0, then the multi-task mode is terminated, the touch key and LED are not working. And the
control right of the I/O port returns to the GPIO controller.
Note:
1. The SINGLE control bit is invalid in touch key and LED time-sharing multi-tasking mode. Only
software writing TSGO can control the module on and off.
2. When the touch key scan time is terminated and turned to LED action time, the last key is almost
incomplete. At this time, the hardware processing will not produce TSIF, and not update the registers
related to the touch data, but the hardware will remember this channel number. The incomplete
channel will be re-scanned and start a new round of scanning after the LED action period ends and
turn to the touch key scanning time.
3. The circuit diagram of LED and touch multiplexing is as above. It should be noted that the LED's
light-emitting color is different, and the equivalent capacitance of the LED represented will be
different. The larger the capacitance, the more unfavorable the touch button, and the sensitivity will
decrease. Generally speaking, the capacitance value of the red LED may be 35pF, but the yellow light
will be as high as 100pF. At this time, if you want to increase the sensitivity of the touch button, you
can connect a 1N4148 diode in series. The capacitance of 1N4148 is only 4pF, and 1N4148 string a
100pF yellow LED, the parasitic capacitance of the key will be slightly smaller than 4pF.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 667 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C OM0
C OM1
C OM2
C OM3
C OM4
C OM5
C OM6
C OM7
SE G0
SE G1
SE G2
SE G3
SE G4
SE G5
SE G6
SE G7
C OM1
C OM2
C OM3
C OM4
C OM5
C OM6
C OM7
SE G0
SE G1
SE G2
SE G3
SE G4
SE G5
SE G6
SE G7
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 668 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C OM1
C OM2
C OM3
C OM4
C OM5
C OM6
C OM7
SEG0
SEG1
SEG2
SEG3
SEG4
SEG5
SEG6
SEG7
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 669 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
U1
ST C8 G1 K0 8 T
P1 .4 1 20 P1 .1
P1 .4 /A D C4 /M ISO /I2 CS DA /X3 2 O /C C P1 _ 3 /TK 4 /CO M 4 C OM 1 /T K1 /C C P0 /A DC 1 /P1 .1
P1 .5 2 19 P1 .0
P1 .5 /A D C5 /S CL K/I2 C SC L/X3 2 I/C C P2 _ 3 /TK 5 /CO M 5 C OM 0 /T K0 /C C P1 /A DC 0 /P1 .0
P1 .6 3 18 P3 .7
D P1 .6 /A D C6 /R x D _ 3 /M C LK O _ 2 /X TA LO /T K6 /C O M 6SE G7 /T K1 5 /CM P +/CC P2 /C C P2 _ 2 /Tx D _ 2 /IN T3 /P3 .7 D
P1 .7 4 17 P3 .6
P1 .7 /A D C7 /T x D _ 3 /X TA LI/T K7 /C O M 7 SE G6 /T K1 4 /CM P -/C CP 1 _ 2 /R x D _ 2 /IN T2 /A DC 1 4 /P 3 . 6
P1 .3 5 16 P3 .5
P1 .3 /A D C3 /M O SI/T2 C LK O /E CI/CC P0 _ 3 /TK 3 /C OM SE3G5 /T K1 3 /SS_ 4 /CC P0 _ 2 /T0 CL KO /T1 /A DC 1 3 /P 3 . 5
6 15 P3 .4
TK _ C A P SE G4 /T K1 2 /M OS I_ 4 /CM P O/EC I_ 2 /T1 CL KO /T0 /A DC 1 2 /P 3 . 4
P5 .4 7 14 P3 .3
P5 .4 /A D C2 /R ST /M C LK O /S S/T2 /EC I_ 3 /TK 2 /C OM 2 SE G3 /T K1 1 /I2 CS DA _ 4 /M ISO _ 4 /IN T1 /A DC 1 1 /P 3 . 3
V CC 8 13 P3 .2
A VC C /V C C SE G2 /T K1 0 /I2 CS CL _ 4 /SC LK _ 4 /IN T0 /A DC 1 0 /P 3 . 2
9 12 P3 .1
22 uF 10 4 V RE F+ SE G1 /T K9 /T x D /A D C9 /P 3 . 1
10 11 P3 .0
V RE F-/A G ND /GN D SE G0 /T K8 /IN T4 /R x D /A D C8 /P 3 . 0
C OM7
C OM6
C OM5
C OM3
C OM2
C OM1
SEG0
SEG5
SEG1
SEG0
SEG5
SEG1
12
11
10
12
11
10
9
7
36 41AS 36 41AS
b
K1
K2
K3
K1
K2
K3
a
f
C C
P3 .0 SE G0
47 0R
P3 .1 SE G1
K4
K4
d
g
e
c
47 0R
P3 .2 SE G2
1
6
47 0R
P3 .3 SE G3
47 0R
C OM4
C OM0
共阴数码管
SEG4
SEG3
SEG7
SEG2
SEG6
SEG4
SEG3
SEG7
SEG2
SEG6
P3 .4 SE G4
47 0R
P3 .5 SE G5
47 0R
P3 .6 SE G6
C OM7
C OM6
C OM5
C OM3
C OM2
C OM1
SEG0
SEG5
SEG1
SEG0
SEG5
SEG1
B 47 0R B
P3 .7 SE G7
47 0R
12
11
10
12
11
10
9
7
P1 .0 C OM 0
36 41B S 36 41B S
P1 .1 C OM 1
K1
K2
K3
K1
K2
K3
b
a
f
P5 .4 C OM 2
P1 .3 C OM 3
P1 .4 C OM 4
P1 .5 C OM 5
P1 .6 C OM 6
K4
K4
d
g
e
P1 .7 C OM 7 c
1
6
A A
共阳数码管
C OM4
C OM0
SEG4
SEG3
SEG7
SEG2
SEG6
SEG4
SEG3
SEG7
SEG2
SEG6
1 2 3 4
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 670 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P1M0 = 0xff;
P1M1 = 0x00;
P3M0 = 0xff;
P3M1 = 0x00;
P5M0 = 0x10;
P5M1 = 0x00;
P_SW2 = 0x80;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 671 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
COM2_DA = PATTERN[2];
COM3_DA = PATTERN[3];
COM4_DA = PATTERN[4];
COM5_DA = PATTERN[5];
COM6_DA = PATTERN[6];
COM7_DA = PATTERN[7];
COM0_DC = PATTERN[8];
COM1_DC = PATTERN[9];
COM2_DC = PATTERN[10];
COM3_DC = PATTERN[11];
COM4_DC = PATTERN[12];
COM5_DC = PATTERN[13];
COM6_DC = PATTERN[14];
COM7_DC = PATTERN[15];
while (1);
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 672 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
executed.
Instructions related to TSL include:
MOV DPTR,#data16
INC 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. AU0 will be enabled
automatically if AU1 is enabled. If AU0 is enabled alone, there is no effect to AU1. To enable AU1
or AU0 independently, the TA register must be used to trigger the DPS protection mechanism.
For more detail, please refer to the description of the TA register. In addition, DPTR0 / DPTR1
will be incremented / decremented automatically only after executing the following three
instructions.
MOVC A,@A+DPTR
MOVX A,@DPTR
MOVX @DPTR,A
SEL: DPTR register select bit.
0: Default. DPTR0 is selected as current Data pointer.
1: DPTR1 is selected as current Data pointer.
The selection of current DPTR using SEL is valid for the following instructions,
MOV DPTR,#data16
INC DPTR
MOVC A,@A+DPTR
MOVX A,@DPTR
MOVX @DPTR,A
JMP @A+DPTR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 674 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 675 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 676 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOVC A,@A+DPTR ; Read data from the program space indicated by DPTR0,
; When done, DPTR0 increments automatically and select DPTR1 as the current DPTR
MOVX @DPTR,A ; write the content of ACC to XDARA indicated by DPTR1,
; When done, DPTR1 decrements automatically and select DPTR0 as the current DPTR
DJNZ R7,COPY_NEXT ;
SJMP $
END
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN:
MOV SP, #5FH
MOV P0M0, #00H
MOV P0M1, #00H
MOV P1M0, #00H
MOV P1M1, #00H
MOV P2M0, #00H
MOV P2M1, #00H
MOV P3M0, #00H
MOV P3M1, #00H
MOV P4M0, #00H
MOV P4M1, #00H
MOV P5M0, #00H
MOV P5M1, #00H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 677 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
SJMP $
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 678 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Product MDU16
STC8G1K08 family
STC8G1K08-8Pin family ●
STC8G1K08A family ●
STC8G2K64S4 family ●
STC8G2K64S2 family ●
STC8G1K08T family
STC15H2K64S4 family ●
A hardware multiply / divide unit MDU16 is integrated in the STC8G series of microcontrollers. It supports the
following operations,
data normalization (It takes 3 to 20 clocks of operation time)
logical left shift (It takes 3 to 18 clocks of operation time)
logical right shift (It takes 3 to 18 clocks of operation time)
16-bit multiply by 16-bit (It takes 10 clocks of operation time)
16-bit divide by 16-bit (It takes 9 clocks of operation time)
32-bit divide by 16-bit (It takes 17 clocks of operation time)
All operations are based on unsigned integer data types.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 679 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Dividend: {MD3,MD2,MD1,MD0}
Divisor: {MD5,MD4}
Quotient: {MD3,MD2,MD1,MD0}
Remainder: {MD5,MD4}
16-bit divided by 16-bit division:
Dividend: {MD1,MD0}
Divisor: {MD5,MD4}
Quotient: {MD1,MD0}
Remainder: {MD5,MD4}
16-bit multiplicated by 16-bit multiplication:
Multiplicand: {MD1,MD0}
Multiplier: {MD5,MD4}
Product: {MD3,MD2,MD1,MD0}
32-bit logical shift left / logical shift right
Operand: {MD3,MD2,MD1,MD0}
32-bit data normalization:
Operand: {MD3,MD2,MD1,MD0}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 680 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Netizen 2: "With regard to the MDU function of STC8G, I would like to share a little bit of my own experience.
If there is something wrong, please criticize and advise and improve together."
1. Functions 1 and 2 are effective for reducing and expanding integer data. First, when performing double-
operand operations, if the lengths of the two numbers are not the same, they need to be converted to the same
length before the operation is performed. For example, if a 32-bit integer is multiplied by an 8-bit integer, 8 bits
must be converted to 32 bits. Secondly, the result of AD sampling needs to be shifted when it is converted to the
specified digit precision. Finally, for example, for network communication, certain bits of data need to be
extracted for command analysis or data decomposition and synthesis, and displacement is very important. Since
the 8051 only has an instruction to move 1 bit, multi-bit movement requires additional loop code and requires a
lot of instruction cycles. Therefore, using MDU will be several times faster than 51 assembly instructions.
2. Function 3 is a necessary function for converting integers to floating-point numbers. For a full-precision 32-
bit integer, it generally takes more than 100 instruction cycles to implement this function, so the MDU has a
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 681 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
relatively large increase in the speed of rotation. Since the output of AD equipment and various three-axis
acceleration outputs are generally integers (such as 16-bit ones), real number operations and trigonometric
functions must be performed. The output of integers must be converted to floating-point numbers, and every
time This data type conversion must be performed to collect data, and the number of conversions required is a
lot. For high-speed data acquisition and applications such as drone control, the overall performance
improvement is considerable if DMU is used.
3. Function 6 is the necessary division function for fixed-point real number operations. Function 4 is the 16-bit
x 16-bit multiplication operation corresponding to function 6 with 32-bit result. The most common application
of function 6 is scale conversion in data processing. For example, for the integer conversion of a 10-digit AD
collected with a reference voltage of 5 volts, the calculation formula for displaying the 2-digit fixed decimal
point of a 3-digit digital tube is: N32=ADN *500/1023. At this time, as long as (1) send AD sample value AND
to MX (DM1MD0), (2) send 500 to NX (MD5MD4), (3) execute function 4, the result is 32 bits, (4) send 1023
to NX ( MD5MD4), (3) execute function 6, the 16-bit result is in MX, just get it back. Another common
application is to draw dots and lines on dot matrix screens such as TFT, such as digital oscilloscopes, which
require multiplication and division of coordinate transformation-first multiply to a 32-bit integer, and then
divide by a 16-bit integer to get 16 bits result.
4. The combination of function 4 and function 6 is the hardware basis for implementing discrete convolution. If
floating-point acceleration hardware is not used, the realization of the four arithmetic operations of floating-
point numbers is an order of magnitude slower than the realization of the four arithmetic operations of integers.
Therefore, the predecessors invented the method of using integer variables to achieve convolution. First of all,
for example, when we commonly convert JPG image data to RGB image data or vice versa, Fourier transform is
required. Since the length of image data is fixed (8 bits or 16 bits), discrete Fourier transform can be used To
achieve, basically only 8-bit or 16-bit integer multiplication and a very small amount of 32-bit multiplication
and division are used. In this way, our early digital cameras could be realized. Secondly, the common template
processing in PS image processing also uses the two-dimensional matrix convolution method, which also
requires a huge number of integers (8-bit image visual image size requires 16-bit and 32-bit intermediate
calculation results). Adding calculations and using discrete convolution will greatly increase the computing
speed. Therefore, the STC8 microcontroller with MDU can be used not only to collect and display images in
real time, but also to process images in real time. Finally, artificial intelligence also involves a large number of
vector and matrix operations, such as neural network convolution, which can be implemented with a
combination of function 4 and function 6. MDU should be able to be applied in small intelligent scenes. Only to
realize these functions, the cooperation of STC8's enhanced dual data pointer is needed, and a special
knowledge structure is required, and a function library is specially compiled to provide users with use, in order
to give full play to the huge advantages of STC8's MDU.
C language code
//Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 682 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
////////////////////////////////////////////////////////////////////////////////
//16 bits by 16 bits
////////////////////////////////////////////////////////////////////////////////
unsigned long res;
unsigned int dat1, dat2;
////////////////////////////////////////////////////////////////////////////////
//32 bit divided by 16 bit
////////////////////////////////////////////////////////////////////////////////
unsigned long res;
unsigned long dat1;
unsigned int dat2;
////////////////////////////////////////////////////////////////////////////////
// Shift left or right:
////////////////////////////////////////////////////////////////////////////////
unsigned long res;
unsigned long dat1;
unsigned char num; // The number of bits to shift, given by the user
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 684 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
As shown above, select the "Keil Simulation Settings" page firstly, click "Add MCU model to Keil", and in the
following directory selection window that appears, navigate to the installation directory of Keil (usually "C: \
Keil \") , After press "OK" button, the prompt message shown on the right in the following figure appears,
indicating that the installation was successful. The STC Monitor51 emulation driver STCMON51.DLL will also
be installed when adding the header file. The installation directory of the driver and header file is shown above.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 685 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Then select the responding MCU model from the list. Here we select the model of "STC8A8K64S4A12" and
click "OK" to complete the selection.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 686 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Save the project. If there is no error while compiling the project, you can set the following projects.
One additional note:
When a C language project is created and a startup file "STARTUP.A51" is added to the project, there is a
macro definition named "IDATALEN", which is a macro used to define the size of the IDATA. The default
value is 128, which is 80H in hexadecimal, and it is also the size of IDATA in the startup file that needs to be
initialized to 0. Therefor if IDATA is defined as 80H, the code in STARTUP.A51 will initialize the RAM of 00-
7F of IDATA to 0. Similarly, if IDATA is defined as 0FFH, the RAM of 00-FF of IDATA will be initialized to 0.
The IDATA size of the STC8 series of microcontrollers is 256 bytes (DATA of 00-7F and IDATA of 80H-FFH).
Because the last 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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 687 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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. Then complete the setup.
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"
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 688 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
page, click the button of the corresponding model. After the program downloading completes, the simulator is
ready for use.
5.Start simulation
Connect the completed simulation chip to the computer through the serial port.
After compiling the project we created before without errors, press "Ctrl + F5" to start 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.
The current maximum number of breakpoints is 20 (in theory, any number of breakpoints can be set, but too
many breakpoints will affect the speed of debugging).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 689 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
At the bottom of the "Debug" menu in the figure above, there is a small black triangle, which means that there
are hidden items (mainly due to the size of the display layout).
Mouse over the small triangle to drag out all items automatically, as shown below:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 690 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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 use.
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 691 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The figures below are the schematic and PCB layout of the converter board.
1 2 3 4
R3
20 1R
D D
12
11
10
9
8
7
6
5
4
3
2
1
U1 40
V CC
1 39
P1 .0 P0 .0 /A D 0
2 38
P1.6
P1.5
P1.4
P1.3
P1.2
P4.7
P1.1
P1.0
P0.7
P0.6
P0.5
P5.3
P1 .1 P0 .1 /A D 1
3 37
P1 .2 P0 .2 /A D 2
4 13 48 36
P1 .3 P1 .7 P5 .2 P0 .3 /A D 3
5 R ST 14 47 35
P1 .4 P5 .4 P0 .4 P0 .4 /A D 4
6 V CC 1 5 46 34
P1 .5 V CC P0 .3 P0 .5 /A D 5
7 16 45 33
P1 .6 V RE F P0 .2 P0 .6 /A D 6
8 17 44 32
P1 .7 G ND P0 .1 P0 .7 /A D 7
9 18 U2 43 P4 .7 3 1
R ST P4 .0 ST C8 G-4 8 P0 .0 P4 .6 /E A
10 19 42 30
R XD /P3 . 0 P3 .0 P4 .6 P4 .5 /A LE
11 20 41 P4 .6 2 9
TX D /P 3 . 1 P3 .1 A LE/P4 .5 P4 .4 /P SEN
C 12 21 40 28 C
INT 0 /P3 . 2 P3 .2 P2 .7 P2 .7 /A 1 5
13 22 39 27
INT 1 /P3 . 3 P3 .3 P2 .6 P2 .6 /A 1 4
14 23 38 26
T0 /P 3 . 4 P3 .4 P2 .5 P2 .5 /A 1 3
P4.2/WR
15 24
P4.4/RD
37 25
T1 /P 3 . 5 P5 .0 P2 .4 P2 .4 /A 1 2
16 24
W R /P3 . 6
P5.1
P3.5
P3.6
P3.7
P4.1
P4.3
P2.0
P2.1
P2.2
P2.3
P2 .3 /A 1 1
17 23
R D/P3 .7 P2 .2 /A 1 0
18 22
X TA L2 P2 .1 /A 9
19 21
X TA L1 P2 .0 /A 8
20 G ND
25
26
27
28
29
30
31
32
33
34
35
36
G ND
D IP 4 0
R4
10 1R
R7
P3 .6 /W R-P4 .2 10 1R
B P3 .7 /R D -P 4 . 4 B
V CC V CC R5 R6
10 1R 10 1R
R 1,C 1 可不焊 R1
10 K
R ST
R2 C2 C3
20 1R 0.1u 10 u
C1 Title
SW 1 10 u
A SM 3 X6 A
Size N u mb er R ev is io n
A
D ate: 2 1 -F eb -2 0 2 0 Sh eet o f
File: C :\U s ers \Liu \D o w n lo ad s \ST C8 G-8 9 C5 2D-2
raw
0 2n0 B
-2y-1: 9 . d d b
1 2 3 4
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 692 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
This conversion board can be used for STC8G series LQFP48 to STC89C52RC / STC89C58RD + series
simulation.
RxD3/AD0/ADC8/PWM00/P0.0 1 40 VCC
TxD3/AD1/ADC9/PWM01/P0.1 2 39 P0.0/PWM00/ADC8/AD0/RxD3
RxD4/AD2/ADC10/PWM02/P0.2 3 38 P0.1/PWM01/ADC9/AD1/TxD3
TxD4/AD3/ADC11/PWM03/P0.3 4 37 P0.2/PWM02/ADC10/AD2/RxD4
T3/AD4/ADC12/PWM04/P0.4 5 36 P0.3/PWM03/ADC11/AD3/TxD4
T3CLKO/AD5/ADC13/PWM05/P0.5 6 35 P0.4/PWM04/ADC12/AD4/T3
STC8G2K64S4 - LQFP48
STC89C52RC – PDIP40
PWMFLT2/T4/AD6/ADC14/PWM06/P0.6 7 34 P0.5/PWM05/ADC13/AD5/T3CLKO
PWMFLT3/T4CLKO/AD7/PWM07/P0.7 8 33 P0.6/PWM06/ADC14/AD6/T4/PWMFLT2
RST(NC) 9 32 P0.7/PWM07/AD7/T4CLKO/PWMFLT3
INT4/RxD/PWM30/P3.0 10 31 EA(P4.7/PWM47/TxD2_2)
TxD/PWM31/P3.1 11 To 30 ALE(P4.5/PWM45)
I2CSCL_4/SCLK_4/INT0/PWM32/P3.2 12 29 PSEN(P4.6/PWM46/RD/RxD2_2)
I2CSDA_4/MISO_4/INT1/PWM33/P3.3 13 28 P2.7/PWM27/A15/CCP2_3
CMPO/MOSI_4/ECI_2/T1CLKO/T0/PWM34/P3.4 14 27 P2.6/PWM26/A14/CCP1_3
PWMFLT/CCP0_2/SS_4/T0CLKO/T1/PWM35/P3.5 15 26 P2.5//PWM25/A13/CCP0_3/I2CSCL_2/SCLK_2
CCP1_2/CMP-/RxD_2/INT2/PWM36/P3.6 16 25 P2.4/PWM24/A12/ECI_3/I2CSDA_2/MISO_2
/CCP2/CCP2_2/CMP+TxD_2/INT3/PWM37/P3.7 17 24 P2.3/PWM23/A11/MOSI_2
XTAL2(NC) 18 23 P2.2/PWM22/A10/SS_2
XTAL1(NC) 19 22 P2.1/PWM21/A9
GND 20 21 P2.0/PWM20/A8
Note:
Due to the built-in high-precision R/C clock, no external crystal is needed, XTAL1 and XTAL2 can be
empty.
WR and RD are P4.2/ WR and P4.4/ RD respectively, not traditional WR/P3.6 and RD/P3.7.
(In the conversion board, P4.2 and P3.6 are connected together, and P4.4 and P3.7 are connected
together. When this conversion board is used to access the external bus, P3.6 and P3.7 should be set
to high-impedance input mode, so that P4.2 and P4.4 can normally output the bus read and write
signals. If the external bus is not needed to be accessed, P4.2 and P4.4 should be set to high-
impedance input mode, and P3.6 and P3.7 are ordinary I/O.)
The STC8G series MCUs are low-level reset, it is not compatible with the high-level reset of the
traditional 8051, so the RST pin is left floating, and replaced by the reset button and reset circuit on the
conversion board.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 693 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 694 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Plug in the USB device, the system will pop up the following dialog box automatically after finding the device,
select "No, not this time".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 695 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 696 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the following dialog box that pops up, select the "Continue Anyway" button.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 697 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The system will automatically install the driver when connected, as shown below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 698 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The following dialog box appears to indicate that the driver installation is complete.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 699 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 700 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 701 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 702 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 703 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Restart the computer firstly and keep pressing F8 until the following startup screen appears.
Select ‘Disable Driver Signature Enforcement’. The digital signature verification function is temporarily turn
off after startup.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 704 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 705 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 706 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 707 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
When the driver installation starts, the following dialog box will pop up, select "Always install this driver
software".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 708 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Next, the system will install the driver automatically, as shown below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 709 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The following dialog box appears to indicate that the driver installation is complete.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 710 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 711 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 712 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Open the STC-ISP download software of V6.79 (or newer version) (due to permission reasons, downloading the
software in Windows 8 will not copy the driver files to the relevant system directory. It requires manual
installation by the user. 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" F:\", then the STC-USB driver is in the" F:\ STC-USB Driver
"directory))
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 713 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 714 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 715 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 716 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
When the driver installation begins, the following dialog box will pop up, select "Always install this driver
software".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 717 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Next, the system will install the driver automatically, as shown below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 718 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The following dialog box appears to indicate that the driver installation is complete.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 719 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 720 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 721 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Firstly, move the mouse to the lower right corner of the screen and select the "Settings" button.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 722 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 723 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the computer settings, select the "Start Now" button under the "Advanced Startup" item in the "General"
property page.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 724 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 725 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 726 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 727 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the "Startup Settings" window below, click the "Restart" button to restart the computer.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 728 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 729 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 730 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 731 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the computer settings, select "Update and Recovery" (this is not the same as Windows 8, which is "General").
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 732 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Select the "Restore" property page in the update and recovery page, and click the "Start Now" button under the
"Advanced Startup" item.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 733 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 734 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 735 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 736 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the "Startup Settings" window below, click the "Restart" button to restart the computer.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 737 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 738 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
By default, the driver without digital signature cannot be successfully installed in Windows 10 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.
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 739 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Then select the "Update and Security" item in the settings window.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 740 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 741 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the recovery window, click the "Restart Now" button in the "Advanced Startup" item.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 742 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Before the computer restarts, the system will enter the following boot menu firstly and select the
"Troubleshooting" item.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 743 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 744 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 745 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 746 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
When the following screen appears, click the "Restart" button to restart the computer.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 747 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
After the computer restarts, the "Startup Settings" window will pop up. Press the "F7" button to select the
"Prohibit driver forcing signature" item.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 748 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 749 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Right-click the unknown device and select "Update Driver" from the right-click menu.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 750 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In the pop-up driver installer selection screen, select the "Browse my computer for driver software" item.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 751 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 752 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 753 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
During the driver installation process, the following warning screen will pop up, select "Always install this
driver software".
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 754 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 755 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 756 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 757 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 758 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
3. Click the "Download / Program" button to start downloading the user code.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 759 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
4. Until the prompt "Operation succeeded", it means that the program code download is complete.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 760 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2. The circuit diagram of using RS232 to serial port conver to connect the computer to the RS485 control to
download (automatic control or I / O port control).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 761 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 762 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
F.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.
Tool type Online Offline Burner Online simulation Price (RMB)
Download download download
U8W support support support Need to set pass- 100
through mode
U8W-Mini support support not support Need to set pass- 50
through mode
Universal USB to support not support not support support 30
serial port
The microcontroller is
completely power off
Power on the microcontroller External manual reset, the microcontroller also starts
from the system ISP monitoring program area.
(Cold start)
The microcontroller runs the ISP monitoring program to detect whether there is a
The microcontroller runs ISP legal command stream. It takes tens of milliseconds to hundreds of milliseconds. If
monitoring program there is no legal download command stream, run the user program immediately.
If you have set [P3.2, P3.3] = [0, 0], it will judge whether to download the user
program. After a cold start, such as [P3.2, P3.3] ≠ [0, 0], Running the user program
directly will only take 50μs, which can be ignored. It is recommended that the user
Check if P3.0 has a legal select [P3.2, P3.3] not at the same time as [0, 0], then the user program will be run
download instruction immediately, and the system ISP monitoring program will be skipped. (Note 1)
No
Yes
【Cold start programming】
The MCU is in a power off state firstly, and the user must click the
Download the user program and enter the [Download/Program] button of the STC-ISP control software on the PC
user program area to send the download command stream, and then power on the MCU.
Note: Because [P3.0, P3.1] is used for download/simulation (download/simulation interface is only available
[P3.0, P3.1]), it is recommended that users put serial port 1 on P3.6/P3.7 Or P1.6/P1.7, if the user does not want
to switch and insists on using P3.0/P3.1 to work or communicate as the serial port 1, be sure to check the "Next
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 763 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
time cold restart" on the software when downloading the program The program can be downloaded only when
P3.2/P3.3 is 0/0". 【Note 1】
[Note 1]: The programming protection pins of STC15, STC8 series and later new chips are P3.2/P3.3, and the
programming protection pins of earlier chips are P1.0/P1.1.
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. It can support the following and the upcoming STC full range
of chips.
The offline download tool can be used for downloading without the computer, and can be used for mass
production and remote upgrades. The offline download board can support multiple functions such as automatic
increment, download limit, and encrypted transmission of user programs.
The following picture shows the front and back views of U8W tools and the front and back views of U8W-Mini.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 764 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
In addition, some of the following wires and tools are used together, such as:
(1) Two male USB cables (shown on the left in the figure below) and USB-Micro cables (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. On the market, some relatively low-quality two-
end male USB cables have much larger internal resistance, which leads to a large voltage drop (for example, the
voltage of the USB is about 5.0V when it is empty. When using a low-quality USB cable to connect
U8W/U8W-Mini/U8 /U8-Mini, the voltage to our download board may drop to 4.2V or lower, causing the chip
to be in a reset state and fail to download successfully).
(2) The download cable connecting U8W/U8W-Mini and the user system (that is, the connecting cable between
U8W/U8W-Mini and the target MCU on the user board), as shown in the figure below:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 765 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The U8W/U8W-Mini download board uses a CH340 USB-to-serial universal chip. This saves the trouble that
some computers without a serial port must buy an additional USB-to-serial tool to download. However, CH340
is the same as other USB-to-serial tools, the driver must be installed before use.
The following is the download location of the STC-ISP software package provided on the STC official website
(www.STCMCUDATA.com):
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 766 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
After downloading, decompress, the path of the CH340 driver installation package is stc-isp-15xx-v6.87K\USB
to UART Driver\CH340_CH341:
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 of the driver is: U8 programmer USB to serial port driver
(http://www.stcmcu.com/STCISP/CH341SER.exe ). The driver address on the website and STC-ISP download
software is shown in the figure below.
After the driver is downloaded to the machine, double-click the executable program and run it. The interface
shown in the figure below appears, click the "Install" button to start the automatic driver installation:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 767 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Then the driver installation successful dialog box pops up, click the "OK" button to complete the installation:
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 class, if there is a device similar to "USB-
SERIAL CH340 (COMx)", it means U8W/U8W-Mini can be used normally. As shown in the figure below
(different computers may have different serial port numbers):
Note: When using STC-ISP to download software later, the selected serial port number must be the
corresponding serial port number, as shown in the figure below:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 768 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The main interfaces and functions of the U8W tool are described in detail below:
If the MCU is on the user system, P3.0/P3.1/Gnd must be connected during online programming/ISP, and
P3.0/P3.1 of the target MCU must not be connected to any other lines during online programming/ISP.
Programming interface: According to different power supply methods, use different download cables to connect
the U8W download board and the user system.
U8W update system program button: It is used to update U8W tools, when there is a new version of U8W
firmware, you need to press this button to update the U8W main control chip (note: you must set the toggle
switch firstly on the update/download selection interface Toggle to upgrade tool firmware).
Offline download user program button: Start offline download button. Firstly, the PC downloads the offline
code to the U8W board, and then uses the download cable to connect the user system to the U8W, and then
press this button to start the offline download (the user code will also start downloading immediately every time
the power is turned on).
Update/download selection interface: When you need to upgrade the underlying firmware of U8W, you need to
turn this toggle switch to the firmware of the upgrade tool. When you need to program the target chip through
U8W, you need to turn the toggle switch to Burn the user program.
(Please refer to the figure above for the connection method of the toggle switch)
Automatic burner/sorter interface: It is a control interface used to control the automatic burner/sorter for
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 769 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
automatic production.
The target chip is installed on the U8W locking base and the U8W connects to the computer for online
download.
Firstly, use the USB cable provided by STC to connect the U8W to the computer, and then install the target
microcontroller on the U8W in the direction shown in the figure below:
Then use STC-ISP to download the software to download the program, the steps are as follows:
The target chip is connected to U8W through the user system leads and U8W is connected to the
computer for online online download.
Firstly, use the USB cable provided by STC to connect the U8W to the computer, and then connect the U8W to
the target microcontroller 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. Select the MCU model;
2. Select the serial port number corresponding to U8W;
3. Open the target file (HEX format or BIN format);
4. Set the hardware options;
5. Click the "Download/Program" button to start burning;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 770 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
6. The step information of the burning process is displayed, and the message "Operation successful!" is
displayed when the burning is completed.
When there is the version number information of the output download board and the corresponding information
of the plug-in Flash in the information box, it means that the U8W download tool has been correctly detected.
During the downloading process, the 4 LEDs on the U8W download tool will be displayed in a 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.
It is recommended that users use the latest version of STC-ISP to download the software (please always pay
attention to the update of the STC-ISP download software on the STC official website
http://www.STCMCUDATA.com. It is strongly recommended that users download the latest version of the
software on the official website http://www.STCMCUDATA. com).
The target chip is installed on the U8W seat and locked and connected to the computer via USB to supply
power to the U8W for offline download.
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:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 771 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
(4) Then press the button as shown in the figure below and release it to start offline downloading:
During the downloading process, the 4 LEDs on the U8W download tool will be displayed in a 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.
The target chip is connected to U8W by the user system lead and connected to the computer via USB to
supply power to U8W for offline download.
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:
It is recommended that users use the latest version of STC-ISP to download the software (please always pay
attention to the update of the STC-ISP download software on the STC official website
http://www.STCMCUDATA.com. It is strongly recommended that users download the latest version of the
software on the official website http://www.STCMCUDATA. com).
During the downloading process, the 4 LEDs on the U8W download tool will be displayed in a marquee mode.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 772 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
The target chip is connected to U8W by the user system lead, and the user system supplies power to U8W
for offline download.
(1) First use the USB cable provided by STC to connect the U8W download board to the computer, as shown in
the figure 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 update of the STC-ISP download software on the STC official website
http://www.STCMCUDATA.com. It is strongly recommended that users download the latest version of the
software on the official website http://www.STCMCUDATA. com).
During the downloading process, the 4 LEDs on the U8W download tool will be displayed in a 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.
The target chip is connected to U8W by the user system lead, and U8W and the user system are
independently powered for offline download.
(1) Firstly, use the USB cable provided by STC to connect the U8W download board to the computer, as shown
in the figure 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 update of the STC-ISP download software on the STC official website
http://www.STCMCUDATA.com. It is strongly recommended that users download the latest version of the
software on the official website http://www.STCMCUDATA. com).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 773 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
During the downloading process, the 4 LEDs on the U8W download tool will be displayed in a 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.
The main interfaces and functions of the U8W-Mini tool are described in detail below:
USB interface
Micro-USB interface Dial here to burn the
user program
Offline programming
U8W firmware, you need to press this button to update the U8W-Mini main control chip (note: you must toggle
the update/download switch on the interface to ‘the upgrade tool firmware’ firstly).
Offline download user program button: Start offline download button. Firstly, the PC downloads the offline
code to the U8W-Mini, and then uses the download cable to connect the user system to the U8W-Mini, and then
press this button to start the offline download (the user will also start downloading immediately every time the
power is turned on).
Update/download selection interface: When you need to upgrade the underlying firmware of U8W-Mini, you
need to move the toggle switch to the firmware of the upgrade tool. When you need to program the target chip
through U8W-Mini, you need to toggle the switch to burn the user program. (Please refer to the figure above for
the connection method of the toggle switch)
USB interface: The USB interface has the same function as the Micro-USB interface, and the user can connect
one of the interfaces to the computer as needed.
The target chip is connected to the U8W-Mini through the user system lead, and the U8W-Mini is
connected to the computer for online online download.
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 figure:
Then use STC-ISP to download the software to download the program, the steps are as follows:
The target chip is connected to the U8W-Mini by the user system lead and connected to the computer via
USB to supply power to the U8W-Mini for offline download.
The steps to use USB to power U8W-Mini for offline download are as follows:
(1) Use the USB cable provided by STC to connect the U8W-Mini download board to the computer, as shown
in the figure below:
(2) Set up in the STC-ISP download software according to the steps shown in the figure below:
During the downloading process, the 4 LEDs on the U8W-Mini 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.
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:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 776 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
(2) Set up in the STC-ISP download software according to the steps shown in the figure below:
During the downloading process, the 4 LEDs on the U8W-Mini 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.
The target chip is connected to the U8W-Mini by the user system lead, and the 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:
(2) Set up in the STC-ISP download software according to the steps shown in the figure below:
Follow the steps in the above figure, after the operation is completed, if the download is successful, it means
that the user code and related setting options have been downloaded to the U8W-Mini download tool.
It is recommended that users use the latest version of STC-ISP to download the software (please always pay
attention to the update of the STC-ISP download software on the STC official website
http://www.STCMCUDATA.com. It is strongly recommended that users download the latest version of the
software on the official website http://www.STCMCUDATA. com).
(3) Then connect the U8W-Mini to the user system as shown in the figure below, and press the button shown in
the figure first and then release it, ready to start offline download, and finally power on/on the user system to
start starting download the user program:
During the downloading process, the 4 LEDs on the U8W-Mini 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.
The process of making a U8W/U8W-Mini download master is similar. To save space, the following uses U8W
as an example to detail how to make a U8W download master.
Before making the U8W download master, you need to dial the "Update/Download Selection Interface" of the
U8W download board to "Upgrade Tool Firmware", as shown in the figure below:
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)
When the following screen appears, it indicates that the U8W control chip is completed:
After the production is completed, do not forget to dial the U8W "Update/Download Selection Interface" back
to the "Burn User Program" mode, and power on the U8W download tool again, as shown in the figure below:
(Otherwise, the programming will not be performed normally)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 778 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
To use U8W/U8-Mini for simulation, you must set U8W/U8-Mini to pass-through mode firstly. The method for
U8W/U8W-Mini to realize the USB-to-serial pass-through mode is as follows:
1. Firstly, the U8W/U8W-Mini firmware must be upgraded to v1.37 and above;
2. After the U8W/U8W-Mini is powered on, it is in normal download mode. At this time, press and hold the
Key1 (download) button on the tool and do not release it. Press the Key2 (power) button again, and then release
the Key2 (power) button. Release the Key1 (download) button again, and the U8W/U8W-Mini will enter the
USB to serial port pass-through mode. (Press Key1→Press Key2→ Release Key2 → Release Key1);
3. The U8W/U8W-Mini tool that enters the pass-through mode is just a simple USB to serial port and does not
have the offline download function. If you need to restore the original function of the U8W/U8W-Mini, you
only need to press the Key2 (power) button separately again.
USB-type online/offline download board U8W/U8W-Mini provides users with the following common control
interfaces:
Function Port Function description
Power control pin P2.6 Active low
Serial port RXD, connect to the TXD of the target chip
P1.0
Download (P3.1)
communication pin Serial TXD, connect to the RXD of the target chip
P1.1
(P3.0)
Programming button P3.6 Active low
P3.2 LED1
P3.3 LED2
Display
P3.4 LED3
P5.5 LED4
P2.4 CE pin of Flash
External serial Flash P2.2 SO pin of Flash
control pin P2.3 SI pin of Flash
P2.1 SCLK pin of Flash
P3.6 Start signal
Automatic programming
P1.5 Completion signal
tool sorting machine
P5.4 OK signal (Good product signal)
signal
P3.7 ERROR signal (Bad product signal)
BEEP control P2.5 Active high (High level sounds)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 779 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
This Flash memory is required when the user program is larger than 41K.
The reference circuit diagram of the button part:
front:
back:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 781 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The function of this button is the same as that of a self-locking switch. When the switch button is pressed for the
first time, the switch is turned on and held, that is, self-locking. When the switch button is pressed for the
second time, the switch turns off the power. In view of the characteristics of self-locking switches that are easily
damaged during use, we designed a set of circuits that use light touch switches to replace self-locking switches
to improve the service life of the tools.
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 use the STC universal USB to serial
tool to download the program to the MCU are:
1. Use STC universal USB to serial port tool to connect the MCU to be burned with the computer;
2. Open STC's ISP download software;
3. Select the MCU model;
4. Select the serial port corresponding to the STC universal USB to serial port tool;
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 supply power to the MCU and start
downloading.
【Cold start burning】
In addition, the USB interface has the same function as the Micro-USB interface, and the user can connect one
of the interfaces to the computer as needed.
The 0V signal pin of the programming interface has a 470ohm resistor grounded. It can be downloaded only
when P1.0/P1.1=0/0 or P3.2/P3.3=0/0 is set. You can set P1.0, P1 .1 or P3.2, P3.3 are connected to the 0V signal
pin.
STC universal USB to serial port tool uses CH340 USB to serial chip (can plug in crystal oscillator, more
accurate), just download the general CH340 serial driver and install it. The following is the CH341SER serial
driver provided by STC official website (www.STCMCUDATA.com) download location:
After downloading, decompress, the path of the CH340 driver installation package is stc-isp-15xx-v6.87K\USB
to UART Driver\CH340_CH341:
Take the CH341SER serial port driver provided by STC official website as an example, double-click the
"CH341SER.exe" installation package, and click the "Install" button on the pop-up main interface to start
installing the driver:
Then the driver installation successful dialog box pops up, click the "OK" button to complete the installation:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 782 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
F.4.4 Use the STC universal USB to serial tool to download the
program to the MCU
1. Use STC universal USB to serial port tool to connect the MCU to be burned with the computer:
8. When the prompt box in the lower right corner displays "Detecting target MCU...", press the "power switch"
on the STC universal USB to serial port tool to supply power to the MCU, and then start downloading [cold
start programming];
9. Wait for the download to end. If the download is successful, the prompt box in the lower right corner will
display "Operation successful!".
F.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.
After the Keil software is installed, you also need to install the STC simulation driver. The installation steps of
STC's simulation driver are as follows:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 783 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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:
You can see the following files in the relevant directory of Keil, which means that the driver is installed
correctly.
By default, the main control chip of STC is not a simulation chip and does not have a simulation function, so, if
simulation is required, the main control chip of STC needs to be set as a simulation chip.
The steps of making a simulation chip are as follows:
Firstly, use the STC universal USB to serial port tool to connect the MCU to the computer;
Then open STC's ISP download software, and select the serial port number corresponding to the serial port tool
in the serial port number drop-down list;
Select the MCU model;
Select the IRC frequency of the user program to run, and the frequency selected when making the simulation
chip is consistent with the frequency set by the simulated user program, in order to achieve the real running
effect.
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:
Next, you need to press the "power switch" on the STC universal USB to serial port tool to power the MCU
[cold start], and then you can start to make the simulation chip.
If the setting is successful, the following screen will appear:
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 a macro used to define the size of IDATA. The default value is
128, which is 80H in hexadecimal, and it is also the size of IDATA that needs to be initialized to 0 in the startup
file. When IDATA is defined as 80H, then the code in STARTUP.A51 will initialize the RAM of IDATA 00-7F
to 0; similarly, if IDATA is defined as 0FFH, it will initialize the RAM of IDATA 00-FF to 0.
The IDATA size of the STC8H series microcontroller we selected is 256 bytes (00-7F DATA and 80H-FFH
IDATA), but because the last 17 bytes of RAM have written ID numbers and related test parameters, If users
need to use this part of data in the program, they must not define IDATALEN as 256.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 784 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Press the shortcut key "Alt+F7" or select "Option for Target ‘Target1’" in the menu "Project"
Configure the project in the "Option for Target ‘Target1’" dialog box:
Step 1. Enter the project setting page and select the "Debug" setting page;
Step 2. Select the hardware emulation "Use …" on the right;
Step 3. Select "STC Monitor-51 Driver" item in the simulation driver drop-down list;
Step 4. Click the "Settings" button to enter the serial port settings screen;
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.
Make sure to complete the simulation settings.
The detailed steps are shown in the figure below:
After finishing all the work above, 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.
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).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 785 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 786 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
BOM list:
Label Model Package Note
U10 SP3485EN SOP8 RS485 chip
R66 10K 0603 Resistor
R107 3.3K 0603 Resistor
R108 3.3K 0603 Resistor
R109 3.3K 0603 Resistor
R112 33R 0603 Resistor
R113 33R 0603 Resistor
R114 100K 0603 Resistor
T10 SS8550 SOT-23 PNP Triode
D3 1N5819 0603 Schottky diode
D8 P6SMB6.8CA DO-214AA TVS diode
D9 P6SMB6.8CA DO-214AA TVS diode
CN2 SIP4 Communication Interface
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 787 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
"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 command.
The function of "user-defined download" is mainly used in the early development stage of the project,
which can download user code without power-off (without re-power-on to the target chip). The specific
implementation method is: User needs to add a piece of code to detect the custom command in user program.
When the command is detected, execute the assembly code of "MOV IAP_CONTR, # 60H" or the C language
code of "IAP_CONTR = 0x60;" , MCU will reset to ISP area to execute ISP code automatically.
As shown in the figure below, set the custom command sequence with a baud rate of 115200, no parity bit,
and one stop bit: 0x12, 0x34, 0x56, 0xAB, 0xCD, 0xEF, 0x12. When the option "Send custom commands
before each download" is checked, the user-defined download function can be implemented.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 788 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Click "Send user-defined download command" or click the "Download / Program" button in the lower left
corner of the window, the application will send the serial data as shown below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 789 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
All STC8G series microcontrollers that can customize the EEPROM size during ISP download are IAP series
microcontrollers. At present, the STC8H series have the following types of microcontrollers as the IAP series:
STC8G1K12, STC8G1K17, STC8G1K12A, STC8G1K17A, STC8G1K12-8Pin, STC8G1K17-8Pin,
STC8G1K12T, STC8G1K17G2, STC8G8K64. STC8G2K64S4 is taken as an example to explain in detail the
method of using STC's IAP microcontroller to develop the user's own ISP program, and gives the assembly and
C source code based on the Keil environment.
Since the EEPROM of the IAP microcontroller of the STC8G series is set by the user during ISP download, if
the user needs to implement his own ISP when downloading the user’s own ISP program, the user needs to
follow the figure below to set all 64K Set to EEPROM, so that the user program space and EEPROM space are
completely overlapped, and users can modify and update their own program space.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 790 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The following assumes that the user has set the entire 64K program space as EEPROM. Now the entire 64K
program space is divided as follows:
0000
62.5K
F9FF
FA00
0.5K User ISP area
FBFF
FC00
Reset entry mapping
0.5K
area
FDFF
FE00
User parameter area
0.5K
(Cannot run 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. At this time, the user program area can be erased and rewritten to achieve the purpose of updating the user
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 791 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
program.
Yes
Software reset
The third step, the firmware program description of the lower computer
The firmware program of the lower computer includes two parts: ISP (ISP code) and AP (user code)
UARTBAUD EQU 0FFE8H ; Define the serial port baud rate (65536-11059200/4/115200)
ISPCODE EQU 0FA00H ; ISP module entry address (page 1), which is also the
address of the external interface
APENTRY EQU 0FC00H ; Application entry address (1 page)
ORG 0000H
RESET:
MOV SCON,#50H ; Set the serial port mode (8 data bits, no parity bit)
MOV AUXR,#40H ; Timer 1 is 1T mode
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 792 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
ORG ISPCODE
ISP_DOWNLOAD:
CLR A
MOV PSW,A ; ISP module uses the 0th group of registers
MOV IE,A ; Close all interrupts
CLR RI ; Clear serial port receiving flag
SETB TI ; Set serial port sending flag
CLR TR0
MOV SP,#5FH ; Set the stack pointer
MOV A,#5AH ; Return 5A 55 to the PC, indicating that the ISP erase
module is ready
LCALL ISP_SENDUART
MOV A,#055H
LCALL ISP_SENDUART
LCALL ISP_RECVACK ; Receive response data
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 793 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
INC IAP_ADDRH
DJNZ R7,ISP_ERASEAP ; Determine whether the erasure is complete
LCALL ISP_RECVUART ; Mapping user code resets the entry code to the mapping
area
LCALL ISP_PROGRAMIAP ;0000
LCALL ISP_RECVUART
LCALL ISP_PROGRAMIAP ;0001
LCALL ISP_RECVUART
LCALL ISP_PROGRAMIAP ;0002
ISP_SOFTRESET:
MOV IAP_CONTR,#20H ; Software reset system
SJMP $
ISP_ENTRY:
MOV WDT_CONTR,#17H ; Clear watchdog
MOV IAP_CONTR,#80H ; Enable IAP function
MOV IAP_TPS,#11 ; Set IAP waiting time parameters
MOV IAP_ADDRL,#LOW ISP_DOWNLOAD
MOV IAP_ADDRH,#HIGH ISP_DOWNLOAD
MOV IAP_DATA,#00H ; Test Data 1
MOV IAP_CMD,#1 ; Read command
MOV IAP_TRIG,#5AH ; Trigger ISP command
MOV IAP_TRIG,#0A5H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 794 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MOV A,IAP_DATA
CJNE A,#0E4H,ISP_ENTRY ; If you cannot read the data, you need to wait for the
voltage to stabilize
INC IAP_ADDRL ; Test address FC01H
MOV IAP_DATA,#45H ; Test Data 2
MOV IAP_CMD,#1 ; Read command
MOV IAP_TRIG,#5AH ; Trigger ISP command
MOV IAP_TRIG,#0A5H
MOV A,IAP_DATA
CJNE A,#0F5H,ISP_ENTRY ; If you cannot read the data, you need to wait for the
voltage to stabilize
MOV SCON,#50H ; Set the serial port mode (8 data bits, no parity bit)
MOV AUXR,#40H ; Timer 1 is 1T mode
MOV TMOD,#00H ; Timer 1 works in mode 0 (16-bit reload)
MOV TH1,#HIGH UARTBAUD ; Set reload value
MOV TL1,#LOW UARTBAUD
SETB TR1 ; Start timer 1
SETB TR0
ISP_RECVACK:
LCALL ISP_RECVUART
JC GOTOAP
XRL A,#7FH
JZ ISP_RECVACK ; Skip synchronized data
CJNE A,#25H,GOTOAP ; Response data 1 detection
LCALL ISP_RECVUART
JC GOTOAP
CJNE A,#69H,GOTOAP ; Response data 2 detection
RET
ISP_RECVUART:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 795 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CLR A
MOV TL0,A ; Initialize the timeout timer
MOV TH0,A
CLR TF0
MOV WDT_CONTR,#17H ; Clear watchdog
ISP_RECVWAIT:
JBC TF0,ISP_RECVTIMEOUT ; Timeout detection
JNB RI,ISP_RECVWAIT ; Wait for the reception to complete
MOV A,SBUF ; Read serial port data
CLR RI ; Clear flag
CLR C ; Receive serial data correctly
RET
ISP_RECVTIMEOUT:
SETB C ; Timeout exit
RET
ISP_SENDUART:
MOV WDT_CONTR,#17H ; Clear watchdog
JNB TI,ISP_SENDUART ; Waiting for the completion of the previous data
transmission
CLR TI ; Clear flag
MOV SBUF,A ; Send current data
RET
ISP_ERASEIAP:
MOV WDT_CONTR,#17H ; Clear watchdog
MOV IAP_CMD,#3 ; Erase command
MOV IAP_TRIG,#5AH ; Trigger ISP command
MOV IAP_TRIG,#0A5H
NOP
NOP
NOP
NOP
RET
ISP_PROGRAMIAP:
MOV WDT_CONTR,#17H ; Clear watchdog
MOV IAP_CMD,#2 ; Programming command
MOV IAP_DATA,A ; Send current data to IAP data register
MOV IAP_TRIG,#5AH ; Trigger ISP command
MOV IAP_TRIG,#0A5H
NOP
NOP
NOP
NOP
MOV A,IAP_ADDRL ;IAP address +1
ADD A,#01H
MOV IAP_ADDRL,A
MOV A,IAP_ADDRH
ADDC A,#00H
MOV IAP_ADDRH,A
RET
ORG APENTRY
LJMP RESET
END
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 796 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
void main()
{
SCON = 0x50; // Define the serial port mode as 8bit variable, no parity bit
AUXR = 0x40;
TH1 = BAUD >> 8;
TL1 = BAUD;
TR1 = 1;
ES = 1; // Enable serial port interrupt
EA = 1; // Enable the global interrupt
P1M0 = 0;
P1M1 = 0;
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 797 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
while (1)
{
P1++;
}
}
UARTBAUD EQU 0FFE8H ; Define the serial port baud rate (65536-
11059200/4/115200)
ISPPROGRAM EQU 0FA00H ; ISP download program entry address
ORG 0000H
LJMP START ; System reset entry
ORG 0023H
LJMP UART_ISR ; Serial port interrupt entry
UART_ISR:
PUSH ACC
PUSH PSW
JNB TI,CHECKRI ; Detect transmission interruption
CLR TI ; Clear flag
CHECKRI:
JNB RI,UARTISR_EXIT ; Detect receive interrupt
CLR RI ; Clear flag
MOV A,SBUF
CJNE A,#7FH,ISNOT7F
INC CNT7F
MOV A,CNT7F
CJNE A,#16,UARTISR_EXIT
LJMP ISPPROGRAM ; Call the download module (****Important Statement****)
ISNOT7F:
MOV CNT7F,#0
UARTISR_EXIT:
POP PSW
POP ACC
RETI
START:
MOV R0,#7FH ;Clear RAM
CLR A
MOV @R0,A
DJNZ R0,$-1
MOV SP,#7FH ; Initialize SP
MOV SCON,#50H ; Set the serial port mode (8-bit variable, no parity bit)
MOV AUXR,#15H ; BRT works in 1T mode, and start BRT
MOV TMOD,#00H ; Timer 1 works in mode 0 (16-bit reload)
MOV TH1,#HIGH UARTBAUD ; Set reload value
MOV TL1,#LOW UARTBAUD
SETB TR1 ; Start timer 1
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 798 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
MAIN:
INC P0
SJMP MAIN
END
User code can be written in C or assembly language, but one thing needs to be noted for assembly code is that
the instruction at the reset entry address of 0000H must be a long jump statement (similar to LJMP START). In
the user code, the serial port needs to be set up, and when the download conditions are met, the PC value is
jumped to ISPPROGRAM (that is, the absolute address of FA00H) to achieve code update. For assembly code,
we can use the "LJMP 0FA00H" instruction to call, as shown below.
In the C code, you must define a function pointer variable, and assign this variable to 0xFA00, and then call it,
as shown in the figure below.
Select the serial port number and set the same serial port baud rate as the lower computer.
Open the source data file to be downloaded, either in Bin or Intel hex format.
Click the "Download Data" button to start downloading data.
The sixth step, how to use the firmware of the lower computer
The lower computer has two target files "IAPISP.hex" and "AP.hex". For a new microcontroller, the
"IAPISP.hex" must be written into the chip using the ISP download tool of STC Technology for the first time as
shown below. After the update, there is no need to write the "IAPISP.hex" file. The "AP.hex" in the attachment
is just a template of the user program. When the download conditions are met, the user only needs to jump the
PC value to the address of FA00H, and then achieve code update.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 799 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
But how do users judge whether ISP download is in progress? When to write 0x60 to register IAP_CONTR to
trigger a soft reset? Regarding these two issues, four methods of judgment are introduced below:
The serial port ISP of STC microcontroller uses P3.0 and P3.1 fixedly. 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 download.
C laguage code
// The test operating frequency is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P3M0 = 0x00;
P3M1 = 0x00;
P30 = 1;
while (1)
{
if (!P30) IAP_CONTR = 0x60; // The low level of P3.0 is the serial port start signal
// Reset to the system area by software
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 800 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Use the falling edge interrupt of P3.0/INT4 port to detect the serial port start signal.
Method B is similar to method A, except that method A uses query mode, and method B uses interrupt mode.
Because the P3.0 port of the STC microcontroller is the interrupt port of INT4.
C laguage code
// The test operating frequency is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
void main()
{
P3M0 = 0x00;
P3M1 = 0x00;
while (1)
{
... // User code
}
}
Use the serial port of P3.0/RxD port to receive and check the 7F sent by the ISP download software.
Method A and Method B are very simple, but easy to be interfered. If there is any interference signal on the P3.0
port, it will trigger a software reset, so method C is to verify the serial port data.
When the STC ISP download software performs ISP download, it will use the lowest baud rate (usually 2400) +
even parity 9+1 stop bit to continuously send the handshake command 7F firstly, so the user can set the serial
port in the program to 9 bit data bit + 2400 baud rate, and then continue to detect 7F, for example, continuous
detection of 8 7Fs means that it is determined that ISP download is required, and then the software reset is
triggered.
C laguage code
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 801 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
#include "reg51.h"
#include "intrins.h"
char cnt7f;
if (RI)
{
RI = 0;
if ((SBUF == 0x7f) && (RB8 == 1)) // Handshake command 7F sent by ISP download software
//The even parity bit of 7F is 1
{
if (++cnt7f == 8) // After 8 consecutive 7Fs are detected
IAP_CONTR = 0x60; // Reset to system area
}
else
{
cnt7f = 0;
}
}
}
void main()
{
P3M0 = 0x00;
P3M1 = 0x00;
cnt7f = 0;
while (1)
{
... //User code
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 802 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Use P3.0/RxD serial port to receive and detect user download commands sent by ISP download software.
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 STC's ISP download software to customize a set of dedicated
user download commands (you can specify the baud rate, check bit and stop bit). If this function is enabled, the
ISP download software will use the user-specified baud rate, check bit and stop bit to send the user download
command before ISP download, and then send the handshake command. The user only needs to monitor the
serial port command sequence in his own code. When the correct user download command is detected, the
software is reset to the system 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 baudrate, no parity bit and 1 stop bit. The settings in the ISP download software are as follows:
#include "reg51.h"
#include "intrins.h"
char stage;
if (TI)
{
TI = 0;
}
if (RI)
{
RI = 0;
dat = SBUF;
switch (stage)
{
case 0:
default:
L_Check1st:
if (dat == 'S') stage = 1;
else stage = 0;
break;
case 1:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 803 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
void main()
{
P3M0 = 0x00;
P3M1 = 0x00;
SCON = 0x50; // Set the user serial port mode to 8 bits data
TMOD = 0x00;
AUXR = 0x40;
TH1 = BR2400 >> 8; // Set the serial port baud rate to 115200
TL1 = BR2400;
TR1 = 1;
ES = 1;
EA = 1;
stage = 0;
while (1)
{
... //User code
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 804 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
C language code
/*Note: When using this code to download the STC8G 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"
// Variable definitions
BOOL f1ms; //1ms flag
BOOL UartBusy; // Serial transmit busy flag
BOOL UartReceived; // Serial data receiving completion flag
BYTE UartRecvStep; // Serial data receiving control
BYTE TimeOut; // Serial communication timeout counter
BYTE xdata TxBuffer[256]; // Serial data transmission buffer
BYTE xdata RxBuffer[256]; // Serial data receiving buffer
char code DEMO[256]; // Demo code data
// Functions declarations
void Initial(void);
void DelayXms(WORD x);
BYTE UartSend(BYTE dat);
void CommInit(void);
void CommSend(BYTE size);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 805 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Initial();
if (Download(DEMO, 256))
{
// download successfully
P3 = 0xff;
DelayXms(500);
P3 = 0x00;
DelayXms(500);
P3 = 0xff;
DelayXms(500);
P3 = 0x00;
DelayXms(500);
P3 = 0xff;
DelayXms(500);
P3 = 0x00;
DelayXms(500);
P3 = 0xff;
}
else
{
// download failed
P3 = 0xff;
DelayXms(500);
P3 = 0xf3;
DelayXms(500);
P3 = 0xff;
DelayXms(500);
P3 = 0xf3;
DelayXms(500);
P3 = 0xff;
DelayXms(500);
P3 = 0xf3;
DelayXms(500);
P3 = 0xff;
}
while (1);
}
f1ms = TRUE;
if (Counter100-- == 0)
{
Counter100 = 100;
if (TimeOut) TimeOut--;
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 806 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
if (TI)
{
TI = 0;
UartBusy = FALSE;
}
if (RI)
{
RI = 0;
dat = SBUF;
switch (UartRecvStep)
{
case 1:
if (dat != 0xb9) goto L_CheckFirst;
UartRecvStep++;
break;
case 2:
if (dat != 0x68) goto L_CheckFirst;
UartRecvStep++;
break;
case 3:
if (dat != 0x00) goto L_CheckFirst;
UartRecvStep++;
break;
case 4:
RecvSum = 0x68 + dat;
RecvCount = dat - 6;
RecvIndex = 0;
UartRecvStep++;
break;
case 5:
RecvSum += dat;
RxBuffer[RecvIndex++] = dat;
if (RecvIndex == RecvCount) UartRecvStep++;
break;
case 6:
if (dat != HIBYTE(RecvSum)) goto L_CheckFirst;
UartRecvStep++;
break;
case 7:
if (dat != LOBYTE(RecvSum)) goto L_CheckFirst;
UartRecvStep++;
break;
case 8:
if (dat != 0x16) goto L_CheckFirst;
UartReceived = TRUE;
UartRecvStep++;
break;
L_CheckFirst:
case 0:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 807 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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;
TMOD = 0x00;
TH0 = HIBYTE(T1MS);
TL0 = LOBYTE(T1MS);
TR0 = 1;
TH1 = HIBYTE(BR(MINBAUD));
TL1 = LOBYTE(BR(MINBAUD));
TR1 = 1;
ET0 = 1;
ES = 1;
EA = 1;
}
UartBusy = TRUE;
ACC = dat;
TB8 = P;
SBUF = ACC;
return dat;
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 808 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
UartSend(0x46);
UartSend(0xb9);
UartSend(0x6a);
UartSend(0x00);
sum = size + 6 + 0x6a;
UartSend(size + 6);
for (i=0; i<size; i++)
{
sum += UartSend(TxBuffer[i]);
}
UartSend(HIBYTE(sum));
UartSend(LOBYTE(sum));
UartSend(0x16);
while (UartBusy);
CommInit();
}
// Shake hands
CommInit();
while (1)
{
if (UartRecvStep == 0)
{
UartSend(0x7f);
DelayXms(10);
}
if (UartReceived)
{
arg = RxBuffer[4];
if (RxBuffer[0] == 0x50) break;
return FALSE;
}
}
// Set parameters (set the parameters such as the highest baud rate used by the slave chip and erase wait time)
TxBuffer[0] = 0x01;
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)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 809 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
{
if (TimeOut == 0) return FALSE;
if (UartReceived)
{
if (RxBuffer[0] == 0x01) break;
return FALSE;
}
}
//prepare
TH1 = HIBYTE(BR(MAXBAUD));
TL1 = LOBYTE(BR(MAXBAUD));
DelayXms(10);
TxBuffer[0] = 0x05;
TxBuffer[1] = 0x00;
TxBuffer[2] = 0x00;
TxBuffer[3] = 0x5a;
TxBuffer[4] = 0xa5;
CommSend(5);
while (1)
{
if (TimeOut == 0) return FALSE;
if (UartReceived)
{
if (RxBuffer[0] == 0x05) break;
return FALSE;
}
}
// Erase
DelayXms(10);
TxBuffer[0] = 0x03;
TxBuffer[1] = 0x00;
TxBuffer[2] = 0x00;
TxBuffer[3] = 0x5a;
TxBuffer[4] = 0xa5;
CommSend(5);
TimeOut = 100;
while (1)
{
if (TimeOut == 0) return FALSE;
if (UartReceived)
{
if (RxBuffer[0] == 0x03) break;
return FALSE;
}
}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 810 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
cnt = 0;
while (addr < size)
{
TxBuffer[cnt+offset] = pdat[addr];
addr++;
cnt++;
if (cnt >= 128) break;
}
CommSend(cnt + offset);
while (1)
{
if (TimeOut == 0) return FALSE;
if (UartReceived)
{
if ((RxBuffer[0] == 0x02) && (RxBuffer[1] == 'T')) break;
return FALSE;
}
}
TxBuffer[0] = 0x02;
}
//// Do not write hardware options when downloading programs from the master chip to the slave chip.
//DelayXms(10);
//for (cnt=0; cnt<128; cnt++)
//{
// TxBuffer[cnt] = 0xff;
//}
//TxBuffer[0] = 0x04;
//TxBuffer[1] = 0x00;
//TxBuffer[2] = 0x00;
//TxBuffer[3] = 0x5a;
//TxBuffer[4] = 0xa5;
//TxBuffer[33] = arg;
//TxBuffer[34] = 0x00;
//TxBuffer[35] = 0x01;
//TxBuffer[41] = 0xbf;
//TxBuffer[42] = 0xbd; //P5.4 is I/O port
////TxBuffer[42] = 0xad; //P5.4 is reset pin
//TxBuffer[43] = 0xf7;
//TxBuffer[44] = 0xff;
//CommSend(45);
//while (1)
//{
// if (TimeOut == 0) return FALSE;
// if (UartReceived)
// {
// if ((RxBuffer[0] == 0x04) && (RxBuffer[1] == 'T')) break;
// return FALSE;
// }
//}
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 811 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
// Download completed
return TRUE;
}
Note: If user needs to set different working frequencies, please refer to the example codes in chapters 7.3.7 and
7.3.8.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 812 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Simple call
In the third-party application, it is only a simple process of creating and publishing the project program. All
other download operations are carried out in the publishing project program. The third-party application only
needs to wait for the completion of the publishing project program and clean up the site.
VC code
BOOL IspProcess()
{
// Define related variables
STARTUPINFO si;
PROCESS_INFORMATION pi;
CString path;
// Variables initialization
memset(&si, 0, sizeof(STARTUPINFO));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
// Clean up
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 813 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
return TRUE;
}
else
{
AfxMessageBox(_T("Failed to create process !"));
return FALSE;
}
}
Advanced call
To create and publish the project program in the third-party application, and perform all ISP download
operations in the third-party application, including selecting the serial port, starting ISP programming, stopping
ISP programming, and closing the publishing project program, it is not necessary to publish the project program
to interact with the interface.
VC 代码
// Define the data structure of the callback function parameters
struct CALLBACK_PARAM
{
DWORD dwProcessId; // Main process ID
HWND hMainWnd; // Main window handle
};
// Callback function for enumerating windows, used to get the handle of the main window
BOOL CALLBACK EnumWindowCallBack(HWND hWnd, LPARAM lParam)
{
CALLBACK_PARAM *pcp = (CALLBACK_PARAM *)lParam;
DWORD id;
GetWindowThreadProcessId(hWnd, &id);
if ((pcp->dwProcessId == id) && (GetParent(hWnd) == NULL))
{
pcp->hMainWnd = hWnd;
return FALSE;
}
return TRUE;
}
BOOL IspProcess()
{
// Define related variables
STARTUPINFO si;
PROCESS_INFORMATION pi;
CALLBACK_PARAM cp;
CString path;
// Variables initialization
memset(&si, 0, sizeof(STARTUPINFO));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
memset(&cp, 0, sizeof(CALLBACK_PARAM));
// Get the handle of the main window of the published project program
cp.dwProcessId = pi.dwProcessId;
cp.hMainWnd = NULL;
EnumWindows(EnumWindowCallBack, (LPARAM)&cp);
if (cp.hMainWnd != NULL)
{
HWND hProgram;
HWND hStop;
HWND hPort;
// Get the handle of part of the control in the main window of the publishing project
hProgram = ::GetDlgItem(cp.hMainWnd, ID_PROGRAM);
hStop = ::GetDlgItem(cp.hMainWnd, ID_STOP);
hPort = ::GetDlgItem(cp.hMainWnd, ID_COMPORT);
// Set the serial port number in the release project program, the third parameter is 0: COM1, 1: COM2, 2:
COM3, ...
::SendMessage(hPort, CB_SETCURSEL, 0, 0);
//编程完成后关闭发布项目程序
::SendMessage(cp.hMainWnd, WM_CLOSE, 0, 0);
}
// Clean up
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 815 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return TRUE;
}
else
{
AfxMessageBox(_T("创建进程失败 !"));
return FALSE;
}
}
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. Open Keil firstly and select "New uVision Project ..." from the "Project" menu to complete the creation of an
empty project.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 816 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2. In the project tree of the empty project, right-click "Source Group 1" and select "Add Existing Files to
Group" Source Group 1 "..." from the right-click menu.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 817 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
3. In the file dialog that pops up, add the source file multiple times.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 818 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Complete the creation of the multi-file project as shown in the figure below.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 819 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 820 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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 Interrupt vector Interrupt type
0 0003 H INT0
1 000B H Timer 0
2 0013 H INT1
3 001B H Timer 1
4 0023 H UART 1
5 002B H ADC
6 0033 H LVD
7 003B H PCA
8 0043 H UART 2
9 004B H SPI
10 0053 H INT2
11 005B H INT3
12 0063 H Timer 2
13 006B H
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 821 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
14 0073 H Simulation A5
15 007B H Simulation PIN
16 0083 H INT4
17 008B H UART 3
18 0093 H UART 4
19 009B H Timer 3
20 00A3 H Timer 4
21 00AB H Comparator
22 00B3 H Waveform generator 0
23 00BB H Waveform generator fault 0
24 00C3 H I2C
25 00CB H USB
26 00D3 H PWM1
27 00DB H PWM2
28 00E3 H Waveform generator 1
29 00EB H Waveform generator 2
30 00F3 H Waveform generator 3
31 00FB H Waveform generator 4
32 0103 H Waveform generator 5
Waveform generator fault
33 010B H
2
Waveform generator fault
34 0113 H
4
35 011B H Touch Key
36 0123 H RTC
37 012B H P0 interrupt
38 0133 H P1 interrupt
39 013B H P2 interrupt
40 0143 H P3 interrupt
41 014B H P4 interrupt
42 0153 H P5 interrupt
43 015B H P6 interrupt
44 0163 H P7 interrupt
45 016B H P8 interrupt
46 0173 H P9 interrupt
It is not difficult to find that starting from the interrupt of the waveform generator 5, there will be errors when
all subsequent interrupt service routines be compiled in keil, as shown in the following figure:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 822 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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)
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 823 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2. Create a new assembly language file, such as "isr.asm", add it to the project, and add "LJMP 006BH" at the
address "0103H", as shown below:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 824 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
3. Compile successfully.
Now, after being compiled by Keil's C51 compiler, there is an "LJMP PWM5_ISR" at 006BH and an "LJMP
006BH" 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:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 825 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
After the execution of the interrupt service routine is completed, it returns through the RETI instruction. The
entire interrupt response process just executed an additional LJMP statement.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 826 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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 1:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 827 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 828 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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
2. Then enter the code shown in the figure below at address 0103H of the assembly file.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 829 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
3. After compiling, you can find the interrupt service routine at the address of 0103H.
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. PSW, ACC, B, DPL, DPH and R0 ~ R7 are included generally. In addition to the
PSW must be pushed onto the stack, registers which are used in the user subroutine must be pushed onto the
stack.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 830 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Note 1
If the operating temperature is higher than 85°C (such as around 125°C), because the frequency of the internal
IRC clock has a large temperature drift at high temperatures, it is recommended to use an external high
temperature clock or crystal oscillator. In addition, when the temperature is high, and the frequency does not run
fast, it is recommended to use a working frequency below 24M. If the system must run at a higher temperature,
please use an external high-reliability low-frequency active clock.
If the operating temperature is around -55°C, the operating voltage should not be too low. It is strongly
recommended that the MCU-VCC voltage should not be lower than 3.0V. In addition, the power supply must
also rise as fast as possible, preferably within milliseconds.
0.90 equivalent to
Normal mode current (700KHz) - - mA
traditional 8051 9M
0.91 equivalent to
Normal mode current (800KHz) - - mA
traditional 8051 11M
0.91 equivalent to
Normal mode current (900KHz) - - mA
traditional 8051 12M
0.94 equivalent to
Normal mode current (1MHz) - - mA
traditional 8051 13M
1.05 equivalent to
Normal mode current (2MHz) - - mA
traditional 8051 26M
1.17 equivalent to
Normal mode current (3MHz) - - mA
traditional 8051 40M
1.26 equivalent to
Normal mode current (4MHz) - - mA
traditional 8051 53M
1.40 equivalent to
Normal mode current (5MHz) - - mA
traditional 8051 66M
1.49 equivalent to
Normal mode current (6MHz) - - mA
traditional 8051 79M
2.09 equivalent to
Normal mode current (12MHz) - - mA
traditional 8051 158M
3.16 equivalent to
Normal mode current (24MHz) - - mA
traditional 8051 317M
0.9 Turn on Schmitt
- - V
9 trigger
VIL1 Input low voltage
1.0 Turn off Schmitt
- - V
7 trigger
Turn on Schmitt
1.18 - - V
trigger
VIH1 Input high voltage1(general I/O)
Turn off Schmitt
1.09 - - V
trigger
0.9
VIH2 Input high voltage2(RST pin) 1.18 - V
9
IOL1 Output low-level sink current - 20 - mA Port voltage 0.45V
Output high level current (bi-direction
IOH1 200 270 - uA
mode)
Output high level current (Push-pull
IOH2 - 20 - mA Port voltage 2.4V
mode)
IIL Logic 0 input current - - 50 uA Port voltage 0V
ITL Logical 1 to 0 transition current 100 270 600 uA Port voltage 2.0V
RPU I/O port pull-up resistor 5.8 5.9 6.0 KΩ
I/O high current drive, I/O fast
25 MHz PxDR=0, PxSR=0
conversion
I/O low current drive, I/O fast
22 MHz PxDR=1, PxSR=0
I/O conversion
speed I/O high current drive, I/O slow
16 MHz PxDR=0, PxSR=1
conversion
I/O low current drive, I/O slow
12 MHz PxDR=1, PxSR=1
conversion
Turn off all analog and
the fastest speed 10 MHz
digital filtering
Compara Analog filter time 0.1 us
tor
0 System LCDTY=0
Digital filter time
n+2 clock LCDTY=n (n=1~63)
Power-down mode power
IPD2 consumption when the comparator is - 400 - uA
enabled
IPD3 Power-down mode power - 470 - uA
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 832 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
trigger
1.3
VIH2 Input high voltage2(RST pin) 1.60 - V
2
IOL1 Output low-level sink current - 20 - mA Port voltage 0.45V
Output high level current (bi-direction
IOH1 200 270 - uA
mode)
Output high level current (Push-pull
IOH2 - 20 - mA Port voltage 2.4V
mode)
IIL Logic 0 input current - - 50 uA Port voltage 0V
ITL Logical 1 to 0 transition current 100 270 600 uA Port voltage 2.0V
RPU I/O port pull-up resistor 4.1 4.2 4.4 KΩ
I/O high current drive, I/O fast
36 MHz PxDR=0, PxSR=0
conversion
I/O low current drive, I/O fast
32 MHz PxDR=1, PxSR=0
I/O conversion
speed I/O high current drive, I/O slow
26 MHz PxDR=0, PxSR=1
conversion
I/O low current drive, I/O slow
22 MHz PxDR=1, PxSR=1
conversion
Turn off all analog and
the fastest speed 10 MHz
digital filtering
Compara Analog filter time 0.1 us
tor
0 System LCDTY=0
Digital filter time
n+2 clock LCDTY=n (n=1~63)
Power-down mode power
IPD2 consumption when the comparator is - 460 - uA
enabled
Power-down mode power
IPD3 - 520 - uA
consumption when LVD is enabled
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 834 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
STC8G1K08A series
1. The STC8G1K08A series is currently mass-produced with version B chips. There is no problem, please feel
free to use it.
2. The PCA interrupt shutdown instruction of STC8G1K08A series A version chips cannot be completed within
one clock. The user must add an additional NOP instruction after the shutdown instruction. (Because enabling
or disabling the EA total interrupt can take effect within one clock, if the user needs to mask the interrupt
immediately, the method of turning off the EA can be used). This problem does not affect the normal use of the
chip.
3. Special attention: Since all I/O of STC8G series (except ISP download port P3.0/P3.1) are in high-impedance
input mode after power-on, the external level of I/O is not fixed. If the MCU directly enters the power-down
mode/stop mode, which will cause additional power consumption for I/O. Before the MCU enters the power-
down mode/stop mode, all I/O ports must be set according to the actual situation. In this mode, all unused
external I/Os that are floating need to be set to quasi-bidirectional ports, and the output high level is fixed.
Especially for chips with some pins, because there are some I/O ports inside the chip that are not wired to
external pins, these I/Os are also in a floating state. This part of the I/O also needs to be set as a quasi-
bidirectional port. And is fixed output high level.
STC8G2K64S4/S2 series
1. For the C version of the STC8G2K64S4/S2 series currently mass-produced chips, except for the problem that
the disable interrupt command of the PCA interrupt cannot be completed within one clock, the other known
issues of the A and B versions have all been corrected.
2. STC8G2K64S4/S2 series currently mass-produced version B chips, PCA pulse outputing problem and
P2.0/P2.1 port outputing PWM waveform problem have been corrected.
3. For STC8G2K64S4/S2 series currently mass-produced version B chips, PCA interrupt disable instruction can
not be completed within one clock, the user must add an additional NOP instruction after the disable interrupt
instruction. (Because enabling or disabling the EA total interrupt can take effect within one clock, if the user
needs to mask the interrupt immediately, the method of turning off the EA can be used). This problem does not
affect the normal use of the chip.
4. For STC8G2K64S4/S2 series currently mass-produced version B chips, when the P0.5 port is enabled to
output PWM waveform, the output of P0.5 port will be immediately terminated when an external abnormality
occurs, but the hardware has not set the P0.5 port to high-impedance input state, but switch to pull-up
bidirectional port mode. Therefore, if there is a need to enable the PWM output function of port P0.5 in the
project, please note that port P0.5 can still output a current of 20 ~ 30uA when an abnormality occurs.
5. For STC8G2K64S4/S2 series currently mass-produced version B chips, the initial value of the level
conversion speed control register of all ports after power-on is 00H, that is, the default is fast flip speed after
power-on, which is different from other series. The initial value of the level conversion speed control register of
other series is FFH, that is, it defaults to the slow reversal speed after power-on.
6. For STC8G2K64S4/S2 series currently mass-produced version B chips, when the enhanced PWM output
waveform is required, the CPU cannot enter the power saving mode, and neither IDLE mode/standby mode nor
STOP mode/stop mode will work.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 835 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
7. The PCA high-speed pulse output function of the STC8G2K64S4/S2 series A version chip will be affected by
the same set of I/O port flips. For details, please refer to the reference code of the STC8G1K08 series in this
section
8. The enhanced PWM function of STC8G2K64S4/S2 series A version of the chip has bugs in P2.0 and P2.1
ports. The other 43 I/O ports can output PWM waveforms correctly. It is recommended not to use P2.0 and P2.
1 to output PWM waveform.
9. The PCA interrupt disable instruction of STC8G2K64S4/S2 series A version chips cannot be completed
within one clock. The user must add an additional NOP instruction after the disable interrupt instruction.
(Because enabling or disabling the EA total interrupt can take effect within one clock, if the user needs to mask
the interrupt immediately, the method of turning off the EA can be used). This problem does not affect the
normal use of the chip.
10. Special attention: Since all I/O of STC8G series (except ISP download port P3.0/P3.1) are in high-
impedance input mode after power-on, the external level of I/O is not fixed. If the MCU directly enters the
power-down mode/stop mode at this time, it will cause additional power consumption for I/O. Before the MCU
enters the power-down mode/stop mode, all I/O ports must be set according to the actual situation. In this mode,
all unused I/Os that are external floating need to be set to quasi-bidirectional ports, and output high level.
Especially for chips with some I/O ports inside the chip that are not wired to external pins, these I/Os are also in
a floating state. This part of the I/O also needs to be set as a quasi-bidirectional port, and output high level.
STC8G1K08 series
1. The interrupts of LVD, Timer 2, INT2, INT3 and INT4 of STC8G1K08 series C version chip and D version
chip can not be disabled within one clock, the user must add 1 more NOP after the disable interrupt instruction
instruction. (On the basis of the C version chip, the D version chip has modified the problem that the high-speed
pulse output will be affected by the same set of I/O port flips)
2. The PCA high-speed pulse output function of the STC8G1K08 series C version chips will be affected by the
same set of I/O port flips. It is recommended not to use the high-speed pulse output function (the D version of
the chip does not have this problem).
3. Special attention: Since all I/O of STC8G series (except ISP download port P3.0/P3.1) are in high-impedance
input mode after power-on, the external level of I/O is not fixed. If the MCU directly enters the power-down
mode/stop mode at this time, it will cause additional power consumption for I/O. Before the MCU enters the
power-down mode/stop mode, all I/O ports must be set according to the actual situation. In this mode, all
unused I/Os that are external floating need to be set to quasi-bidirectional ports, and output high level.
Especially for chips with some I/O ports inside the chip that are not wired to external pins, these I/Os are also in
a floating state. This part of the I/O also needs to be set as a quasi-bidirectional port. And fixed output high level.
STC8G1K08T series
1. STC8G1K08T series B version chip has been available for samples, please stop using A version chip and use
B version chip for testing
2. Special attention: Since all I/O of STC8G series (except ISP download port P3.0/P3.1) are in high-impedance
input mode after power-on, the external level of I/O is not fixed. If the MCU directly enters the power-down
mode/stop mode at this time, it will cause additional power consumption for I/O. Before the MCU enters the
power-down mode/stop mode, all I/O ports must be set according to the actual situation. In this mode, all
unused I/Os that are external floating need to be set to quasi-bidirectional ports, and output high level.
Especially for chips with some I/O ports inside the chip that are not wired to external pins, these I/Os are also in
a floating state. This part of the I/O also needs to be set as a quasi-bidirectional port, and output high level.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 836 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
5. The size and gap of the key induction plate (capacitive sensor)
In the case of meeting the aesthetic design requirements of the panel, the optimal touch sensing effect must be
obtained through a reasonable arrangement of the sensing plate size and the interval size. The induction plate is
placed on the bottom layer, and the IC is also placed on the bottom layer. There should be no vias in the
connection between the induction plate and the IC. The distance between the edges of adjacent sensing plates is
preferably above 1.5mm (dimension D in the figure below). If the PCB area allows, try to use a larger distance.
The distance between the copper paving and the induction plate is 0.5mm (dimension E in the figure below).
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 837 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
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, and the
frame shape of the silk screen is the same as that of the bottom sensor disk. The top layer corresponding to the
bottom sensor disk must not be coated with copper, otherwise the touch action will be shielded. The copper on
the top layer is the same as the copper on the bottom layer.
7. Wiring processing
It is better to use a smaller line width for the connection between the induction plate and the IC, such as
between 10 and 15 mils. The connection between the induction pad and the touch chip should not cross the lines
with strong interference, high frequency, and high current. Do not run other signal lines within 1.5mm of the
connection between the sensor plate and the touch chip, the farther away the better. The top layer corresponds to
the bottom layer of the induction plate and the connection line, it is best not to put any line.
1. Firstly, you need to prepare the following tools, soldering iron, hot air gun, tweezers, fixing frame and other
tools.
2. The PCB boards and chips that need to be soldered are as follows:
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 838 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
4. Then tin the bottom of the chip. After the tin is applied, the tin should be flattened, and the tin should be
minimized, 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.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 839 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
6. Put the chip on the pad, be sure to place it straight, and then blow it with a hot air gun at an even speed until
the tin melts, usually within 20 seconds.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 840 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
I/O ports
After the STC8G series microcontrollers are powered on, the I/O ports mode is different from that of the STC15
series. All I/O ports of STC15 series microcontrollers are in 8051 quasi-bidirectional port mode after power-on.
For STC8G series microcontrollers, except for ISP download pins P3.0/P3.1 which are quasi-bidirectional port
modes, all the other I/O ports are in high-impedance input mode after power-on. The traditional 8051 and STC
15 series microcontrollers are in quasi-bidirectional port mode and output high level after power on. Often there
will be moments that the motor moves or the LED flashes in the systems where I/Os are used to drive motors or
LED lights when the microcontroller is powered on. The I/O of the STC8G series is in high-impedance input
mode after power-on, which can avoid this kind of malfunction of the motor and LED.
Because in STC8G series microcontrollers, all the other I/O ports except ISP download pin P3.0/P3.1 which is
quasi-bidirectional port mode are in high-impedance input mode after power-on, before the I/O ports of the
STC8G series output signals, the two registers PxM0 and PxM1 must be used to set the I/O working mode.
Reset pin
The P5.4 port of the STC8G series and STC15 series is generally used as a normal I/O port. When the user sets
P5.4 as the reset pin function during ISP download, the P5.4 port is the reset pin of the microcontroller. For the
STC15H series, when the reset pin is high, the microcontroller is in the reset state, and when the reset pin is low,
the microcontroller is released from the reset state. The reset levels of STC8 series and STC15H series are
reversed, that is, for STC8G series, when the reset pin is low, the microcontroller is in the reset state, and when
the reset is high, the microcontroller is released from the reset state.
Therefore, when the user enables the reset pin function of port P5.4, it is necessary to pay attention to the reset
level.
ADC
The ADC_CONTR, ADC_RES, ADC_RESL registers addresses of STC8G series and STC15 series are the
same. But the STC8G series adds two new registers: ADCCFG and ADCTIM.
STC15 series start ADC conversion bit ADC_START is located at BIT3 of register ADC_CONTR, while
STC8G series is located at BIT6 of ADC_CONTR
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 841 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
The STC15 series ADC conversion complete flag ADC_FLAG is located at BIT4 of the register ADC_CONTR,
while the STC8G series is located at BIT5 of ADC_CONTR
STC15 series ADC speed control bit ADC_SPEED is located in BIT6-BIT5 of register ADC_CONTR, and
STC8G series is located in BIT3-BIT0 of ADCCFG
The alignment control bit ADRJ of the STC15 series ADC conversion result is located at BIT5 of the register
CLK_DIV, while the alignment control bit RESFMT of the STC8G series is located at BIT5 of ADCCFG
The STC8G series adds a more precise ADC conversion timing control mechanism, which can be set through
the register ADCTIM
EEPROM
The waiting time for EEPROM erasing and programming of STC15 series is set by Bit2-Bit0 of the register
IAP_CONTR. The setting is only an approximate frequency range value. The STC8G series adds a new register
IAP_TPS (SFR address: 0F5H), dedicated to setting EEPROM erasing and programming waiting time, and the
user does not need to calculate, just fill in IAP_TPS directly according to the current CPU working frequency,
and the hardware will automatically calculate the waiting time. (For example: the current CPU operating
frequency is 24MHz, you only need to fill in 24 to IAP_TPS)
I/O ports
After the STC8G series MCU is powered on, the I/O mode is different from that of the STC8A/8F series. All
I/O ports of STC8A/8F series microcontollers are in the quasi-bidirectional mode of 8051 after power-on. All of
the I/O ports of STC8G series microcontrollers except for the ISP download pin P3.0/P3.1 which are the quasi-
bidirectional mode are in high-impedance input mode after power-on. The traditional 8051 and STC 15/8A/8F
series microcontrollers are in quasi-bidirectional mode and output high level after power-on. Often there will be
moments that the motor moves or the LED flashes in the systems where I/Os are used to drive motors or LED
lights when the microcontroller is powered on. The I/O of the STC8G series is in high-impedance input mode
after power-on, which can avoid this kind of malfunction of the motor and LED.
Because in STC8G series microcontrollers, all the other I/O ports except ISP download pin P3.0/P3.1 which is
quasi-bidirectional port mode are in high-impedance input mode after power-on, before the I/O ports of the
STC8G series output signals, the two registers PxM0 and PxM1 must be used to set the I/O working mode.
Reset pin
The P5.4 port of the STC8G series and STC8A/8F series is generally used as a normal I/O port. When the user
sets P5.4 as the reset pin function during ISP download, the P5.4 port is the reset pin of the microcontroller. For
the STC8A/8F series, when the reset pin is high, the microcontroller is in the reset state, and when the reset pin
is low, the microcontroller is released from the reset state. The reset levels of STC8 series and STC15H series
are reversed, that is, for STC8G series, when the reset pin is low, the microcontroller is in the reset state, and
when the reset is high, the microcontroller is released from the reset state.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 842 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Therefore, when the user enables the reset pin function of port P5.4, it is necessary to pay attention to the reset
level.
EEPROM
The waiting time for EEPROM erasing and programming of STC8A/8F series is set by Bit2-Bit0 of the register
IAP_CONTR. The setting is only an approximate frequency range value. The STC8G series adds a new register
IAP_TPS (SFR address: 0F5H), dedicated to setting EEPROM erasing and programming waiting time, and the
user does not need to calculate, just fill in IAP_TPS directly according to the current CPU working frequency,
and the hardware will automatically calculate the waiting time. (For example: the current CPU operating
frequency is 24MHz, you only need to fill in 24 to IAP_TPS)
I/O ports
After the STC15H series microcontrollers are powered on, the I/O ports mode is different from that of the
STC15F/L/W series. All I/O ports of STC15F/L/W series microcontrollers are in 8051 quasi-bidirectional port
mode after power-on. For STC15H series microcontrollers, except for ISP download pins P3.0/P3.1 which are
quasi-bidirectional port modes, all the other I/O ports are in high-impedance input mode after power-on. The
traditional 8051 and STC 15 series microcontrollers are in quasi-bidirectional port mode and output high level
after power on. Often there will be moments that the motor moves or the LED flashes in the systems where I/Os
are used to drive motors or LED lights when the microcontroller is powered on. The I/O of the STC15H series
is in high-impedance input mode after power-on, which can avoid this kind of malfunction of the motor and
LED.
Because in STC15H series microcontrollers, all the other I/O ports except ISP download pin P3.0/P3.1 which is
quasi-bidirectional port mode are in high-impedance input mode after power-on, before the I/O ports of the
STC8G series output signals, the two registers PxM0 and PxM1 must be used to set the I/O working mode.
Reset pin
The P5.4 port of the STC15H series and STC15F/L/W series is generally used as a normal I/O port. When the
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 843 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
user sets P5.4 as the reset pin function during ISP download, the P5.4 port is the reset pin of the microcontroller.
For the STC15H series, when the reset pin is high, the microcontroller is in the reset state, and when the reset
pin is low, the microcontroller is released from the reset state. The reset levels of STC8 series and STC15H
series are reversed, that is, for STC15H series, when the reset pin is low, the microcontroller is in the reset state,
and when the reset is high, the microcontroller is released from the reset state.
Therefore, when the user enables the reset pin function of port P5.4, it is necessary to pay attention to the reset
level.
ADC
The ADC_CONTR, ADC_RES, ADC_RESL registers addresses of STC15H series and STC15F/L/W series are
the same. But the STC15H series adds two new registers: ADCCFG and ADCTIM.
The STC15F/L/W series start ADC conversion bit ADC_START is located at BIT3 of register ADC_CONTR,
while STC15H series is located at BIT6 of ADC_CONTR
The STC15F/L/W series ADC conversion complete flag ADC_FLAG is located at BIT4 of the register
ADC_CONTR, while the STC15H series is located at BIT5 of ADC_CONTR
STC15F/L/W series ADC speed control bit ADC_SPEED is located in BIT6-BIT5 of register ADC_CONTR,
and STC15H series is located in BIT3-BIT0 of ADCCFG
The alignment control bit ADRJ of the STC15F/L/W series ADC conversion result is located at BIT5 of the
register CLK_DIV, while the alignment control bit RESFMT of the STC15H series is located at BIT5 of
ADCCFG
The STC15H series adds a more precise ADC conversion timing control mechanism, which can be set through
the register ADCTIM
EEPROM
The waiting time for EEPROM erasing and programming of STC15F/L/W series is set by Bit2-Bit0 of the
register IAP_CONTR. The setting is only an approximate frequency range value. The STC15H series adds a
new register IAP_TPS (SFR address: 0F5H), dedicated to setting EEPROM erasing and programming waiting
time, and the user does not need to calculate, just fill in IAP_TPS directly according to the current CPU working
frequency, and the hardware will automatically calculate the waiting time. (For example: the current CPU
operating frequency is 24MHz, you only need to fill in 24 to IAP_TPS)
Comparators
The positive pole of the comparator in STC15W series is P5.5 and the negative pole is P5.4. The positive pole
of the comparator in STC15H series is P3.7 and the negative pole is P3.6.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 844 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2022/3/9
1. Update data sheet
2022/1/25
1. Update the reference circuit diagram of TL431/CD431 in the document
2021/8/27
1. Correct the comment error in the sample program in the ADC chapter
2. Add sample programs to the enhanced PWM chapter
2021/7/19
1. Add STC15H series special models
2. The precautions for adding STC15H series to replace STC15F/L/W series
2021/7/7
1. Add DIP8 pin description of STC8G1K08A series
2. Add the pin description of DIP16 and DIP20 of STC8G1K08 series
3. In the enhanced PWM chapter, a sample program of "generating three complementary PWM waveforms with
a dead zone with a phase difference of 120 degrees" is added.
4. In the Enhanced PWM chapter, a sample program of "PWM waveform with output duty ratio of 100% and
0%" is added.
2021/6/26
1. Modified the calculation formula of enhanced PWM output frequency
2. Add STC8G2K48S4 model
3. Add STC8G2K48S2 model
2021/5/10
1. Add the description of ADC power switch delay
2. Added the principle description and calculation formula of using the 15th channel of the ADC to reverse
the input voltage of the external channel
3. Modify the wrong description of the maximum available FLASH size of some series
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 845 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2021/3/8
1. Using STC8G1K17 model as an example how users plan their own EEPROM
2. Added STC8 series naming highlights in the appendix
2021/2/26
1. Add description about USB simulation download
2. Added descriptions of 8-bit clock prescaler registers for Timer 2, Timer 3, and Timer 4
3. The touch button sensitivity adjustment capacitor description of the touch button chip (it is
recommended to use a monolithic capacitor)
2021/2/4
1. Correct the initial value of the CLKDIV register after reset
2. Update the reference circuit diagram of driving common cathode/common anode LED
3. Update the price of STC8G2K64S4-QFN32
4. Add description of initial value of special function register
5. Modify the description error in the 3V/5V device hybrid system application in the I/O port chapter
6. Add application reference circuit diagram under the pin diagram
2020/12/4
1. Correct some errors in the sample program
2. Add serial port to LIN bus example program
2020/11/25
1. Correct some errors in the sample program
2. Update interrupt structure diagram
3. Update the application notes of STC8G2K64S4/STC8G2K64S2 series
4. Add sample program for PCA module to use ECI external clock mode
2020/10/16
1. Update the price of LQFP32 package of STC8G2K64S4
2. Correct the error in the pin description of the STC8G1K08 series
3. Add the load capacitance description of the external crystal oscillator circuit
2020/9/23
1. Update application notes
2. Modify some description errors in the PCA/CCP/PWM chapter
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 846 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2020/9/4
1. Modify some typos in the document
2. Update STC8G2K64S4/S2 application notes
3. Completes the internal hardware block diagram of timer 0/1/2/3/4 in the timer chapter
4. Correct the stop description of Mode 3 of Timer 0 (Mode 3 of Timer 0 is a non-maskable interrupt. Once
it is started, it cannot be stopped by software, and the chip must be reset to stop it)
5. Organize document chapter order
6. Add STC8G2K64S4-LQFP32 pin diagram
7. "Microcontroller power supply control reference circuit" is added to the chapter of typical application
circuit diagrams
8. Add 20M, 27M, 30M, 33.1776M, 35M and 36.864MHz IRC parameters to the special parameter list in
Chapter 7.3 "Special Parameters in Memory"
9. Update the example code of Chapter 7.3.7 "User-defined internal IRC frequency"
2020/8/26
1. Add the chapter of timer calculation formula
2. Add the chapter of serial port baud rate calculation formula
3. Add 15-bit enhanced PWM output frequency calculation formula chapter
4. Add ADC related calculation formula chapters
5. Add 12-bit ADC static parameter reference data
6. Add the parameter of the number of clocks required for MDU16 operation
7. Add the time parameter required for EEPROM operation
8. The special function registers in all chapters are listed separately as directory subsections for easy
searching
9. The precautions for adding STC8G series MCU to replace STC8A/8F series
2020/8/21
1. Modify some errors in the description of the document
2. Add 15-bit enhanced PWM feature description
2020/8/10
1. Add watchdog timer chapter
2. Organize the chapter on wake-up timer after power failure
3. Update application notes
4. Add the appendix chapter about STC download tool usage instructions
2020/8/6
1. Explain the working temperature
2. Add the application downloading circuit diagram using the universal USB to serial tool
3. Update application notes
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 847 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2020/7/16
1. Add description of BUS_SPEED register
2. Add welding instructions for QFN/DFN packaged chips
3. Add EEPROM programming instructions
4. Add the method of setting U8W/U8-Mini to pass-through mode in the chapter of downloading
application circuit diagram
2020/7/3
1. Add the appendix chapter, "How to reset the user program to the system area for ISP download without
power failure"
2. Add an appendix chapter, "Use STC's IAP series MCU to develop your own ISP program"
3. Add the appendix chapter, "Precautions for STC8G series MCU to replace STC15 series"
4. Add appendix chapter, "Official website description"
5. In the ADC chapter, add ADC conversion timing diagram
6. Delete the enhanced PWM on ports P0/P1/P3/P4/P5 in the STC8G2K64S2 series
2020/6/15
1. Add ADC_VRef+ pin description
2. Add instructions for using diodes and resistors in the USB-to-serial reference circuit
3. Modify the description of the I/O port drive current control register PxDR (1: normal drive current; 0:
strong drive current)
4. Add description of I2C slave device address
2020/6/8
1. Add the description of the fastest conversion speed of ADC
2. Detailed description of I2C bus speed setting
3. Update the reference circuit diagram of ISP download in simulated USB mode
4. Add DFN8, QFN20, QFN32, QFN48, QFN64 substrate descriptions in the package drawing
5. Add PCA outputing 10-bit PWM sample program
6. Add sample program for comparator multiplexing (comparator + ADC input) application
2020/5/29
1. Addition circuit application is added in ADC chapter
2. Add the description of the register EAXFR
3. Add the method of using a third-party application to call the release project program
2020/5/25
1. Add negative pressure detection circuit in ADC chapter
2. Fix garbled characters in some pictures
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 848 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2020/5/20
1. Update the power consumption parameters of the clock stop mode when the low-voltage detection
wake-up function is enabled in the electrical characteristics
2. Update the power consumption parameters of the clock stop mode when the comparator power-down
wake-up function is enabled in the electrical characteristics
3. The ADCTIM register is added to the ADC sample program to control the internal timing of the ADC
4. Correct some typos in the document
5. Add an interrupt that can be used to wake up from clock stop mode in the features of each
microcontroller series
6. Add the PWM frequency calculation formula and the method of outputting full high level and full low
level in the PCA chapter
7. Added ISP download step guide in the ISP download application circuit diagram
8. Add power-down wake-up timer to wake up the power-saving mode sample program
2020/5/14
1. Add the description of comparator multiplexing
2. Add PWM trigger ADC sample program
3. Add ADC working clock frequency description in ADC chapter
4. Add ADC reference circuit diagram in ADC chapter
5. Update the power consumption parameters of low voltage detection, comparator, etc. in electrical
characteristics
6. Add reference circuit diagram for power-on reset and button reset
2020/4/29
1. Change the serial port download reference circuit diagram, the series resistance on the TxD pin of the
MCU is changed from 300 ohms to 100 ohms
2. Fix the error in the power supply part of the reference circuit diagram using PL2303GL for ISP
download
2020/4/26
1. Modified the package size drawing of DFN8 (3mm*3mm)
2. Update I/O speed parameters in electrical characteristics
3. Update the speed parameter of the comparator in the electrical characteristics
4. Add LED driver example program
5. Add the reference pin diagram of PDIP40 of STC8G2K64S4 series and STC8G2K64S2 series
6. Correct the time point of setting TI and RI in the serial port note in chapter 13.6
7. Add the description of analog filtering and digital filtering in the chapter of Comparator
8. In Appendix E, the connection error between MAX232 and RS485 is corrected
2020/4/8
1. Add application precautions for STC8G1K08T series chips
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 849 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2. Modify the parameters of STC8G2K64S4 model in the chapter "Special parameters in memory"
3. Correct the formula for calculating voltage in the chapter "Using ADC channel 15 to measure external
voltage or battery voltage"
4. Amend the special function register related to LED driver of STC8G1K08T series
5. Add instructions for using the power-down wake-up timer register
6. Update the content about the overall drive current in the I/O port chapter
2020/3/26
1. IRC24MCR register is renamed HIRCCR
2. Add the reference circuit diagram of STC8G2K64S4-LQFP48 model which uses PL2303GL to download
3. Add STC8G2K64S4-LQFP48 model direct soft simulation USB download reference circuit diagram
4. Update the power consumption of the chip in the DC characteristics at different operating frequencies
5. Update application notes
6. Add a description at the beginning of the enhanced PWM chapter
7. Add "Touch Button PCB Design Guide" appendix chapter
2020/3/6
1. Rearranged the structure of the pin diagram chapter.
2. Correct the chip characteristics of STC8G1K17, STC8G1K17A models.
2020/3/5
1. Fixed touch key interrupt vector entry address
2. Correct touch key interrupt enable bit and special function register bit of interrupt priority
2020/3/4
1. Correct the part of the document about the description of the internal reference voltage.
2. Corrected some sample code errors in the PWM chapter.
3. Add the application circuit diagram of general precision ADC and high precision ADC.
4. Add the static parameters of the ADC module.
5. Add STC8G1K08T-20PIN touch key series.
6. Add touch key controller description section.
7. Add touch key reference circuit diagram.
8. Add LED driver description section.
2020/2/26
1. Add DFN8 package drawing.
2020/2/24
1. Add "Handling of compilation errors in Keil with interrupt numbers greater than 31" section
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 850 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
2020/1/20
1. Add "Using PCA module to implement DAC" reference circuit diagram
2. Add "a typical triode control" circuit
3. Add "Typical LED Control" circuit
4. Add the reference circuit of “Interconnecting I/O Ports of 3V/5V Devices in Mixed Voltage Power
Supply System”
5. Add "How to make I / O port to low level when power on reset" reference circuit
6. Add the reference circuit of “Drive 8 digital tubes (serial extension, 3 wires) with 74HC595”
7. Add "I / O port direct drive digital LED" reference circuit
8. Add "Automatically launch ISP download after receiving user commands when running user
programs" description
2020/1/17
1. Add the number clocks of MDU16 operation
2. Correct the descriptions in important notes
2020/1/15
1. Add "ADC as capacitive sensing touch key" chapter
2. Add "ADC as Key Scan Application Circuit Diagram" section
3. Add appendix "RS485 automatic control or I/O port control circuit diagram"
4. Add appendix "Part of RS485 circuit diagrams in U8W download tool"
2019/12/30
1. Update chip selection and price list
2. Add example code to generate user-specified frequency
2019/12/24
1. Modify the main control chip in the reference circuit diagram of the comparator section to STC8G
series of microcontrollers
2. Modify the main control chip in the reference circuit diagram of the ADC chapter to STC8G series of
microcontrollers
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 851 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
3. Name the channel used to measure the internal voltage in the ADC module as the 15th channel
4. Renamed the original STC8G1K08 series to STC8G1K08-20PIN series
5. Renamed the original STC8G2K64S4 series to STC8G2K64S4-48PIN series
6. Add STC8G1K08-8PIN series
7. Add STC8G1K08A-8PIN series
8. Add STC8G2K64S2-48PIN series
9. Correct the parameters of LVR voltage and electrical characteristics
2019/11/27
1. Add STC8G2K64S4 series
2. Add important instructions of STC8G1K08 series
2019/11/11
1. Add product authorization letter
2. Unified the name of Flash program memory and ROM in the document
3. Add USB download step demo (Appendix C)
2019/10/22
1. Add QFN20 pin out
2. Add QFN20 package diagram
3. Update the example program
2019/10/15
1. Correct four levels voltage of LVR
2. Correct the temperature drift range of the internal high-precision IRC
3. Correct the internal reference voltage
4. Update DC characteristics table data
2019/10/09
1. Remove the power control register (VOCTRL) part, STC8G series does not have this function
2. Modify the four-level voltage of the LVR
3. Fixed two frequency ranges of IRC
2019/8/13
1. Create STC8G Series MCU Technical Reference Manual Document
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 852 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 853 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Authorization Letter
products in China.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 854 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
Shenzhen.
The core product R&D is in China, with all design capabilities such
with the R&D team taking the lead People who have been engaged in
research and development for more than ten years, have long-term
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 855 -
STC8G Series Manual www.STCMCUDATA.com Technical support: +86-13922809991 Development adviser: +86-13922805190
controllable.
Test: The test after the design of this device is completed in the
All the key processes of this device are completed on our own
production line, which can be supplied for a long time without the
Hereby explain.
Shenzhen Guoxin AI Co., Ltd. Tel: +86-513-5501 2928/2929/2966 Fax: +86-513-5501 2926/2956/2947 - 856 -