|
我感觉咱们的论坛,用UCOS的不是很多,难道大家不喜欢用么??我的程序发信号不好用,不知道为什么?我把发信号的OSSemPost(LedSem); //发信号注释掉,可是接收信号的那个任务还是能执行,按道理我没发信号,那个任务就不应该执行.用感性区的共同讨论一下.
下面是主程序.
/*
*************************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* ATmega128 Sample code
*
* File : APP.C
* By : Jean J. Labrosse
*************************************************************************************************************
*/
#include <mega64.h>
#include "ucos_ii.h"
#include "lio.h"
#include <lcd240128.h>
/*
**************************************************************************************************************
* CONSTANTS
*
* Note(s) : 1) See OS_CFG.H for the default stack size: 'OS_TASK_STK_SIZE'
**************************************************************************************************************
*/
#define CPU_CLK_FREQ 8000000L
#define OS_TASK_START_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_START_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
#define OS_TASK_1_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_1_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
#define OS_TASK_2_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_2_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
#define OS_TASK_3_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_3_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
/*
**************************************************************************************************************
* VARIABLES
**************************************************************************************************************
*/
OS_STK AppTaskStartStk[OS_TASK_START_STK_SIZE];
OS_STK AppTask1Stk[OS_TASK_1_STK_SIZE];
OS_STK AppTask2Stk[OS_TASK_1_STK_SIZE];
OS_STK AppTask3Stk[OS_TASK_1_STK_SIZE+64];
OS_EVENT *LedSem;
typedef struct time_struct
{
unsigned char Date;
unsigned char Hour;
unsigned char Minute;
unsigned char Second;
}TIMER;
TIMER Timer;
/*
**************************************************************************************************************
* FUNCTION PROTOTYPES
**************************************************************************************************************
*/
static void AppTaskStart(void *p_arg);
static void AppTaskCreate(void);
static void AppIOInit(void);
static void KeyScanTask(void *p_arg);
static void SecondTask(void *p_arg);
static void LedFlashTask(void *p_arg);
/*
**************************************************************************************************************
* MAIN
*
* Note(s): 1) You SHOULD use OS_TASK_STK_SIZE (see OS_CFG.H) when setting OSTaskStkSize prior to calling
* OSInit() because OS_TASK_IDLE_STK_SIZE and OS_TASK_STAT_STK_SIZE are set to this value in
* OS_CFG.H.
**************************************************************************************************************
*/
void main (void)
{
/*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
/* IMPORTANT: MUST be setup before calling 'OSInit()' */
OSTaskStkSize = OS_TASK_STK_SIZE; /* Setup the default stack size */
OSTaskHardStkSize = OS_TASK_HARD_STK_SIZE; /* Setup the default hardware stack size */
cls(); //清屏
cls1(); //清屏
fnLCMInit();
Linexy(0,0,239,0); //画线
Linexy(0,17,239,17);
Linexy(0,110,239,110);
Linexy(0,127,239,127);
OSInit();
LedSem = OSSemCreate(0); //创建信号量 /* Initialize "uC/OS-II, The Real-Time Kernel" */
/*---- Any initialization code before starting multitasking ---------------------------------------*/
OSTaskStkSize = OS_TASK_START_STK_SIZE; /* Setup the total stack size */
OSTaskHardStkSize = OS_TASK_START_HARD_STK_SIZE; /* Setup the hardware stack size */
OSTaskCreate(AppTaskStart, (void *)0, (OS_STK *)&AppTaskStartStk[OSTaskStkSize - 1], 0);
/*---- Create any other task you want before we start multitasking --------------------------------*/
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
int i=0;
INT8U temp;
INT8U number;
p_arg = p_arg; /* Prevent compiler warnings */
/* Initialize the ticker */
AppIOInit(); /* Initialize the I/Os */
OSTickISR_Init();
eprintf(90,3,0,"AVR单片机"); //显示
for(i=0;i<20;i++)
{
delay_ms(20);
}
AppTaskCreate();
while (1)
{ /* Task body, always written as an infinite loop. */
number++;
temp = (Timer.Date^Timer.Hour^Timer.Minute^Timer.Second)^number;
OSTimeDly(OS_TICKS_PER_SEC/10);
}
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*
* Description : This function creates the application tasks.
*
* Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OSTaskStkSize = OS_TASK_1_STK_SIZE; /* Setup the default stack size */
OSTaskHardStkSize = OS_TASK_1_HARD_STK_SIZE; /* Setup the default hardware stack size */
OSTaskCreate(LedFlashTask, (void *)0, (OS_STK *)&AppTask1Stk[OSTaskStkSize - 1], 4);
OSTaskStkSize = OS_TASK_1_STK_SIZE+64; /* Setup the default stack size */
OSTaskHardStkSize = OS_TASK_1_HARD_STK_SIZE; /* Setup the default hardware stack size */
OSTaskCreate(KeyScanTask, (void *)0, (OS_STK *)&AppTask3Stk[OSTaskStkSize - 1], 3);
OSTaskStkSize = OS_TASK_1_STK_SIZE;
OSTaskHardStkSize = OS_TASK_1_HARD_STK_SIZE;
OSTaskCreate(SecondTask, (void *)0, (OS_STK *)&AppTask2Stk[OSTaskStkSize - 1], 2);
}
/*
*********************************************************************************************************
* SETUP THE I/Os
*********************************************************************************************************
*/
static void AppIOInit (void)
{
Hardware_init();
Software_init();
}
/*
*********************************************************************************************************
* SETUP THE TICK RATE
*********************************************************************************************************
*/
void OSTickISR_Init (void)
{
TCCR0 = 0x05; /* Set TIMER0 prescaler to CLK/1024 */
TIMSK = 0x01; /* Enable TIMER0 overflow interrupt */
}
/*
*********************************************************************************************************
* SETUP THE TICK RATE
*********************************************************************************************************
*/
void OSTickISR_Handler (void)
{
TCNT0 = 256 - (CPU_CLK_FREQ / OS_TICKS_PER_SEC / 1024);
OSTimeTick(); //检查延时状态的任务是否达到延时时间
}
static void SecondTask(void *lcndata) //任务
{
OS_CPU_SR cpu_sr;
INT8U err;
lcndata=lcndata;
while(1)
{
//OSSemPost(LedSem); //发信号
PORTE.3=1;
eprintf(0+20,3,0,"AVR单片机");//显示
eprintf(0+52,3,0," ");
eprintf(0+70,3,0," ");
OSTimeDly(255);
}
}
static void LedFlashTask(void *p_arg)//;任务2
{
while(1)
{
eprintf(0+52,3,0,"AVR单片机");
eprintf(0+20,3,0," ");
eprintf(0+70,3,0," ");
OSTimeDly(60);
}
}
static void KeyScanTask(void *p_arg) //任务3
{
OS_CPU_SR cpu_sr;
INT8U err;
p_arg = p_arg;
while(1)
{
OSSemPend(LedSem,0, &err); //等待信号
PORTE.4=1;
eprintf(0+52,3,0," ");
eprintf(0+20,3,0," ");
eprintf(0+70,3,0,"123");
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|