c语言回调函数构架程序,C语言回调函数熟练---使用方法(构建程序框架方便好用)...

void KeyCallback ( uint8 keys, uint8 state ); //具体实现函数

void LEDCallback ( uint8 keys, uint8 state ); //具体实现函数

int Ligback( uint8 keys, uint8 state ); //具体实现函数

void HalKeyConfig (uint8 st, halCBack_t cback);//注意指针函数加了typedef后,这里才能当关键字声明

void ShiYong (uint8 ffff, int (*halCBack_t) (uint8 keys, uint8 state));//如果指针函数没有typedef,要这样使用

//注意指针函数加了自定义typedef后,这里才能定义,否则报错

halCBack_t pHalKeyProcessFunction=KeyCallback; //声明指针函数变量并指向一个具体函数地址

halCBack_t taskCall[]=

{

KeyCallback,

LEDCallback

}; //指针函数数组

void main()

{

HalKeyConfig( 1, KeyCallback ); //调用该函数,参数里的指针函数指针指向具体函数即可

HalKeyConfig( 2, LEDCallback );

taskCall[0](11,11);

taskCall[1](22,22);

ShiYong(33,Ligback);

(*pHalKeyProcessFunction)(44,44); //指针函数具体使用

}

void HalKeyConfig (uint8 st, halCBack_t cback)//某个函数,调用指针函数作参数

{

cback(st,st);

}

void ShiYong (uint8 fa, int (*halCBack_t) (uint8 keys, uint8 state))

{

(*halCBack_t) (fa, fa);

cout<

}

void KeyCallback ( uint8 keys, uint8 state ) //具体实现函数

{

cout<

}

void LEDCallback ( uint8 keys, uint8 state ) //具体实现函数

{

cout<

}

int Ligback( uint8 keys, uint8 state ) //具体实现函数

{

cout<

return 1;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值