In mode 0 and mode 2, the serial port 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 timer 1 (8052 can be generated by timer 2). So what is the baud rate? The baud rate is determined by the overflow rate of timer 1:
Baud Rate = (2SMOD/32)*(Timer 1 Overflow Rate)
Note: 2SMOD Here SMOD is the exponent, SMOD is the baud rate double baud rate bit, which is in the PCON register.
When using timer 1 as a baud rate generator, it is usually necessary to configure timer 1 to the 8-bit auto-reload mode, and at the same time disable timer 1 interrupts. So how is the overflow rate of timer 1 calculated? The overflow rate is the overflow frequency. Assuming the crystal frequency is 12MHz and the TH1 value is 0xFE, it only takes two clock pulses to overflow, and the overflow period is 2us, so the overflow frequency is 500KHz. According to the timer section, the timing time is calculated as follows:
Timing time = (maximum count value - counter initial value) * machine cycle = (maximum count value - counter initial value) * (12/crystal frequency (Hz)) (s) = (256-TH1) * (12/OSC_FREQ (Hz)) (s).
Then the overflow frequency is naturally:
OSC_FREQ (Hz) / ((256-TH1) * 12).
So the final baud rate is:
(2SMOD / 32) * (OSC_FREQ (Hz) / ((256-TH1) * 12)).
Now that we have the formula for calculating the baud rate, we can naturally deduce the initial value of TH1 based on 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 frequency is 11.0592MHz, the baud rate is 9600, and SMOD=0, what should the initial value of TH1 be? According to the above formula, we can calculate that TH1=256-11059200/(9600*32*12)=0xFD.
Previous article:51 MCU interrupt priority setting
Next article:51 MCU internal EEPROM reading and writing analysis and routines
Recommended ReadingLatest update time:2024-11-16 14:37
- Popular Resources
- Popular amplifiers
- Siemens PLC Programming Technology and Application Cases (Edited by Liu Zhenquan, Wang Hanzhi, Yang Kun, etc.)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Implementing a Deep Learning Framework with Python (Zhang Juefei, Chen Zhen)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EPWM interrupt cannot be enabled
- Three closed loop servo motor motion control
- Two-input AND gate engineering files and test files
- Help others and achieve self-realization——EEWORLD Q&A List (11th issue)
- ST Motor Review_bygyp1
- Problem of assigning initial value to timer of C51 MCU
- UPS-IPGuard Pro P1902 front panel device wiring diagram:
- 2012 Competition Award-winning Papers, Source Code, PCB (Part 5)
- DCDC Chip
- Seven tips for embedded development