📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: Main.c
** Last modified Date: 2007-04-17
** Last Version: 1.0
** Description: The main function example template 主函数例子模版
**
**------------------------------------------------------------------------------------------------------
** Created By: maliang
** Created date: 2007-04-17
** Version: 1.0
** Descriptions: The original version 初始版本
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
********************************************************************************************************/
#include <includes.h>
/********************************************************************************************************
* CONSTANTS 常量 *
********************************************************************************************************/
/********************************************************************************************************
* VARIABLES 变量 *
********************************************************************************************************/
static OS_STK Task_StartStk[TASK_START_STK_SIZE]; // The stack of start task 启动任务的堆栈
static OS_STK Task_AStk[TASK_A_STK_SIZE];
static OS_STK Task_BStk[TASK_B_STK_SIZE];
OS_EVENT *DispSem;
/********************************************************************************************************
* FUNCTION PROTOTYPES 函数声明 *
********************************************************************************************************/
static void Task_Start (void *p_arg); // The start task 启动任务
static void Task_A (void *p_arg);
static void Task_B (void *p_arg);
static void CreateTask (void);
uint8 err;
/********************************************************************************************************
* MAIN FUNCTION 主函数 *
********************************************************************************************************/
int main (void)
{
IntDisAll(); // Disable all the interrupts 关闭所有中断
//=============================================================================//
OSInit(); // Initialize the kernel of uC/OS-II 初始化uC/OS-II的内核
OSTaskCreate ( Task_Start, // Initialize the start task 初始化启动任务
(void *)0,
&Task_StartStk[TASK_START_STK_SIZE-1],
TASK_START_PRIO );
OSStart(); // Start uC/OS-II 启动uC/OS-II
return(0) ;
}
/********************************************************************************************************
* Task_Start *
********************************************************************************************************/
static void Task_Start (void *p_arg)
{
(void)p_arg;
TargetInit(); // Initialize the target's MCU 初始化目标单片机
#if OS_TASK_STAT_EN > 0
OSStatInit(); // Enable statistics 使能统计功能
#endif
/***Create the other tasks here. 在这里创建其他任务***/
CreateTask();
while (1)
{
OSTaskSuspend(OS_PRIO_SELF); // The start task can be pended here. 启动任务可在这里挂起
}
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*********************************************************************************************************
*/
static void CreateTask (void)
{
DispSem = OSSemCreate(1);
OSTaskCreate (Task_A,(void *)0,
&Task_AStk[TASK_A_STK_SIZE-1], TASK_A_PRIO);
OSTaskCreate (Task_B,(void *)0,
&Task_BStk[TASK_B_STK_SIZE-1], TASK_B_PRIO);
}
/********************************************************************************************************
* The tasks A *
********************************************************************************************************/
static void Task_A(void *p_arg)
{
(void)p_arg;
while(1)
{
OSSemPend(DispSem, 0, &err); // 等待信号量
Led_Toggle(1);
}
}
/********************************************************************************************************
* The tasks B *
********************************************************************************************************/
static void Task_B(void *p_arg)
{
uint8 key;
(void)p_arg;
while(1)
{
key = Key_Read( );
switch(key)
{
case 0xFE: // KEY1
while(Key_Read( )==0xFE); // 等待按键释放,消除按键抖动
err = OSSemPost(DispSem); // 发送信号量
break;
default:
break;
}
Led_Toggle(3);
OSTimeDly(2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -