Tuesday, November 22, 2011

Baud rate in 8051

The 8051 transfers and receives data serially at many different baud rates. The baud rate in 8051 are completely programmable. This is done with help of timer 1.

8051 divides the crystal frequency by 12 to get machine cycle frequency. In case of XTAL = 11.0592 Mhz. so machine cycle here becomes 921.6 Khz. Now the 8051 UART circuitry divides the machine cycle frequency of 921.6 Khz by 32 once more before it is used by timer 1 to set the baud rate.

So 921.6Khz divided by 32 gives 28,800 hz. This is the value of frequency upon which we will perform operation to get variable baud rate. When timer 1 is used to set baud rate it must be programmed in mode 2 8 bit auto reload.
Timer 1 TH1 register values for various baud rates

Baud rate
TH1(decimal)
TH1(hex)
9600
-3
FD
4800
-6
FA
2400
-12
F4
1200
-24
E8

As 28,800/3 = 9600 where -3 is loaded into TH1.
28800/12 = 2400 where -12 is loaded into TH1.
28800/24 = 1200 where -24 = E8 is loaded into TH1.

9 comments: