SlideShare a Scribd company logo
1 of 39
Download to read offline
8051 SERIAL PORT
PROGRAMMING
Processor/C
ontroller
RS 232
Transreceiver
MAX
232
PC
By
A.Usha Rani,Lecturer,
Department of Physics and Electronics
St.Ann’s College for Women
Computers transfer data in two ways:
Parallel
 8 or more lines (wire conductors) are used to
transfer data.
 Serial
The data is sent one bit at a time
Sender Receiver Sender Receiver
Serial Communication
Parallel Communication
Parallel communication
 All bits of data are sent at a time.
 Data transfer speed is high.
 It is not preferred for long distance communication as
it requires more number of wires and becomes
expensive.
 Used for short distance communication
Serial communication
 Only one bit is sent at a time.
 Data transfer speed is low.
 Used for long distance communication.
In serial communication,
 At the transmitting end, the byte of data is
converted into serial bits(using a parallel-in-
serial-out shift register)
 At the receiving end, the serial data is received
and packed into byte(using a serial-in-parallel-
out shift register)
There are three types of communication systems
 Simplex – Data can be transmitted only in
one direction at a time.
 Half Duplex – Data can be transmitted only
in one direction at a time.
 Full duplex – Data can be transmitted in both
directions at a time.
Transmitter
Transmitter
Transmitter
Transmitter
Transmitter Receiver
Receiver
Receiver
Receiver
Transmitter
Simplex
Full Duplex
Half Duplex
 In synchronous communication, common clock is
used for transmitter and receiver.
 A separate link is used to transmit the clock signal.
 In Asynchronous communication, the
synchronization is achieved only at the beginning of
the transmission.
 To transfer data in serial communication, the
receiver and sender agree on set of rules called
protocol.
Synchronous and Asynchronous
serial communication
Serial data communication uses two methods:
Synchronous method - Block of data is transferred at
a time.
– Block-oriented data transfers use the synchronous
method
Asynchronous method –
– A single byte of data is transferred at a time.
– Is widely used for character-oriented transmissions
 Instructions can be written to use either of these
methods.
Format of Asynchronous serial data frame
A non-divisible group of bits which can be
transmitted at a time is called frame.
A frame consists of the actual data and extra
bits(called overhead bits) to maintain
synchronization of the data.
A frame has one start bit, data bits, parity bits and
stop bits.
Each character is placed in between start and stop
bits, this is called framing
The start bit is always one bit
The stop bit can be one or two bits
The start bit is always a 0 (low)
Asynchronous data Frame
Data Transfer Rate
 In serial data communication data transfer rate is
defined in bps (bits per second)
 Another widely used terminology is baud rate – the
number of signal changes per second
 Baud rate and number of signals per second should
not be considered to be same.
 Example: Let two signals be encoded in single
transition and consider that the signal is changing
after every 5ms.
 Baud rate = (1/5ms) = 500
 Number of bits per second = 2x200=400bits /s
RS 232 Standard
 In serial communication for long distances, special
devices were developed to use telephone lines for
communication between two computers which are at
a long distance.
 These devices are called Data Communication
Equipment(DCE). Ex- Modem
 The devices that send or receive data are called Data
Transmission Equipment(DTE). Ex –Computers
 For the maintenance of compatibility between DCE’s
manufactured by different manufacturers and to
establish communication signals between DTE and
DCE an interfacing standard RS232 wad developed.
RS stands for Recommended standard.
Image source: Google
 Since not all pins are used in PC cables, IBM
introduced the DB-9 version of the serial I/O
standard
Image source: Google
Data Communication equipment
Classification
Data communication equipment is classified as:
DTE (Data Terminal Equipment)-Terminal and
computers that send and receive data
DCE (Data Communication Equipment) -
Communication equipment, such as modems
 The simplest connection between a PC and
microcontroller at least requires - three pins, TxD,
RxD, and ground
Image source: Google
RS232 Pins
DTR (data terminal ready)
When terminal is turned on, it sends out signal DTR to
indicate that it is ready for communication
DSR (data set ready)
When DCE is turned on and has gone through the self-test,
it asserts DSR to indicate that it is ready to communicate
RTS (request to send)
When the DTE device has byte to transmit, it asserts RTS
to signal the modem that it has a byte of data to transmit
CTS (clear to send) When the modem has room for
storing the data it is to receive, it sends out signal CTS
to DTE to indicate that it can receive the data now
DCD (data carrier detect)
The modem asserts signal DCD to inform the DTE
that a valid carrier has been detected and that
contact between it and the other modem is
established
RI (ring indicator)
An output from the modem and an input to a PC
indicates that the telephone is ringing
It goes on and off in synchronous with the ringing
sound
Handshaking (Co-ordination) process between
DTE and DCE
When the power is turned ON, DTE sends Data Terminal
Ready(DTR) signal to inform DEC that is ready .
When DCE is ready, it sends Data Set Ready(DSR) signal
to DTE.
After receiving DSR signal, DTE sends request to use data
channel by sending RTS signal to start transmission.
DCE at other end is dialed. The DCE at receiving end
replies by sending signal.
After receiving the signal, DCE sends Data Carrier
Detect(DCD) to DTE.
Then DCE sends Clear to Send(CTS) signal.
Now DTE on transmitter side starts sending signal.
RS232 Standards
 An interfacing standard set by the Electronics
Industries Association (EIA) in 1960.
 Since it was set long before the advent of the TTL
logic family, its input and output voltage levels are
not TTL compatible
 In RS 232 a logic high is voltage between -3V to -25
V
and logic low is voltage between +3V to +25 V.
In TTL a logic high is +5V and logic low is 0V
 Hence to connect TTL compatible microcontroller to
RS 232 system, a voltage converter is needed.
 MAX232 and MAX 233 are most widely used voltage
converters.
MAX 232
MAX 232 has two set of line drivers for transferring and
receiving data.
Line drivers used for TxD( transmission)are called T1
and T2.
Line drivers used for RxD(receiving) are called R1 and
R2.
T1 line driver has designation T1in and T1out.
T1in pin is the TTL side and is connected to TxD of
microcontroller while T1out is RS232 side that is
connected to RxD pin of RS 232 DB connector.
R1 line driver has designation R1in and R1 out.
The R1in pin is RS232 side connected to TxD pin of
RS232 DB and R1 out is TTL side connected to RxD pin of
MAX233
 To save board space, some designers use MAX233 chip
from Maxim
MAX233 performs the same job as MAX232
But eliminates the need for capacitors
MAX233 and MAX232 are not pin compatible
Serial Data Buffer(SBUF) Register
 SBUF is an 8-bit register used for serial communication.
 For a byte data to be transferred using serial mode, it
must be placed in the SBUF register.
 When a byte is written into SBUF, it is framed with the
start and stop bits and transferred serially via the TxD
line
 SBUF also holds the byte of data when it is received by
8051 RxD line.
 When the bits are received serially via RxD, the 8051
deframes it by eliminating the stop and start bits, and
then placing the byte in SBUF
Serial Control(SCON) Register
This register is used to configure baud rate,
synchronization clock source.
It contains status bits which indicate whether the
data is transmitted completely and any new data is
received.
SCON Register
 SM0, SM1-They determine the framing of
data by specifying the number of bits per
character, and the start and stop bits
 SM2 - This enables the multiprocessing
capability of the 8051
SM0 SM1 Mode
0 0 Serial mode 0
0 1 Serial mode 1
1 0 Serial mode 2
1 1 Serial mode 3
Serial Port Modes
SM0 SM1 Mode Description Baud Rate
0 0 Serial mode 0 8-bit shift register 1/12 of the
clock
frequency
0 1 Serial mode 1 8-bit UART Determined by
timer 1
1 0 Serial mode 2 9-bit UART 1/12 of clock
frequency
1 1 Serial mode 3 9- bit UART Determined by
timer 1
SCON Register
REN (receive enable)
When it is high, it allows 8051 to receive data on
RxD pin
When it is low, the receiver is disabled.
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
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
TI and RI are set by hardware and must be cleared by the
software.
Programming Serial Data Transmitting
 In programming the 8051 to transfer character bytes
serially
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)
 TH1 is loaded with one of the values to set baud rate
for serial data transfer
SCON register is loaded with the value
50H(indicating serial mode 1, where an 8-bit data is
framed with start and stop bits)
TR1 is set to 1 to start timer 1
TI is cleared by CLR TI instruction
The character byte to be transferred serially is
written into SBUF register
The TI flag bit is monitored with the use of
instruction JNB TI, xx to see if the character has been
transferred completely.
Importance of TI Flag
The transmission of a character through TxD,
involves following steps
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
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 SBUF
is not overloaded.
If another byte is loaded into the SBUF before TI is
raised, the untransmitted portion of the previous
byte will be lost.
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.
Programming Serial Data Receiving
RI is cleared by CLR RI instruction
The RI flag bit is monitored with the use of
instruction JNB RI,xx to see if an entire character
has been received yet
When RI is raised, SBUF has the byte, and its
contents are moved into a safe place
Importance of RI Flag
 In receiving the data through RxD pin the following
steps are involved
At first start bit is received 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 a 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
can know that a character has been received
completely and is in SBUF register.
The SBUF contents are shifted to a safe place in
some other register or memory before it is lost
After the SBUF contents are copied, 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
Doubling Baud Rate
 There are two ways to increase the baud rate of data
transfer
To use a higher crystal frequency.
To change a bit in the PCON register
PCON register is an 8-bit register
It is not a bit-addressable register
When 8051 is powered up, SMOD is zero
We can set it to high by software and thereby
double the baud rate
Thank you

More Related Content

Similar to serial-200505101453.pdf

Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)Mashood
 
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....ANKUSH445845
 
Serial Communication Uart soc
Serial Communication  Uart socSerial Communication  Uart soc
Serial Communication Uart socSatyam Sharma
 
Universal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP coreUniversal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP coreAneesh Raveendran
 
Embedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdfEmbedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdfkanyaakiran
 
Unit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.ppt
Unit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.pptUnit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.ppt
Unit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.pptaasitworld
 
UART project report by Tarun Khaneja ( 09034406598 )
UART project report by Tarun Khaneja ( 09034406598 )UART project report by Tarun Khaneja ( 09034406598 )
UART project report by Tarun Khaneja ( 09034406598 )Tarun Khaneja
 
Rs 232 & usb ieee1394 communication
Rs 232 & usb  ieee1394 communicationRs 232 & usb  ieee1394 communication
Rs 232 & usb ieee1394 communicationVijay Kumar
 
Embedded real time-systems communication
Embedded real time-systems communicationEmbedded real time-systems communication
Embedded real time-systems communicationVijay Kumar
 
8251 08 Serial
8251 08 Serial8251 08 Serial
8251 08 SerialAisu
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communicationsinaankhalil
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGTotal Project Solutions
 

Similar to serial-200505101453.pdf (20)

8251 USART
8251 USART8251 USART
8251 USART
 
Chap10
Chap10Chap10
Chap10
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)
 
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....
 
Serial Communication Uart soc
Serial Communication  Uart socSerial Communication  Uart soc
Serial Communication Uart soc
 
UART
UARTUART
UART
 
Universal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP coreUniversal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP core
 
Embedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdfEmbedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdf
 
Uart
UartUart
Uart
 
Unit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.ppt
Unit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.pptUnit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.ppt
Unit_V_CPU_PC_interfacing_With_External_Devices_RS232_IEEE_488.ppt
 
UART project report by Tarun Khaneja ( 09034406598 )
UART project report by Tarun Khaneja ( 09034406598 )UART project report by Tarun Khaneja ( 09034406598 )
UART project report by Tarun Khaneja ( 09034406598 )
 
Serial1
Serial1Serial1
Serial1
 
Rs 232 & usb ieee1394 communication
Rs 232 & usb  ieee1394 communicationRs 232 & usb  ieee1394 communication
Rs 232 & usb ieee1394 communication
 
Embedded real time-systems communication
Embedded real time-systems communicationEmbedded real time-systems communication
Embedded real time-systems communication
 
8251 08 Serial
8251 08 Serial8251 08 Serial
8251 08 Serial
 
Project_intership
Project_intershipProject_intership
Project_intership
 
Project_intership
Project_intershipProject_intership
Project_intership
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communication
 
12 mt06ped019
12 mt06ped019 12 mt06ped019
12 mt06ped019
 
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

VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 

Recently uploaded (20)

VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 

