📄 main.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2003, Micrium, Inc, Weston, FL
* All Rights Reserved
*
* EDK-38024
* H8/300L
*
* Filename : main.c
* Programmer : Jean J. Labrosse
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define APP_TASK1_STK_SIZE 50 /* Size of application task #1 stack (# of WORDs) */
#define APP_TASK2_STK_SIZE 25 /* Size of application task #2 stack (# of WORDs) */
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppTask1Stk[APP_TASK1_STK_SIZE];
OS_STK AppTask2Stk[APP_TASK2_STK_SIZE];
INT8U AppDispSel;
INT16U AppTask1Ctr;
INT16U AppTask2Ctr;
/*
*********************************************************************************************************
* PROTOTYPES
*********************************************************************************************************
*/
void AppTask1(void *p_arg); /* Function prototypes of application task */
void AppTask2(void *p_arg); /* Function prototypes of application task */
void AppDispData(void);
void LED_Init(void); /* LED services */
void LED_On(INT8U led);
void LED_Off(INT8U led);
void LED_Toggle(INT8U led);
void Tmr_Init(void); /* Timer services */
void Tmr_ISRClr(void);
/*
*********************************************************************************************************
* main()
*********************************************************************************************************
*/
void main (void)
{
LCD_DispInit(); /* Initialize the LCD */
/* Initialize the LEDs */
OSInit(); /* Initialize uC/OS-II */
OSTaskCreate(AppTask1, /* Create an application task */
(void *)0,
&AppTask1Stk[APP_TASK1_STK_SIZE - 1],
0);
OSStart();
/* Start multitasking */
}
/*
*********************************************************************************************************
* APPLICATION TASK #1
*********************************************************************************************************
*/
void AppTask1 (void *parg)
{
INT16U i;
parg = parg; /* Prevent compiler warning */
Tmr_Init(); /* Initialize the tick interrupts */
#if OS_TASK_STAT_EN > 0
OSStatInit(); /* Initialize uC/OS-II's statistics */
#endif
OSTaskCreate(AppTask2, /* Create a second application task */
(void *)0,
&AppTask2Stk[APP_TASK2_STK_SIZE - 1],
1);
AppDispSel = 0;
AppTask1Ctr = 0;
for (;;) {
//LED_Toggle(2); /* Toggle LED USR2 */
AppDispData(); /* Display data */
OSTimeDly(OS_TICKS_PER_SEC); /* Wait 1 second */
AppTask1Ctr = (AppTask1Ctr + 1) % 10000; /* Increment the task counter */
}
}
/*
*********************************************************************************************************
* APPLICATION TASK #2
*
* Note(s): You can place YOUR task code in this task since this task doesn't do much. In fact, you can
* change how often the task is executed by changing the number of ticks inside the OSTimeDly()
* function.
*
* If you have the full version of uC/OS-II, you can have this task wait for events (semaphore,
* message queue, event flags, etc.).
*********************************************************************************************************
*/
void AppTask2 (void *parg)
{
INT8U buffer[2] = {0x0d, 0x0a};
parg = parg; /* Prevent compiler warning */
AppTask2Ctr = 0;
SerialCommInit();
/* $$$$ YOUR INITIALIZATION CODE GOES HERE $$$$ */
for (;;) {
OSTimeDly(1);
AppTask2Ctr = (AppTask2Ctr + 1) % 10000; /* Increment the task counter */
/* $$$$ YOUR CODE GOES HERE $$$$
//add serial port Init*/
CommDataSend(&buffer[0], 2);
}
}
/*
*********************************************************************************************************
* DISPLAY DATA VALUES ON LCD
*********************************************************************************************************
*/
void AppDispData (void)
{
switch (AppDispSel) { /* Determine what to display on the LCD */
case 0: /* Display "uC.OS" */
LCD_DispStr(1, "uCOS");
LCD_DispIconSet(2);
break;
case 1: /* Display uC/OS-II's version number XX.YY */
LCD_DispINT16U((INT16U)OS_VERSION);
LCD_DispIconSet(2);
break;
case 2: /* CPU Usage (%) */
LCD_DispStr(1, "CPU=");
break;
case 3:
LCD_DispINT16U((INT16U)OSCPUUsage);
break;
case 4: /* Task Counter */
LCD_DispStr(1, "Ctr1");
break;
case 5:
LCD_DispINT16U((INT16U)AppTask1Ctr);
break;
case 6: /* Task Counter */
LCD_DispStr(1, "Ctr2");
break;
case 7:
LCD_DispINT16U((INT16U)AppTask2Ctr);
break;
}
AppDispSel = (AppDispSel + 1) % 8; /* Select next item to display */
}
/*
*********************************************************************************************************
* TIMER SERVICES
* (Assumes Timer A)
*********************************************************************************************************
*/
void Tmr_Init (void)
{
P_TMRA.TMA.BYTE = 0x04; /* Set timer A to generate 75 Hz interrupts */
P_IENR1.BIT.IENTA = 1; /* Enable Timer A interrupts */
}
void Tmr_ISRClr (void)
{
P_IRR1.BIT.IRRTA = 0; /* Clear the timer interrupt */
}
/*
*********************************************************************************************************
* LED CONTROL SERVICES
*********************************************************************************************************
*/
void LED_Init (void)
{
P_IO.PCR3 |= 0x06; /* Enable USR1 and USR2 LEDs */
}
void LED_On (INT8U led)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
switch (led) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -