# Baudrate Calculator

I need to know what the value of TH1 and TL1 should to set the baudrate of an 8051 controller to 115200 Hz. I'm using an oscillator frequency of 11.0952 MHz.

Also, is there any software that calculate baudrate values?

Is on-line baud rate calculator OK? Timer 1 used as baud-rate generator works in auto-reload 8-bit mode, so you only have to set TH1, TL1 is loaded from TH1 at the beginning of each cycle. Check this tutorial.

• Note: the calculator I linked above can be used for both 8-bit timer 0/1 and 16-bit timer 2. – Code Painters May 4 '11 at 14:07

Which variant are you using? A standard 8051 (12 clocks per machine cycle and a 16X serial clock) has a maximum baud rate of 57600 with a 11.0592MHz crystal.

For instance with timer 1 set to 8 bit auto-reload mode, to get 9600 baud you take 11.0592MHz, divide by 12 then 16 to get 57600. Now 57600/9600 = 6 so we need a further division by 6 which we get by setting the timer register TH1 to the two's complement of 6 which is 0xFA.

• What you described is valid for 16-bit operation. As far as I remember only timer 2 can operate as 16-bit counter with auto-reload. Timers 0 and 1 can only be used as 8-bit counters, if auto-reload feature is used (mode 2). – Code Painters May 4 '11 at 14:06
• @Czajnik - Quite right! I should have double-checked before posting. I've edited my answer. – MikeJ-UK May 4 '11 at 14:21

The best calculator for baudrates is the preprocessor of the assembler or compiler you are using. Let the computer do the work.

• There's plenty of source code out there, too. – Toybuilder May 4 '11 at 20:13