SlideShare a Scribd company logo
COMMUNICATING WITH PC USING SERIAL
COMMUNICATION IN 8051
Objectives of the Lab
 Serial Communication Types
 Registers governing Serial communication
 Using timer1 to set baud rate
 Hardware necessities for serial communication
Deciding Pins or Ports to use
Use with
caution
If EA high
*The pins for this
purpose are by
default P3.0(RXD)
and P3.1(TXD) .
Serial Communication
 Serial communication has the advantage over parallel
communication w.r.t number of wires used but the trade-
off done is on speed of communication.
 The quantity that decides the usage of serial or parallel
communication is the distance, the data needs to cover.
 Synchronous method transfers a block of data at a time
while asynchronous transfers a single byte at a time.
 Serial communication is classified into following types.
SCON Register
SM0 SCON.7 Serial Port Mode specifier
SM1 SCON.6 Serial Port Mode specifier
SM2 SCON.5 Used for multiprocessor communication
REN SCON.4 Set/Cleared by software to enable/disable reception
TB8 SCON.3 Not widely used
RB8 SCON.2 Not widely used
TI SCON.1 Transmit Interrupt, Set by HW after the data is successfully sent,
cleared by SW. (At start, keep it high, so we know that the previous
data was sent)
RI SCON.0 Receive Interrupt, Set by HW after the data is successfully received,
cleared by SW.
SM0 and SM1
SM0 SM1 Mode Description Baud Rate
0 0 0 Shift Register Fixed fXTAL/12
0 1 1 8-bit UART Variable (Set by Timer1)
1 0 2 9-bit UART Fixed (fXTAL/12 or fXTAL/64)
1 1 3 9-bit UART Variable (Set by Timer 1)
UART: Universal Asynchronous Receiver Transmitter
Baud Rate: Speed (Bits per Second)
SBUF and TMOD
 SBUF is a very important register in serial communication. It
is not bit addressable and is dual purpose serial read/write.
 When transmitting, data to be transmitted should be in SBUF.
 When receiving, data will be received in SBUF.
 TMOD register is used to set variable baud rate using timer1.
 We will use in 8-bit auto-reload as count is mostly <255.
 To find the TH0 value against baud rate, following is done.
 Baud Rate=Timer1 OV flow rate ÷ 32 => OV= B.R. × 32
 e.g. B.R.= 1200 bps OV=1200*32=38400 b/s
 Delay generated by timer1 should be
1
𝑂𝑉
=
1
38400
𝑠𝑒𝑐𝑜𝑛𝑑𝑠
 Value in timer1=counts=
1
𝑂𝑉
1 𝑚.𝑐.
=
1
38400
12
11059200
=
11059200
12∗38400
= 24
Try fXTAL = 12 MHz
SMOD bit (PCON.7) and Universal
Baud Rates
PCON is not bit addressable, so to clear PCON.7, use
Anl PCON,#01111111b, and to set Orl PCON,#10000000b
Pseudo-Code for Transmitting and
Receiving Data through serial port
1. Move value in SMOD using mode1, keeping REN=1, RI=0 and
TI=1.
2. Configure TMOD for timer1, mode 2 and load value in TH1 and
TL1 for desired baud rate and run timer by setting TR1 high.
3. Use SMOD bit as desired.
4. For transmission of data,
 Clear TI.
 Move data in SBUF
 Then wait till TI gets high i.e. Data is transmitted.
5. For reception of data,
 Wait till RI gets high i.e. Data is received.
 Clear RI
 Move data from SBUF in desired register.
Data Transmit/Receive Protocol
 To transmit a character use mov a,#‘X’.
 During reception, ASCII of a character will be received.
 To transmit integer, first make it ASCII, add a,#30h.
 During reception, use clr c & subb a,#30h to make integer.
 To display a line, use look-up table.
mov dptr,#line1
again:
mov a,#0
movc a,@a+dptr
inc dptr
jz exit1
clr ti
mov sbuf,a
jnb ti,$
jmp again
exit1:
line1: db “Hello World”,0ah,0dh,0
Proteus Devices needed in this Lab
1. AT89c51
2. Virtual Terminal (TXD, RXD, use in cross-connection)
Virtual Terminal Settings:
Baud Rate= as desired. Rest settings as default
Serial communication with PC
 Communicating serially in software is much easier and doesn’t
require electronic equipment and any debugging but hardware
serial communication with PC is quite complicated.
 First of all, we need to use hyper-terminal in windows XP. It’s
location is in ‘Start>Programs>Accessories>Communication
>Hyper-terminal.’ (Settings=> Bits per second: B.R. ,
Data bits=8, Parity=None, Flow-Control=None)
 Then, we have to use a serial cable. (Straight/Cross)
 Then, a level converter IC.
 And finally the microcontroller coded with serial
communication.
Serial communication with PC
Level converter IC
Serial Port and Cable
Serial cables have serial ports on both sides of it. If internally pin2 and pin3 of one port
are short with pin2 and pin3 of other port it is straight cable, if pin2 of one port is
connected to pin3 of other port and pin3 of one port is connected to pin2, this is cross cable.
RS-232 to TTL converter
(MAX-232)
 As we know, that the microcontroller level low is ‘0 volts’ and level
high is ‘5 volts’, these are called TTL levels.
 RS-232 levels are different than TTL levels and thus we need a
conversion of levels.
 In RS-232, a level low is represented by ‘+3~+25 volts’ where as a
level high is represented by ‘-3~-25 volts’.
*MAX-233 doesn’t require capacitors but is costly.
Debugging Stages:
1. First of all check the serial-cable, whether it is straight or
cross.
2. Then check the serial-cable, whether it is functioning or not.
For this short pins 2 & 3 and write something in hyper-
terminal, if data is echoed, the cable is fine.
3. Then check the level converter IC, by shorting its TXD and
RXD pins on the side of μC.
4. μC 8051 should already be checked by LED test.
5. The program should be verified in PROTEUS.
Final Remark on μC 8051 LAB:
Small Size, Low-Cost, Same
Function: AT89C2051
Lab Tasks
 Serially communicate with PC. If key pressed is that of
your workstation number then display ‘Workstation#xy’
otherwise display ‘Invalid input’.
 Quiz Next Week of Timers.
1. Last Week Submissions: Project SW, HW and Report
(ADC0804 submission)
2. Vivas from Project and μC Lab
3. Lab Manual Submission

More Related Content

PDF
8051 serial communication
PPT
Serial Communication Part-16
PDF
Asynchronous Serial Communication and standards
PPT
8051 serial communication-UART
PPTX
Serial Communication
PPTX
PPTX
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter
8051 serial communication
Serial Communication Part-16
Asynchronous Serial Communication and standards
8051 serial communication-UART
Serial Communication
Universal synchronous asynchronous receiver transmitter(usart) and AtoD Coverter

What's hot (20)

PPTX
Serial communication
PPTX
Serial communication in LPC2148
PPTX
Universal Serial Communication Interface
PPT
PPTX
Microcontroller serial communication
PPTX
PPTX
Serial data transfer
PDF
PDF
Serial communication of microcontroller 8051
PPT
Serial Communication
PPTX
Mridul_Verma_Intern_Tech_Adityaa_UART
PDF
Universal asynchronous receiver-transmitter UART Dsa project report
PPT
Seminar on serial communication
PPSX
USART - 8251 / usart-8251A Pallav Shukla
PPTX
UART(universal asynchronous receiver transmitter ) PPT
PDF
Verification of uart ip core using uvm
PDF
Design and implementation of uart on soc
PDF
Serial1
PPT
8251 08 Serial
PPT
Master synchronous serial port (mssp)
Serial communication
Serial communication in LPC2148
Universal Serial Communication Interface
Microcontroller serial communication
Serial data transfer
Serial communication of microcontroller 8051
Serial Communication
Mridul_Verma_Intern_Tech_Adityaa_UART
Universal asynchronous receiver-transmitter UART Dsa project report
Seminar on serial communication
USART - 8251 / usart-8251A Pallav Shukla
UART(universal asynchronous receiver transmitter ) PPT
Verification of uart ip core using uvm
Design and implementation of uart on soc
Serial1
8251 08 Serial
Master synchronous serial port (mssp)
Ad

Viewers also liked (6)

PPT
Controlling stepper motor using serial communication with computer
PPTX
Direct memory access (dma) with 8257 DMA Controller
PPTX
Serial Communication
PPT
Hard disk
PPTX
Direct Memory Access(DMA)
PPTX
ANTIVIRUS AND VIRUS Powerpoint presentation
Controlling stepper motor using serial communication with computer
Direct memory access (dma) with 8257 DMA Controller
Serial Communication
Hard disk
Direct Memory Access(DMA)
ANTIVIRUS AND VIRUS Powerpoint presentation
Ad

Similar to Micro c lab8(serial communication) (20)

