UART communication in 8051 microcontroller is one of the most widely used serial communication methods in embedded systems. It allows the 8051 to exchange data with external devices such as computers, GSM modules, Bluetooth modules, GPS receivers, and sensors. UART (Universal Asynchronous Receiver Transmitter) is simple, reliable, and ideal for point-to-point communication. In this tutorial, you will learn how UART works in the 8051, including register configuration, baud rate calculation, programming steps, and real-world applications with C code examples. This guide is designed for beginners, engineering students, and embedded system learners.
UART communication in the 8051 microcontroller enables reliable serial data transfer with external devices such as GSM, Bluetooth, GPS, and PCs. By configuring UART registers and baud rate correctly, real-time monitoring and control applications can be easily implemented. This technology forms the backbone of many embedded communication projects.
UART (Universal Asynchronous Receiver/Transmitter) communication is an asynchronous serial data transmission technique. Since it is asynchronous, no clock signal is shared between the transmitter and receiver.
| Feature | UART | SPI | I2C |
|---|---|---|---|
| Type | Asynchronous | Synchronous | Synchronous |
| Pins | TX, RX | MOSI, MISO, SCK, SS | SDA, SCL |
| Speed | Moderate | High | Moderate |
| Devices | Point-to-Point | Multi-Slave | Multi-Master |
UART operation in the 8051 microcontroller is controlled using three important registers.
The SCON (Serial Control) register is used to select the UART mode and control transmission and reception.
| Bit | Name | Function |
|---|---|---|
| SM0, SM1 | Mode Select | Selects UART mode |
| REN | Receive Enable | Enables reception |
| TI | Transmit Interrupt | Set after transmission |
| RI | Receive Interrupt | Set after reception |
The PCON register controls power and baud rate.
SMOD bit doubles the baud rate when set.
The SBUF (Serial Buffer) register stores:
The 8051 supports four UART modes.
| Mode | Description | Baud Rate |
|---|---|---|
| 0 | Shift Register Mode | Fixed |
| 1 | 8-bit UART | Variable |
| 2 | 9-bit UART | Fixed |
| 3 | 9-bit UART | Variable |

Follow these steps to implement UART communication:

Concept:
GSM modules such as SIM800/SIM900 communicate using AT commands via UART.
| GSM Module | 8051 |
|---|---|
| TXD | P3.0 (RXD) |
| RXD | P3.1 (TXD) |
| GND | GND |
Sample UART C Code (Send SMS):
#include
void uart_init(){
TMOD = 0x20;
TH1 = 0xFD; // 9600 baud @ 11.0592MHz
SCON = 0x50;
TR1 = 1;
}
void uart_tx(char ch){
SBUF = ch;
while(TI==0);
TI = 0;
}
void uart_string(char *s){
while(*s)
uart_tx(*s++);
}
void main(){
uart_init();
uart_string("AT\r\n");
uart_string("AT+CMGF=1\r\n");
uart_string("AT+CMGS=\"+919xxxxxxxxx\"\r\n");
uart_string("Hello from 8051");
uart_tx(0x1A); // CTRL+Z
while(1);
}
Concept:
HC-05 works as a wireless serial cable.
char rx;
void main(){
uart_init();
while(1){
while(RI==0);
rx = SBUF;
RI = 0;
uart_tx(rx); // Echo received data
}
}
Concept:
GPS modules continuously send NMEA sentences via UART.
char gps;
void main(){
uart_init();
while(1){
while(RI==0);
gps = SBUF;
RI = 0;
uart_tx(gps);
}
}
Concept:
Sensor values are transmitted to a PC for real-time monitoring.
void main(){
uart_init();
while(1){
uart_string("Temp = 30C\r\n");
}
}
Concept:
Sensor data is transmitted to an SD card module via UART-SPI converter.
void main(){
uart_init();
while(1){
uart_string("Sensor Value: 123\r\n");
}
}
UART communication in 8051 is used in:
UART communication in 8051 microcontroller is a fundamental concept in embedded systems. By correctly configuring UART registers and baud rate timing, reliable serial communication can be achieved with real-world devices. Mastering UART makes it easier to work with advanced protocols such as SPI, I2C, and modern microcontrollers.
Timer 1 generates the required baud rate by operating in 8-bit auto-reload mode.
Cause:
Cause:
Indian Institute of Embedded Systems – IIES