51 baud rate

Source: Internet
Author: User

The serial port of 51 chips can work in several different working modes. The working mode is set to use the scon register. The specific definitions of its bits are as follows:
Sm0 SM1 SM2 Ren tb8 rb8 Ti ri
Sm0 and SM1 are bits in the working mode of the serial port, so that the two can be set in four modes. Set the working mode of the serial port.

When using the serial port for communication, a very important parameter is the baud rate. normal communication can be performed only when the baud rate of the upper and lower computers is the same. The baud rate refers to the number of BITs that can be transmitted per second on the serial port. The baud rate referred to here. For example, the standard 9600 does not mean that 9600 bytes can be transferred per second. Instead, it means that 9600 binary places can be transferred per second, and 8 binary places can be transferred for a single byte, if you use serial port Mode 1 for transmission, plus the Start and Stop bits, each Data byte occupies 10 binary digits. When the 9600 baud rate is transmitted in Mode 1, the number of bytes transmitted per second is 9600 bytes 10 = 960 bytes.

The serial port operating mode of 51 chip 0 has a fixed baud rate. For fosc/12, the baud rate can reach 1 m based on a 12 m crystal oscillator. The baud rate of Mode 2 is fixed at fosc/64 or fosc/32. The specific usage depends on the smod bit in the pcon register. For example, if smod is 0 and the baud rate is focs/64, smod is 1, and the baud rate is focs/32.

The baud rate of Modes 1 and 3 is variable, depending on the overflow rate of the timer 1 or 2 (52 chips), that is, each time the timer 1 overflows, the serial port sends data. So how do we calculate the value of the registers related to the baud rate settings of these two modes? You can use the following formula for calculation.

In the above example, if the smod bit in the pcon register is set to 1, the baud rate can be increased by 2 times. Generally, the timer 1 is used to work in the timer mode 2. At this time, the TL1 In the timer value is used as the count, and the TH1 is used as the auto-Reload value. In this timer mode, after the timer overflows, the value of TH1 is automatically loaded to TL1 and starts counting again, so that the timing is more accurate without intervention by software. The formula for calculating the overflow rate of timer 1 in this timer mode 2 is as follows:
Overflow rate = (counting rate)/(Initial Value of 256-th1)

Overflow rate = fosc/[12 * (Initial Value of 256-th1)]
In the above formula, the "counting rate" is related to the frequency of the crystal oscillator used. In 51 chips, after the timer is started, the value of the timing register TH is increased by one at each machine cycle, A machine cycle is equal to twelve oscillation cycles, so we can know that the counting rate of 51 chips is 1/12 of the crystal oscillator frequency, and a 12 m crystal oscillator is used on 51 chips, then the counting rate of 51 is 1 m. Generally, a 11.0592 M crystal is used to obtain a standard error-free baud rate. Why? After computing, you will know. For example, we want to get the baud rate of 9600, the crystal oscillator is 11.0592m and 12 m, the timer 1 is Mode 2, and the smod is set to 1, respectively, to see what the value of the required TH1 is. Substitution formula:
11.0592 m
9600 = (2 Jun 32) × (11.0592 M/12)/(256-th1 ))
Th1 = 250

12 m
9600 = (2 Jun 32) × (12 M/12)/(256-th1 ))
Th1 ≈ 249.49

 

The above calculation shows that the calculated TH1 is not an integer when the 12 m crystal is used, while the value of Th1 can only be an integer, in this way, it will have a certain error and cannot produce a precise 9600 baud rate. Of course, a certain error can be accepted during use. Even if a 11.0592 M crystal oscillator is used, the baud rate will produce an error due to the error in the crystal itself, however, the crystal error has a very small effect on the baud rate, which is negligible.

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.