《怎么从STM32F10xxx固件库V2.0.3晋级为STM32F10xxx规范外设库V3.0.0》一文中的“3.3.2 SysTick”讲到:
/*初始化时钟*/
void Init_SysTick(void)
{
/* Disable SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Disable the SysTick Interrupt */
SysTick_ITConfig(DISABLE);
/* Configure HCLK clock as SysTick clock source */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
/* SysTick interrupt each 1000 Hz with HCLK equal to 72MHz */
SysTick_SetReload(9000);
/* Enable the SysTick Interrupt */
SysTick_ITConfig(ENABLE);
}
/*延时1ms函数*/
__IO uint32_t TimingDelay;
void delay_ms(__IO uint32_t nTime)
{
/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0);
/* Disable SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Clear SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Clear);
}
/*stm32f10x_it.c中的void SysTick_Handler(void)函数改为*/
extern __IO uint32_t TimingDelay;
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay–;
}
}
/*用法,延时1秒*/
delay_ms(1000);
/*初始化时钟*/
void Init_SysTick(void)
{
if(SysTick_Config(SystemCoreClock / 1000)) //留意:3.5库中SystemFrequency 被SystemCoreClock 替代。
while(1);
}
/*延时1ms函数*/
__IO uint32_t TimingDelay;
void delay_ms(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/*stm32f10x_it.c中的void SysTick_Handler(void)函数改为*/
extern __IO uint32_t TimingDelay;
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay–;
}
}
/*用法,延时1秒*/
delay_ms(1000);