How to interface computer's Serial Port (RS232) with 8051 microcontroller (AT89C51)
Summary
Several devices collect data from sensors and need to send it to another unit, like a computer, for further processing. Data transfer/communication is generally done in two ways: parallel and serial. In the parallel mode, data transfer is fast and uses more number of lines. This mode is good for short range data transfer.
Serial communication on the other hand, uses only one or two data lines to transfer data and is generally used for long distance communication. In serial communication the data is sent as one bit at a time. This article describes the interfacing of 8051 microcontroller (AT89C51) with a computer via serial port, RS232. Serial communication is commonly used in applications such as industrial automation systems, scientific analysis and certain consumer products.
Description
Serial Port
The microcontroller AT89C51 has an inbuilt UART for carrying out serial communication. The serial communication is done in the asynchronous mode. A serial port, like other PC ports, is a physical interface to establish data transfer between computer and an external hardware or device. This transfer, through serial port, takes place bit by bit.
IBM introduced the DB-9 RS-232 version of serial I/O standard, which is most widely used in PCs and several devices. In RS232, high and low bits are represented by flowing voltage ranges:
Bit | Voltage Range (in V) | |
0 | +3 | +25 |
1 | -25 | -3 |


SM0 | SM1 | SM2 | REN | TB8 | RB8 | TI | RI |
D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
In program, Timer1 is used with auto reload setting. The baud rate is fixed to 9600bps by loading TH1 to 0xFD. The value 0x50 is loaded in the SCON register. This will initialize the serial port in Mode1. The program continuously receives a character (say ‘a’) from the serial port of the computer and transmits it back.
Video
Code
This Code is only visible to Registered users. Please Login/Register
Components
|
MAX232 The MAX232 IC is used to convert the TTL/CMOS logic levels to RS232 logic levels during serial communication of microcontrollers with PC. The controller operates at TTL logic level (0-5V) whereas the serial communication in PC works... |
|
AT89C51 Microcontroller AT89C51 is an 8-bit microcontroller and belongs to Atmel's 8051 family. ATMEL 89C51 has 4KB of Flash programmable and erasable read only memory (... |
- 102456 reads
