Microcontroller
Microcontroller
• 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-
• 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
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
• -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
• .
Transfer A Letter Y Serially At 9600 Baud & Also To Send N Through Port O
Connected To Displace Device
→ 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