The following is calculated by software: 12M crystal oscillator, timer mode 16 bit, 12T, 1 millisecond time
void Timer0Init(void) //1 millisecond@12.000MHz{ AUXR &= 0x7F; //Timer clock 12T mode TMOD &= 0xF0; //Set timer mode TMOD |= 0x01; //Set timer mode TL0 = 0x18; //Set the initial timing value TH0 = 0xFC; //Set the initial timing value TF0 = 0; // Clear TF0 flag TR0 = 1; //Timer 0 starts timing}1.2.3.4.5.6.7.8.9.10.
Verify the software's results:
The crystal oscillator is 12M, and one oscillation takes (1/12M) seconds.
A machine cycle of a 12T microcontroller is 12 clock cycles (0.000001 seconds).
The time consumed by a 12M crystal oscillator 12T to work in one machine cycle is (1/12M)*12 seconds = 0.000001 seconds = 1 microsecond
The delay requirement is 1 millisecond, which is 1000 microseconds.
The lower 8 bits and the upper 8 bits are 16 bits in total, 65535, which can only hold 65535 microseconds of time.
THX=(65536-1000)/256=252=0xFC
TLX=(65536-1000)%256 =18=0x18
【Manual calculation】 Use 11.0592M to delay 20 milliseconds
20 milliseconds = 0.02 seconds
One machine cycle takes (12/(11.0592*10^6)) seconds
The cycle used for 0.02 seconds = 0.02/(12/(11.0592*10^6)) = 18432 machine cycles
11.0592M 12T 1 bit 20 milliseconds
TH0=(65536-18432)/256=0xB8
TH0=(65536-18432)%256=0x00
The software verifies my calculations:
void Timer0Init(void) //20 milliseconds @ 11.0592MHz { AUXR &= 0x7F; //Timer clock 12T mode TMOD &= 0xF0; //Set timer mode TMOD |= 0x01; //Set timer mode TL0 = 0x00; //Set the initial timing value TH0 = 0xB8; //Set the initial value of timing TF0 = 0; // Clear TF0 flag TR0 = 1; //Timer 0 starts timing}1.2.3.4.5.6.7.8.9.10.
EA---Global enable bit.
EA=1, turn on the global interrupt control. Under this condition, each interrupt control bit determines whether the corresponding interrupt is turned on or off.
EA=0, turn off all interrupts.
ET2---Timer/Counter 2 interrupt enable bit.
ET2=1, turn on T2 interrupt.
ET2=0, turn off T2 interrupt.
ES---Serial port interrupt enable bit.
ES=1, turn on serial port interrupt.
ES=0, turn off serial port interrupt.
ET1---Timer/Counter 1 interrupt enable bit.
ET1=1, turn on T1 interrupt.
ET1=0, turn off T1 interrupt.
EX1---External interrupt 1 interrupt enable bit.
EX1=1, turn on external interrupt 1 interrupt.
EX1=0, turn off external interrupt 1.
ET0---Timer/Counter 0 interrupt enable bit.
ET0=1, turn on T0 interrupt.
ET0=0, turn off T0 interrupt.
EX0---External interrupt 0 interrupt enable bit.
EX0=1, turn on external interrupt 0 interrupt.
EX0=0, turn off external interrupt 0.
Previous article:C51 WARNING L6: XDATA SPACE MEMORY OVERLAP
Next article:51 single chip microcomputer menu implementation problem
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- Pengpaiwei PT32L033 series overview and features
- Introduction to TI's fifth-generation DSP product TMS320C5X
- 51 Microcontroller timer 0 affects the normal operation of timer 1. How to solve it?
- Drone battery power monitoring system based on Gizwits IoT platform
- Linear power supply chips are hot? Problem analysis
- 【RT-Thread Reading Notes】5. RT-Thread Study Chapter 6 Reading Notes (Part 2)
- Please advise on the spike problem on the 5V power supply
- MSP430 and ATK-NEO-6M GPS module
- 802.11af White-Fi Technology
- [Nucleo G071 Review] Detecting HTS221 Temperature and Humidity Sensor Data