1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| #include "includes.h" #define TASK_STK_SIZE 512 char *s1="你的学号"; char *s2="你的姓名";
OS_STK StartTaskStk[TASK_STK_SIZE]; OS_STK MyTaskStk[TASK_STK_SIZE]; OS_STK YouTaskStk[TASK_STK_SIZE]; INT16S key;
INT8U err; INT8U y=0;
OS_EVENT *a; INT8U count = 0;
void Fun(INT8U x,INT8U y); void StartTask(void *data); void MyTask(void *data); void YouTask(void *data);
void main (void) { OSInit( ); PC_DOSSaveReturn( ); PC_VectSet(uCOS, OSCtxSw); a = OSSemCreate(0); OSTaskCreate(StartTask, (void*)0, &StartTaskStk[TASK_STK_SIZE - 1], 0); OSStart( ); }
void StartTask (void *pdata) { #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; #endif pdata = pdata; OS_ENTER_CRITICAL( ); PC_VectSet(0x08, OSTickISR); PC_SetTickRate(OS_TICKS_PER_SEC); OS_EXIT_CRITICAL( );
OSStatInit( ); OSTaskCreate(MyTask, (void*)0, &MyTaskStk[TASK_STK_SIZE - 1], 1); OSTaskCreate(YouTask, (void*)0, &YouTaskStk[TASK_STK_SIZE - 1], 2);
for (;;) { if (PC_GetKey(&key) == TRUE) { if (key == 0x1B) { PC_DOSReturn(); } } OSTimeDlyHMSM(0, 0, 3, 0); } }
void MyTask (void *pdata) { #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; #endif pdata = pdata; for (;;) { OSSemPend(a,0,&err); PC_DispStr(0,++y, s1, DISP_BGND_BLACK+DISP_FGND_WHITE ); Fun(12,y); OSTimeDlyHMSM(0, 0, 1, 0); } }
void YouTask (void *pdata) { #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; #endif pdata = pdata; for (;;) { PC_DispStr(0,++y, s2, DISP_BGND_BLACK+DISP_FGND_YELLOW ); OSTimeDlyHMSM(0, 0, 1, 0); ++count; if(count == 6) { OSSemPost(a); count = 0; } } } void Fun(INT8U x,INT8U y) { PC_DispStr(x,y,"invoked Fun()!", DISP_BGND_BLACK+DISP_FGND_BLUE ); }
|