0% found this document useful (0 votes)
26 views17 pages

Unit 2 - 8051 Serial Communication

The document provides an overview of the 8051 microcontroller's serial communication capabilities, detailing the use of SBUF, SCON, and PCON registers for data transmission and control. It describes four modes of serial data transmission: Shift Register Mode, Standard UART, 9-Bit UART, and 9-Bit UART with variable baud rate, along with their operational details. Additionally, it outlines steps for programming both a serial transmitter and receiver to communicate at a baud rate of 9600 with 8-bit data and 1 stop bit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views17 pages

Unit 2 - 8051 Serial Communication

The document provides an overview of the 8051 microcontroller's serial communication capabilities, detailing the use of SBUF, SCON, and PCON registers for data transmission and control. It describes four modes of serial data transmission: Shift Register Mode, Standard UART, 9-Bit UART, and 9-Bit UART with variable baud rate, along with their operational details. Additionally, it outlines steps for programming both a serial transmitter and receiver to communicate at a baud rate of 9600 with 8-bit data and 1 stop bit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

8051 – Serial

Communication
1
8051 - UART
2

8051 Serial data communication circuit uses


 SBUF to hold data
 SCON register to control data communication

 PCON register to control data rates

 RXD (P3.0) and TXD (P3.1) pins to connect to the data

network
SBUF (Serial BUFfer Register) 99H
3

SBUF is physically two registers


 Write – only
 Used to hold data to be transmitted out via TXD pin
 Read – only
 Used to hold the received data from external sources via
RXD pin
SCON (Serial port CONtrol register
98H*)
4
PCON (Power CONtrol register 87H)
5
Serial Data Transmission
Modes
6

MODE0: SHIFT REGISTER MODE


MODE1: S TA N D A R D UA R T
MODE2: 9 – BIT UART
MODE3: 9 – B I T U A R T W I T H VA R I A B L E
BAUD
Mode 0: Shift Register Mode
7

It configures SBUF to receive or transmit


eight data bits using pin RXD for both
functions
Pin TXD is used to supply shift pulses
The shift frequency is fixed at FOSC/12
During Transmission:
 Data is shifted out of RXD, on every falling edge of

clock pulse
During Reception:
 data is sampled on every falling edge of clock pulse
and shifted to SBUF on every raising edge of clock
Used in high speed serial communication
Mode 1: Standard UART
8

8 – Bit UART with variable baud rate


UART is used as a 10 bit full duplex receiver
and transmitter that may receive or transmit
data same time
Pin RXD receives all data
Pin TXD transmits all data
Mode 1: Standard UART Operation
9

During Transmission:
 Data is transmitted as start bit first, eight data bits (LSB first)

and a stop bit.


 Transmitter Interrupt flag TI is set once all ten bits have been

sent.
 Each bit time interval is inverse of baud rate frequency.

During Reception:
 Data bits are shifted into the receiver at programmed baud rate,
and the data word will be loaded to SBUF if RI = 0, Implies that
program has read the previous data byte and ready to receive
the next byte
 Of the original 10 bits, the start bit is discarded, the eight data
bits go to SBUF, and the stop bit is saved in RB8 of SCON.
 Then RI is set to 1 indicating a new data byte has been received.
Mode1 : Baud rates
10

 8051 divides the crystal frequency by 12d to get


the machine cycle frequency and it is further
divided by 32d by serial communication circuitry
and is given to timer 1 to set baud rate.
 Timer 1 in 8 – bit auto reload mode is used to
generate baud rates

 If Fosc = 11.0592 MHz; then


Mode 1 : Baud rates (Contd..)
11

TH1 register values for various baud rates

SMOD = 0 SMOD = 1

Baud TH1 TH1 TH1 TH1


Rate (Decimal) (Hex) (Decimal) (Hex)
9600 -3 (253) FD -6(250) FA

4800 -6(250) FA -12 (244) F4

2400 -12 (244) F4 -24 (232) E8


Mode 2: 9 – Bit UART
12

11 bits are transmitted


 1 start bit

 9 data bits

 1 stop bit

The 9th data bit is copied from bit TB8 in SCON during
transmission and stored in bit RB8 of SCON when data
is received.
Baud rate is

If SMOD =0;

Is SMOD = 1;
Mode 3: 9 – Bit UART with variable baud rate
13

Similar to Mode2 except in baud rate


Problem 1
14

WRITE AN ALP TO TRANSFER THE


M E S S A G E ‘ Y E S ’ S E R I A L LY A T 9 6 0 0 B A U D ,
8 - B I T D AT A , 1 - S T O P B I T.
Steps to program Serial Transmitter
15

1. Calculate Timer 1 count to initialize with required baud


rate
2. Initialize TMOD register to use timer1 in mode 2
3. Load TH1 with its initial count
4. Start timer 1 to run (It provides baud rate)
5. Initialize SCON register to select its mode of operation
6. Copy character to be transmitted in SBUF which itself
starts transmitting
7. Monitor TI flag if it is 1 go to next step else wait
8. Clear TI flag
9. Go to step 6 to display next character else go to step 10
10. End
Problem 2
16

WRITE AN ALP TO RECEIVE ‘YES’


S E R I A L LY AT 9 6 0 0 B A U D , 8 - B I T C H A R A N D
1 S T O P B I T.
Steps to program Serial Receiver
17

1. Calculate Timer 1 count to initialize with required


baud rate
2. Initialize TMOD register to use timer1 in mode 2
3. Load TH1 with its initial count
4. Start timer 1 to run (It provides baud rate)
5. Initialize SCON register to select its mode of
operation and make REN = 1 to enable receiver
which itself starts reception
6. Monitor RI flag if it is 1 go to next step else wait
7. Copy SBUF and save it
8. Clear RI flag for next byte reception
9. End

You might also like