SerialCommunication and PCON Reg
SerialCommunication and PCON Reg
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
•Small Connectors
•Distributed Computing
•Sensor Networking
Serial v/s Parallel Communication
• As far as the conductor wire is concerned, the baud rate and bps
are the same, and we use the terms interchangeably
• 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
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
In order to transmit and receive both device should agree upon the common baud
rate
Generation of Baud Rate in 8051
MO M1 MODE Oscillator
frequency
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
If SMOD =0 , then
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
Since Mode 1 has variable Baud rate. Let us assume the Baud rate we
transmit is 9600.
Baud Rate of Mode 1
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
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.
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
Quiz
Assignment Questions
Thank you