SlideShare a Scribd company logo
1
Unit 5: 8051 Serial Port Programming
(Part 3)
Subject: Processor Architecture & Interfacing
(SPPU, Pune 2015 Course of Information Technology)
Class: SEIT Semester: II
Prepared By,
Ms. K. D. Patil, Assistant Professor
Department of Information Technology
(NBA accredited)
Sanjivani College of Engineering, Kopargaon-423603.
Maharashtra, India.
(An Autonomous Institute, Affiliated with SPPU, Pune.)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 certified
Contents
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
2
 Part 1
 Basics of Communication
 Serial Vs Parallel communication
 Synchronous Vs Asynchronous communication
 Data Framing in Asynchronous Serial Communication
 Baud Rate
 Part 2
 Special Function Registers
 Operating modes of Serial Communication
 Doubling Baud Rate in 8051
 Part 3
 Importance of TI Flag
 Importance of RI Flag
 Examples
Importance of TI flag
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
3
 The steps that 8051 goes through in transmitting a character via
TxD
 The byte character to be transmitted is written into the SBUF register
 The start bit is transferred
 The 8-bit character is transferred on bit at a time
 The stop bit is transferred. It is during the transfer of the stop bit that
8051 raises the TI flag, indicating that the last character was
transmitted
 By monitoring the TI flag, we make sure that we are not overloading the
SBUF. If we write another byte into the SBUF before TI is raised, the
un-transmitted portion of the previous byte will be lost
 After SBUF is loaded with a new byte, the TI flag bit must be forced to 0
by CLR TI in order to transfer new byte
Importance of TI flag
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
4
 By checking the TI flag bit, we know whether or not the 8051
is ready to transfer another byte
 It must be noted that TI flag bit is raised by 8051 itself when
it finishes data transfer
 It must be cleared by the programmer with instruction CLR TI
 If we write a byte into SBUF before the TI flag bit is raised,
we risk the loss of a portion of the byte being transferred
 The TI bit can be checked by
 The instruction JNB TI,xx
 Using an interrupt
Programming 8051 to transfer
character byte Serially
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
5
1. TMOD register is loaded with the value 20H, indicating the use
of timer 1 in mode 2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with one of the values to set baud rate for
serial data transfer
3. The SCON register is loaded with the value 50H, indicating serial
mode 1, where an 8-bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1
5. TI is cleared by CLR TI instruction
6. The character byte to be transferred serially is written into SBUF
register
7. The TI flag bit is monitored with the use of instruction JNB TI, xx
to see if the character has been transferred completely
8. To transfer the next byte, go to step 5
Example No. 1
6
Write 8051 ALP to transfer letter “A” serially at 4800
baud, continuously.
Solution:
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
SM0 SM1 SM2 REN TB0 RB0 TI RI
SCON
GATE C/T M1 M0 GATE C/T M1 M0
TMOD
Example No. 2
7
Write a program for the 8051 to transfer “YE” serially at 9600 baud, 8-bit data, 1 stop bit, do
this continuously
Solution:
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-3 ;9600 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV A,#”Y” ;transfer “Y”
ACALL LOOP
MOV A,#”E” ;transfer “E”
ACALL LOOP
SJMP AGAIN ;keep doing it
LOOP: MOV SBUF,A ;load SBUF serial data transfer subroutine
HERE: JNB TI,HERE ;wait for the last bit
CLR TI ;get ready for next byte
RET
Example No. 3
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
8
Write 8051 ALP to transfer letter “Y” serially at 9600 baud,
continuously, also send a letter “N” through Port 0 which is connected to
display device
Solution:
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-3 ;9600 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV SBUF, #”Y” ;transfer “Y” serially
HERE: JNB TI,HERE ;wait for the last bit
CLR TI ;get ready for next byte
MOV P0, # “N”
SJMP AGAIN
Example No. 4
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
9
Write 8051 ALP to send FFH and 00H data serially using 8051 serial communication mode
Solution:
ORG 00H
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-3 ;9600 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV A, # 0FFh
ACALL LOOP
MOV A, # 00H
ACALL LOOP
SJMP AGAIN
LOOP: MOV SBUF, A ; cleared for reception of data
HERE: JNB YI,HERE ;wait for the character to come in
CLR TI
END
Importance of RI flag
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
10
 In receiving bit via its RxD pin, 8051 goes through the following
