Share this

Design of serial communication between AT89S52 microcontroller and PC

2026-04-06 09:05:48 · · #1
Introduction Serial communication between a microcontroller and a PC, also known as serial communication between a lower-level machine and a higher-level machine, can solve the hazards to workers caused by poor working conditions. It also enables real-time online remote centralized monitoring and management of microcontrollers distributed across the work site via a control platform, improving both working conditions and efficiency. This paper elaborates on the circuit and program design for serial communication. 1 Circuit Design Communication interface standards include RS232, RS423A, RS422A, and RS485, with RS232 and RS485 being the most commonly used. RS232 is widely used in microcomputer serial communication interfaces. With a modem, this communication can transmit data over telephone lines over distances of thousands of kilometers; without a modem, it can transmit over distances of tens of meters. This project uses a direct RS-232 connection without a modem and a DB-9 connector. The microcontroller used is the AT89S52, with its serial input (RXD) and serial output (TXD) connected to the PC's COM port. RS232 uses positive and negative voltages to represent logic states, which differs from TTL's high and low level representation. Therefore, to connect to a computer interface or TTL devices, a level and logic conversion between RS232 and TTL is necessary. This conversion can be achieved using discrete components or integrated chips; this paper uses the MAX232 to perform TTL-EIA (Electronic Industries Association) bidirectional level conversion. The MAX232 has internal voltage multiplier and conversion circuits, requiring only a +5V power supply to operate, making it very convenient to use. When connecting it to the AT89S52, the simplest connection method can be used (see Figure 1). The T1 IN pin of the MAX232 is connected to the serial input line P3.1TXD of the AT89S52, and the R1 OUT pin is connected to the serial input line P3.0RXD of the AT89S52. The T1 OUT and R1 IN pins of the MAX232 are connected to pins 2 and 3 of the RS232, respectively. A 0.1μF capacitor must be connected to the MAX232 pump power supply pins, as shown in C26, C27, C28, and C29 in the figure. Because a level conversion chip is used in the circuit, only pins 2, 3, and 5 of the connectors used by the microcontroller and the PC serial port need to be connected accordingly; pins 2 and 3 do not need to be crossed (as shown in Figure 2). If connecting between PCs or two COM ports of the same PC, pins 2 and 3 of the two connectors need to be crossed. 2. Program Design The main program is designed as follows: The AT89S52 microcontroller uses Timer 1, operating in mode 2, with an 11.059 MHz crystal oscillator, a baud rate of 9600 Hz, and a time constant of FDH. The microcontroller first sends a hexadecimal handshake signal "aaH" to the PC. When the PC receives the signal correctly, it replies with BBH, using the sum of the array adr[] as the checksum. When the test is normal, the array tri[] is sent. The complete program code is as follows: The communication between the upper and lower computers can be verified using serial port debugging software installed on the upper computer. The above program runs normally after being debugged with the software.
Read next

CATDOLL Ava Hard Silicone Head

The head made from hard silicone does not have a usable oral cavity. You can choose the skin tone, eye color, and wig, ...

Articles 2026-02-22