SlideShare a Scribd company logo
1 of 12
Timers, Counters & Serial I/O(Unit 5)
Session 7
Microcontroller & Applications
(IV Semester)
Electronics & Communication Engineering
Prepared by,
Ishwarkumar Nirale
GPT Mudhol
Electronics & Communication Engineering -15EC42TT
Contents:
• Serial data reception
• Sample programs
• Importance of the RI flag
• Interfacing RS232 to 8051
Electronics & Communication Engineering 15EC42T 2
Serial data reception
3
In programming of the 8051 to receive character bytes serially, the
following steps must be taken.
Step 1: The TMOD register is loaded with the value 20H, indicating
the use of Timer 1 in mode 2 (8-bit auto-reload) to set the baud rate.
Step 2: TH1 is loaded with one of the values (mentioned in baud rate
table) to set the baud rate (assuming XTAL = 11.0592MHz).
Step 3: The SCON register is loaded with the value 50H, indicating
serial mode 1, where 8-bit data is framed with start and stop bits and
receive enable is turned on.
Serial data reception
4
Step 4: TR1 is set to 1 to start Timer 1.
Step 5: RI is cleared with the “CLR RI” instruction.
Step 6: The RI flag bit is monitored to see if an entire character has
been received yet.
Step 7: When RI is raised, the contents of SBUF are moved into any
register.
Step 8: To receive the next character, go to Step 5.
Serial data reception
5
Flowchart:
Sample Programs
6
Write an ALP and 8051 in C to receive bytes of data serially and put them in P1. Set the
baud rate at 4800, 8-bit data, and 1 stop bit.
MOV TMOD, #20H
MOV TH1, #-6 ; 4800 baud
MOV SCON, #50H ; mode 1
SETB TR1
HERE:JNB RI, HERE ; wait for char to come in (RI=1)
MOV A, SBUF ; save incoming byte in A
MOV P1, A ; send to port 1
CLR RI ; clear, get ready for next byte
SJMP HERE ;Repeat
Sample Programs
7
8051 C Code
#include<reg51.h>
void main (void)
{
unsigned char mybyte;
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
while(1)
{
while(RI==0);
mybyte=SBUF;
P1=mybyte;
RI=0;
} }
Importance of RI flag bit
8
 To understand the importance of the role of RI, look at the
sequence of steps that the 8051 goes through in receiving a character
via RxD.
 The 8-bit character is received one bit at time. When the last bit is
received, a byte is formed and placed in SBUF. The stop bit is
received. When receiving the stop bit the 8051 makes RI = 1,
indicating that an entire character byte has been received and must be
picked up before it gets overwritten by an incoming character.
 By checking the RI flag bit when it is raised, we know that a
character has been received and is sitting in the SBUF register. We
copy the SBUF contents to a safe place in some other register or
memory before it is lost.
Importance of RI flag bit
9
 After the SBUF contents are copied into a safe place, the RI flag bit
must be forced to 0 in order to allow the next received character
byte to be placed in SBUF. Failure to do this causes loss of the
received character.
 From the above discussion we conclude that by checking the RI flag
bit we know whether or not the 8051 has received a character byte.
If we fail to copy SBUF into a safe place, we risk the loss of the
received byte. More importantly, it must be noted that the RI flag bit
is raised by the 8051, but it must be cleared by the programmer.
Interfacing RS232 to 8051
10
 The 8051 has two pins that are used specifically for transferring and
receiving data serially. These two pins are called TxD and RxD and
are part of the port 3 group (P3.0 and P3.1). Pin 11 of the 8051
(P3.1) is assigned to TxD and pin 10 (P3.0) is designated as RxD.
These pins are TTL compatible; therefore, they require a line driver
to make them RS232 compatible. One such line driver is the
MAX232 chip.
 Since the RS232 is not compatible with today’s microprocessors
and microcontrollers, we need a line driver (voltage converter) to
convert the RS232′s signals to TTL voltage levels that will be
acceptable to the 8051 ‘s TxD and RxD pins. One example of such
a converter is MAX232.
Interfacing RS232 to 8051
11
 The MAX232 converts from RS232 voltage levels to TTL voltage
levels, and vice versa. One advantage of the MAX232 chip is that it
uses a +5 V power source which, is the same as the source voltage
for the 8051. In other words, with a single +5 V power supply we
can power both the 8051 and MAX232, with no need for the dual
power supplies that are common in many older systems
Thank you
Electronics & Communication Engineering 15EC32T 12

More Related Content

Similar to Serial communication in 8051 microcontroller

Sereial com. ppt
Sereial com. pptSereial com. ppt
Sereial com. ppt
gaurav5345
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
Rashmi
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
Moeez Shem
 
Radio frequency identification system
Radio frequency identification systemRadio frequency identification system
Radio frequency identification system
Aminu Bugaje
 

Similar to Serial communication in 8051 microcontroller (20)

Sereial com. ppt
Sereial com. pptSereial com. ppt
Sereial com. ppt
 
Chap10
Chap10Chap10
Chap10
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Class10
Class10Class10
Class10
 
Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....Microcontrollers and microprocessors in electrical communication engineering....
Microcontrollers and microprocessors in electrical communication engineering....
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)
 