steps
 It receives the start bit Indicating that the next bit is the first bit of the
character byte it is about to receive
 The 8-bit character is received one bit at time
 The stop bit is received, When receiving the stop bit 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
 After the SBUF contents are copied into a safe place, the RI flag bit must
be forced to 0 by CLR RI in order to allow the next received character
byte to be placed in SBUF. Failure to do this causes loss of the received
character
Importance of RI flag
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
11
 By checking the RI flag bit, we know whether or not the 8051
received a character byte
 If we failed to copy SBUF into a safe place, we risk the loss of
the received byte
 It must be noted that RI flag bit is raised by 8051 when it finish
receive data
 It must be cleared by the programmer with instruction CLR RI
 If we copy SBUF into a safe place before the RI flag bit is
raised, we risk copying garbage
 The RI bit can be checked by
 The instruction JNB RI, target
 Using an interrupt
Programming 8051 to Receive
character byte Serially
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
12
1. TMOD register is loaded with the value 20H, indicating the use
of timer 1 in mode 2 (8-bit auto-reload) to set baud rate
2. The TH1 is loaded with one of the values to set baud rate for
serial data transfer
3. The SCON register is loaded with the value 50H, indicating serial
mode 1, where an 8-bit data is framed with start and stop bits
4. TR1 is set to 1 to start timer 1
5. RI is cleared by CLR RI instruction
6. The RI flag bit is monitored with the use of instruction JNB RI, xx
to see if the character has been received
7. When RI is raised, SBUF has the byte. Its contents are moved into
safe place
8. To receive the next byte, go to step 5
Example No. 5
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
13
Write 8051 ALP to receive data which has been sent in
Serial form and send it out to Port 0 in parallel form
Solution:
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-3 ;9600 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
CLR RI ; cleared for reception of data
HERE: JNB RI,HERE ;wait for the character to come in
MOV A, SBUF ; move received data in A
MOV P0, A
Reference
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
14
 “The 8051 Microcontroller and Embedded Systems
using Assembly and C” , Muhammad Ali Mazidi,
Janice Gillispie Mazidi, Rolin D. McKinlay, Second
Edition, Pearson publication
Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani
COE, Kopargaon
15

More Related Content

PDF
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
PDF
Inside the Triton compiler - Peter Bell - May 2023
PDF
control system made easy hand written notes Gate ECE
PPTX
Modeling of an RLC circuit
PPTX
Serial communication in 8051 microcontroller
PPT
Serial.ppt and it contains all information
PDF
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
PPT
12 mt06ped019
SE PAI Unit 5_Timer Programming in 8051 microcontroller_Part 2
Inside the Triton compiler - Peter Bell - May 2023
control system made easy hand written notes Gate ECE
Modeling of an RLC circuit
Serial communication in 8051 microcontroller
Serial.ppt and it contains all information
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 2
12 mt06ped019

Similar to SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3 (20)

