STM32F407 uCOS-III工程

## uCOS_III_STM32F407

STM32F407ZGT6 uCOS-III LED TFTLCD UART KEY TOUCH

uCOS-III STM32F407ZGT6移植

工程所创建任务:

1、LED1 500ms闪烁一次
2、LED2 5000ms闪烁一次
3、USART1 100ms发送一次数据
4、LCD显示:检测四个按键,按下后显示上下左右;检测触摸按键,按下后文字提示;显示3任务中的数值累加记录

以上!

 

工程文件百度网盘地址:

链接:https://pan.baidu.com/s/1cFU4Ld9s7XQ6navILSs3Sg 
提取码:q4cf 

 

app_cfg.h

 

/*
*********************************************************************************************************
*                                            TASK PRIORITIES
*********************************************************************************************************
*/

#define  APP_CFG_TASK_START_PRIO                           2u
#define	APP_CFG_TASK_LED1_PRIO	3u
#define APP_CFG_TASK_LED2_PRIO	3u
#define APP_CFG_TASK_CALC_PRIO	4u
#define APP_CFG_TASK_LCD_PRIO	4u

/*
*********************************************************************************************************
*                                            TASK STACK SIZES
*********************************************************************************************************
*/

#define  APP_CFG_TASK_START_STK_SIZE                     128u
#define APP_CFG_TASK_LED1_STK_SIZE	512u
#define APP_CFG_TASK_LED2_STK_SIZE	512u
#define APP_CFG_TASK_CALC_STK_SIZE	512u
#define APP_CFG_TASK_LCD_STK_SIZE	512u

 

 

app.c

 

#include  <includes.h>

static  OS_TCB   AppTaskStartTCB;
static  CPU_STK  AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
static	OS_TCB	AppTaskLed1TCB;
static	CPU_STK	AppTaskLed1Stk[APP_CFG_TASK_LED1_STK_SIZE];
static	OS_TCB	AppTaskLed2TCB;
static	CPU_STK	AppTaskLed2Stk[APP_CFG_TASK_LED2_STK_SIZE];
static	OS_TCB	AppTaskCalcTCB;
static	CPU_STK	AppTaskCalcStk[APP_CFG_TASK_CALC_STK_SIZE];
static	OS_TCB	AppTaskLcdTCB;
static	CPU_STK	AppTaskLcdStk[APP_CFG_TASK_LCD_STK_SIZE];

static  void  AppTaskStart          (void     *p_arg); 
static  void  AppTaskLed1          (void     *p_arg);
static  void  AppTaskLed2          (void     *p_arg);
static  void  AppTaskCalc          (void     *p_arg);
static  void  AppTaskLcd          (void     *p_arg);

void LcdClear();
u16 testNumber = 0;

int main(void)
{
	
    OS_ERR  err;
	
		//初始化
		SysTick_Init(168);	
		HSI_SetSysClock(16, 432, 2, 9); //216M
		USART1_Init(9600);	//9600波特率
	
		LED_Init();
		TFTLCD_Init();			
		FSMC_SRAM_Init();
		KEY_Init();
		Touch_Key_Init(4);

    OSInit(&err);                                               /* Init uC/OS-III.                                      */

    OSTaskCreate((OS_TCB       *)&AppTaskStartTCB,              /* Create the start task                                */
                 (CPU_CHAR     *)"App Task Start",
                 (OS_TASK_PTR   )AppTaskStart,
                 (void         *)0u,
                 (OS_PRIO       )APP_CFG_TASK_START_PRIO,
                 (CPU_STK      *)&AppTaskStartStk[0u],
                 (CPU_STK_SIZE  )APP_CFG_TASK_START_STK_SIZE / 10u,
                 (CPU_STK_SIZE  )APP_CFG_TASK_START_STK_SIZE,
                 (OS_MSG_QTY    )2u,
                 (OS_TICK       )0u,
                 (void         *)0u,
                 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR       *)&err);

    OSStart(&err);                                              /* Start multitasking (i.e. give control to uC/OS-III). */

    return (0u);
}

