目录
一、执行不同任务原理
- 栈不同
- 创建任务时可以传入不同的参数
二、代码实现
1、定义结构体
struct oled_info{
int x;
int y;
int flag;
int num;
};
2、给结构体赋值
struct oled_info oled_info1 = {0,0,1,0};
struct oled_info oled_info2 = {0,3,2,10};
struct oled_info oled_info3 = {0,6,3,20};
3、函数实现
void oled_print(void *param)
{
int flag = 1;
char str[16];
struct oled_info *info = param;
for( ;; )
{
if(flag)
{
flag = 0;
info->num ++;
sprintf(str,"task%d:%d",info->flag,info->num);
OLED_ShowString(info->x,info->y,(unsigned char *)str,16);
flag = 1;
}
HAL_Delay(500);
}
}
4、创建任务传参
xTaskCreate(oled_print,"oledprint_task1",128,&oled_info1,osPriorityNormal,NULL);
xTaskCreate(oled_print,"oledprint_task2",128,&oled_info2,osPriorityNormal,NULL);
xTaskCreate(oled_print,"oledprint_task3",128,&oled_info3,osPriorityNormal,NULL);