SlideShare a Scribd company logo
1
The 8051 Microcontroller
and Embedded Systems
Chapter 10
8051 Serial Communications
From the text by Mazidi & Mazidi (2000)
2
Serial Vs Parallel
3
Serial Transfers
4
Serial Transfers
A protocol is a set of rules agreed by both the sender and receiver
on
How the data is packed
How many bits constitute a character
When the data begins and ends
Asynchronous serial data communication is widely used for
character-oriented transmissions
Each character is placed in between start and stop bits, this is
called framing
Block-oriented data transfers use the synchronous method
The start bit is always one bit, but the stop bit can be one or
two bits
5
Asynchronous
• Bit timing is important since both
transmitter and receiver need to be in
agreement of timing.
• Bit Width = 1/Baud rate or bit rate
• 9600 Baud = bit width of 104uS
6
Setting Baud Rate
• For Baud rate, OSC/12 then /32.
• Timer 1 in Mode 2 is used as Baud Rate
Generator.
• 28,800/3 = 9600 baud
• 28,800/12 = 2400 baud
• 28,800/24 = 1200 baud
• And so on.
7
8
SBUF
• Serial buffer, SBUF is used to hold data to
be transmitted on TxD, and holds received
data on RxD.
• Note that there are actually 2 SBUFs, but
one is read only and one is write only.
MOV SBUF, A
MOV A, SBUF
9
SCON
• SCON, serial control register, is used for
serial control.
Mode 0: In this
mode the serial port
function as half
duplex serial port
with fixed baud
rate.
10
• REN (receive enable)
SCON is a bit-addressable register
When REN is high, it allows 8051 to receive data
on RxD pin; If low the receiver is disable
• TI (transmit interrupt)
When 8051 finishes the transfer of 8-bit character
It raises TI flag to indicate that it is ready to
transfer another byte
TI bit is raised at the beginning of the stop bit
11
• RI (receive interrupt)
When 8051 receives data serially via RxD, it
gets rid of the start and stop bits and places
the byte in SBUF register
It raises the RI flag bit to indicate that a byte
has been received and should be picked up
before it is lost
RI is raised halfway through the stop bit
12
Programming the 8051 to transfer serially
a. Initialize the timer 1 in mode 2 to perform auto reload.
b. Set the baud
c. Load SCON with 50H, indicating serial mode1 where 8 bits data
are transmit with one start and one stop bit
d. Set TR1 to start timer
e. clear interrupt flag, CLR, TI
f. Character byte to be transfer serially is being written into SBUF
g. TI flag is monitored with the use of JNB TI, XX
h. To transfer the next character, go to step e
13
Programming the 8051 to receive data serially
a. Initialize the timer 1 in mode 2 to perform auto reload.
b. Set the baud
c. Load SCON with 50H, indicating serial mode1 where 8 bits data
are transmit with one start and one stop bit
d. Set TR1 to start timer
e. clear interrupt flag, CLR, RI
f. Character byte to be transfer serially is being written into SBUF
g. TI flag is monitored with the use of JNB RI, XX
h. To transfer the next character, go to step e
14
Output?
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-6 ;4800 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV SBUF,#”A” ;letter “A” to transfer
HERE: JNB TI,HERE ;wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ;keep sending A
15
Problems
1. Write a program to transfer the letter ‘y’ serially at 9600
baud connected to P3.1 continuously.
2. Write program to take data through ports P0, P1, and P2
one after another and transfer the data serially one by
one.
3. Write the program to receive the data which has been
send in serial form and send it out to port 0 in parallel
form. Save the data at RAM location 60H
4. Write the program to transfer the numbers 1 to 9 serially.
5. Discuss how baud in 8051 can be doubled?
16
Problem 1
MOV TMOD, #20H
MOV TH1, #-3
MOV SCON, #50H
SETB TR1
CLR TI
AGAIN:MOV SBUF, #‘Y’
HERE: JNB TI, HERE
CLR TI
SJMP AGAIN
17
Problem 2
MOV TMOD, #20H
MOV TH1, #-3
MOV SCON, #50H
MOV P0,#0FFH ; MAKE P0 input port
MOV P0,#0FFH
MOV P0,#0FFH
SETB TR1
CLR TI
AGAIN: MOV A, P0
ACALL SEND
MOV A, P1
ACALL SEND
MOV A, P2
ACALL SEND
SJMP AGAIN
SEND: MOV SBUF, A
HERE: JNB TI, HERE
CLR TI
RET
18
DOUBLING THE BAUDS RATE
There are two ways to increase the baud rate of
data transfer
To use a higher frequency crystal
To change a bit in the PCON register
PCON register is an 8-bit register
When 8051 is powered up, SMOD is zero
We can set it to high by software and thereby
double the baud rate
19
Baud rates for SMOD=0
Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz
and
921.6 kHz / 32 = 28,800 Hz since SMOD = 0
20
Baud rates for SMOD=1
Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz
and
921.6 kHz / 16 = 57,600 Hz since SMOD = 1
MOV A, PCON
SETB ACC.7
MOV PCON, A

More Related Content

PPT
12 mt06ped019
PPTX
Microcontrollers and microprocessors in electrical communication engineering....
PPTX
INTERFACING 8051-MICROCONTROLLER with timer and display
PPT
8051 serial communication-UART
PPT
Seminar on serial communication
PPTX
Serial communication
PPTX
8051 serialp port
12 mt06ped019
Microcontrollers and microprocessors in electrical communication engineering....
INTERFACING 8051-MICROCONTROLLER with timer and display
8051 serial communication-UART
Seminar on serial communication
Serial communication
8051 serialp port

Similar to Serial.ppt and it contains all information (20)

PDF
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
PPTX
8051 serial communication1
PPTX
Serial Communication in 8051
PDF
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
PPTX
DATA TRANSFER SCHEMES OF 8085
PDF
8051 serial communication
PPTX
Micro c lab8(serial communication)
PPTX
Serial communication in 8051 microcontroller .pptx
PPTX
Serial Communication
PPTX
PPT
Chap10
PPTX
Serial data transfer
PPT
8051f.ppt microcontroller serial port operation
PPTX
Serial communication in 8051 microcontroller
PDF
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
PPT
Interfacing rs232
PPTX
8051 SERIAL PORTS.pptx
PPT
8051 microcontroller notes continuous
PDF
Microcontrollers iii
PPT
RS232 serial communicaiton protocol for embedded systems
SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3
8051 serial communication1
Serial Communication in 8051
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
DATA TRANSFER SCHEMES OF 8085
8051 serial communication
Micro c lab8(serial communication)
Serial communication in 8051 microcontroller .pptx
Serial Communication
Chap10
Serial data transfer
8051f.ppt microcontroller serial port operation
Serial communication in 8051 microcontroller
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
Interfacing rs232
8051 SERIAL PORTS.pptx
8051 microcontroller notes continuous
Microcontrollers iii
RS232 serial communicaiton protocol for embedded systems
Ad

Recently uploaded (20)

PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Institutional Correction lecture only . . .
PPTX
Lesson notes of climatology university.
PDF
Classroom Observation Tools for Teachers
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
master seminar digital applications in india
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
202450812 BayCHI UCSC-SV 20250812 v17.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Institutional Correction lecture only . . .
Lesson notes of climatology university.
Classroom Observation Tools for Teachers
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
master seminar digital applications in india
Final Presentation General Medicine 03-08-2024.pptx
GDM (1) (1).pptx small presentation for students
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial diseases, their pathogenesis and prophylaxis
STATICS OF THE RIGID BODIES Hibbelers.pdf
Cell Types and Its function , kingdom of life
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Ad

