0% found this document useful (0 votes)
48 views

Microcontroller

The document discusses serial data communication using the 8051 microcontroller. It describes the different transmission and reception modes of the 8051 UART. Mode 1 is the most commonly used mode which uses a 10-bit frame with 1 start bit, 8 data bits and 1 stop bit. It also provides the programming steps to configure the timer 1 and SCON registers to set the baud rate and enable serial transmission and reception in mode 1. Examples of calculating standard baud rates like 9600 and 1200 bps are given using a 11.0592 MHz crystal frequency.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Microcontroller

The document discusses serial data communication using the 8051 microcontroller. It describes the different transmission and reception modes of the 8051 UART. Mode 1 is the most commonly used mode which uses a 10-bit frame with 1 start bit, 8 data bits and 1 stop bit. It also provides the programming steps to configure the timer 1 and SCON registers to set the baud rate and enable serial transmission and reception in mode 1. Examples of calculating standard baud rates like 9600 and 1200 bps are given using a 11.0592 MHz crystal frequency.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

MC&ES SERIAL DATA COMMUNICATION-II

8TH CLASS 23rd AUGUST 2023


DATA TRANSMISSION &RECEPTION

Transmission – Data transmition is initiated by writing data to the SBUF register. TI


Flag is set to 1 when the data has been transmitted and signified that the SBUF is empty.
you must wait for the signal of TI flag.
Reception – Data receive through the RXD pin bit 
REN bit in SCON must be set or 1 position to receive data
For mode 0 RI must be cleared
RI flag is set to 1 after receiving all the data
Not under program control only through REN we have to control.
DATA TRANSMISSION MODES

• Works in four different modes Mode 0 ,1, 2 3


• Modes are selected by SM0 and SM1 bits in SCON
• Mode 0-fixed Baud Rate-Shift Register
• Mode-1 8 bit
• Mode 2 & 3 9 bit-
MODE 0-ONLY SYNCHRONOUS MODE

• In mode 0, serial data are transmitted and received through the RXD
pin, while the TXD pin output clocks. The baud rate is fixed at 1/12 the
oscillator frequency. On transmit, the least significant bit (LSB bit) is
sent/received first.
MODE 1
• UART is designed mainly for this mode and frame format of this mode is compatible
with COM port of PCs. The programmer can set its transmission/reception rate using
Timer 1.
• In mode 1, 10 bits are transmitted through the TXD pin or received through the RXD
pin in the following manner:
• a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1).
• The START bit is only used to initiate data receive, while the STOP bit is
automatically written to the RB8 bit of the SCON register.
• Our Discussion is only about Mode One
• Remaining modes 2 & 3 are Hostel readable
SERIAL DATA MODE ONE-

• SET SMO to 0 AND SM1 1 for Mode 1 01


• SBUF BECOME 10 BIT FULL DUPLEX RECEIVER &
TRANSMITTER
• 8 DATA BITS -ONE START BIT- ONE STOP BIT
• RXD PIN RECEIVES THE DATA
• TXD PIN TRANSMITS THE DATA
• ORDER OF TRANSMISSION:START BIT-LSB-MSB-STOP BITS
TRANSMISSION

• Data transmission begins by writing data to the SBUF register. The START
and STOP bits are added by hardware to form a 10-bit frame.
• Then, the 10-bit parallel-to-serial conversion is performed and one bit (LSB
first) at a time is transmitted through the TXD pin
• Once the complete frame is transmitted, the TI flag is set automatically by the
serial port hardware to indicate the end of data transmission
• We need to monitor the TI flag to conform that SBUF register is not
overloaded
• If the TI flag is set, it implies that last character transmission is completed and now
SBUF is empty and
• then new byte can be written to it to start the next transmission. If a new byte is
written to SBUF before TI is raised, the
• Un transmitted part of the previous byte will be lost.
• It should be noted that the microcontroller sets the TI flag when it completes byte
transfer, whereas it must be cleared by the programmer after the next byte
is loaded into SBUF.
RECEPTION

• The data reception begins when REN = 1 and high-to-low transition (start bit) is detected
on the RXD pin.
• The received byte is loaded into SBUF register (the START and STOP bits are separated
by UART hardware once complete frame is received) and stop bit into RB8 (SCON bit 2)
only if the following two conditions are met.
• (i) RI = 0, showing that previous data byte is read by the program
• (ii) Either SM2 = 0 or stop bit = 1. Normally SM2 = 0 and character will be accepted irrespective of the
status of stop bit. A program may check RB8 to ensure that the stop bit is correct, if required. If these two
conditions are not met, the received character is ignored and RI is not set and the receiver circuit waits for
the next start bit
• EACH BIT TIME REMAINS LOW OR HIGH DURING CERTAIN TIME
INTERVAL
• TIME INTERVAL = 1/BAUD RATE FREQUENCY
• BIT WILL BE MAINTAINED HIGH OR LOW DURING THIS PERIOD
• RECEIVING INITIATED BY FALLING EDGE OF START BIT
• CONTINUES TILL HALFWAY OF NEXT START BIT
• ANTI NOISE MEASURE
WHEN 10 BITS ARE RECEIVED

• Start bit is discarded


• 8 data bits enters into SBUF register
• Stop bit is saved in RB8 bit of SCON
• RI becomes HIGH indicates new byte is received
• Check empty of SBUF before transmitting or receiving otherwise mix up with
previous data and leads to error.
MODE ONE BAUD RATES

• Timer One Is Used To Generate Baud Rate / Baud


