/*******************************************************************************
* Function Name : SysTick_Config_MAX
* Description : Configure a SysTick Base time to MAX timeout.
* Input : None
* Output : None
* Return : None
* Author : www.mcuisp.com
*******************************************************************************/
void SysTick_Config_MAX(void)
{
/* Configure HCLK/8 clock as SysTick clock source */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
/* SysTick Reload By Max Value */
SysTick_SetReload(0x00ffffff);
/* Disable the SysTick Interrupt, use for free count */
SysTick_ITConfig(DISABLE);
/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);
}
//--
/*******************************************************************************
* Function Name : DelayCyclesBySysTick
* Description : delay N SysTicks.
* Input : u32 ticks,the number of ticks desired to delay
* Output : None
* Return : None
* Author : www.mcuisp.com
*******************************************************************************/
void DelayCyclesBySysTick(u32 ticks)
{
u32 ui32,ui32a,systickprescale;
if((SysTick->CTRL&SysTick_Counter_Enable)==0)return;
systickprescale=SysTick->LOAD;
if(systickprescale<250)return;
for(;ticks>=systickprescale;)
{
ticks=ticks-systickprescale-200;
ui32=SysTick_GetCounter();
for(;;)
{
ui32a=SysTick_GetCounter();
if(ui32a>ui32)
{
ui32a=ui32+systickprescale-ui32a;
}
else
{
ui32a=ui32-ui32a;
}
if(ui32a>=(systickprescale-200))break;
}
}
ui32=SysTick_GetCounter();
for(;;)
{
ui32a=SysTick_GetCounter();
if(ui32a>ui32)
{
ui32a=ui32+systickprescale-ui32a;
}
else
{
ui32a=ui32-ui32a;
}
if(ui32a>=ticks)break;
}
}
//--
说明:SysTick->Load要大一些,否则循环太快。一般作为操作系统时钟的话,为10ms级别,完全可用。我一般设成最大值0x00ffffff(不是必须的)。