PPTX
Microcontrollers and microprocessors in electrical communication engineering....
PPT
Seminar on serial communication
PPTX
INTERFACING 8051-MICROCONTROLLER with timer and display
PDF
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
PPTX
Serial Communication in 8051
PPTX
Serial communication
PPT
8051 serial communication-UART
PPTX
8051 serialp port
PPTX
UNIT V - INTERFACING MICROCONTROLLER (1).pptx
PPTX
DATA TRANSFER SCHEMES OF 8085
DOCX
Architecture of 8051
DOC
Unit iii microcontrollers final1
PPTX
Micro c lab8(serial communication)
PDF
EC8691 - UNIT 5.pdf
PPTX
UNIT 5.pptx
PPTX
Unit -2 and 3 mekirirygiygyuguiguihiiqio
PPTX
UNIT 5 Interfacing and Mixed Signal Controller.pptx
PPTX
8051 Microcontroller_module_4.1.pptx
PPTX
Intel 8051 Programming in C
Microcontrollers and microprocessors in electrical communication engineering....
Seminar on serial communication
INTERFACING 8051-MICROCONTROLLER with timer and display
SE PAI Unit 5_Serial Port Programming in 8051 microcontroller_Part 1
Serial Communication in 8051
Serial communication
8051 serial communication-UART
8051 serialp port
UNIT V - INTERFACING MICROCONTROLLER (1).pptx
DATA TRANSFER SCHEMES OF 8085
Architecture of 8051
Unit iii microcontrollers final1
Micro c lab8(serial communication)
EC8691 - UNIT 5.pdf
UNIT 5.pptx
Unit -2 and 3 mekirirygiygyuguiguihiiqio
UNIT 5 Interfacing and Mixed Signal Controller.pptx
8051 Microcontroller_module_4.1.pptx
Intel 8051 Programming in C
Ad

More from KanchanPatil34 (20)

PDF
Unit 1_Data Validation_Validation Techniques.pdf
PDF
Unit 1_Concet of Feature-Feature Selection Methods.pdf
PDF
Unit 1_Introduction to ML_Types_Applications.pdf
PDF
Unit 6_Cyber Laws Indian Act_Digital Signature.pdf
PDF
Unit 6_DoS and DDoS_SQL Injection_tools.pdf
PDF
Unit 6_keylogger_Spywares_virus_worms.pdf
PDF
Unit 6_Introduction_Phishing_Password Cracking.pdf
PDF
Unit 5_Social Engineering and Cyberstalking.pdf
PDF
Unit 5_Classification of Cyber Crimes.pdf
PDF
Unit 5_Introduction to Cyber Security.pdf
PDF
Unit 4_SSL_Handshake Protocol_Record Layer Protocol.pdf
PDF
Unit 4_IPSec_AH_ESP_IKE_SA_Tunnel_Transport.pdf
PDF
Unit 3_Private Key Management_Protection.pdf
PDF
Unit 3_Kerberos Protocol_Working_Version.pdf
PDF
Unit 3_Digital Certificate_Intro_Types.pdf
PDF
Unit 3_Digital Signature Model Details.pdf
PDF
Unit 3_Hash function and MD5 working.pdf
PDF
Unit 3_Secure Hash Algorithm_SHA_Working.pdf
PDF
AES Solved Example on Encryption all rounds.pdf
PDF
Unit 2_AES_AES_Structure_Encryption_Example.pdf
Unit 1_Data Validation_Validation Techniques.pdf
Unit 1_Concet of Feature-Feature Selection Methods.pdf
Unit 1_Introduction to ML_Types_Applications.pdf
Unit 6_Cyber Laws Indian Act_Digital Signature.pdf
Unit 6_DoS and DDoS_SQL Injection_tools.pdf
Unit 6_keylogger_Spywares_virus_worms.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 5_Social Engineering and Cyberstalking.pdf
Unit 5_Classification of Cyber Crimes.pdf
Unit 5_Introduction to Cyber Security.pdf
Unit 4_SSL_Handshake Protocol_Record Layer Protocol.pdf
Unit 4_IPSec_AH_ESP_IKE_SA_Tunnel_Transport.pdf
Unit 3_Private Key Management_Protection.pdf
Unit 3_Kerberos Protocol_Working_Version.pdf
Unit 3_Digital Certificate_Intro_Types.pdf
Unit 3_Digital Signature Model Details.pdf
Unit 3_Hash function and MD5 working.pdf
Unit 3_Secure Hash Algorithm_SHA_Working.pdf
AES Solved Example on Encryption all rounds.pdf
Unit 2_AES_AES_Structure_Encryption_Example.pdf
Ad

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Pharma ospi slides which help in ospi learning
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Institutional Correction lecture only . . .
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
master seminar digital applications in india
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Presentation on HIE in infants and its manifestations
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
A systematic review of self-coping strategies used by university students to ...
O5-L3 Freight Transport Ops (International) V1.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Pharma ospi slides which help in ospi learning
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Institutional Correction lecture only . . .
Microbial diseases, their pathogenesis and prophylaxis
master seminar digital applications in india
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Computing-Curriculum for Schools in Ghana
human mycosis Human fungal infections are called human mycosis..pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Presentation on HIE in infants and its manifestations
Chinmaya Tiranga quiz Grand Finale.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
2.FourierTransform-ShortQuestionswithAnswers.pdf