PDF
Lecture 3 - Serial Communicationkahfag.pdf
PDF
MPS W8-L2L3 Programming AVR Serial Port Ia (in C).pdf
PPTX
Serial Communication in 8051
PDF
EC8691 - UNIT 5.pdf
PPT
AN INTRODUCTION TO SERIAL PORT INTERFACING
PPTX
The presentation is about USART and serial communication
PPT
Batch 25(a)
PPT
12 mt06ped019
DOCX
Tutorial
PPTX
8051 serial communication1
PDF
Serial Port Device Driver
PPTX
Microcontrollers and microprocessors in electrical communication engineering....
PPTX
45039336 rs232
PPTX
INTERFACING 8051-MICROCONTROLLER with timer and display
PDF
PA UNIT 4 (FR INFORMATION TECHNOLOGY) SPPU
PPT
Interfacing rs232
PPTX
8251 USART.pptx
PDF
Firmware implementation of UART using Bare metal programming
PPTX
Sereial com. ppt
PPTX
8251 USART
Lecture 3 - Serial Communicationkahfag.pdf
MPS W8-L2L3 Programming AVR Serial Port Ia (in C).pdf
Serial Communication in 8051
EC8691 - UNIT 5.pdf
AN INTRODUCTION TO SERIAL PORT INTERFACING
The presentation is about USART and serial communication
Batch 25(a)
12 mt06ped019
Tutorial
8051 serial communication1
Serial Port Device Driver
Microcontrollers and microprocessors in electrical communication engineering....
45039336 rs232
INTERFACING 8051-MICROCONTROLLER with timer and display
PA UNIT 4 (FR INFORMATION TECHNOLOGY) SPPU
Interfacing rs232
8251 USART.pptx
Firmware implementation of UART using Bare metal programming
Sereial com. ppt
8251 USART

More from Mashood (12)

