简单灯控实验
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "ILI93xx.h"
- #include "usart.h"
- #include "24cxx.h"
- #include "flash.h"
- #include "touch.h"
- #include "timer.h"
- #include "malloc.h"
- #include "GUI.h"
- #include "ff.h"
- #include "MMC_SD.h"
- #include "fontupd.h"
- #include "exfuns.h"
- #include "includes.h"
- #include "Button_USE.h"
- #include "WM.h"
- #include "DIALOG.h"
- //任务优先级
- #define START_TASK_PRIO 3
- //任务堆栈大小
- #define START_STK_SIZE 128
- //任务控制块
- OS_TCB StartTaskTCB;
- //任务堆栈
- CPU_STK START_TASK_STK[START_STK_SIZE];
- //任务函数
- void start_task(void *p_arg);
- //TOUCH任务
- //设置任务优先级
- #define TOUCH_TASK_PRIO 4
- //任务堆栈大小
- #define TOUCH_STK_SIZE 128
- //任务控制块
- OS_TCB TouchTaskTCB;
- //任务堆栈
- CPU_STK TOUCH_TASK_STK[TOUCH_STK_SIZE];
- //touch任务
- void touch_task(void *p_arg);
- //LED0任务
- //设置任务优先级
- #define LED0_TASK_PRIO 5
- //任务堆栈大小
- #define LED0_STK_SIZE 128
- //任务控制块
- OS_TCB Led0TaskTCB;
- //任务堆栈
- CPU_STK LED0_TASK_STK[LED0_STK_SIZE];
- //led0任务
- void led0_task(void *p_arg);
- //EMWINDEMO任务
- //设置任务优先级
- #define EMWINDEMO_TASK_PRIO 6
- //任务堆栈大小
- #define EMWINDEMO_STK_SIZE 512
- //任务控制块
- OS_TCB EmwindemoTaskTCB;
- //任务堆栈
- CPU_STK EMWINDEMO_TASK_STK[EMWINDEMO_STK_SIZE];
- //emwindemo_task任务
- void emwindemo_task(void *p_arg);
- int main(void)
- {
- OS_ERR err;
- CPU_SR_ALLOC();
-
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- LED_Init(); //LED端口初始化
- TFTLCD_Init(); //LCD初始化
- KEY_Init(); //按键初始化
- mem_init(); //初始化内部内存池
- TP_Init(); //触摸屏初始化
-
- OSInit(&err); //初始化UCOSIII
- OS_CRITICAL_ENTER(); //进入临界区
- //创建开始任务
- OSTaskCreate((OS_TCB * )&StartTaskTCB, //任务控制块
- (CPU_CHAR * )"start task", //任务名字
- (OS_TASK_PTR )start_task, //任务函数
- (void * )0, //传递给任务函数的参数
- (OS_PRIO )START_TASK_PRIO, //任务优先级
- (CPU_STK * )&START_TASK_STK[0], //任务堆栈基地址
- (CPU_STK_SIZE)START_STK_SIZE/10, //任务堆栈深度限位
- (CPU_STK_SIZE)START_STK_SIZE, //任务堆栈大小
- (OS_MSG_QTY )0, //任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息
- (OS_TICK )0, //当使能时间片轮转时的时间片长度,为0时为默认长度,
- (void * )0, //用户补充的存储区
- (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项
- (OS_ERR * )&err); //存放该函数错误时的返回值
- OS_CRITICAL_EXIT(); //退出临界区
- OSStart(&err); //开启UCOSIII
- while(1);
- }
- //开始任务函数
- void start_task(void *p_arg)
- {
- OS_ERR err;
- CPU_SR_ALLOC();
- p_arg = p_arg;
- CPU_Init();
- #if OS_CFG_STAT_TASK_EN > 0u
- OSStatTaskCPUUsageInit(&err); //统计任务
- #endif
-
- #ifdef CPU_CFG_INT_DIS_MEAS_EN //如果使能了测量中断关闭时间
- CPU_IntDisMeasMaxCurReset();
- #endif
- #if OS_CFG_SCHED_ROUND_ROBIN_EN //当使用时间片轮转的时候
- //使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms
- OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
- #endif
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);//开启CRC时钟
- GUI_Init(); //STemWin初始化
-
- OS_CRITICAL_ENTER(); //进入临界区
- //STemWin Demo任务
- OSTaskCreate((OS_TCB* )&EmwindemoTaskTCB,
- (CPU_CHAR* )"Emwindemo task",
- (OS_TASK_PTR )emwindemo_task,
- (void* )0,
- (OS_PRIO )EMWINDEMO_TASK_PRIO,
- (CPU_STK* )&EMWINDEMO_TASK_STK[0],
- (CPU_STK_SIZE)EMWINDEMO_STK_SIZE/10,
- (CPU_STK_SIZE)EMWINDEMO_STK_SIZE,
- (OS_MSG_QTY )0,
- (OS_TICK )0,
- (void* )0,
- (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
- (OS_ERR* )&err);
- //触摸屏任务
- OSTaskCreate((OS_TCB* )&TouchTaskTCB,
- (CPU_CHAR* )"Touch task",
- (OS_TASK_PTR )touch_task,
- (void* )0,
- (OS_PRIO )TOUCH_TASK_PRIO,
- (CPU_STK* )&TOUCH_TASK_STK[0],
- (CPU_STK_SIZE)TOUCH_STK_SIZE/10,
- (CPU_STK_SIZE)TOUCH_STK_SIZE,
- (OS_MSG_QTY )0,
- (OS_TICK )0,
- (void* )0,
- (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
- (OS_ERR* )&err);
- //LED0任务
- OSTaskCreate((OS_TCB* )&Led0TaskTCB,
- (CPU_CHAR* )"Led0 task",
- (OS_TASK_PTR )led0_task,
- (void* )0,
- (OS_PRIO )LED0_TASK_PRIO,
- (CPU_STK* )&LED0_TASK_STK[0],
- (CPU_STK_SIZE)LED0_STK_SIZE/10,
- (CPU_STK_SIZE)LED0_STK_SIZE,
- (OS_MSG_QTY )0,
- (OS_TICK )0,
- (void* )0,
- (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
- (OS_ERR* )&err);
- OS_TaskSuspend((OS_TCB*)&StartTaskTCB,&err); //挂起开始任务
- OS_CRITICAL_EXIT(); //退出临界区
- }
- //EMWINDEMO任务
- void emwindemo_task(void *pdata)
- {
- GUI_CURSOR_Show();
- //更换皮肤
- BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);
- CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX);
- DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX);
- FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);
- HEADER_SetDefaultSkin(HEADER_SKIN_FLEX);
- MENU_SetDefaultSkin(MENU_SKIN_FLEX);
- MULTIPAGE_SetDefaultSkin(MULTIPAGE_SKIN_FLEX);
- PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
- RADIO_SetDefaultSkin(RADIO_SKIN_FLEX);
- SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
- SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX);
- SPINBOX_SetDefaultSkin(SPINBOX_SKIN_FLEX);
- while(1)
- {
- Main_task();
- }
- }
- //TOUCH任务
- void touch_task(void *p_arg)
- {
- OS_ERR err;
- while(1)
- {
- GUI_TOUCH_Exec();
- OSTimeDlyHMSM(0,0,0,5,OS_OPT_TIME_PERIODIC,&err);//延时5ms
- }
- }
- //LED0任务
- void led0_task(void *p_arg)
- {
- OS_ERR err;
- while(1)
- {
- LED0 = !LED0;
- OSTimeDlyHMSM(0,0,0,500,OS_OPT_TIME_PERIODIC,&err);//延时500ms
- }
- }
复制代码
所有资料51hei提供下载:
EMWIN灯控实验.7z
(1.71 MB, 下载次数: 21)
|