For example, to write a delay function with a delay of 10ms: (12M crystal oscillator)
void delay_10ms()
{
unsigned char i,j,k;
for(i=5;i>0;i--)
{
for(j=4;j>0;j--)
{
for(k=248;j>0;j--);
}
}
}
Principle: 3 layers of for loops, the number of loops is NUM = 4X5X248 = 4960 times. Each loop has a conditional judgment (such as i > 0) and a self-decrement statement (such as i--), so each loop consumes two machine cycles.
Therefore, the total machine cycles consumed is SUM = NUM x 2 = 9920
Because the frequency of the 12M crystal oscillator is 1us per machine cycle, the time taken for this function is 9920us = 9.920 ms, which is approximately 10ms. If the assignment statement, stack push and pop operations are included, the total time is about 10ms.
Previous article:Two modes of external interrupts of microcontrollers
Next article:Delay and timer of 51 single chip microcomputer
Recommended ReadingLatest update time:2024-11-15 17:18
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- EEWORLD University Hall ---- IoT Moment: When Intelligence is No Longer Intelligent
- Renovation of old things + I use old forehead thermometer to realize turning over monitoring
- 30 50-yuan Jingdong cards are waiting for you! Prize-winning quiz | Infineon's one-stop BMS solution
- How to determine the similarity of two signal waveforms
- NO7. Evaluation and Prospect of Rapid lot Kit in Smart Home and Smart Grid Scenarios
- MSP430FR6043 Ultrasonic Sensing Evaluation Module
- 【Me and Yatli】+ Upcoming review
- NE555 timer problem
- Road lighting system solutions based on the Internet of Things
- [Jihai M3 core APM32E103VET6S MINI development board] 05. ADC high-speed sampling and DAC analog peripheral functions