STM32學(xué)習(xí)筆記—SysTick定時器
void SysTick_Configuration(void)
{
/* Select AHB clock(HCLK) as SysTick clock source 設(shè)置AHB時鐘為SysTick時鐘*/
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
/* Set SysTick Priority to 3 設(shè)置SysTicks中斷搶占優(yōu)先級 3, 從優(yōu)先級0*/
NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 3, 0);
/* SysTick interrupt each 1ms with HCLK equal to 72MHz 每1ms發(fā)生一次SysTick中斷*/
SysTick_SetReload(72000);
/* Enable the SysTick Interrupt */
SysTick_ITConfig(ENABLE);
}
延時函數(shù),需要延時處調(diào)用:
view plaincopy to clipboardprint?
void Delay(u32 nTime)
{
/* Enable the SysTick Counter 允許SysTick計數(shù)器*/
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0)
; //等待計數(shù)至0
/* Disable the SysTick Counter 禁止SysTick計數(shù)器*/
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Clear the SysTick Counter 清零SysTick計數(shù)器*/
SysTick_CounterCmd(SysTick_Counter_Clear);
}
void Delay(u32 nTime)
{
/* Enable the SysTick Counter 允許SysTick計數(shù)器*/
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0)
; //等待計數(shù)至0
/* Disable the SysTick Counter 禁止SysTick計數(shù)器*/
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Clear the SysTick Counter 清零SysTick計數(shù)器*/
SysTick_CounterCmd(SysTick_Counter_Clear);
}
中斷函數(shù),定時器減至零時調(diào)用,放在stm32f10x_it.c文件中
view plaincopy to clipboardprint?
void SysTickHandler(void)
{
TimingDelay--;
}
塵埃粒子計數(shù)器相關(guān)文章:塵埃粒子計數(shù)器原理
評論