0% found this document useful (0 votes)
406 views56 pages

SerialCommunication and PCON Reg

This document provides information about serial communication using the 8051 microcontroller. It begins by explaining the advantages of serial over parallel communication, such as reduced cabling costs and noise interference. It then describes the basics of serial communication including synchronous vs asynchronous transmission, different transmission modes, and how data is framed in asynchronous serial communication using start and stop bits. The document discusses serial communication standards like RS-232 and how the 8051's serial port pins TxD and RxD are connected. It provides details on the 8051's serial communication registers like SBUF for transmitting and receiving data and SCON for configuring the serial port. Finally, it touches on using timers to generate the baud rate for synchronous data transmission between devices.

Uploaded by

priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
406 views56 pages

SerialCommunication and PCON Reg

This document provides information about serial communication using the 8051 microcontroller. It begins by explaining the advantages of serial over parallel communication, such as reduced cabling costs and noise interference. It then describes the basics of serial communication including synchronous vs asynchronous transmission, different transmission modes, and how data is framed in asynchronous serial communication using start and stop bits. The document discusses serial communication standards like RS-232 and how the 8051's serial port pins TxD and RxD are connected. It provides details on the 8051's serial communication registers like SBUF for transmitting and receiving data and SCON for configuring the serial port. Finally, it touches on using timers to generate the baud rate for synchronous data transmission between devices.

Uploaded by

priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

SRI KRISHNA COLLEGE OF ENGINEERING AND TECHNOLOGY

Kuniamuthur, Coimbatore, Tamilnadu, India


An Autonomous Institution, Affiliated to Anna University,
Accredited by NAAC with “A” Grade & Accredited by NBA (CSE, ECE, IT, MECH ,EEE, CIVIL& MCT)

Course : MICROCONTROLLERS AND


INTERFACING
Module : I – 8051 Microcontroller
Topic : Serial Communication & PCON
Faculty : Ms. K. Priyadharsini

www.skcet.ac.in
Serial Communication in
8051
Lecture Video

Lecture Video:

https://drive.google.com/open?id=11QauQsj2aOg
GKNDSNa5D3oG1NIQVq0OQ

Animation Video:
https://drive.google.com/open?id=10rMZkcpwbvqoj
A4WoMwiUVkkk4OeBu3I
Serial v/s Parallel Communication
Why

•To reduce cost of Cabling

•Minimize the effect of noise

•Inherent device Characteristics

•Small Connectors

•Distributed Computing

•Sensor Networking
Serial v/s Parallel Communication

Parallel Communication Serial Communication


Often 8 or more lines (wire conductors) are The data is sent one bit at a time on a
used to transfer data. Multiple bits are single line (wire)
transferred at a time.
Preferred for short-distance Preferred over long-distance
communication communication
Costly as more resources are required Comparatively cheaper
Speed of data transfer is high Slow
Basics of Serial Communication

• Serial communication uses single data line making it much


cheaper
• Enables two computers in different cities to communicate
over the telephone
• Byte of data must be converted to serial bits using a parallel-
in-serial- out shift register and transmitted over a single data
line
• At thereceiving end there must be a serial-in-parallel-out
shift register
• If transferred on the telephone line, it must be converted to
audio tones by modem for short distance
Modes of Serial Communication
Modes of Serial Communication

• In simplex transmissions, the computer can only send data.


There is only one wire.
• If the data can be transmitted and received, then
it is a duplex transmission
• Duplex transmissions can be half or full
duplex depending on whether or not the data transfer
can be simultaneous
• If the communication is only one way at a time, it is half
duplex
• If both sides can communicate at the same time, it is full
duplex
 Full duplex requires two wire conductors for the data
lines (in addition to the signal ground)
Basics of Serial Communication
• Serial Communication can be
 Asynchronous
 Synchronous
Synchronous Communication
• Synchronous methods transfer a block of data (characters) at a
time
• The events are referenced to a clock
• Example: SPI bus, I2C bus
Asynchronous Communication
• Asynchronous methods transfer a single byte at a time
• There is no clock. The bytes are separated by start and stop bits.
• Example: UART
Basics of Serial Communication

