Beruflich Dokumente
Kultur Dokumente
Contents
• 1 UART Registers
• 2 UART Register Configuration
• 3 Baud Rate Calculation
• 4 Uart Init Steps
• 5 Steps To Send Char
• 6 Steps To Receive Char
• 7 Code
• 8 Using ExploreEmbedded Libraries
• 9 Downloads
UART Registers
The below table shows the registers associated with 8051 UART.
Register Description
SCON Serial Control Register
TCON Timer Control Register for Baud Rate Generator
TMOD Timer Mode Control for Baud Rate Generator
SBUFF Serial Buffer holds the data to be transmitted and the data received
SCON
7 6 5 4 3 2 1 0
SM0 SM1 SM2 REN TB8 RB8 TI RI
SM0 SM1 Operation Description Baud Rate Source
0 0 Mode 0 8-bit UART 1/12 the quartz frequency
0 1 Mode 1 8-bit UART Determined by the timer 1
1 0 Mode 2 9-bit UART 1/32 the quartz frequency
1 1 Mode 0 9-bit UART Determined by the timer 1
• SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit. When
set, it enables multiprocessor communication in mode 2 and 3, and eventually mode 1. It
should be cleared in mode 0.
• REN - Reception Enable bit enables serial reception when set. When cleared, serial
reception is disabled.
• TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of
transmitting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit.
• RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th bit
received is a logic 0. Set by hardware if 9th bit received is a logic 1.
• TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is sent.
It's a signal to the processor that the line is available for a new byte to transmit. It must be
cleared from within the software.
• RI - Receive Interrupt flag is automatically set upon one-byte receive. It signals that byte is
received and should be read quickly prior to being replaced by a new data. This bit is also
cleared from within the software.
TMOD
Timer1 Timer 0
7 6 5 4 3 2 1 0
Gate C/T M1 M0 Gate C/T M1 M0
• Gate Control
0 = Timer enabled
1 = Timer enabled if INTx\ is high
• M1-M0:Mode Control
TCON
7 6 5 4 3 2 1 0
TF1 TR1 TF0 TR0
Usually, an 11.0592 Mhz crystal oscillator is used to provide the clock to 8051. The value seems to
be odd but we see how it makes sense. From above discussion
If we look at the standard baud rates used for serial communication shown in the table below, we can
observe that all the baud rates are factors or multiples of the Tclk (28.8K)! This results in low error
rates and hence is a commonly used crystal with 8051.
Now with Fosc = 11.0592Mhz, TH1 value for 9600 baudrate will be: TH1 = 256-(11.0592*10^6)/(32 *
12 * 9600) = 253 = 0xFD = -3
Code
Below is the sample code to Transmit and receive the chars at 9600 baudrate with 11.0592Mhz
clock.
Have an opinion, suggestion , question or feedback about the article let it out here!