新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32學(xué)習(xí)筆記—SysTick定時器

STM32學(xué)習(xí)筆記—SysTick定時器

作者: 時間:2013-01-24 來源:網(wǎng)絡(luò) 收藏

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ù)器原理

上一頁 1 2 下一頁

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