"); //-->
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; 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"; //char* s="MyTask:我要求YouTask自己删除自己!"; char* s="MyTask:I Request YouTask Self Delete Self!"; #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>30) { while(OSTaskDelReq(2)!=OS_TASK_NOT_EXIST) { PC_DispStr( 10,8, s, DISP_BGND_BLUE+DISP_FGND_YELLOW ); OSTimeDly(1); } } if(x>50) { x=0; y+=2; } 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) { //char *s1="YouTask:我必须要删除我自己了!"; //char *s2="YouTask:我已经删除我自己了!"; char *s1="YouTask:I Must Delete Myself!"; char *s2="YouTask:I Have Delete Myself!"; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif pdata = pdata; /* Prevent compiler warning */ for (;;) { if(OSTaskDelReq(OS_PRIO_SELF)==OS_TASK_DEL_REQ) { PC_DispStr( 10,10, s1, DISP_BGND_BLACK+DISP_FGND_WHITE ); OSTimeDlyHMSM(0, 0, 15, 0); PC_DispStr( 10,12, s2, DISP_BGND_BLACK+DISP_FGND_WHITE ); OSTaskDel(OS_PRIO_SELF); } 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 */ } }
运行
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。