• To support serial communication, special interfaces are built in


the microcontroller.
• The microcontrollers use special IC chips called UART
(universal asynchronous receiver-transmitter) and USART
(universal synchronous asynchronous receiver-transmitter)
• 8051 chip has a built-in UART
Data Framing in Asynchronous Serial
Communication
• Data is transmitted in 0s and 1s

• To have a sense of synchronization between transmitter and


receiver and to make sense of the data, transmitter and receiver
agree on a set of rules i.e protocol, which describes

 how the data is packed


 how many bits constitute a character
 when the data begins and ends
Data Framing in Asynchronous Serial
Communication
Start and stop bits

• Each character is placed between start and stop bits. This is


called framing.
• Start bit is always one bit, stop bit can be one, two or one and
half bits
• In 8051 serial port, when there is no transmission, the TxD
line is held high. This is called mark.
• Start bit is always a 0 (low), stop bit(s) is 1 (high)
• LSB is sent out first
Data Framing in Asynchronous Serial
Communication
Framing ASCII A

• The transmission begins with a start bit, followed by the LSB(D0),


then the rest of the bits until MSB (D7), and finally, the one stop
bit indicating the end of the character.

• When there is no transfer, the signal is 1 (high), which is referred


to as mark
Data Framing in Asynchronous Serial
Communication
• Assuming that we are transferring a text of ASCII
characters
file using 1 stop bit, we have a total of 10 bits for
each character

 This gives 25% overhead, i.e. each 8-bit character with


an extra 2 bits

• In some systems in order to maintain data integrity, the


parity bit of the character byte is included in the data frame
 UART chips allow programming of the parity bit for odd-,
even-, and no-parity options
Data Transfer Rate in Asynchronous Serial
Communication
• The rate of data transfer in serial data communication is stated in bps
(bits per second)

• Another widely used terminology for bps is baud rate


 It is modem terminology and is defined as the number of signal
changes per second
 In modems, there are occasions when a single change of signal
transfers several bits of data

• As far as the conductor wire is concerned, the baud rate and bps
are the same, and we use the terms interchangeably

• The data transfer rate of given computer system depends on


communication ports incorporated into that system
 IBM PC/XT could transfer data at the rate of 100 to 9600 bps
RS232 Standards
The UART, however does not operate at the line
voltage required by RS232 Standards. The UART
operates at TTL logical level (i.e 0 to 5v).

For noise immunity and long distance communication


the RS232 dictates the transmission of bits at higher
voltage rage and different polarities. (i.e -9v to +9.v)

Binary 0 : UART 0v : RS232 :3-25v


Binary 1 : UART 5v : RS232 :-3v to -25v
RS232 Standards
• An interfacing standard RS232 was set by the Electronics
Industries Association (EIA) in 1960
• The standard was set long before the advent of the TTL logic
family, its input and output voltage levels are not TTL compatible
• Rules
 Voltage specifications
Binary 0 :+3v to +25v
Binary 1 :-3v to -25v
These are called as negative logic. Where TTL is called
as Positive logic.
• Signal Specifications
DB9 pin connections
• RS232 supports both DB25 and DB 9 pin
connector
• DB-9 Pin Connector
TxD and RxD in 8051

• 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)
 These pins are TTL compatible; therefore, they require a
line driver to make them RS232 compatible
• We need a line driver (voltage converter) to convert the
R232’s signals to TTL voltage levels that will be acceptable to
8051’s TxD and RxD pins
MAX 232
SBUF Register

• A byte of data to be transferred via the TxD line must be placed in the
SBUF register
• SBUF holds the byte of data when it is received by the RxD line
• SBUF can be accessed like any other register
 MOV SBUF, #'D' ;load SBUF=44H, ASCII for 'D‘
 MOV SBUF, A
 MOV A, SBUF ;copy accumulator into SBUF
;copy SBUF into accumulator
Transmit
Receive
SBUF Register

 When a byte is written in SBUF, it is framed by 8051 with the


start and stop bits and transferred serially via the TxD pin

 When the bits are received serially via RxD, it is deframed


