The first delay function:
void delay(u16 num)
{
u16 i,j;
for(i=0;i for(j=0;j<0x800;j++); } eg: delay(50); The second delay function: void Delayms(u16 ms) { u16 i,j; u8k; for(i=0;i for(j=0;j<0x0500;j++) k++; } The third delay function: static u8 fac_us=0;//us delay multiplier static u16 fac_ms=0;//ms delay multiplier //Initialize delay function //SYSTICK clock is fixed to 1/8 of the HCLK clock //SYSCLK: system clock void delay_init(u8 SYSCLK) { SysTick->CTRL&=0xfffffffb;//Clear bit2, select external clock HCLK/8 fac_us=SYSCLK/8; fac_ms=(u16)fac_us*1000; } //Delay nms //Pay attention to the range of nms //SysTick->LOAD is a 24-bit register, so the maximum delay is: //nms<=0xffffff*8*1000/SYSCLK //SYSCLK unit is Hz, nms unit is ms //Under 72M conditions, nms<=1864 void delay_ms(u16 nms) { u32 temp; SysTick->LOAD=(u32)nms*fac_ms;//Time loading (SysTick->LOAD is 24bit) SysTick->VAL =0x00; //Clear the counter SysTick->CTRL=0x01; //Start the countdown do { temp=SysTick->CTRL; } while(temp&0x01&&!(temp&(1<<16))); //Wait for time to arrive SysTick->CTRL=0x00; //Close counter SysTick->VAL =0X00; //Clear the counter } //Delay nus //nus is the number of us to be delayed. void delay_us(u32 nus) { u32 temp; SysTick->LOAD=nus*fac_us; //Time loading SysTick->VAL=0x00; //Clear the counter SysTick->CTRL=0x01; //Start the countdown do { temp=SysTick->CTRL; } while(temp&0x01&&!(temp&(1<<16))); //Wait for time to arrive SysTick->CTRL=0x00; //Close counter SysTick->VAL =0X00; //Clear the counter }
Previous article:STM32 system tick timer (systick) application
Next article:STM32 about BOOT0 and BOOT1 settings
Recommended ReadingLatest update time:2024-11-16 19:39
- Popular Resources
- Popular amplifiers
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
- [HPM6750 Review Part 2] CoreMark Verification (Comparison between external flash xip and internal sram)
- This week's review information is here~
- "Head First Design Pattern (Chinese Edition)", a must-read for programmers!
- Huawei RF Basic Knowledge Training Full Solution PDF
- TI's AXC level translator
- I would like to ask the experts to help explain the filtering principle of this picture, as well as the calculation of inductance and capacitance parameters.
- Disassembly preview, does anyone know what this is?
- 【TGF4042 Signal Generator】+ Unboxing Review
- 【Smart Sports Watch】Work Submission
- TMS320F2812 complete program to implement SVPWM