UART Communication in 8051 Microcontroller

uart communication in 8051

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.

This tutorial covers

  • Basics of UART communication
  • UART registers in 8051
  • UART operating modes
  • Baud rate calculation
  • UART programming steps
  • Practical UART applications with C code

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.

Basics of UART Communication

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.

How UART Works

  • No clock line required
  • Uses TX (Transmit) and RX (Receive) pins
  • UART pins in 8051:
    • P3.1 – TXD
    • P3.0 – RXD
  • Data format:
    • 1 Start bit
    • 8 Data bits
    • 1 Stop bit
  • Communication speed is determined by the baud rate

Register Now for Embedded Systems Training

 

UART vs SPI vs I2C

FeatureUARTSPII2C
TypeAsynchronousSynchronousSynchronous
PinsTX, RXMOSI, MISO, SCK, SSSDA, SCL
SpeedModerateHighModerate
DevicesPoint-to-PointMulti-SlaveMulti-Master

Registers Used in UART Communication in 8051

UART operation in the 8051 microcontroller is controlled using three important registers.

1. SCON Register in 8051

The SCON (Serial Control) register is used to select the UART mode and control transmission and reception.

BitNameFunction
SM0, SM1Mode SelectSelects UART mode
RENReceive EnableEnables reception
TITransmit InterruptSet after transmission
RIReceive InterruptSet after reception

2. PCON Register

The PCON register controls power and baud rate.
SMOD bit doubles the baud rate when set.

3. SBUF Register in 8051

The SBUF (Serial Buffer) register stores:

  • Data to be transmitted
  • Data received via UART

Download Embedded Systems Course Brochure

 

UART Modes in 8051 Microcontroller

The 8051 supports four UART modes.

ModeDescriptionBaud Rate
0Shift Register ModeFixed
18-bit UARTVariable
29-bit UARTFixed
39-bit UARTVariable

Baud Rate Calculation in 8051 UART

  • The baud rate in 8051 UART communication is generated using Timer 1
  • Timer 1 is configured in Mode 2 (8-bit auto-reload)
  • Used in UART Mode 1 and Mode 3
  • Common crystal frequency: 11.0592 MHz
  • This ensures accurate baud rates such as 9600, 4800, 2400 bps, etc.

Baud Rate Calculation

UART Programming Steps in 8051

Follow these steps to implement UART communication:

  • Configure Timer 1 in Mode 2
  • Load baud rate value into TH1
  • Configure UART mode using SCON register
  • Enable serial reception
  • Load data into SBUF
  • Monitor TI and RI flags

UART-PROGRAMMING

 

Practical UART Communication Examples

GSM Module Interfacing with 8051 (SMS Sending)

Concept:
GSM modules such as SIM800/SIM900 communicate using AT commands via UART.

Connections:

GSM Module8051
TXDP3.0 (RXD)
RXDP3.1 (TXD)
GNDGND

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);
}

Bluetooth HC-05 Interfacing with 8051

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
    }
}

GPS Module Interfacing with 8051

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);
    }
}

PC-Based Monitoring System

Concept:
Sensor values are transmitted to a PC for real-time monitoring.

void main(){
    uart_init();
    while(1){
        uart_string("Temp = 30C\r\n");
    }
}

Sensor Data Logging with SD Card

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");
    }
}

Talk to Academic Advisor

Applications of UART Communication

UART communication in 8051 is used in:

  • GSM-based projects
  • Bluetooth communication
  • GPS tracking systems
  • Industrial monitoring
  • IoT and data logging systems

Conclusion

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.

Frequently Asked Questions

Timer 1 generates the required baud rate by operating in 8-bit auto-reload mode.

  • TI (Transmit Interrupt): Set after transmission
  • RI (Receive Interrupt): Set after reception
    Both flags must be cleared by software.
  • P3.0 – RXD (Receive)
  • P3.1 – TXD (Transmit)

Cause:

  • Timer 1 not reconfigured after reset
  • PCON SMOD bit not reinitialized

Cause:

  • COM port already in use
  • USB-TTL driver issue

Author

Embedded Systems Trainer – IIES

Updated On: 02-01-26


10+ years of hands-on experience delivering practical training in Embedded Systems and it's design