interfacing of temperature sensor LM 35 with 8051.pdf
interfacing of temperature sensor LM 35 with 8051.pdfinterfacing of temperature sensor LM 35 with 8051.pdf
interfacing of temperature sensor LM 35 with 8051.pdf
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Presentation On: "Micro-controller 8051 & Embedded System"
Presentation On: "Micro-controller 8051 & Embedded System"Presentation On: "Micro-controller 8051 & Embedded System"
Presentation On: "Micro-controller 8051 & Embedded System"
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
 
8051 Interrupts
8051 Interrupts8051 Interrupts
8051 Interrupts
 
Emb day2 8051
Emb day2 8051Emb day2 8051
Emb day2 8051
 
Unit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller pptsUnit iv introduction to 8051 microcontroller ppts
Unit iv introduction to 8051 microcontroller ppts
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
 
Radio frequency identification system
Radio frequency identification systemRadio frequency identification system
Radio frequency identification system
 
serial-200505101453.pdf
serial-200505101453.pdfserial-200505101453.pdf
serial-200505101453.pdf
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 

Recently uploaded

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Serial communication in 8051 microcontroller

  • 1. Timers, Counters & Serial I/O(Unit 5) Session 7 Microcontroller & Applications (IV Semester) Electronics & Communication Engineering Prepared by, Ishwarkumar Nirale GPT Mudhol Electronics & Communication Engineering -15EC42TT
  • 2. Contents: • Serial data reception • Sample programs • Importance of the RI flag • Interfacing RS232 to 8051 Electronics & Communication Engineering 15EC42T 2
  • 3. Serial data reception 3 In programming of the 8051 to receive character bytes serially, the following steps must be taken. Step 1: The TMOD register is loaded with the value 20H, indicating the use of Timer 1 in mode 2 (8-bit auto-reload) to set the baud rate. Step 2: TH1 is loaded with one of the values (mentioned in baud rate table) to set the baud rate (assuming XTAL = 11.0592MHz). Step 3: The SCON register is loaded with the value 50H, indicating serial mode 1, where 8-bit data is framed with start and stop bits and receive enable is turned on.
  • 4. Serial data reception 4 Step 4: TR1 is set to 1 to start Timer 1. Step 5: RI is cleared with the “CLR RI” instruction. Step 6: The RI flag bit is monitored to see if an entire character has been received yet. Step 7: When RI is raised, the contents of SBUF are moved into any register. Step 8: To receive the next character, go to Step 5.
  • 6. Sample Programs 6 Write an ALP and 8051 in C to receive bytes of data serially and put them in P1. Set the baud rate at 4800, 8-bit data, and 1 stop bit. MOV TMOD, #20H MOV TH1, #-6 ; 4800 baud MOV SCON, #50H ; mode 1 SETB TR1 HERE:JNB RI, HERE ; wait for char to come in (RI=1) MOV A, SBUF ; save incoming byte in A MOV P1, A ; send to port 1 CLR RI ; clear, get ready for next byte SJMP HERE ;Repeat
  • 7. Sample Programs 7 8051 C Code #include<reg51.h> void main (void) { unsigned char mybyte; TMOD=0x20; TH1=0xFA; SCON=0x50; TR1=1; while(1) { while(RI==0); mybyte=SBUF; P1=mybyte; RI=0; } }
  • 8. Importance of RI flag bit 8  To understand the importance of the role of RI, look at the sequence of steps that the 8051 goes through in receiving a character via RxD.  The 8-bit character is received one bit at time. When the last bit is received, a byte is formed and placed in SBUF. The stop bit is received. When receiving the stop bit the 8051 makes RI = 1, indicating that an entire character byte has been received and must be picked up before it gets overwritten by an incoming character.  By checking the RI flag bit when it is raised, we know that a character has been received and is sitting in the SBUF register. We copy the SBUF contents to a safe place in some other register or memory before it is lost.
  • 9. Importance of RI flag bit 9  After the SBUF contents are copied into a safe place, the RI flag bit must be forced to 0 in order to allow the next received character byte to be placed in SBUF. Failure to do this causes loss of the received character.  From the above discussion we conclude that by checking the RI flag bit we know whether or not the 8051 has received a character byte. If we fail to copy SBUF into a safe place, we risk the loss of the received byte. More importantly, it must be noted that the RI flag bit is raised by the 8051, but it must be cleared by the programmer.
  • 10. Interfacing RS232 to 8051 10  The 8051 has two pins that are used specifically for transferring and receiving data serially. These two pins are called TxD and RxD and are part of the port 3 group (P3.0 and P3.1). Pin 11 of the 8051 (P3.1) is assigned to TxD and pin 10 (P3.0) is designated as RxD. These pins are TTL compatible; therefore, they require a line driver to make them RS232 compatible. One such line driver is the MAX232 chip.  Since the RS232 is not compatible with today’s microprocessors and microcontrollers, we need a line driver (voltage converter) to convert the RS232′s signals to TTL voltage levels that will be acceptable to the 8051 ‘s TxD and RxD pins. One example of such a converter is MAX232.
  • 11. Interfacing RS232 to 8051 11  The MAX232 converts from RS232 voltage levels to TTL voltage levels, and vice versa. One advantage of the MAX232 chip is that it uses a +5 V power source which, is the same as the source voltage for the 8051. In other words, with a single +5 V power supply we can power both the 8051 and MAX232, with no need for the dual power supplies that are common in many older systems
  • 12. Thank you Electronics & Communication Engineering 15EC32T 12