Frequency For Mode 1 Using Overflow Flag.
• Timer 1 In Mode 2 Auto reload Mode
BAUD RATE FREQUENCY

When Timer is in mode 2


• Fbaud= [2smod/32] x [Oscillator Clock Frequency] / [12d x
(256 d– (TH1)]
• If Timer is not in mode 2 then
• f baud =2SMOD ÷ 32d X (timer 1 overflow frequency)
•  
WHAT VALUE SHOULD BE LOADED INTO THE TH1 REGISTER TO
GET A BAUD RATE OF (I) 9600 BITS PER SECOND, AND (II) 1200 BPS
FOR SERIAL TRANSMISSION? ASSUME CRYSTAL FREQUENCY TO
BE 11.0592 MHZ
•.
• The value of TH1 can be found as,

• TH1 = 256 -{(FOSC x 2SMOD) ÷ (12 × 32× FBAUD)}

• (i) For 9600 bps rate, assuming SMOD = 0


• TH1 = 256 – {(11.0592 × 106 × 20 ) ÷ (384 × 9600)} = 253 = FDH
• (ii) For 1200 bps rate, assuming SMOD = 0
• TH1 = 256 – {(11.0592 × 106 × 1) ÷ (384 × 1200)} = 232 = E8H
PROGRAM FOR TIMER AND SCON

• MOV TMOD,#20H Timer 1 mode 2


• MOV SCON,#40H Serial Mode 1
• MOV TH1.#0FDH Baud rate 9600
For the 8051 the Timer 1' is used to generate the baud rate in Auto reload
mode.
STANDARD BAUD RATES

• As per protocols serial data communication is following


standard baud rates
• Example:9600 is standard baud rate
• Then the required oscillator frequency is 11.0592 MHz
EXAMPLE TO CALCULATE BAUD RATE

XTAL=11.0592 MHz is divided by 12 = 921.6 kHz and then, 921.6 kHz/32 = 28,800 Hz
is the frequency provided by UART to Timer 1 to set baud rates.
28,800/3= 9600 where, = FD is loaded with TH1
• 28,800/6= 2400 where, =F4 is loaded with TH1
• But, if you try to change the value loaded to TH1 other than listed above, The baud
rate will not be supported by the BIOS of the PC and serial communication between
8051 microcontroller may not occur properly. However, you can program PC to
transfer data at such speed.
Step 1: The baud rate in the 8051 is programmable and can be set through Timer
1.

Step 2: The 8051 has external clock of frequency 11.0592 MHz, which is first
divided by 12. After which the machine cycle frequency is 921.6 kHz.

Step 3: Now, machine cycle frequency 921.6 kHz is divided by the 8051
microcontroller serial communication UART circuitry by 921.6 kHz divided by 32
gives you the frequency of 28,800 Hz.

Step 4: The baud rate should be programmed in mode 2 as we use Timer 1. To get
baud rates compatible with PC, we must load TH1 with values: -3, -6, -12, -24.
These values are fixed to find out suitable baud rate compatible with PCs COM
port. PC baud rates values are set by the vendors and are fixed.
TXD(P3.1) RXD

8051 COM port of PC or device

RXD(P3.0) TXD
• -SMOD 0 11.0592
Division factor to achieve different baud rates
Baud Rate TH1 (Hex)
9600 FD
4800 FA
2400 F4
1200 E8
8051 MICROCONTROLLER PROGRAMMING STEPS

• Configure Timer 1 in auto-reload mode.


• Load TH1 with value as per required baud rate e.g. for 9600 baud rate load 0xFD. (-3 in
decimal)
• Load SCON with serial mode and control bits. e.g. for mode 1 and enable reception, load
0x50.
• Start timer1 by setting TR1 bit to 1.
• Load transmitting data in the SBUF register.
• Wait until loaded data is completely transmitted by polling the TI flag.
• When the TI flag is set, clear it, and repeat above steps to transmit more data.
Write a program to transfer the message “YES” serially at 9600 baud,
8-bit data, 1 stop bit. Do this continuously.
PROGRAM THE 8051 TO RECEIVE BYTES OF DATA SERIALLY, AND PUT
THEM IN PI. SET THE BAUD RATE AT 4800, 8-BIT DATA, AND 1 STOP BIT

• .
Transfer A Letter Y Serially At 9600 Baud & Also To Send N Through Port O
Connected To Displace Device

• MOV TMOD,#20H – T1 Mode2


MOV TH1,#-3— 9600 baud rate
MOV SCON,#50H- 8bit-1stop-RENE
SETB R1 Start Timer
• AGAIN MOV,SBUF,# ‘Y’
• HERE JNB TI ,HERE
• CLR T1 clear T1 for next transmission
• MOV Po # ’N’
• SJMP AGAIN--repeat
8051

→ Y

P3.1

→ N → Display
Device
Po
SERIAL COMMUNICATION 8051 MICROCONTROLLER USING
KEIL
• Simulation Result (In Keil μVision 4.0 IDE)
• The transmitted data using UART can be observed in
serial output windows. Open serial windows from “
View → Serial Windows → UART#1 menu. The
snapshot of the output is shown
MODE 2-• ASYNCHRONOUS MODE

• 11 bit data frame (start bit, 8 data bit, programmable 9 bit and stop bit)
• • On transmission 9th bit is TB 8 bit of SCON
• • On reception 9th bit is placed in RB 8 bit of SCON
• • 9th bit may be used for data or as a parity bit
• • Baud rate may be 1/32 or 1/64 of oscillator frequency
MODE 3

• is the same as Mode 2 in all respects except the baud


rate. The baud rate in Mode 3 is variable.

You might also like