owmdpmbd 发表于 2025-1-10 08:22:01

继续打卡08.定时器周期性调度任务

#include "task.h"
#include "io.h"
static TASK_COMPONENTS Task_Comps[]=
{
//状态计数周期函数
       
{0, 300,   300,   LED0_Blink},      /* task 1 Period: 300ms */
{0, 600,   600,   LED1_Blink},      /* task 1 Period: 600ms */
{0, 900,   900,   LED2_Blink},      /* task 1 Period: 600ms */
{0, 10,    10,    KEY_Task},      /* task 1 Period: 600ms */       
};

u8 Tasks_Max = sizeof(Task_Comps)/sizeof(Task_Comps);

//========================================================================
// 函数: Task_Handler_Callback
// 描述: 任务标记回调函数.
// 参数: None.
// 返回: None.
// 版本: V1.0, 2012-10-22
//========================================================================
void Task_Marks_Handler_Callback(void)
{
    u8 i;
    for(i=0; i<Tasks_Max; i++)
    {
      if(Task_Comps.TIMCount)      /* If the time is not 0 */
      {
            Task_Comps.TIMCount--;   /* Time counter decrement */
            if(Task_Comps.TIMCount == 0) /* If time arrives */
            {
                /*Resume the timer value and try again */
                Task_Comps.TIMCount = Task_Comps.TRITime;
                Task_Comps.Run = 1;      /* The task can be run */
            }
      }
    }
}

//========================================================================
// 函数: Task_Pro_Handler_Callback
// 描述: 任务处理回调函数.
// 参数: None.
// 返回: None.
// 版本: V1.0, 2012-10-22
//========================================================================
void Task_Pro_Handler_Callback(void)
{
    u8 i;
    for(i=0; i<Tasks_Max; i++)
    {
      if(Task_Comps.Run) /* If task can be run */
      {
            Task_Comps.Run = 0;      /* Flag clear 0 */
            Task_Comps.TaskHook();   /* Run task */
      }
    }
}




owmdpmbd 发表于 2025-1-11 08:56:00

继续打卡08.定时器周期性调度任务

香河英茂工作室 发表于 2025-1-30 14:01:25

这个地方我也研究了很久,之前对定时器没有了解,于是反复看,终有所得,我感到这是个分水岭。
页: [1]
查看完整版本: 继续打卡08.定时器周期性调度任务