设计KeyTask任务,当按下KEY0时动态创建任务,最多可以创建10个任务,这10个任务都执行一个函数MyTask,要求优先级是(PRIO_BASE+0,1,2,3,4,5,6,7,8,9),还要向不同的任务传递不同的参数(0,1,2,3,4,5,6,7,8,9)给MyTask函数,优先级为 (PRIO_BASE+0,1,2,3,4,5,6,7,8,9)的任务分别输出数字(0,1,2,3,4,5,6,7,8,9)到LCD屏。当按下KEY1时动态的删除刚创建的一个任务, 最多可删除10个任务。
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "lcd.h"
- int main(void)
- {
- u8 x=0;
- u8 lcd_id[12]; //存放LCD ID字符串
- delay_init(); //延时函数初始化
- uart_init(9600); //串口初始化为9600
- LED_Init(); //初始化与LED连接的硬件接口
- LCD_Init();
- POINT_COLOR=RED;
- sprintf((char*)lcd_id,"LCD ID:%04X",lcddev.id);//将LCD ID打印到lcd_id数组。
- while(1)
- {
- switch(x)
- {
- case 0:LCD_Clear(WHITE);break;
- case 1:LCD_Clear(BLACK);break;
- case 2:LCD_Clear(BLUE);break;
- case 3:LCD_Clear(RED);break;
- case 4:LCD_Clear(MAGENTA);break;
- case 5:LCD_Clear(GREEN);break;
- case 6:LCD_Clear(CYAN);break;
- case 7:LCD_Clear(YELLOW);break;
- case 8:LCD_Clear(BRRED);break;
- case 9:LCD_Clear(GRAY);break;
- case 10:LCD_Clear(LGRAY);break;
- case 11:LCD_Clear(BROWN);break;
- }
- POINT_COLOR=RED;
- LCD_ShowString(30,40,200,24,24,"Mini STM32 ^_^");
- LCD_ShowString(30,70,200,16,16,"TFTLCD TEST");
- LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
- LCD_ShowString(30,110,200,16,16,lcd_id); //显示LCD ID
- LCD_ShowString(30,130,200,12,12,"2014/3/7");
- x++;
- if(x==12)x=0;
- LED0=!LED0;
- delay_ms(1000);
- }
- }
复制代码
|