Microprocessors and Microcontrollers
Project report submitted for the partial fulfilment
of the requirements for the degree of
Bachelor of
Technology in
Electronics and Communication Engineering
By
Ishaan Mishra – 23UEC552
Course
Coordinator
Dr. Rohit Rana
Table of Contents
1. Introduction Page 2
2. Working Page 3
2.1 Working of the Project Page 3
2.2 Transmitter Microcontroller Page 3
2.3 Receiver Microcontroller Page 3
2.4 Synchronization and Display Page 3
2.5 Key Features Page 3
3. Theory Page 5
4. Circuit Diagram Page 6
5. Simulation Results and program Page 7
6. Flowchart/Algorithm Page 14
7. Conclusion Page 15
1|Page
Introduction
Serial communication is essential in embedded systems, enabling data exchange between devices sequentially.
Among the various protocols, Universal Asynchronous Receiver/Transmitter (UART) is widely used for its
simplicity and reliability. It is particularly suited for direct communication between devices like
microcontrollers.
This project focuses on implementing UART-based serial communication between two 8051 microcontrollers,
which feature an inbuilt UART module. The project involves configuring the UART module, including setting
the serial control (SCON) register, generating the baud rate using a timer, and ensuring data integrity with start
and stop bits. Both polling and interrupt-driven methods are examined for handling data transmission and
reception.
The project’s practical example demonstrates one microcontroller transmitting data and the other receiving and
processing it. This highlights the reliability of UART for low-complexity, short-distance communication.
The work emphasizes the significance of UART in applications such as industrial automation, IoT, and home
automation, where robust communication between microcontrollers is vital. By implementing UART, this
project lays the groundwork for understanding its role in embedded systems and opens pathways to exploring
advanced communication protocols. The project provides valuable insights into the efficient use of UART in
resource- constrained environments.
2|Page
2 Working
2.1 Working of the Project
This project demonstrates serial UART communication between two 8051 microcontrollers. The
communication involves transmitting data from one microcontroller and receiving it on another. The
transmitted data is used to control an LED and display status messages on an LCD.
2.2 Transmitter Microcontroller:
The transmitter microcontroller is equipped with a push button (switch) connected to pin P1.4. When
the button is pressed or released, the microcontroller sends corresponding data via the UART
module to the receiver.
1. Serial Communication Initialization: The serial_init function configures the UART module
by setting Timer 1 in Mode 2 (8-bit auto-reload) and loading TH1 with a value for a 9600
baud rate. The serial mode is configured via the SCON register.
2. Data Transmission: If the switch is pressed, the microcontroller sends the character 'A' using
the serial_send function. If the switch is released, it sends the character 'B'.
3. LCD Display: The microcontroller displays the switch status ("ON" or "OFF") on the LCD
using lcd_cmd and lcd_data functions, updating the status dynamically based on the button's
state.
2.3 Receiver Microcontroller:
The receiver microcontroller receives the data sent by the transmitter and takes appropriate
actions based on the received data.
1. Serial Communication Initialization: The UART module is configured similarly to
the transmitter for compatibility.
2. Data Reception: The serial_receive function waits for incoming data via UART. When
data is received, it is processed based on its value.
3. Control Logic:
o If the received data is 'A', the receiver microcontroller turns the LED ON (using
pin P1.4) and updates the LCD with the message "LED STATUS: ON".
o If the received data is 'B', the LED is turned OFF, and the LCD displays
"LED STATUS: OFF".
2.4 Synchronization and Display:
The transmitter and receiver maintain synchronization through the UART protocol. The
transmitter sends data framed with start and stop bits, ensuring reliable communication. The
receiver interprets these frames and performs actions accordingly.
2.5 Key Features:
The LCD is initialized to display dynamic messages about the switch and LED status.
The LED's state changes instantly based on the transmitted data.
Delays are used to provide smooth operation and avoid flickering in the LCD or LED.
3|Page
This project showcases how UART facilitates real-time inter-device communication and control,
highlighting its significance in embedded systems.
4|Page
3. Theory
Serial communication is a method of transmitting data one bit at a time over a communication
channel. In embedded systems, it is widely used for efficient, low-cost data transfer. UART
(Universal Asynchronous Receiver/Transmitter) is a common serial communication protocol that
operates asynchronously, meaning it does not require a clock signal for data synchronization. Instead,
it relies on start, stop, and optional parity bits for proper data framing.
The 8051 microcontroller includes an inbuilt UART module, simplifying the implementation of serial
communication. The UART registers, such as SCON for mode selection and TH1 for baud rate
configuration, are configured to enable data transmission and reception. Timer 1 in Mode 2 is used to
generate the required baud rate for communication.
This project establishes UART communication between two 8051 microcontrollers. The transmitter
microcontroller reads the state of a push button and sends corresponding data ('A' or 'B') to the
receiver. The receiver interprets the data and acts by controlling an LED and displaying status
messages on an LCD.
The project highlights UART's reliability in low-complexity, short-distance communication, making
it an essential protocol for applications like IoT, automation, and inter-device communication in
embedded systems.
5|Page
4. Circuit Diagram
Circuit Diagram in Proteus
6|Page
5. Simulation Results
5.1 Diagrams
Displaying LED OFF status
7|Page
Displaying LED ON status
8|Page
5.2 Code for receiver end:-
#include <reg51.h> // Include header file for 8051 microcontroller
sbit rs = P1^0; // Register Select pin for LCD connected to P1.0
sbit rw = P1^1; // Read/Write pin for LCD connected to P1.1
sbit e = P1^2; // Enable pin for LCD connected to P1.2
sbit led1 = P1^4; // LED pin connected to P1.4
//============
unsigned char received_data; // Variable to store the received serial data
// Function to create a small delay (in milliseconds)
void usdelay(unsigned char time)
{
unsigned i, j;
for (i = 0; i < time; i++) // Outer loop for delay count
for (j = 0; j < 10; j++); // Inner loop to achieve the desired delay
}
// Function to send a command to the LCD
void lcd_cmd(unsigned char command)
{
P2 = command; // Load command into port P2 (connected to LCD data pins)
rs = 0; // Set RS pin to 0 (command mode)
rw = 0; // Set RW pin to 0 (write mode)
e = 1; // Generate a high-to-low pulse on the Enable pin
usdelay(1); // Small delay for the Enable pulse
e = 0; // Set Enable pin low to complete the command
}
// Function to send data to the LCD
void lcd_data(unsigned char disp_data)
{
P2 = disp_data; // Load data into port P2 (connected to LCD data
pins) rs = 1; // Set RS pin to 1 (data mode)
rw = 0; // Set RW pin to 0 (write mode)
e = 1; // Generate a high-to-low pulse on the Enable pin
usdelay(1); // Small delay for the Enable pulse
e = 0; // Set Enable pin low to complete the data write
}
// Function to initialize the LCD
void lcd_init()
{
lcd_cmd(0x38); // Configure LCD for 2 lines and 5x7 matrix
usdelay(100); // Small delay after the command
lcd_cmd(0x0F); // Turn on the display and enable cursor blinking
usdelay(100); // Small delay after the command
lcd_cmd(0x01); // Clear the LCD screen
usdelay(100); // Small delay after the command
lcd_cmd(0x80); // Set the cursor to the beginning of the first line
usdelay(100); // Small delay after the command
}
9|Page
// Function to initialize the UART for serial communication
void serial_init()
{
TMOD = 0x20; // Configure Timer 1 in Mode 2 (8-bit auto-reload)
TH1 = 0xFD; // Load Timer 1 with the value for a 9600 baud rate
SCON = 0x50; // Set serial mode to 1, enable reception
TR1 = 1; // Start Timer 1
}
// Function to receive data over UART
unsigned char serial_receive()
{
while (!RI); // Wait until the receive interrupt flag (RI) is
set RI = 0; // Clear the RI flag after data is received
return SBUF; // Return the received data from the SBUF register
}
// Main function
void main()
{
serial_init(); // Initialize UART
lcd_init(); // Initialize the
LCD
led1 = 0; // Turn off the LED
initially P1 = 0x00; // Clear
Port 1
while (1) // Infinite loop
{
received_data = serial_receive(); // Receive data over UART
// If received data is 'A', turn ON the LED and update the LCD
if (received_data == 'A')
{
lcd_cmd(0x82); // Set the cursor to a specific position
lcd_data('L'); // Display "LED STATUS: ON" on the LCD
lcd_data('E');
lcd_data('D');
lcd_data(' ');
lcd_data('S');
lcd_data('T');
lcd_data('A');
lcd_data('T');
lcd_data('U');
lcd_data('S');
lcd_cmd(0xC7); // Set the cursor to a new position
lcd_data('O');
lcd_data('N');
lcd_data(' ');
led1 = 1; // Turn ON the LED
}
// If received data is 'B', turn OFF the LED and update the LCD
else if (received_data == 'B')
{
lcd_cmd(0x82); // Set the cursor to a specific position
10 | P a g e
lcd_data('L'); // Display "LED STATUS: OFF" on the LCD
10 | P a g e
lcd_data('E');
lcd_data('D');
lcd_data(' ');
lcd_data('S');
lcd_data('T');
lcd_data('A');
lcd_data('T');
lcd_data('U');
lcd_data('S');
lcd_cmd(0xC7); // Set the cursor to a new position
lcd_data('O');
lcd_data('F');
lcd_data('F');
led1 = 0; // Turn OFF the LED
usdelay(1000); // Delay before the next operation
}
}
}
5.3 Code for transfer end:-
#include <reg51.h> // Include header file for 8051 microcontroller
sbit rs = P1^0; // Register Select pin for LCD connected to P1.0
sbit rw = P1^1; // Read/Write pin for LCD connected to P1.1
sbit e = P1^2; // Enable pin for LCD connected to P1.2
sbit sw = P1^4; // Switch input pin connected to P1.4
//===============
// Function to create a small delay (in milliseconds)
void usdelay(unsigned char time)
{
unsigned i, j;
for (i = 0; i < time; i++) // Outer loop for delay count
for (j = 0; j < 10; j++); // Inner loop to achieve the desired delay
}
// Function to send a command to the LCD
void lcd_cmd(unsigned char command)
{
P2 = command; // Load the command into port P2 (connected to LCD data pins)
rs = 0; // Set RS pin to 0 (command mode)
rw = 0; // Set RW pin to 0 (write mode)
e = 1; // Generate a high-to-low pulse on the Enable pin
usdelay(1); // Small delay for the Enable pulse
e = 0; // Set Enable pin low to complete the command
}
// Function to send data to the LCD
11 | P a g e
void lcd_data(unsigned char disp_data)
{
P2 = disp_data; // Load data into port P2 (connected to LCD data
pins) rs = 1; // Set RS pin to 1 (data mode)
rw = 0; // Set RW pin to 0 (write mode)
e = 1; // Generate a high-to-low pulse on the Enable pin
usdelay(1); // Small delay for the Enable pulse
e = 0; // Set Enable pin low to complete the data write
}
// Function to initialize the LCD
void lcd_init()
{
lcd_cmd(0x38); // Configure LCD for 2 lines and 5x7 matrix
usdelay(100); // Small delay after the command
lcd_cmd(0x0F); // Turn on the display and enable cursor blinking
usdelay(100); // Small delay after the command
lcd_cmd(0x01); // Clear the LCD screen
usdelay(100); // Small delay after the command
lcd_cmd(0x80); // Set the cursor to the beginning of the first line
usdelay(100); // Small delay after the command
}
// Function to create a millisecond delay (different method)
void msdelay(unsigned char time)
{
unsigned i, j;
for (i = 0; i < time; i++) // Outer loop for delay count
for (j = 0; j < 1275; j++); // Inner loop to achieve the desired delay
}
// Function to initialize the UART for serial communication
void serial_init()
{
TMOD = 0x20; // Configure Timer 1 in Mode 2 (8-bit auto-reload)
TH1 = 0xFD; // Load Timer 1 with the value for a 9600 baud rate
SCON = 0x50; // Set serial mode to 1, enable reception
TR1 = 1; // Start Timer 1
sw = 1; // Set the switch state to ON initially
}
// Function to send data over UART
void serial_send(unsigned char data1)
{
SBUF = data1; // Load data into the serial buffer register
while (!TI); // Wait until the transmission interrupt flag (TI) is
set TI = 0; // Clear the TI flag after data is sent
}
// Main function
void main()
{
serial_init(); // Initialize UART for serial
communication lcd_init(); // Initialize the LCD for
display
12 | P a g e
while (1) // Infinite loop
{
if (sw) // If the switch is ON
{
serial_send('A'); // Send 'A' over UART
lcd_cmd(0x81); // Set the cursor to a specific position
// Display "Switch status: ON" on the LCD
lcd_data('S');
lcd_data('w');
lcd_data('i');
lcd_data('t');
lcd_data('c');
lcd_data('h');
lcd_data(' ');
lcd_data('s');
lcd_data('t');
lcd_data('a');
lcd_data('t');
lcd_data('u');
lcd_data('s');
lcd_data(':');
lcd_cmd(0xC7); // Move cursor to a new position
lcd_data('O');
lcd_data('N');
lcd_data(' ');
usdelay(1000); // Delay before the next operation
}
else // If the switch is OFF
{
serial_send('B'); // Send 'B' over UART
usdelay(1000); // Delay before the next operation
lcd_cmd(0x81); // Set the cursor to a specific position
// Display "Switch status: OFF" on the LCD
lcd_data('S');
lcd_data('w');
lcd_data('i');
lcd_data('t');
lcd_data('c');
lcd_data('h');
lcd_data(' ');
lcd_data('s');
lcd_data('t');
lcd_data('a');
lcd_data('t');
lcd_data('u');
lcd_data('s');
lcd_data(':');
lcd_cmd(0xC7); // Move cursor to a new position
lcd_data('O');
lcd_data('F');
lcd_data('F');
}
}}
13 | P a g e
[Link]/Algorithm
Start
|
V
Initialize LCD
|
V
Initialize UART
|
V
Is switch ON? ----> Yes ----> Send 'A' over UART----> Display "Switch Status: ON" on LCD
| |
No V
| Wait for 1 second
V
Send 'B' over UART
|
V
Display "Switch Status: OFF" on LCD
|
V
Wait for 1 second
|
V
Go to Step 4 (Loop back to check switch status)
|
V
End (Program continuously loops)
14 | P a g e
7. Conclusion
This project demonstrates the integration of an 8051 microcontroller with an LCD
display and UART for serial communication to monitor and control the status of a
switch. The system consists of an 8051 microcontroller connected to an LCD, a
UART module for communication, and a switch input. It monitors the switch's state
(ON/OFF) and performs two main tasks: updating the LCD display with the switch's
current status and transmitting the status via UART to an external device.
The LCD is initialized to operate in 2-line mode with a 5x7 dot matrix configuration.
Commands and data are sent to the LCD using dedicated functions. The UART is
configured to operate at a baud rate of 9600 for serial communication. The switch's
state is continuously monitored in a loop. If the switch is ON, the microcontroller
sends the character 'A' via UART and displays "Switch status: ON" on the LCD. If
the switch is OFF, the character 'B' is sent via UART, and "Switch status: OFF" is
displayed.
This project highlights how simple embedded systems can combine input/output
operations, serial communication, and real-time display updates, making it a useful
demonstration of microcontroller-based control and monitoring applications.
15 | P a g e
16 | P a g e