ex12.c

来自「51单片机上可以使用的操作系统」· C语言 代码 · 共 50 行

C
50
字号
//
// Example 12 This program show how to suspend task ans resume task
// Author Taiyun Wnag 
// data:2003/2/22
///////////////////////////////////////////////////////////////////////////


#include "sposvar.h"
#include "spos.h"

int err;				//Error No
int t1stack[25];		//Task 1 stack
int t2stack[25];		//Task 2 stack

volatile unsigned int *P_IOB_BUFFER =(unsigned int*)(0x7006);	//Port B data register
volatile unsigned int *P_IOB_DIR =(unsigned int*)(0x7007);		//Port B direction register
volatile unsigned int *P_IOB_ATTRIB = (unsigned int*)(0x7008);	//Port B attribute register

main()
{
	void Task1();
    void Task2();
	SpSInit();									//Initialize OS kernel
   *P_IOB_DIR = 0XFFFF;							//Set Port B direction
   *P_IOB_ATTRIB = 0XFFFF;						//Set Port B attribute
	err = SpSTaskCreate(Task1,0,t1stack+24,1);	//Create first task
	err = SpSTaskCreate(Task2,0,t2stack+24,2);	//create second task
	SpSStart();									//Start multitask kernel
}
void Task1()
{
    unsigned int i = 1;
	while(1) {
		SpSTimeDly(11);							//Delay 11 tick
		SpSTaskSuspend(2);						//Suspend task 2
		SpSTimeDly(17);							//Delay 17 tick
		SpSTaskResume(2);						//Resume task 2
	}
}
void Task2()
{
	unsigned int i = 0x80;
	while(1) {
		for(i = 0x80;i != 0;i>>=1) {
            *P_IOB_BUFFER = i;
            SpSTimeDly(1);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?