求解这个程序的延时原理
其中nowtime是实时更新的,Time是一个结构体,其成员有Timebackup(初始时间)Delay(延时时间)Init(初始化标志 在此没有用)。问通过Times如何能够实现延时Delay的时间
void TimeS(TIMER_STRUCT *Time)
{
if(!Time->Init)//起始时间初始化
{
Time->Init = TRUE;
Time->TimeBackup = u16S;
Time->Delay = 0;
}
else
{
DelayAdd(u16S,Time);
}
}
static void DelayAdd(u16 NowTime,TIMER_STRUCT *Time)
{
if(NowTime > (Time->TimeBackup))
{
u16 Temp = NowTime - Time->TimeBackup;
if((0xffff - Time->Delay) >= Temp)
{
Time->Delay += Temp;
}
}
Time->TimeBackup = NowTime;
}