by 8051 by eliminating the stop and start bits, making a
byte out of the data received, and then placing it in the
SBUF

 Framing need not be done by programmer explicitly


SBUF Register

• The special function register SBUF is physically two registers.


 One is, write-only and is used to hold data to be transmitted
out
of the 8051 via TXD.
 The other is, read-only and holds the received data from
external sources via RXD.
• Both mutually exclusive registers have the same address 099H.
• SBUF is not bit addressable
SCON Register

SCON is an 8-bit register used to program the start bit, stop bit, and data bits
of data framing, among other Things
SM0 SM1 SM2 REN TB8 RB8 TI RI

• SM0 : Serial Mode Specifier


• SM1 : Serial Mode Speceifier
• SM2 : Used for multiprocessor Communication
• REN : Set/Cleared by Software to enable/disable reception
• TB8 : not used in Mode 1
• RB8 : Not used in Mode 1
• TI : Transmit interrupt flag. Set by HW at the begin of the stop bit mode 1.
And cleared by SW
• RI : Receive interrupt flag. Set by HW at the begin of the stop bit mode 1.
And cleared by SW
TIMER
SCON Register

SM0, SM1 determine the framing of data by specifying the


number of bits per character, and the start and stop bits

SM0 SM1 Serial Mode


0 0 Mode 0
0 1 Mode 1
1 0 Mode 2
1 1 Mode 3
Baud Rate

What will be the duration of each Bit we transmit?

Baud Rate decides the duration of each bit to be transmitted.

1 bit= 1/ 9600 sec.

In order to transmit and receive both device should agree upon the common baud
rate
Generation of Baud Rate in 8051

Timer T1 is used to generate baud rate in 8051uc.


Timer T1 operate in mode 2 (auto Reload mode).
In order to make the baud rate double we keep
SMOD bit in PCON reg to 1.
Doubling the Baud Rate
DIFFERENT MODES OF SERIAL
COMMUNICATION
DIFFERENT MODES OF SERIAL COMMUNICATION

MO M1 MODE Oscillator
frequency

0 0 MODE 0 – Shift Register osc/12


0 1 MODE 1- 8 – Bit UART Variable –
Determined by
T1

1 0 MODE 2- 9 – Bit UART osc/64 or osc/32

1 1 MODE 3- 9 – Bit UART Variable –


Determined by
T1
Serial Data Transmission Modes

Mode 0
• In this mode, the serial port works like a shift register and the
data transmission works synchronously with a clock
frequency of fosc /12.
• Serial data is received and transmitted through RXD.
• 8 bits are transmitted/ received at a time.
• Pin TXD outputs the shift clock pulses of frequency fosc
/12, which is connected to the external circuitry for
synchronization.
• The shift frequency or baud rate is always 1/12 of the
oscillator frequency.
Baud Rate of Mode 0

f baud = (2 SMOD /12) fosc.

If SMOD =0 , then

f baud = (2 0 /12) 12 M H z. = 1mbps (Fixed)


Serial Data Transmission Modes

Mode 1
• In mode-1, the serial port functions as a standard Universal
Asynchronous Receiver Transmitter (UART) mode.
• 10 bits are transmitted through TXD or received through RXD.
• The 10 bits consist of one start bit (which is usually '0'), 8 data
bits (LSB is sent first/received first), and a stop bit (which is
usually '1').
• Once received, the stop bit goes into RB8 in the special
function register SCON. The baud rate is variable.
Baud Rate of Mode 1

f baud = (2 SMOD /32) * ( fosc / 12 (256-TH1)) .

Since Mode 1 has variable Baud rate. Let us assume the Baud rate we
transmit is 9600.
Baud Rate of Mode 1

The generating frequency by the timer is 28800Hz. But we need a baud


rate about 9600.

So,

28800/9600= 3.

Hence T1 has start after three clock ticks in order to Start the serial
Communication. This can be done by using Auto Reload.
Baud Rate of Mode 1


00

tick 1


FD

tick 1
Serial Data Transmission Modes

Mode 2

• In this mode 11 bits are transmitted through TXD or received


through RXD.
• The various bits are as follows: a start bit (usually '0'), 8 data bits
(LSB first), a programmable 9 th (TB8 or RB8)bit and a stop bit
(usually '1').
• While transmitting, the 9 th data bit (TB8 in SCON) can be assigned
the value '0' or '1'.
• The baud rate is programmable to either 1/32 or 1/64 of the
oscillator frequency.
f baud = (2 SMOD /64) fosc.
Serial Data Transmission Modes

Mode 3
• In this mode 11 bits are transmitted through TXD or received
through RXD.
• The various bits are: a start bit (usually '0'), 8 data bits (LSB
first), a programmable 9 th bit and a stop bit (usually '1').
• Mode-3 is same as mode-2, except the fact that the baud rate
in mode-3 is variable (i.e., just as in mode-1).
• f baud = (2 SMOD /32) * ( fosc / 12 (256-TH1)) .
• This baud rate holds when Timer-1 is programmed in
Mode-2.
Value to be loaded to Start Serial Communication

SCON = 50h

TCON = 20h
TI and RI Flags

TI (transmit interrupt)
• When 8051 finishes the transfer of the 8-bit character, it
raises the 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 the 8051 receives data serially via RxD, it places
the byte in the SBUF register then 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
Programming the 8051 to transfer character
byte as serially
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 value 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 .The TI flag bit is monitored with the use of instruction
JNB TI,xx to see if the character has been transferred completely.

7. To transfer the next byte, go to step 5.


Steps that 8051 goes through in transmitting
a character via TxD
1. The byte character to be transmitted is written into the SBUF
register
2. The start bit is transferred
3. The 8-bit character is transferred on bit at a time
4. 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
5. 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 untransmitted portion of the previous byte will be lost
6. After SBUF is loaded with a new byte, the TI flag bit must be
forced to
0 by CLR TI in order for this new byte to be transferred
Importance of TI Flag

• By checking the TI flag bit, we know whether or


not the 8051 is ready to transfer another byte.

• 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 the 8051 to receive character
bytes serially
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 value 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 entire character has been received yet.
7. When RI is raised, SBUF has the byte, its contents are
moved into a safe place.
8. To transfer the next byte, go to step 5.
Steps that 8051 goes through in receiving a
character via RxD
1. It receives the start bit
 Indicating that the next bit is the first bit of the character byte it is
about
to receive
2. The 8-bit character is received one bit at time
3. 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
4. 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
5. 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

• By checking the RI flag bit, we know whether or


not the 8051 received a character byte

• If we copy SBUF into a safe place before the RI


flag bit is raised, we risk copying garbage
PCON Register
PCON register and Power Saving Modes in
8051
PCON register and Power Saving Modes in
8051
• Generally speaking, the microcontroller is inactive for the
most part and just waits for some external signal in order to
takes its role in a show.
• This can cause some problems in case batteries are used for
power supply.
• In extreme cases, the only solution is to set the whole
electronics in sleep mode in order to minimize consumption.
PCON register and Power Saving Modes in
8051
Idle Mode
• Upon the IDL bit of the PCON register is set, the
microcontroller turns off the CPU unit while peripheral units
such as serial port, timers and interrupt system continue
operating normally
• In Idle mode, the state of all registers and I/O ports remains
unchanged.
• In order to exit the Idle mode and make the
microcontroller operate normally, it is necessary to
reset.
• It will cause the IDL bit to be automatically cleared and
the program resumes operation from instruction having
set the IDL bit.
PCON register and Power Saving Modes in
8051
Power Down Mode
• By setting the PD bit of the PCON register from within the
program, the microcontroller is set to Power down mode,
• In power down mode, internal oscillator is off and reduces
power consumption enormously.
• The only way to get the microcontroller back to normal
mode is by reset.
• While the microcontroller is in Power Down mode, the state
of all SFR registers and I/O ports remains unchanged.
• By setting it back into the normal mode, the contents of the
SFR register is lost, but the content of internal RAM is
saved.
ASSESSMENT

Quiz

Assignment Questions

Thank you

You might also like