PPTX
Patience (1).pptx
PPTX
Micro c lab7(timers)
PPTX
Micro c lab6(lcd)
PPTX
Micro c lab5(stepper-motor)
PPTX
Micro c lab4(keypad)
PPTX
Micro c lab3(ssd)
PPTX
Micro c lab2(led patterns)
PPTX
Micro c lab1(intro to 8051)
PPT
Amplifiers (analog electronics ii lab)
PDF
Pcb design using proteus
PPT
Function Generator
PPT
Speed Measuring Circuit
Patience (1).pptx
Micro c lab7(timers)
Micro c lab6(lcd)
Micro c lab5(stepper-motor)
Micro c lab4(keypad)
Micro c lab3(ssd)
Micro c lab2(led patterns)
Micro c lab1(intro to 8051)
Amplifiers (analog electronics ii lab)
Pcb design using proteus
Function Generator
Speed Measuring Circuit

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Pharma ospi slides which help in ospi learning
PPTX
GDM (1) (1).pptx small presentation for students
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Pharma ospi slides which help in ospi learning
GDM (1) (1).pptx small presentation for students
STATICS OF THE RIGID BODIES Hibbelers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
Microbial disease of the cardiovascular and lymphatic systems
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Module 4: Burden of Disease Tutorial Slides S2 2025
Orientation - ARALprogram of Deped to the Parents.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
RMMM.pdf make it easy to upload and study
Chinmaya Tiranga quiz Grand Finale.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Micro c lab8(serial communication)

  • 1. COMMUNICATING WITH PC USING SERIAL COMMUNICATION IN 8051
  • 2. Objectives of the Lab  Serial Communication Types  Registers governing Serial communication  Using timer1 to set baud rate  Hardware necessities for serial communication
  • 3. Deciding Pins or Ports to use Use with caution If EA high *The pins for this purpose are by default P3.0(RXD) and P3.1(TXD) .
  • 4. Serial Communication  Serial communication has the advantage over parallel communication w.r.t number of wires used but the trade- off done is on speed of communication.  The quantity that decides the usage of serial or parallel communication is the distance, the data needs to cover.  Synchronous method transfers a block of data at a time while asynchronous transfers a single byte at a time.  Serial communication is classified into following types.
  • 5. SCON Register SM0 SCON.7 Serial Port Mode specifier SM1 SCON.6 Serial Port Mode specifier SM2 SCON.5 Used for multiprocessor communication REN SCON.4 Set/Cleared by software to enable/disable reception TB8 SCON.3 Not widely used RB8 SCON.2 Not widely used TI SCON.1 Transmit Interrupt, Set by HW after the data is successfully sent, cleared by SW. (At start, keep it high, so we know that the previous data was sent) RI SCON.0 Receive Interrupt, Set by HW after the data is successfully received, cleared by SW.
  • 6. SM0 and SM1 SM0 SM1 Mode Description Baud Rate 0 0 0 Shift Register Fixed fXTAL/12 0 1 1 8-bit UART Variable (Set by Timer1) 1 0 2 9-bit UART Fixed (fXTAL/12 or fXTAL/64) 1 1 3 9-bit UART Variable (Set by Timer 1) UART: Universal Asynchronous Receiver Transmitter Baud Rate: Speed (Bits per Second)
  • 7. SBUF and TMOD  SBUF is a very important register in serial communication. It is not bit addressable and is dual purpose serial read/write.  When transmitting, data to be transmitted should be in SBUF.  When receiving, data will be received in SBUF.  TMOD register is used to set variable baud rate using timer1.  We will use in 8-bit auto-reload as count is mostly <255.  To find the TH0 value against baud rate, following is done.  Baud Rate=Timer1 OV flow rate ÷ 32 => OV= B.R. × 32  e.g. B.R.= 1200 bps OV=1200*32=38400 b/s  Delay generated by timer1 should be 1 𝑂𝑉 = 1 38400 𝑠𝑒𝑐𝑜𝑛𝑑𝑠  Value in timer1=counts= 1 𝑂𝑉 1 𝑚.𝑐. = 1 38400 12 11059200 = 11059200 12∗38400 = 24 Try fXTAL = 12 MHz
  • 8. SMOD bit (PCON.7) and Universal Baud Rates PCON is not bit addressable, so to clear PCON.7, use Anl PCON,#01111111b, and to set Orl PCON,#10000000b
  • 9. Pseudo-Code for Transmitting and Receiving Data through serial port 1. Move value in SMOD using mode1, keeping REN=1, RI=0 and TI=1. 2. Configure TMOD for timer1, mode 2 and load value in TH1 and TL1 for desired baud rate and run timer by setting TR1 high. 3. Use SMOD bit as desired. 4. For transmission of data,  Clear TI.  Move data in SBUF  Then wait till TI gets high i.e. Data is transmitted. 5. For reception of data,  Wait till RI gets high i.e. Data is received.  Clear RI  Move data from SBUF in desired register.
  • 10. Data Transmit/Receive Protocol  To transmit a character use mov a,#‘X’.  During reception, ASCII of a character will be received.  To transmit integer, first make it ASCII, add a,#30h.  During reception, use clr c & subb a,#30h to make integer.  To display a line, use look-up table. mov dptr,#line1 again: mov a,#0 movc a,@a+dptr inc dptr jz exit1 clr ti mov sbuf,a jnb ti,$ jmp again exit1: line1: db “Hello World”,0ah,0dh,0
  • 11. Proteus Devices needed in this Lab 1. AT89c51 2. Virtual Terminal (TXD, RXD, use in cross-connection) Virtual Terminal Settings: Baud Rate= as desired. Rest settings as default
  • 12. Serial communication with PC  Communicating serially in software is much easier and doesn’t require electronic equipment and any debugging but hardware serial communication with PC is quite complicated.  First of all, we need to use hyper-terminal in windows XP. It’s location is in ‘Start>Programs>Accessories>Communication >Hyper-terminal.’ (Settings=> Bits per second: B.R. , Data bits=8, Parity=None, Flow-Control=None)  Then, we have to use a serial cable. (Straight/Cross)  Then, a level converter IC.  And finally the microcontroller coded with serial communication.
  • 13. Serial communication with PC Level converter IC
  • 14. Serial Port and Cable Serial cables have serial ports on both sides of it. If internally pin2 and pin3 of one port are short with pin2 and pin3 of other port it is straight cable, if pin2 of one port is connected to pin3 of other port and pin3 of one port is connected to pin2, this is cross cable.
  • 15. RS-232 to TTL converter (MAX-232)  As we know, that the microcontroller level low is ‘0 volts’ and level high is ‘5 volts’, these are called TTL levels.  RS-232 levels are different than TTL levels and thus we need a conversion of levels.  In RS-232, a level low is represented by ‘+3~+25 volts’ where as a level high is represented by ‘-3~-25 volts’. *MAX-233 doesn’t require capacitors but is costly.
  • 16. Debugging Stages: 1. First of all check the serial-cable, whether it is straight or cross. 2. Then check the serial-cable, whether it is functioning or not. For this short pins 2 & 3 and write something in hyper- terminal, if data is echoed, the cable is fine. 3. Then check the level converter IC, by shorting its TXD and RXD pins on the side of μC. 4. μC 8051 should already be checked by LED test. 5. The program should be verified in PROTEUS.
  • 17. Final Remark on μC 8051 LAB: Small Size, Low-Cost, Same Function: AT89C2051
  • 18. Lab Tasks  Serially communicate with PC. If key pressed is that of your workstation number then display ‘Workstation#xy’ otherwise display ‘Invalid input’.  Quiz Next Week of Timers. 1. Last Week Submissions: Project SW, HW and Report (ADC0804 submission) 2. Vivas from Project and μC Lab 3. Lab Manual Submission