serial-200505101453.pdf

  • 1. 8051 SERIAL PORT PROGRAMMING Processor/C ontroller RS 232 Transreceiver MAX 232 PC By A.Usha Rani,Lecturer, Department of Physics and Electronics St.Ann’s College for Women
  • 2. Computers transfer data in two ways: Parallel  8 or more lines (wire conductors) are used to transfer data.  Serial The data is sent one bit at a time Sender Receiver Sender Receiver Serial Communication Parallel Communication
  • 3. Parallel communication  All bits of data are sent at a time.  Data transfer speed is high.  It is not preferred for long distance communication as it requires more number of wires and becomes expensive.  Used for short distance communication Serial communication  Only one bit is sent at a time.  Data transfer speed is low.  Used for long distance communication.
  • 4. In serial communication,  At the transmitting end, the byte of data is converted into serial bits(using a parallel-in- serial-out shift register)  At the receiving end, the serial data is received and packed into byte(using a serial-in-parallel- out shift register)
  • 5. There are three types of communication systems  Simplex – Data can be transmitted only in one direction at a time.  Half Duplex – Data can be transmitted only in one direction at a time.  Full duplex – Data can be transmitted in both directions at a time.
  • 7.  In synchronous communication, common clock is used for transmitter and receiver.  A separate link is used to transmit the clock signal.  In Asynchronous communication, the synchronization is achieved only at the beginning of the transmission.  To transfer data in serial communication, the receiver and sender agree on set of rules called protocol. Synchronous and Asynchronous serial communication
  • 8. Serial data communication uses two methods: Synchronous method - Block of data is transferred at a time. – Block-oriented data transfers use the synchronous method Asynchronous method – – A single byte of data is transferred at a time. – Is widely used for character-oriented transmissions  Instructions can be written to use either of these methods.
  • 9. Format of Asynchronous serial data frame A non-divisible group of bits which can be transmitted at a time is called frame. A frame consists of the actual data and extra bits(called overhead bits) to maintain synchronization of the data. A frame has one start bit, data bits, parity bits and stop bits. Each character is placed in between start and stop bits, this is called framing The start bit is always one bit The stop bit can be one or two bits The start bit is always a 0 (low)
  • 11. Data Transfer Rate  In serial data communication data transfer rate is defined in bps (bits per second)  Another widely used terminology is baud rate – the number of signal changes per second  Baud rate and number of signals per second should not be considered to be same.  Example: Let two signals be encoded in single transition and consider that the signal is changing after every 5ms.  Baud rate = (1/5ms) = 500  Number of bits per second = 2x200=400bits /s
  • 12. RS 232 Standard  In serial communication for long distances, special devices were developed to use telephone lines for communication between two computers which are at a long distance.  These devices are called Data Communication Equipment(DCE). Ex- Modem  The devices that send or receive data are called Data Transmission Equipment(DTE). Ex –Computers  For the maintenance of compatibility between DCE’s manufactured by different manufacturers and to establish communication signals between DTE and DCE an interfacing standard RS232 wad developed. RS stands for Recommended standard.
  • 14.  Since not all pins are used in PC cables, IBM introduced the DB-9 version of the serial I/O standard Image source: Google
  • 15. Data Communication equipment Classification Data communication equipment is classified as: DTE (Data Terminal Equipment)-Terminal and computers that send and receive data DCE (Data Communication Equipment) - Communication equipment, such as modems  The simplest connection between a PC and microcontroller at least requires - three pins, TxD, RxD, and ground Image source: Google
  • 16. RS232 Pins DTR (data terminal ready) When terminal is turned on, it sends out signal DTR to indicate that it is ready for communication DSR (data set ready) When DCE is turned on and has gone through the self-test, it asserts DSR to indicate that it is ready to communicate RTS (request to send) When the DTE device has byte to transmit, it asserts RTS to signal the modem that it has a byte of data to transmit
  • 17. CTS (clear to send) When the modem has room for storing the data it is to receive, it sends out signal CTS to DTE to indicate that it can receive the data now DCD (data carrier detect) The modem asserts signal DCD to inform the DTE that a valid carrier has been detected and that contact between it and the other modem is established RI (ring indicator) An output from the modem and an input to a PC indicates that the telephone is ringing It goes on and off in synchronous with the ringing sound
  • 18. Handshaking (Co-ordination) process between DTE and DCE When the power is turned ON, DTE sends Data Terminal Ready(DTR) signal to inform DEC that is ready . When DCE is ready, it sends Data Set Ready(DSR) signal to DTE. After receiving DSR signal, DTE sends request to use data channel by sending RTS signal to start transmission.
  • 19. DCE at other end is dialed. The DCE at receiving end replies by sending signal. After receiving the signal, DCE sends Data Carrier Detect(DCD) to DTE. Then DCE sends Clear to Send(CTS) signal. Now DTE on transmitter side starts sending signal.
  • 20. RS232 Standards  An interfacing standard set by the Electronics Industries Association (EIA) in 1960.  Since it was set long before the advent of the TTL logic family, its input and output voltage levels are not TTL compatible  In RS 232 a logic high is voltage between -3V to -25 V and logic low is voltage between +3V to +25 V. In TTL a logic high is +5V and logic low is 0V  Hence to connect TTL compatible microcontroller to RS 232 system, a voltage converter is needed.  MAX232 and MAX 233 are most widely used voltage converters.
  • 22. MAX 232 has two set of line drivers for transferring and receiving data. Line drivers used for TxD( transmission)are called T1 and T2. Line drivers used for RxD(receiving) are called R1 and R2. T1 line driver has designation T1in and T1out. T1in pin is the TTL side and is connected to TxD of microcontroller while T1out is RS232 side that is connected to RxD pin of RS 232 DB connector. R1 line driver has designation R1in and R1 out. The R1in pin is RS232 side connected to TxD pin of RS232 DB and R1 out is TTL side connected to RxD pin of
  • 23. MAX233  To save board space, some designers use MAX233 chip from Maxim MAX233 performs the same job as MAX232 But eliminates the need for capacitors MAX233 and MAX232 are not pin compatible
  • 24. Serial Data Buffer(SBUF) Register  SBUF is an 8-bit register used for serial communication.  For a byte data to be transferred using serial mode, it must be placed in the SBUF register.  When a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TxD line  SBUF also holds the byte of data when it is received by 8051 RxD line.  When the bits are received serially via RxD, the 8051 deframes it by eliminating the stop and start bits, and then placing the byte in SBUF
  • 25. Serial Control(SCON) Register This register is used to configure baud rate, synchronization clock source. It contains status bits which indicate whether the data is transmitted completely and any new data is received.
  • 26. SCON Register  SM0, SM1-They determine the framing of data by specifying the number of bits per character, and the start and stop bits  SM2 - This enables the multiprocessing capability of the 8051 SM0 SM1 Mode 0 0 Serial mode 0 0 1 Serial mode 1 1 0 Serial mode 2 1 1 Serial mode 3
  • 27. Serial Port Modes SM0 SM1 Mode Description Baud Rate 0 0 Serial mode 0 8-bit shift register 1/12 of the clock frequency 0 1 Serial mode 1 8-bit UART Determined by timer 1 1 0 Serial mode 2 9-bit UART 1/12 of clock frequency 1 1 Serial mode 3 9- bit UART Determined by timer 1
  • 28. SCON Register REN (receive enable) When it is high, it allows 8051 to receive data on RxD pin When it is low, the receiver is disabled. 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
  • 29. 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 TI and RI are set by hardware and must be cleared by the software.
  • 30. Programming Serial Data Transmitting  In programming the 8051 to transfer character bytes serially 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)  TH1 is loaded with one of the values to set baud rate for serial data transfer SCON register is loaded with the value 50H(indicating serial mode 1, where an 8-bit data is framed with start and stop bits)
  • 31. TR1 is set to 1 to start timer 1 TI is cleared by CLR TI instruction The character byte to be transferred serially is written into SBUF register The TI flag bit is monitored with the use of instruction JNB TI, xx to see if the character has been transferred completely.
  • 32. Importance of TI Flag The transmission of a character through TxD, involves following steps 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 During the transfer of the stop bit that 8051 raises the TI flag indicating that the last character was transmitted
  • 33. By monitoring the TI flag, we make sure that SBUF is not overloaded. If another byte is loaded into the SBUF before TI is raised, the untransmitted portion of the previous byte will be lost. By checking the TI flag bit, we know whether or not the 8051 is ready to transfer another byte
  • 34.  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.
  • 35. Programming Serial Data Receiving RI is cleared by CLR RI instruction The RI flag bit is monitored with the use of instruction JNB RI,xx to see if an entire character has been received yet When RI is raised, SBUF has the byte, and its contents are moved into a safe place
  • 36. Importance of RI Flag  In receiving the data through RxD pin the following steps are involved At first start bit is received 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 a 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
  • 37. By checking the RI flag bit when it is raised we can know that a character has been received completely and is in SBUF register. The SBUF contents are shifted to a safe place in some other register or memory before it is lost After the SBUF contents are copied, 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
  • 38. Doubling Baud Rate  There are two ways to increase the baud rate of data transfer To use a higher crystal frequency. To change a bit in the PCON register PCON register is an 8-bit register It is not a bit-addressable register When 8051 is powered up, SMOD is zero We can set it to high by software and thereby double the baud rate