STC89C52RC serial port baud rate program

First, here is the full code:

C

#include

#define uchar unsigned char

#define uint unsigned int

void send(uchar state)

{

SBUF = state;

while (TI == 0);

TI = 0;

}

void SCON_init(void)

{

TMOD = 0x20; // 6T mode, 11.05992@115200

SCON = 0x50;

PCON = 0x80;

TL1 = 0xFF;

TH1 = 0xFF;

TR1 = 1;

/*SCON = 0x50; // Timer 2 mode, 11.0592@115200

TH2 = 0xFF;

TL2 = 0xFD;

RCAP2H = 0xFF;

RCAP2L = 0xFD;

TCLK = 1;

RCLK = 1;

C_T2 = 0;

EXEN2 = 0;

TR2 = 1;*/

}

void main()

{

SCON_init();

while (1)

{

send('A');

}

}

Second, some notes:

The SCON_init function is used to configure and initialize the serial port baud rate. It should be called once at the beginning of the main program. In this code, two different methods are shown for setting up the serial communication. The part without comments represents the 6T mode configuration, while the commented section demonstrates the 12T mode using Timer 2.

The choice between 6T and 12T mode is made by the programmer during development, and no special code is needed to switch between them. Note that Timer 2 is only available on certain enhanced 51 microcontrollers, such as the STC89C52RC. This setup ensures reliable serial communication at a specific baud rate, typically 115200 bps in this example.

This code can be modified to send other characters or data by changing the argument passed to the send() function. It's also common to add error checking or loop control to prevent infinite loops in real-world applications.

Silicone Heat Shrink Tube

Heat Shrink Tubing, also known as heat shrinkable protection tubing, provides insulation protection for wires, cables and wire terminals. With high temperature shrinkage, soft flame retardant, insulation and corrosion protection, etc., it is widely used for insulation protection of various wiring harnesses, solder joints, inductors, and rust and corrosion protection of metal tubes and bars. Heat Shrink Tube flame retardant, insulation, temperature resistance, heat shrinkable tubing is a special polyolefin material heat shrinkable tubing, also called EVA material. It is soft and flexible. Heat (125 degrees) will shrink, widely used in a variety of harnesses, solder joints, inductors, insulation protection, metal tubes, bars, rust, corrosion. Commonly used in the wire connector, choose the right heat shrink tubing, set on the wire connector, heated with a hot air gun, the heat shrink tubing contraction, the connector set firmly. Can be used for general electronics, electrical appliances, batteries and other packaging insulation. Through the use of heaters can be made to tighten, play insulation, protection and other functions.

Non-slip Heat Shrink Tube,Heat Shrink Tube,Silicone Heat Shrinkable Tube

Dongguan Liansi Electronics Co.,Ltd , https://www.liansisleeve.com