SE PAI Unit 5_Serial Port Programming in 8051 micro controller_Part 3

  • 1. 1 Unit 5: 8051 Serial Port Programming (Part 3) Subject: Processor Architecture & Interfacing (SPPU, Pune 2015 Course of Information Technology) Class: SEIT Semester: II Prepared By, Ms. K. D. Patil, Assistant Professor Department of Information Technology (NBA accredited) Sanjivani College of Engineering, Kopargaon-423603. Maharashtra, India. (An Autonomous Institute, Affiliated with SPPU, Pune.) NAAC ‘A’ Grade Accredited, ISO 9001:2015 certified
  • 2. Contents Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 2  Part 1  Basics of Communication  Serial Vs Parallel communication  Synchronous Vs Asynchronous communication  Data Framing in Asynchronous Serial Communication  Baud Rate  Part 2  Special Function Registers  Operating modes of Serial Communication  Doubling Baud Rate in 8051  Part 3  Importance of TI Flag  Importance of RI Flag  Examples
  • 3. Importance of TI flag Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 3  The steps that 8051 goes through in transmitting a character via TxD  The byte character to be transmitted is written into the SBUF register  The start bit is transferred  The 8-bit character is transferred on bit at a time  The stop bit is transferred. It is during the transfer of the stop bit that 8051 raises the TI flag, indicating that the last character was transmitted  By monitoring the TI flag, we make sure that we are not overloading the SBUF. If we write another byte into the SBUF before TI is raised, the un-transmitted portion of the previous byte will be lost  After SBUF is loaded with a new byte, the TI flag bit must be forced to 0 by CLR TI in order to transfer new byte
  • 4. Importance of TI flag Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 4  By checking the TI flag bit, we know whether or not the 8051 is ready to transfer another byte  It must be noted that TI flag bit is raised by 8051 itself when it finishes data transfer  It must be cleared by the programmer with instruction CLR TI  If we write a byte into SBUF before the TI flag bit is raised, we risk the loss of a portion of the byte being transferred  The TI bit can be checked by  The instruction JNB TI,xx  Using an interrupt
  • 5. Programming 8051 to transfer character byte Serially Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 5 1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload) to set baud rate 2. The TH1 is loaded with one of the values to set baud rate for serial data transfer 3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit data is framed with start and stop bits 4. TR1 is set to 1 to start timer 1 5. TI is cleared by CLR TI instruction 6. The character byte to be transferred serially is written into SBUF register 7. The TI flag bit is monitored with the use of instruction JNB TI, xx to see if the character has been transferred completely 8. To transfer the next byte, go to step 5
  • 6. Example No. 1 6 Write 8051 ALP to transfer letter “A” serially at 4800 baud, continuously. Solution: 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 SM0 SM1 SM2 REN TB0 RB0 TI RI SCON GATE C/T M1 M0 GATE C/T M1 M0 TMOD
  • 7. Example No. 2 7 Write a program for the 8051 to transfer “YE” serially at 9600 baud, 8-bit data, 1 stop bit, do this continuously Solution: MOV TMOD,#20H ;timer 1,mode 2(auto reload) MOV TH1,#-3 ;9600 baud rate MOV SCON,#50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1 AGAIN: MOV A,#”Y” ;transfer “Y” ACALL LOOP MOV A,#”E” ;transfer “E” ACALL LOOP SJMP AGAIN ;keep doing it LOOP: MOV SBUF,A ;load SBUF serial data transfer subroutine HERE: JNB TI,HERE ;wait for the last bit CLR TI ;get ready for next byte RET
  • 8. Example No. 3 Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 8 Write 8051 ALP to transfer letter “Y” serially at 9600 baud, continuously, also send a letter “N” through Port 0 which is connected to display device Solution: MOV TMOD,#20H ;timer 1,mode 2(auto reload) MOV TH1,#-3 ;9600 baud rate MOV SCON,#50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1 AGAIN: MOV SBUF, #”Y” ;transfer “Y” serially HERE: JNB TI,HERE ;wait for the last bit CLR TI ;get ready for next byte MOV P0, # “N” SJMP AGAIN
  • 9. Example No. 4 Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 9 Write 8051 ALP to send FFH and 00H data serially using 8051 serial communication mode Solution: ORG 00H MOV TMOD,#20H ;timer 1,mode 2(auto reload) MOV TH1,#-3 ;9600 baud rate MOV SCON,#50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1 AGAIN: MOV A, # 0FFh ACALL LOOP MOV A, # 00H ACALL LOOP SJMP AGAIN LOOP: MOV SBUF, A ; cleared for reception of data HERE: JNB YI,HERE ;wait for the character to come in CLR TI END
  • 10. Importance of RI flag Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 10  In receiving bit via its RxD pin, 8051 goes through the following steps  It receives the start bit Indicating that the next bit is the first bit of the character byte it is about to receive  The 8-bit character is received one bit at time  The stop bit is received, When receiving the stop bit 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  After the SBUF contents are copied into a safe place, the RI flag bit must be forced to 0 by CLR RI in order to allow the next received character byte to be placed in SBUF. Failure to do this causes loss of the received character
  • 11. Importance of RI flag Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 11  By checking the RI flag bit, we know whether or not the 8051 received a character byte  If we failed to copy SBUF into a safe place, we risk the loss of the received byte  It must be noted that RI flag bit is raised by 8051 when it finish receive data  It must be cleared by the programmer with instruction CLR RI  If we copy SBUF into a safe place before the RI flag bit is raised, we risk copying garbage  The RI bit can be checked by  The instruction JNB RI, target  Using an interrupt
  • 12. Programming 8051 to Receive character byte Serially Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 12 1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload) to set baud rate 2. The TH1 is loaded with one of the values to set baud rate for serial data transfer 3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8-bit data is framed with start and stop bits 4. TR1 is set to 1 to start timer 1 5. RI is cleared by CLR RI instruction 6. The RI flag bit is monitored with the use of instruction JNB RI, xx to see if the character has been received 7. When RI is raised, SBUF has the byte. Its contents are moved into safe place 8. To receive the next byte, go to step 5
  • 13. Example No. 5 Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 13 Write 8051 ALP to receive data which has been sent in Serial form and send it out to Port 0 in parallel form Solution: MOV TMOD,#20H ;timer 1,mode 2(auto reload) MOV TH1,#-3 ;9600 baud rate MOV SCON,#50H ;8-bit, 1 stop, REN enabled SETB TR1 ;start timer 1 CLR RI ; cleared for reception of data HERE: JNB RI,HERE ;wait for the character to come in MOV A, SBUF ; move received data in A MOV P0, A
  • 14. Reference Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 14  “The 8051 Microcontroller and Embedded Systems using Assembly and C” , Muhammad Ali Mazidi, Janice Gillispie Mazidi, Rolin D. McKinlay, Second Edition, Pearson publication
  • 15. Prepared By: Ms. K. D. Patil, Dept. of Information Technology, Sanjivani COE, Kopargaon 15