STC8A8K64D4 Series Manual
14.8.10 UART to LIN BUS
C language code
// Operating frequency for test is 22.1184MHz
/************* Function Description **************
This routine is based on the experiment box 8 to program and test, whose main control chip is STC8H8K64U.
It is can be used for general reference when using STC8G and STC8H series chips.
Connect the LIN transceiver through the UART interface to realize the LIN bus signal transceiver test routine. UART1 is connected to
the computer through the serial port tool.
UART2 is connected to an external LIN transceiver (TJA1020/1) and connected to the LIN bus.
Forward the data sent by the computer serial port to the LIN bus; forward the data received from the LIN bus to the computer serial
port.
Default transmission rate: 9600 baud rate, switch baud rate before sending LIN data, send 13 dominant interval signals.
When downloading, select the clock 22.1184MHz (users can modify the frequency by themselves).
******************************************/
#include "reg51.h"
#include "intrins.h"
#define MAIN_Fosc 22118400L
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
sfr AUXR = 0x8E;
sfr S2CON = 0x9A;
sfr S2BUF = 0x9B;
sfr TH2 = 0xD6;
sfr TL2 = 0xD7;
sfr IE2 = 0xAF;
sfr INT_CLKO = 0x8F;
sfr P_SW1 = 0xA2;
sfr P_SW2 = 0xBA;
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;