📄 test__.c
字号:
/*
*************************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* ATmega128 Sample code
*
* File : APP.C
* By : Jean J. Labrosse
*************************************************************************************************************
*/
#include <mega8.h>
#include "ucos_ii.h"
#include "lio.h"
//#include "lcd.h"
//#include "key.h"
//#include "menu.h"
//#include "pic_db.h"
/*
**************************************************************************************************************
* CONSTANTS
*
* Note(s) : 1) See OS_CFG.H for the default stack size: 'OS_TASK_STK_SIZE'
**************************************************************************************************************
*/
#define CPU_CLK_FREQ 7372800L
#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
/*
**************************************************************************************************************
* 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_STK AppTask4Stk[OS_TASK_1_STK_SIZE];
INT8U disp_buf[9];
//OS_EVENT *KeyMbox;
//OS_EVENT *KeyEscSem;
OS_EVENT *LedSem;
typedef struct time_struct
{
unsigned char Date;
unsigned char Hour;
unsigned char Minute;
unsigned char Second;
}TIMER;
TIMER Timer;
/*
**************************************************************************************************************
* FUNCTION PROTOTYPES
**************************************************************************************************************
*/
void main(void);
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);
static void MenuProcTask(void *p_arg);
void menu_select(unsigned char key);
/*
**************************************************************************************************************
* 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 */
OSInit();
LedSem = OSSemCreate(0); /* Initialize "uC/OS-II, The Real-Time Kernel" */
//KeyMbox = OSMboxCreate((void *)1);
/*---- 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)
{
INT8U temp;
INT8U number;
p_arg = p_arg; /* Prevent compiler warnings */
/* Initialize the ticker */
AppIOInit(); /* Initialize the I/Os */
OSTickISR_Init();
//OSMutexCreate(1,&temp);
AppTaskCreate();
while (TRUE)
{ /* Task body, always written as an infinite loop. */
number++;
temp = (Timer.Date^Timer.Hour^Timer.Minute^Timer.Second)^number;
PORTD^=temp;
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_2_STK_SIZE; /* Setup the default stack size */
// OSTaskHardStkSize = OS_TASK_2_HARD_STK_SIZE; /* Setup the default hardware stack size */
OSTaskCreate(SecondTask, (void *)0, (OS_STK *)&AppTask2Stk[OSTaskStkSize - 1], 2);
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_2_STK_SIZE; /* Setup the default stack size */
// OSTaskHardStkSize = OS_TASK_2_HARD_STK_SIZE; /* Setup the default hardware stack size */
// OSTaskCreate(MenuProcTask, (void *)0, (OS_STK *)&AppTask4Stk[OSTaskStkSize - 1], 3);
}
/*
*********************************************************************************************************
* 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();
}
//秒定时中断
//INT8U t1s=0;
bit flash_bit=0;
static void SecondTask(void *lcndata)
{
//OS_MUTEX_DATA mutex_data;
OS_CPU_SR cpu_sr;
INT8U err;
lcndata=lcndata;
Timer.Hour = 0;
Timer.Minute = 0;
Timer.Second = 0;
while(1)
{
if(++Timer.Second == 60)
{
Timer.Second = 0;
if(++Timer.Minute == 60)
{
Timer.Minute = 0;
if(++Timer.Hour == 24)
{
Timer.Hour = 0;
Timer.Date++;
}
}
}
if(flash_bit == 0)
{
OS_ENTER_CRITICAL();
HEXtoDEC(2,Timer.Date,0);
HEXtoDEC(2,Timer.Hour,2);
HEXtoDEC(2,Timer.Minute,4);
HEXtoDEC(2,Timer.Second,6);
OSSemPost(LedSem);
OS_EXIT_CRITICAL();
}
OSTimeDly(OS_TICKS_PER_SEC);
}
}
static void LedFlashTask(void *p_arg)
{
OS_CPU_SR cpu_sr;
INT8U err;
p_arg = p_arg;
while(1)
{
OSSemPend(LedSem,0, &err);
OS_ENTER_CRITICAL();
LED_display(disp_buf,0);
OS_EXIT_CRITICAL();
}
}
/*
*********************************************************************************************
* 按键扫描
* Ver : 1.00
* Date : 2003.03
* By : Danli
* Date : 2003.04
***********************************************************************************************
*/
/********************************************************************************************/
// 按键扫描
//Function:用于中断
// (1)First:
// ADMUX = ADC_KEY_CHANNEL;
// (2)
// key_scan()
//注意:
// 必须配合特殊的扫描方式
// 1,2,3....16 main adc + key adc start + key adc end & get
/********************************************************************************************/
unsigned char KEY_value;
unsigned int key_timer;
bit F_KEY_OK;
bit F_KEY_1REL;
bit F_KEY_1IN;
void KEY_SCAN (unsigned int key_adc_value)
{
if (key_adc_value > 100)
{
//需要求高低温和容差!!!
if ( (100 < key_adc_value) && ( key_adc_value < 200) )
KEY_value = 0x01;
else if ( ( 200 < key_adc_value) && ( key_adc_value < 300))
KEY_value = 0x02;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -