1. 500ms delay subroutine
program:
void delay500ms(void)
{
unsigned char i,j,k;
for(i=15;i>0;i--)
for(j=202;j>0;j--)
for(k=81;k>0;k--);
}
Calculation:
The program has three layers of loops
One layer of loop n: R5*2 = 81*2 = 162us DJNZ 2us
Second layer loop m: R6*(n+3) = 202*165 = 33330us DJNZ 2us + R5 assignment 1us = 3us
Three-layer loop: R7*(m+3) = 15*33333 = 499995us DJNZ 2us + R6 assignment 1us = 3us
Outside the loop: 5us subroutine call 2us + subroutine return 2us + R7 assignment 1us = 5us
Total delay time = three-layer loop + outside loop = 499995+5 = 500000us = 500ms
Calculation formula: Delay time = [(2*R5+3)*R6+3]*R7+5
2. 200ms delay subroutine
program:
void delay200ms(void)
{
unsigned char i,j,k;
for(i=5;i>0;i--)
for(j=132;j>0;j--)
for(k=150;k>0;k--);
}
3. 10ms delay subroutine
program:
void delay10ms(void)
{
unsigned char i,j,k;
for(i=5;i>0;i--)
for(j=4;j>0;j--)
for(k=248;k>0;k--);
}
4. 1s delay subroutine
program:
void delay1s(void)
{
unsigned char h,i,j,k;
for(h=5;h>0;h--)
for(i=4;i>0;i--)
for(j=116;j>0;j--)
for(k=214;k>0;k--);
}
Previous article:MSP430 Tutorial 14: MSP430 MCU ADC12 Module
Next article:Common methods for hardware anti-interference of single-chip microcomputer system
Recommended ReadingLatest update time:2024-11-15 15:54
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- TE's latest trend report | "How does temperature monitoring affect the generator market"
- 【NXP Rapid IoT Review】+7. Understand what each icon means
- The challenges of power tools brought about changes, and the three-phase brushless DC motor was born.
- 【bk7231N】Tuya product line learning
- EEWORLD University Hall ---- Deep Learning Theory (National Taiwan University Li Hongyi, Chinese)
- Serial port related software
- Simple DC voltage doubling circuit
- MicroPython makes some objects const
- Today I suddenly thought that volunteers are needed all over the country. Can you develop some volunteer robots?
- Monthly fixed dry goods, ADI March Chinese information