是不是要这样的效果
typedef struct {
int time_count;
char flag;
}timer_t;
timer_t timer1={10, false},timer2={100, false};
timer_interrupt()//将其初始化成1ms,或者其它最小时间粒度
{
if(timer1.time_count == 0){
timer1.flag = true;
timer1.time_count= 10;
} else{timer1.time_count--; }
if(timer2.time_count == 0){
timer2.flag = true;
timer2.time_count= 100;
}else{timer2.time_count--; }
}
void main(void)
{
while(1){
if(timer1.flag == true){
timer1.flag == false;
do something;
}
if(timer2.flag == true){
timer2.flag == false;
do something others;
}
}
} |