📄 test.c
字号:
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
pdata = pdata;
for (;;)
{
PC_DispStr( 2, 8," ", DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 39, 8," ", DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 2,14," ", DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 46,14," ", DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
for(i=1;i<5;i++) /*显示“请减速通过路口左拐”,同时闪烁50秒结束*/
{
//PC_DispStr( 2, 8," ", DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);
//PC_DispStr( 39, 8," ", DISP_FGND_RED + DISP_BGND_LIGHT_GRAY);
//PC_DispStr( 2,14," ", DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
//PC_DispStr( 46,14," ", DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 2,15,"Go through the street turn Left ", DISP_FGND_YELLOW + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 46,15,"Go through the street turn Left ", DISP_FGND_YELLOW + DISP_BGND_LIGHT_GRAY);
OSTimeDlyHMSM(0,0,0,500);
PC_DispStr( 2,15," ", DISP_FGND_YELLOW + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 46,15," ", DISP_FGND_YELLOW + DISP_BGND_LIGHT_GRAY);
OSTimeDlyHMSM(0,0,0,500);
PC_DispStr( 2,15,"Go through the street turn Left ", DISP_FGND_YELLOW + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 46,15,"Go through the street turn Left ", DISP_FGND_YELLOW + DISP_BGND_LIGHT_GRAY);
}
OSTimeDlyHMSM(0,0,1,0);
OSTaskResume(12); /*唤醒Task1 */
OSTaskSuspend(OS_PRIO_SELF);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #5
*
* Description: 东西向安装一检测器,在东西向通行1分钟后,检测南、北向等候汔车数分别在第6行2、36列位置
* 以橙色显示“向南行等候汔车数为X位”、 “向北行等候汔车数为Y”。
*
*********************************************************************************************************
*/
void Task5 (void *pdata)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
char t[10];
pdata = pdata;
for (;;)
{
if(c)
{
srand((unsigned)time(NULL));
p = random(100);
m=rand()%p;
//OSSemPend(RandomSem, 0, &err); /* Acquire semaphore to perform random numbers */
//if(err == OS_NO_ERR)
//{
//m = random(1000); /* make a random number in the range 0 to 1000 */
//n = random(1000); /* make a random number in the range 0 to 1000 */
sprintf(South_wait,"%s %2d %s","There are",m,"cars ------> South");
PC_DispStr( 2, 14,South_wait, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
srand((unsigned)time(NULL));
n=rand()%p;
sprintf(North_wait,"%s %2d %s","There are",n,"cars ------> North");
PC_DispStr( 46, 14,North_wait, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
if(x+y > 0 && x+y < 200){
sprintf(t, "%5d", ((x+y) - (m+n))/(m+n)); /* Display #id */
PC_DispStr( 2, 19,t, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
sprintf(t, "%5d", ((m+n) - (x+y))/(x+y)); /* Display #id */
PC_DispStr( 2, 20,t, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
p1 = (((x+y) - (m+n))/(m+n));
if (p1 > 0){
id = 15;}
p2 = (((m+n) - (x+y))/(x+y));
if (p2 > 0){
id = 5;}
/*if (((x+y) - (m+n))/(m+n) >1){
id = 15;}
else if (((m+n) - (x+y))/(x+y) >1){
id = 5;}*/
if (p1 <1 && p2 <1){
id = 10;}
}
//OSSemPost(RandomSem); /* Release semaphore */
//}
c=FALSE;
}
else
{
//OSSemPend(RandomSem, 0, &err); /* Acquire semaphore to perform random numbers */
//if(err == OS_NO_ERR)
//{
//m = random(1000); /* make a random number in the range 0 to 1000 */
//n = random(1000); /* make a random number in the range 0 to 1000 */
srand((unsigned)time(NULL));
p = random(100);
x=rand()%p;
sprintf(West_wait,"%s %2d %s","There are",x,"cars ------> West");
PC_DispStr( 2, 7,West_wait, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
srand((unsigned)time(NULL));
y=rand()%p;
sprintf(East_wait,"%s %2d %s","There are",y,"cars ------> East");
PC_DispStr( 46, 7,East_wait, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
//OSSemPost(RandomSem); /* Release semaphore */
//}
sprintf(t, "%5d", ((m+n) - (x+y))/(x+y)); /* Display #id */
PC_DispStr( 46, 19,t, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
sprintf(t, "%5d", ((x+y) - (m+n))/(m+n)); /* Display #id */
PC_DispStr( 46, 20,t, DISP_FGND_BLUE + DISP_BGND_LIGHT_GRAY);
p1 = (((m+n) - (x+y))/(x+y));
if (p1 >0){
//if (((m+n) - (x+y))/(x+y) >1){
id = 15;}//}
//else if (((x+y) - (m+n))/(m+n) >1){
//id = 5;}
//else{
// id = 10;}
p2 = (((x+y) - (m+n))/(m+n));
if (p2 >0){
id = 5;}
if (p1 <1 && p2 <1){
id = 10;}
c=TRUE;
}
OSTimeDly(500); /* Delay 500 clock tick */
OSTaskSuspend(OS_PRIO_SELF);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #6
*
* Description:
*
*********************************************************************************************************
*/
void Task6 (void *pdata)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
pdata = pdata;
for (;;)
{
ss=OSMboxPend(Str_Box,10,&err);
if(err==OS_NO_ERR)
{
if(d)
{
PC_DispStr( 2, 7,ss, DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 46, 7,ss, DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
d=FALSE;
}
else
{
PC_DispStr( 2, 14,ss, DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
PC_DispStr( 46, 14,ss, DISP_FGND_GREEN + DISP_BGND_LIGHT_GRAY);
d=TRUE;
}
}
OSTimeDlyHMSM(0,0,1,0); /* Wait one second */
//OSTaskSuspend(OS_PRIO_SELF);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* UPDATE THE DISPLAY
*********************************************************************************************************
*/
static void TaskStartDisp (void)
{
char s[80];
#if OS_TASK_STAT_EN > 0
sprintf(s, "%5d", OSTaskCtr); /* Display #tasks running */
PC_DispStr(18, 22, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
sprintf(s, "%3d", OSCPUUsage); /* Display CPU usage in % */
PC_DispStr(36, 22, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
sprintf(s, "%5d", OSCtxSwCtr); /* Display #context switches per second */
PC_DispStr(18, 23, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
#endif
sprintf(s, "V%1d.%02d", OSVersion() / 100, OSVersion() % 100); /* Display uC/OS-II's version number */
PC_DispStr(75, 24, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
switch (_8087) { /* Display whether FPU present */
case 0:
PC_DispStr(71, 22, " NO FPU ", DISP_FGND_YELLOW + DISP_BGND_BLUE);
break;
case 1:
PC_DispStr(71, 22, " 8087 FPU", DISP_FGND_YELLOW + DISP_BGND_BLUE);
break;
case 2:
PC_DispStr(71, 22, "80287 FPU", DISP_FGND_YELLOW + DISP_BGND_BLUE);
break;
case 3:
PC_DispStr(71, 22, "80387 FPU", DISP_FGND_YELLOW + DISP_BGND_BLUE);
break;
}
}
/*
*********************************************************************************************************
* CLOCK TASK
*********************************************************************************************************
*/
void TaskClk (void *pdata)
{
char s[40];
pdata = pdata;
for (;;) {
PC_GetDateTime(s);
PC_DispStr(60, 23, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
OSTimeDlyHMSM(0, 0, 0, 500);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -