📄 app.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1998-2005, Micrium, Weston, FL
* All Rights Reserved
*
*
* Microchip Application Code
*
* File : APP.C
* By : Eric Shufo
*********************************************************************************************************
*/
#include "includes.h"
/*
*********************************************************************************************************
* HARD CONFIG
*********************************************************************************************************
*/
#define DEBUGPIC24H
//#define RELEASEPIC24H
_FOSCSEL( FNOSC_PRIPLL & IESO_ON & TEMP_OFF );
// Primary (XT, HS, EC) Oscillator with PLL
// Two-speed Oscillator Startup is enabled
// Temperature Protection Disabled
_FOSC(FCKSM_CSECME & OSCIOFNC_OFF & POSCMD_XT);
// Clock Switching and Fail Safe Clock Monitor is enabled
// OSC2 Pin Function: OSC2 is Clock Output
// Primary Oscillator Mode: XT Crystanl
#ifdef DEBUGPIC24H
_FWDT(FWDTEN_OFF & WINDIS_OFF & WDTPRE_PR32 & WDTPOST_PS512 );
// Watchdog Timer disabled
// Windowed WDT is disabled
// WDT的时钟源LPRC产生32kHz(标称值),5位模式为1 ms
// WDT复位时间1ms*512=512ms
// (LPRC(低功耗RC) can be disabled by clearing SWDTEN bit in RCON register
_FGS(GCP_OFF); // Disable Code Protection
#endif
#ifdef RELEASEPIC24H
_FWDT(FWDTEN_ON & WINDIS_OFF & WDTPRE_PR32 & WDTPOST_PS512 );
// Watchdog Timer Enabled
// Windowed WDT is disabled
// WDT的时钟源LPRC产生32kHz(标称值),5位模式为1 ms
// WDT复位时间1ms*512=512ms
// (LPRC(低功耗RC) can be disabled by clearing SWDTEN bit in RCON register
_FGS(GSS_HIGH); // Enable Code Protection
#endif
_FPOR(FPWRT_PWR1); // Turn off the power-up timers.
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppStartTaskStk[APP_TASK_START_STK_SIZE];
OS_STK LCDDISPLAYTaskStk[LCDDISPLAY_TASK_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppStartTask(void *p_arg);
static void LCDDISPLAYTask(void *p_arg);
#if OS_VIEW_MODULE > 0
static void AppTerminalRx(INT8U rx_data);
#endif
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary 68HC12 and C initialization.
* Arguments : none
*********************************************************************************************************
*/
INT16S main (void)
{
INT8U err;
BSP_IntDisAll(); /* Disable all interrupts until we are ready to accept them */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreateExt(AppStartTask,
(void *)0,
(OS_STK *)&AppStartTaskStk[0],
APP_TASK_START_PRIO,
APP_TASK_START_PRIO,
(OS_STK *)&AppStartTaskStk[APP_TASK_START_STK_SIZE-1],
APP_TASK_START_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreateExt(LCDDISPLAYTask,
(void *)0,
(OS_STK *)&LCDDISPLAYTaskStk[0],
LCDDISPLAY_TASK_PRIO,
LCDDISPLAY_TASK_PRIO,
(OS_STK *)&LCDDISPLAYTaskStk[LCDDISPLAY_TASK_STK_SIZE-1],
LCDDISPLAY_TASK_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if OS_TASK_NAME_SIZE > 11
OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
return (-1); /* Return an error - This line of code is unreachable */
}
/*$PAGE*/
/*
*********************************************************************************************************
* 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.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppStartTask (void *p_arg)
{
INT8U i;
INT8U j;
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
#if OS_TASK_STAT_EN > 0
OSStatInit(); /* Determine CPU capacity */
#endif
#if OS_VIEW_MODULE > 0
OSView_Init(38400);
OSView_TerminalRxSetCallback(AppTerminalRx);
OSView_RxIntEn(); /* Enable Rx Interrupts */
#endif
LED_Off(0); /* Turn OFF all the LEDs */
while (TRUE) { /* Task body, always written as an infinite loop. */
for (i = 0; i < 4; i++) { /* Sweep right then left 4 times */
for (j = 1; j <= 8; j++) { /* Scroll the LEDs to the right */
LED_On(j);
OSTimeDlyHMSM(0, 0, 0, 25); /* Delay 25ms */
LED_Off(j);
}
for (j = 7; j >= 2; j--) { /* Scroll the LEDs to the left */
LED_On(j);
OSTimeDlyHMSM(0, 0, 0, 25);
LED_Off(j);
}
}
for (i = 0; i < 4; i++) { /* Blink all 8 LEDs 4 times */
LED_On(0);
OSTimeDlyHMSM(0, 0, 0, 25);
LED_Off(0);
OSTimeDlyHMSM(0, 0, 0, 25);
}
}
}
static void LCDDISPLAYTask(void *p_arg)
{
INT8U i;
while(TRUE)
{
i++;
i++;
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (INT8U rx_data)
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -