E_Bool Ticker_Out(u32 *pTicker, u32 uCompareValue)
{
u32 uTicks = 0;
uTicks = BSP_Get_SysTick();
if(0 == uCompareValue)
{
*pTicker = uTicks;
return True;
}
else
{
if(uTicks >= (*pTicker))
{
uTicks = uTicks - (*pTicker);
}
else
{
uTicks = (U32_MAX_VALUE - (*pTicker)) + uTicks;
}
if (uTicks >= uCompareValue)
{
return True;
}
}
return False;
}
u32 BSP_Get_SysTick(void)
{
return gSystickTimes; /* 获取系统心跳 */
}
void SysTick_Handler(void)
{
gSystickTimes++; /* 系统心跳计数 */
}
int main()
{
E_Bool eState = False;
static u32 uSampleTicker = 0;
while(1)
{
eState = Ticker_Out(&uSampleTicker, 500);
if(True == eState)
{
Ticker_Out(&uSampleTicker, 0);
LED_ON();
}
}
}
|