Systick实验中,Systick用来定时。来看看程序中什么地方出现过Systick相关的语句。
main.c:
/* SysTick end of count event each 1ms with input clock equal to 9MHz (HCLK/8, default) */
SysTick_SetReload(9000);
/* Enable SysTick interrupt */
SysTick_ITConfig(ENABLE);
/*******************************************************************************
* Function Name : Delay
* Description : Inserts a delay time.
* Input : nTime: specifies the delay time length, in milliseconds.
* Output : None
* Return : None
*******************************************************************************/
void Delay(u32 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);
}
/*******************************************************************************
* Function Name : TimingDelay_Decrement
* Description : Decrements the TimingDelay variable.
* Input : None
* Output : TimingDelay
* Return : None
*******************************************************************************/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
stm32f10x_it.c:
void SysTickHandler(void)
{
TimingDelay_Decrement();
}
Systick的应用:
初始化时:
首先我们要确定Systick的时钟源,再确定重装载值,如果用中断方式,
这里可以打开Systick中断始能。
定时运行时:
使能Systick时钟,判断systick定时到0,到0以后,失能Systick时钟,再清0重载寄存器。