Serial.ppt and it contains all information

  • 1. 1 The 8051 Microcontroller and Embedded Systems Chapter 10 8051 Serial Communications From the text by Mazidi & Mazidi (2000)
  • 4. 4 Serial Transfers A protocol is a set of rules agreed by both the sender and receiver on How the data is packed How many bits constitute a character When the data begins and ends Asynchronous serial data communication is widely used for character-oriented transmissions Each character is placed in between start and stop bits, this is called framing Block-oriented data transfers use the synchronous method The start bit is always one bit, but the stop bit can be one or two bits
  • 5. 5 Asynchronous • Bit timing is important since both transmitter and receiver need to be in agreement of timing. • Bit Width = 1/Baud rate or bit rate • 9600 Baud = bit width of 104uS
  • 6. 6 Setting Baud Rate • For Baud rate, OSC/12 then /32. • Timer 1 in Mode 2 is used as Baud Rate Generator. • 28,800/3 = 9600 baud • 28,800/12 = 2400 baud • 28,800/24 = 1200 baud • And so on.
  • 7. 7
  • 8. 8 SBUF • Serial buffer, SBUF is used to hold data to be transmitted on TxD, and holds received data on RxD. • Note that there are actually 2 SBUFs, but one is read only and one is write only. MOV SBUF, A MOV A, SBUF
  • 9. 9 SCON • SCON, serial control register, is used for serial control. Mode 0: In this mode the serial port function as half duplex serial port with fixed baud rate.
  • 10. 10 • REN (receive enable) SCON is a bit-addressable register When REN is high, it allows 8051 to receive data on RxD pin; If low the receiver is disable • TI (transmit interrupt) When 8051 finishes the transfer of 8-bit character It raises TI flag to indicate that it is ready to transfer another byte TI bit is raised at the beginning of the stop bit
  • 11. 11 • RI (receive interrupt) When 8051 receives data serially via RxD, it gets rid of the start and stop bits and places the byte in SBUF register It raises the RI flag bit to indicate that a byte has been received and should be picked up before it is lost RI is raised halfway through the stop bit
  • 12. 12 Programming the 8051 to transfer serially a. Initialize the timer 1 in mode 2 to perform auto reload. b. Set the baud c. Load SCON with 50H, indicating serial mode1 where 8 bits data are transmit with one start and one stop bit d. Set TR1 to start timer e. clear interrupt flag, CLR, TI f. Character byte to be transfer serially is being written into SBUF g. TI flag is monitored with the use of JNB TI, XX h. To transfer the next character, go to step e
  • 13. 13 Programming the 8051 to receive data serially a. Initialize the timer 1 in mode 2 to perform auto reload. b. Set the baud c. Load SCON with 50H, indicating serial mode1 where 8 bits data are transmit with one start and one stop bit d. Set TR1 to start timer e. clear interrupt flag, CLR, RI f. Character byte to be transfer serially is being written into SBUF g. TI flag is monitored with the use of JNB RI, XX h. To transfer the next character, go to step e
  • 14. 14 Output? MOV TMOD,#20H ;timer 1,mode 2(auto reload) MOV TH1,#-6 ;4800 baud rate MOV SCON,#50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1 AGAIN: MOV SBUF,#”A” ;letter “A” to transfer HERE: JNB TI,HERE ;wait for the last bit CLR TI ;clear TI for next char SJMP AGAIN ;keep sending A
  • 15. 15 Problems 1. Write a program to transfer the letter ‘y’ serially at 9600 baud connected to P3.1 continuously. 2. Write program to take data through ports P0, P1, and P2 one after another and transfer the data serially one by one. 3. Write the program to receive the data which has been send in serial form and send it out to port 0 in parallel form. Save the data at RAM location 60H 4. Write the program to transfer the numbers 1 to 9 serially. 5. Discuss how baud in 8051 can be doubled?
  • 16. 16 Problem 1 MOV TMOD, #20H MOV TH1, #-3 MOV SCON, #50H SETB TR1 CLR TI AGAIN:MOV SBUF, #‘Y’ HERE: JNB TI, HERE CLR TI SJMP AGAIN
  • 17. 17 Problem 2 MOV TMOD, #20H MOV TH1, #-3 MOV SCON, #50H MOV P0,#0FFH ; MAKE P0 input port MOV P0,#0FFH MOV P0,#0FFH SETB TR1 CLR TI AGAIN: MOV A, P0 ACALL SEND MOV A, P1 ACALL SEND MOV A, P2 ACALL SEND SJMP AGAIN SEND: MOV SBUF, A HERE: JNB TI, HERE CLR TI RET
  • 18. 18 DOUBLING THE BAUDS RATE There are two ways to increase the baud rate of data transfer To use a higher frequency crystal To change a bit in the PCON register PCON register is an 8-bit register When 8051 is powered up, SMOD is zero We can set it to high by software and thereby double the baud rate
  • 19. 19 Baud rates for SMOD=0 Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz and 921.6 kHz / 32 = 28,800 Hz since SMOD = 0
  • 20. 20 Baud rates for SMOD=1 Machine cycle freq. = 11.0592 MHz / 12 = 921.6 kHz and 921.6 kHz / 16 = 57,600 Hz since SMOD = 1 MOV A, PCON SETB ACC.7 MOV PCON, A