## Saturday, April 30, 2016

### 8051 Serial Baudrate Calculation

Baud Rate is a number of sent/received bits per second. In case the UART is used, baud rate depends on: selected mode, oscillator frequency and in some cases on the state of the SMOD bit of the SCON register.

All the necessary formulas are specified in the table:
SM1 SM0 Mode Mode Description Baud Rate
0 0 0 8-bit Shift Register Oscillator / 12
0 1 1 8-bit UART Set by Timer 1 (*)
1 0 2 9-bit UART Oscillator / 64 (*)
1 1 3 9-bit UART Set by Timer 1 (*)
(*) Baud rate is doubled if PCON.7 (SMOD) is set.

Mode 0: Oscillator / 12 = 11.059 MHz/12 = 921,583 baud

Mode 2: Oscillator / 64 = 11.059 MHz/64 = 172,797 baud

Mode 1 & 3: Baud rate is determined by how frequently timer 1 overflows. The most common method is to configure timer 1 in 8-bit auto reload mode and set a reload value (TH1) that causes Timer 1 to overflow at a frequency appropriate to generate a baud rate.

The following equation is used to determine the TH1 value.

TH1 = 256 - ((Crystal / 384) / Baud) where 384 = 32 * 12

If PCON.7 is set then TH1 = 256 - ((Crystal / 192) / Baud)

To achieve 19200,
TH1 = 256 - ((Crystal / 192) / Baud)
TH1 = 256 - ((11059000 / 192) / 19200)
TH1 = 256 - ((57699) / 19200)
TH1 = 256 - 3 = 253

Timer 1 is usually used as a clock generator as it enables various baud rates to be easily set. The whole procedure is simple and is as follows:
• First, enable Timer 1 overflow interrupt.
• Configure Timer T1 to operate in auto-reload mode.
• Depending on needs, select one of the standard values from the table and write it to the TH1 register. That's all.
BaudrateTH1SMOD Bit
OSC (MHZ)
bps11.05921214.74561620
150 40H 30H 00H 0
300 A0H 98H 80H 75H 52H 0
600 D0H CCH C0H BBH A9H 0
1200 E8H E6H E0H DEH D5H 0
2400 F4H F3H F0H EFH EAH 0
4800 F3H EFH EFH 1
4800 FAH F8H F5H 0
9600 FDH FCH 0
9600 F5H 1
19200 FDH FCH 1
38400 FEH 1
76800 FFH 1

Related topics:
8051 Crystal and Baudrate   |   8051 Timer Delay Calculation   |   8051 Serial Port   |   8051 Serial Port Programming   |   8051 Timer Programming   |   8051 Timers   |   8051 Software Development Tools   |   8051 Development Boards and Evaluation Kits   |   8051 Features   |   8051 History   |   8051 Enhanced Version 8052

List of topics: 8051