📄 app.c
字号:
/*******************************************************************************
*************************** * Copyright : COPYRIGHT(C) 1997-2005
* Project Name : UCOS2纯系统
* File name :
* Crystal : 16MHZ
* PCB P/N :
* Comments :
* SoftWareP/N :
* ----------< History >---------------------------------------------------------
* File Version : 1.0
* Author : jjx
* E-Mail :
* Date : 2008 10 08
* Comments :
*******************************************************************************/
#include "includes.h"
#include "Publics.H"
//在os_cfg.h中作修改
#define OS_TASK_START_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_START_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
OS_STK AppTaskStartStk[OS_TASK_START_STK_SIZE];
/*
**************************************************************************************************************
* FUNCTION PROTOTYPES
**************************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppTaskCreate(void);
static void AppIOInit(void);
void watchdog_init(void);
void BeeIO(void)
{
PORTB&=~(1<<PB5);
//PORTB|=1<<PB5;
DDRB|=1<<PB5;
}
void timer1_init(void) //接15脚,OC1A,为定时器T/C1
{
TCCR1B=0x00; //关闭
//TCCR3B = 0x00; //stop
OCR1AH = 0x00; //16位的比较PWM高位
//OCR3AH = 0x00;
//OCR3AL = 0xe6; //2 k
//OCR3AL = 0x99; //3 k
//OCR3AL = 0x73; //4 k
//OCR3AL = 0x5c; //5 k
//OCR3AL = 0x4c; //6 k
//OCR1AL = 0x41;
//OCR1AL = 0x89;
OCR1AL = 0xe6;
//OCR1AL = 0x73; //7 k形 //16位的比较PWM低位
//OCR3AL = 0x39; //8 k
//OCR3AL = 0x33; //9 k
//OCR3AL = 0x2e; //10 k
TCCR1A=0x40; //CTC模式
}
/*
**************************************************************************************************************
* 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)
{
INT8U it =0;
INT8U ko=0;
INT8U temp; // 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
AppIOInit();
BeeIO();
timer1_init();
OSInit(); // Initialize "uC/OS-II, The Real-Time Kernel"
watchdog_init();
//---- Any initialization code before starting multitasking --------------//
// View_Pic(aVfdDispRAM1,DisplayBuff1,1);
AppTaskCreate();
AppTaskStart(&temp);
//---- Create any other task you want before we start multitasking -------//
WDR();
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)
{
p_arg = p_arg; // Prevent compiler warnings
OSTickISR_Init(); // Initialize the ticker
}
/*
*********************************************************************************************************
* 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)
{
Init_AppTask1(); //任务1初始化
Init_AppTask2(); //任务2初始化
Init_AppTask6(); //任务6初始化
Init_AppTask8(); //任务8初始化
}
//----------------------------------------------------------------------------//
//SETUP THE TICK RATE //中断在os_cpu_a.s上做定义并与ucos系统相结合
//----------------------------------------------------------------------------//
void OSTickISR_Init (void)
{
TCNT0 =0;
TCCR0 = 0x07; // Set TIMER0 prescaler to CLK/1024
TIMSK = 0x01; // Enable TIMER0 overflow interrupt
}
//----------------------------------------------------------------------------//
// SETUP THE TICK RATE
//----------------------------------------------------------------------------//
void OSTickISR_Handler (void)
{
TCNT0 = 0x64; //100HZ
OSTimeTick();
}
//----------------------------------------------------------------------------//
//函数介绍: 看门狗初始化 (prescale: 2048K cycles = 2s)
//输入参数:--
// 输出参数:--
//返 回 值:--
//----------------------------------------------------------------------------//
void watchdog_init(void)
{
WDR();
WDTCR = (1<<WDCE)|(1<<WDE);
WDTCR = (1<<WDE)|(1<<WDP2)|(1<<WDP1)|(1<<WDP0);
}
//----------------------------------------------------------------------------//
// SETUP I/Os
//----------------------------------------------------------------------------//
static void AppIOInit (void) /*IO全部初始化为高阻态*/
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x00;
DDRG = 0x00;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -