Instructions
Instructions
The rate at which the data is transmitted is called baud or transfer rate.
The baud rate is the reciprocal of the time to send one bit.
In asynchronous transmission, baud rate is not equal to number of bits per second.
This is because; each byte is preceded by a start bit and followed by parity and stop
bit.
For example, in synchronous transmission, if data is transmitted with 9600 baud, it
means that 9600 bits are transmitted in one second. For 10 bits 8 bits data transmitted
•
SERIAL DATA COMMUNICATION-PROTOCOLS
• Over the years, dozens of serial protocols have been crafted to meet
particular needs of embedded systems.
• USB (universal serial bus), and Ethernet, are a couple of the well-
known computing serial interfaces.
• Other very common serial interfaces include SPI, I2C, RS-232 and
so on.
8051-SERIAL DATA –BUSINESS PARTERNS
• 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.
SERIAL DATA MODE ONE-
• 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
• RI MUST BE ZERO
• BIT SM2 IS ZERO
• OR STOP BIT SHOULD BE ONE(GENERAL STATE)
• RI ZERO INDICATED PREVIOUS BYTE RECEIVED AND READY FOR NEXT
BYTE
• SM2 ZERO- STOP BIT CAN BE ANY STATE ZERO OR ONE-NOT MUCH USE
HERE
• SM2 =I RECEPTION OF ONLY GOOD STOP BITS-ANTI NOISE SAFE GAURD
BAUD RATE FREQUENCY
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
RXD(P3.0) TXD
Division factor to achieve different baud rates
Baud Rate TH1 (Hex)
9600 FD
4800 FA
2400 F4
1200 E8
• Example 10-1
• With XTAL = 11.0592 MHz, find the TH1 value needed to have the following baud
rates. (a) 9600 (b) 2400 (c) 1200
• Solution:
• The machine cycle frequency of the 8051 = 11.0592 MHz / 12 = 921.6 kHz, and 921.6 kHz / 32 = 28,800 Hz is the
frequency provided by UART to Timer 1 to set baud rate
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 × 1) ÷ (384 × 9600)} = 253 = FDH
• (ii) For 1200 bps rate, assuming SMOD = 0
• TH1 = 256 – {(11.0592 × 106 × 1) ÷ (384 × 1200)} = 232 = E8H
8051 MICROCONTROLLER PROGRAMMING STEPS
• .
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