"); //-->
test.c
/* ********************************************************************************************************* * uC/OS-II * The Real-Time Kernel * * (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL * All Rights Reserved * * EXAMPLE #1 ********************************************************************************************************* */ #include "includes.h" /* ********************************************************************************************************* * CONSTANTS ********************************************************************************************************* */ #define TASK_STK_SIZE 512 /* Size of each task's stacks (# of WORDs) */ OS_STK MyTaskStk[TASK_STK_SIZE]; OS_STK YouTaskStk[TASK_STK_SIZE]; INT16S key; INT8U x=0,y=0; INT8U times=0; void MyTask(void *data); void YouTask(void *data); void main (void) { char* s_M="M"; OSInit(); /* Initialize uC/OS-II */ PC_DOSSaveReturn(); /* Save environment to return to DOS */ PC_VectSet(uCOS, OSCtxSw); /* Install uC/OS-II's context switch vector */ OSTaskCreate(MyTask, s_M, &MyTaskStk[TASK_STK_SIZE - 1], 0); OSStart(); /* Start multitasking */ } /* ********************************************************************************************************* * STARTUP TASK ********************************************************************************************************* */ void MyTask(void *pdata) { char* s_Y="Y"; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif pdata = pdata; /* Prevent compiler warning */ OS_ENTER_CRITICAL(); PC_VectSet(0x08, OSTickISR); /* Install uC/OS-II's clock tick ISR */ PC_SetTickRate(OS_TICKS_PER_SEC); /* Reprogram tick rate */ OS_EXIT_CRITICAL(); OSStatInit(); /* Initialize uC/OS-II's statistics */ OSTaskCreate(&YouTask, s_Y, &YouTaskStk[TASK_STK_SIZE - 1], 2); for (;;) { if(x>50) { x=0; y+=2; } times+=1; if(times==10) { OSSchedLock(); } if(times==80) { OSSchedUnlock(); } PC_DispChar( x,y, *(char*)pdata, DISP_BGND_BLACK+DISP_FGND_WHITE ); x+=1; if (PC_GetKey(&key) == TRUE) { /* See if key has been pressed */ if (key == 0x1B) { /* Yes, see if it's the ESCAPE key */ PC_DOSReturn(); /* Return to DOS */ } } OSTimeDlyHMSM(0, 0, 3, 0); /* Wait one second */ } } void YouTask(void *pdata) { #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif pdata = pdata; /* Prevent compiler warning */ for (;;) { if(x>50) { x=0; y+=2; } PC_DispChar( x,y, *(char*)pdata, DISP_BGND_BLACK+DISP_FGND_WHITE ); x+=1; OSTimeDlyHMSM(0, 0, 1, 0); /* Wait one second */ } }
运行
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。