8051 Serial Port Programming
8051 Serial Port Programming
PORT
PROGRAMMING
Course: MPMC (ET302U)
By Mariya Siddiqui
Introduction to Serial Port Programming
Serial Communication in 8051
Baud rate in 8051
Steps for Serial port programming
Example
What is Serial Port Programming?
I• The serial port programming refers to the process of
sending and receiving data serially between
microcontrollers and external devices such as sensors,
modems, or other through the serial port.
• It involves using a serial communication protocol to
communicate bit by bit over a single communication
channel.
Serial Communication in 8051
I
Basics of serial communication
• Communication protocol
1. UART (Universal Asynchronous Receiver Transmitter)
2. USART (Universal Synchronous Asynchronous Receiver
Transmitter)
• Mode of data transfer
• Mode of communication
• Data transfer rate/ Baud rate
• SFR used for serial communication: 1) SBUF 2)SCON
Baud rate in 8051
I
• Definition: The rate of data transfer stated in bits per second
(bps) is known as baud rate.
• To allow data transfer between the PC and 8051 without any
error, baud rate of both 8051 and baud rate of PC should be
match.
• The 8051 transfers and receives data serially at many different
I baud rates.
• The baud rate in the 8051 is programmable using timer 1 in
mode 2 by given method.
I
• To generate baud rate initial value is loaded to TH1.
• Initial value to be loaded to TH1 to generate baud rate is shown
in table below.
Baud TH1 ( Decimal) TH1 (Hex)
Rate
9600 -3 FD
4800 -6 FA
2400 -12 F4
1200 -24 E8
Steps for Serial Port Programming
1) Configure Timer 1 in Mode 2 (TMOD=20H)
I2) Load proper value of baud rate value in TH1
3) Configure Mode 1 for serial communication (SCON=50H)
4) Start Timer 1 by setting TR1
5) Write data byte in SBUF register
6) Monitor T1 flag to check data transmission
7) When T1 is set, clear T1
8) To Transfer the next character, go to step5 otherwise stop the
Timer
Example
I
THANK YOU