/**
* 开发环境:Microsoft Visual Studio 2016 专业版
* 开发作者:Jack Ming
* 联系方式:1097****4388
* 文档说明:回调函数使用例子
*/
#include "windows.h"
#include "stdio.h"
/**
* 模块消息传递
*/
struct message
{
void * pbuff;
int size;
};
/**
* 定义回调函数
*/
typedef void(*led_blink)(struct message * p_message);
/**
* LED模块
*/
void LED_Blink(struct message * p_message)
{
int key_info[3];
/* 获取key1按键信息 */
key_info[0] = ((int *)p_message)[0];
if (key_info[0] == 1)
{
printf("我亮了...\r\n");
}
}
/**
* key模块
*/
void key_scan(led_blink LED_Blink)
{
struct message message;
int key_info[3] = {0};
int key1 = 0, key2 = 0, key3 = 0; /* 键值 */
int down = 1, up = 0; /* 键状态 */
//key1 = GPIO_ReadBit(GPIOA,Pin1);
/* key1按下,led1闪烁 */
if (key1 == down)
{
key_info[0] = 1; /* key1被按下 */
message.pbuff = key_info;
message.size = 3;
LED_Blink(&message); /* 通知led */
}
/* key2按下,电机转动 */
}
int main(void)
{
while (1)
{
key_scan(LED_Blink);
}
system("pause");
}
回调函数的使用示例
最新推荐文章于 2022-11-09 17:05:32 发布