【发布时间】:2011-06-28 05:15:49
【问题描述】:
我正在寻求有关 16 位设备上的嵌入式应用程序的帮助。 我需要通过函数指针运行几个简单的“任务/函数”。这些任务以预定的时间间隔运行。
typedef struct
{
int timeToRun;
void (*fcn)(void);
} task_t;
task_t tasks[] =
{
{ 13_MSEC, fcn1 },
{ 50_MSEC, fcn2 },
{ 0, NULL }
};
volatile unsigned int time;
main()
{
for (ptr = tasks; ptr->timeToRun !=0; ptr++)
{
if (!(time % ptr->timeToRun))
(ptr->fcn)();
}
}
我有可能在 1ms 运行定时器中断。
interrupt void TimerTick(void)
{
time++;
}
知道如何计算经过的时间吗?如果时间溢出,如何确保 %(模)以定义的速率工作。无论如何如何避免时间溢出并通过 %(模数)获得正确的时间?
【问题讨论】:
标签: timer embedded task 16-bit