static  void  AppTaskStart (void *p_arg)
{
    OS_ERR  err;                                                                         

		printf("%d:", BSP_CPU_ClkFreq());

		CPU_INT32U  cpu_clk_freq;
    CPU_INT32U  cnts;
	 
		(void)p_arg;

		/* Initialize BSP functions   */
    BSP_Init();   
    CPU_Init();
		
		/* Determine SysTick reference freq. */
    cpu_clk_freq = BSP_CPU_ClkFreq();  

		/* Determine nbr SysTick increments  */
    cnts = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz; 

	 /* Init uC/OS periodic time src (SysTick). */
    OS_CPU_SysTickInit(cnts);                                  

	 /* Initialize Memory Management Module  */
    Mem_Init();                                                

#if OS_CFG_STAT_TASK_EN > 0u
		 /* Compute CPU capacity with no task running */
    OSStatTaskCPUUsageInit(&err);                              
#endif

//    CPU_IntDisMeasMaxCurReset();

		OSTaskCreate((OS_TCB       *)&AppTaskLed1TCB,              /* Create the start task                                */
						 (CPU_CHAR     *)"App Task Led1",
						 (OS_TASK_PTR   )AppTaskLed1,
						 (void         *)0u,
						 (OS_PRIO       )APP_CFG_TASK_LED1_PRIO,
						 (CPU_STK      *)&AppTaskLed1Stk[0u],
						 (CPU_STK_SIZE  )APP_CFG_TASK_LED1_STK_SIZE / 10u,
						 (CPU_STK_SIZE  )APP_CFG_TASK_LED1_STK_SIZE,
						 (OS_MSG_QTY    )5u,
						 (OS_TICK       )0u,
						 (void         *)0u,
						 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
						 (OS_ERR       *)&err);
						 
		OSTaskCreate((OS_TCB       *)&AppTaskLed2TCB,              /* Create the start task                                */
						 (CPU_CHAR     *)"App Task Led2",
						 (OS_TASK_PTR   )AppTaskLed2,
						 (void         *)0u,
						 (OS_PRIO       )APP_CFG_TASK_LED2_PRIO,
						 (CPU_STK      *)&AppTaskLed2Stk[0u],
						 (CPU_STK_SIZE  )APP_CFG_TASK_LED2_STK_SIZE / 10u,
						 (CPU_STK_SIZE  )APP_CFG_TASK_LED2_STK_SIZE,
						 (OS_MSG_QTY    )5u,
						 (OS_TICK       )0u,
						 (void         *)0u,
						 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
						 (OS_ERR       *)&err);
						 
		OSTaskCreate((OS_TCB       *)&AppTaskCalcTCB,              /* Create the start task                                */
						 (CPU_CHAR     *)"App Task Calc",
						 (OS_TASK_PTR   )AppTaskCalc,
						 (void         *)0u,
						 (OS_PRIO       )APP_CFG_TASK_CALC_PRIO,
						 (CPU_STK      *)&AppTaskCalcStk[0u],
						 (CPU_STK_SIZE  )APP_CFG_TASK_CALC_STK_SIZE / 10u,
						 (CPU_STK_SIZE  )APP_CFG_TASK_CALC_STK_SIZE,
						 (OS_MSG_QTY    )10u,
						 (OS_TICK       )0u,
						 (void         *)0u,
						 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
						 (OS_ERR       *)&err);
						 
		OSTaskCreate((OS_TCB       *)&AppTaskLcdTCB,              /* Create the start task                                */
						 (CPU_CHAR     *)"App Task Lcd",
						 (OS_TASK_PTR   )AppTaskLcd,
						 (void         *)0u,
						 (OS_PRIO       )APP_CFG_TASK_LCD_PRIO,
						 (CPU_STK      *)&AppTaskLcdStk[0u],
						 (CPU_STK_SIZE  )APP_CFG_TASK_LCD_STK_SIZE / 10u,
						 (CPU_STK_SIZE  )APP_CFG_TASK_LCD_STK_SIZE,
						 (OS_MSG_QTY    )10u,
						 (OS_TICK       )0u,
						 (void         *)0u,
						 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
						 (OS_ERR       *)&err);
    	 
		OSTaskDel(&AppTaskStartTCB, &err);

}

static void AppTaskLed1(void *p_arg )
{
	OS_ERR  err;
	(void)p_arg;
	while (DEF_TRUE)
	{
		led1 = !led1;
		OSTimeDly ( 500, OS_OPT_TIME_DLY, & err );
	}
}

static void AppTaskLed2(void *p_arg )
{
	OS_ERR  err;
	(void)p_arg;
	while (DEF_TRUE)
	{
		led2 = !led2;
		OSTimeDly ( 5000, OS_OPT_TIME_DLY, & err );
	}
}

static void AppTaskCalc(void *p_arg )
{
	OS_ERR  err;
	(void)p_arg;
	while (DEF_TRUE)
	{
		for(int i=0;i<1000;i+=10)
		{
			printf("calc: %f\n", (i / 1000.0f));
			testNumber = i;
			OSTimeDly ( 100, OS_OPT_TIME_DLY, & err );
		}
		
		LcdClear();
		testNumber = 0;
	}
}

static void AppTaskLcd(void *p_arg )
{
	OS_ERR  err;
	(void)p_arg;
	u8 num_len = 0;
	
	FRONT_COLOR=BLUE;
	LCD_Clear(WHITE);
	LCD_Set_Window(0, 0, tftlcd_data.width, tftlcd_data.height);
	LCD_ShowString(64,164,tftlcd_data.width,tftlcd_data.height,12,"https://www.wiyixiao4.com/blog");
	
	while (DEF_TRUE)
	{
		//检测按键
		u8 key = KEY_Scan(0);
		
		if(key > 0)
		{
			LcdClear();
		}
		
		switch(key)
		{
			case KEY_UP:
				LCD_ShowString(64,96,tftlcd_data.width,tftlcd_data.height,16,"UP");
				break;
			case KEY_DOWN:
				LCD_ShowString(64,96,tftlcd_data.width,tftlcd_data.height,16,"DOWN");
				break;
			case KEY_LEFT:
				LCD_ShowString(64,96,tftlcd_data.width,tftlcd_data.height,16,"LEFT");
				break;
			case KEY_RIGHT:
				LCD_ShowString(64,96,tftlcd_data.width,tftlcd_data.height,16,"RIGHT");
				break;
		}
		
		//检测触摸
		if(Touch_Key_Scan(0) == 1)
		{
			LcdClear();
			LCD_ShowString(64,128,tftlcd_data.width,tftlcd_data.height,16,"TOUCH");
		}
		
		//显示串口数据
		if(testNumber < 10)
			num_len = 1;
		else if(testNumber >= 10 && testNumber < 100)
			num_len = 2;
		else 
			num_len = 3;
		LCD_ShowNum(164,96,testNumber,num_len,16);
	}
}

void LcdClear()
{
	LCD_Clear(WHITE);
	LCD_ShowString(64,164,tftlcd_data.width,tftlcd_data.height,12,"https://www.wiyixiao4.com/blog");
}











上一篇:【leetcode】316. 去除重复字母


下一篇:C# MVC 页面静态化导致的问题