8051 single-chip microcomputer serial port baud rate and Timer 1 initial value calculation

Source: Internet
Author: User

In mode 0 and mode 2, serial baud rate is fixed, mode 0 is FOSC/12. Mode 2 is FOSC/32 or FOSC/64, which is determined by the smod bit of the Pcon register.

In mode 1 and Mode 3, the baud rate is a variable value, the baud rate can be generated by the Timer 1 (8052 can be generated by timing 2), then the baud rate is exactly how much? The baud rate is determined by the overflow rate of the timer 1:
Baud rate = (2SMOD/32) * (Timer 1 Overflow rate)
Note: 2SMOD Here the smod is the exponent, the smod is the baud rate double baud rate bit, the bit in the Pcon register.
When using timer 1 as a baud rate generator, it is usually necessary to configure timer 1 as a 8-bit auto-reload mode of operation, while also prohibiting the Timer 1 interrupt, then the rate of overflow of the timer 1 is how to calculate it? Overflow rate is the frequency of overflow, assuming that the crystal oscillator frequency is 12mhz,th1 value of 0xFE, then only two clock pulses will overflow, overflow period of 2us, then the frequency of overflow is 500KHz. According to the timer section, the timing time has the following calculation formula:
Timing time = (maximum count-counter initial value) * Machine Cycle = (maximum count-counter initial value) * (12/Crystal oscillator frequency (Hz)) (s) = (256-th1) * (12/osc_freq (Hz)) (s).
Then the overflow frequency will naturally be:
Osc_freq (Hz)/((256-TH1) *12).
So the last push to the baud rate is:
(2SMOD/32) * (Osc_freq (HZ)/((256-TH1) *12)).

The calculation formula of the baud rate has, it is natural that the initial value of the TH1 can be deduced according to the baud rate:
Baud_rate= (2SMOD/32) * (Osc_freq (HZ)/((256-TH1) *12))
32*12* (256-th1) = (2smod*osc_freq (Hz))/baud_rate
256-th1= (2smod*osc_freq (Hz))/(BAUD_RATE*32*12)
th1=256-(2smod*osc_freq (Hz))/(BAUD_RATE*32*12)
Assuming the crystal oscillator frequency is 11.0592MHz, the baud rate is 9600,smod=0,th1 initial value should be how much? The Th1=256-11059200/(9600*32*12) =0xfd can be calculated according to the above formula.

Transferred from: http://blog.csdn.net/mcgrady_tracy/article/details/18665733

8051 single-chip microcomputer serial port baud rate and Timer 1 initial value calculation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.