⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex2.c

📁 51单片机上可以使用的操作系统
💻 C
字号:
//
// example 2: two tasks
// descriptions: This example based on example 1,
//				 two tasks do not communicate with each other and run independently. 
// author: Taiyun Wang 
// date: 2003/2/22
///////////////////////////////////////////////////////////////////////////


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

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

volatile unsigned int *P_IOA_BUFFER =(unsigned int*)(0x7001);   //Port A data register
volatile unsigned int *P_IOA_DIR =(unsigned int*)(0x7002);      //Port A direction register
volatile unsigned int *P_IOA_ATTRIB = (unsigned int*)(0x7003);  //Port A attribute register

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_IOA_DIR = 0XFFFF;						//Set Port A output
	*P_IOA_ATTRIB = 0XFFFF;						//Set Port A attribute

	*P_IOB_DIR = 0XFFFF;                        //Set port B output
	*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 kenel
}
void Task1()				//task 1
{
	unsigned int i = 1;
	while(1) {
		*P_IOB_BUFFER = i;
		i<<=1;
		if(i == 0x0100)
			i = 1;
		SpSTimeDly(30);							//Delay 30 tick
	}
}
void Task2()				//task 2
{
	
	unsigned int i=0;
	while(1) {
		*P_IOA_BUFFER = i;
		i<<=1;
		if(i == 0)
			i = 1;
		SpSTimeDly(5);							//Delay 5 tick
	}
}

⌨️ 快捷键说明

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