Appendix M Example Routine of ISP download for
STC8A8K64D4 series MCUs using third-party MCU
C language code
/*Note: When using this code to download the STC8A8K64D4 series of microcontrollers, you must execute the Download code before
powering on the target chip, otherwise the target chip will not download correctly.*/
#include "reg51.h"
typedef bit BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
//Macro and constant definition
#define FALSE 0
#define TRUE 1
#define LOBYTE(w) ((BYTE)(WORD)(w))
#define HIBYTE(w) ((BYTE)((WORD)(w) >> 8))
#define MINBAUD 2400L
#define MAXBAUD 115200L
#define FOSC 11059200L //Main chip working frequency
#define BR(n) (65536 - FOSC/4/(n)) // Calculation formula of serial port baud rate of main chip
#define T1MS (65536 - FOSC/1000) // 1ms timing initial value of main chip
#define FUSER 24000000L //STC8 Series target chip operating frequency
#define RL(n) (65536 - FUSER/4/(n)) //STC8 Serial target chip baud rate calculation formula
sfr AUXR = 0x8e;
sfr P3M1 = 0xB1;
sfr P3M0 = 0xB2;
// 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