找回密码
 立即注册
查看: 230|回复: 0

AI8051U实验箱第八集视频结构体和指针函数回调问题

[复制链接]
  • 打卡等级:以坛为家I
  • 打卡总天数:259
  • 最近打卡:2025-04-02 20:10:12

21

主题

80

回帖

1343

积分

金牌会员

积分
1343
发表于 2024-12-6 11:22:49 | 显示全部楼层 |阅读模式

请教下各位老师

AI8051U实验箱第八集视频结构体和指针函数回调问题

1、u8 Tasks_Max = sizeof(Task_Comps)/sizeof(Task_Comps[0]); sizeof(Task_Comps) 是多大值,sizeof(Task_Comps[0]是多大值?

2、指针函数是怎么回调的?

typedef struct { u8 Run; //任务状态:Run/Stop u16 TIMCount; //定时计数器 u16 TRITime; //重载计数器 void (*TaskHook) (void); //任务函数 } TASK_COMPONENTS;

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[0]);

void Task_Marks_Handler_Callback(void) { u8 i; for(i=0; i<Tasks_Max; i++) { if(Task_Comps[i].TIMCount) / If the time is not 0 / { Task_Comps[i].TIMCount--; / Time counter decrement / if(Task_Comps[i].TIMCount == 0) / If time arrives / { /Resume the timer value and try again / Task_Comps[i].TIMCount = Task_Comps[i].TRITime; Task_Comps[i].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[i].Run) / If task can be run / { Task_Comps[i].Run = 0; / Flag clear 0 / Task_Comps[i].TaskHook(); / Run task / } } }

回复

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-6-30 10:26 , Processed in 0.132296 second(s), 49 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表