It is a 24-bit downward-counting timer. Each count takes 1/SYSTICK. SYSTICK is the system timer clock. It can be directly obtained from the system clock or obtained by dividing the system clock by 8.
When the timer counts to 0, the initial value of the timer will be automatically reloaded from the LOAD register and count down again.
If the SysTick interrupt is enabled, an interrupt signal will be generated when the timer counts to 0.
void SysTick_Init(u8 SYSCLK)
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
fac_us=SYSCLK/8; //1us times
fac_ms=(u16)fac_us*1000; //1ms times
}
void delay_us(u32 nus)
{
u32 temp;
SysTick->LOAD=nus*fac_us; //Time initial value
SysTick->VAL=0x00; //Clear the counter
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //Turn on the timer
do
{
temp=SysTick->CTRL;
}while((temp&0x01)&&!(temp&(1<<16))); //Wait for time to arrive
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //Turn off the counter
SysTick->VAL=0x00; //Clear the counter
}
void delay_ms(u16 nms) //Maximum 1864ms
{
u32 temp;
SysTick->LOAD=(u32)nms*fac_ms;
SysTick->VAL=0x00;
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;
do
{
temp=SysTick->CTRL;
}while((temp&0x01)&&!(temp&(1<<16)));
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;
SysTick->VAL=0x00;
}
Previous article:stm32 touch screen XPT2046
Next article:STM32 lights up LED
Recommended ReadingLatest update time:2024-11-16 15:35
- 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
- 2005 National Undergraduate Electronic Design Competition Topic
- EEWORLD University----[High Precision Laboratory] Interface: HDMI
- How to Make DSP Digital Oscillator Generate Phase-Shifted Sine Wave
- WIFI 6 is coming, do you know about it?
- Discuss one of the STM32H750
- Book an appointment to win a gift: Book an appointment for the live broadcast of power integrity design of ideal power distribution network, gain knowledge and win a Keysight gift
- The first article GD32VF103C START development board unboxing running lights
- How to eliminate the influence of gravity acceleration on accelerometer
- MSP430 programmer and emulator
- MSP430 FLL - Frequency Locked Loop