uint8_t current_clock = 0;
void timer_config(void)
{
/* Systick时钟每秒触发CLOCK_SECOND次 */
if (SysTick_Config(SystemCoreClock / CLOCK_SECOND))
{
while (1);
}
}
void SysTick_Handler(void)
{
/* 时间标志累加 */
current_clock++;
}
uint16_t clock_time(void)
{
return current_clock;
}
void timer_set(timer_typedef* ptimer,uint16_t interval)
{
/* 设置时间间隔 */
ptimer->interval = interval;
/* 设置启动时间 */
ptimer->start = clock_time();
}
void timer_reset(timer_typedef * ptimer)
{
ptimer->start =ptimer->start + ptimer->interval;
}
int8_t timer_expired(timer_typedef* ptimer)
{
if((int8_t)(clock_time() - ptimer->start) >= (int8_t)ptimer->interval)
return 1;
else
return 0;
}
想问问这个函数中当ptimer->start=250,ptimer->interval=10时,current_clock为无符号会益出,但我写了程序测了下,它能返回1,高手能讲解下为什么吗?? |