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

📄 ex6.c

📁 51单片机上可以使用的操作系统
💻 C
字号:
//
// example 6: Mail box
// descriptions: First task displays the value of byte in binary way,
//               the second task sends the value to the first task in runing time .
// author: Taiyun Wang 
// date: 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
HEvent mailbox;					//Event handle

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();
	*P_IOB_DIR = 0XFFFF;							//Set Port B is output
	*P_IOB_ATTRIB = 0XFFFF;							//Set Port B arribute
	err = SpSTaskCreate(Task1,0,t1stack+24,1);		//Create first task
	err = SpSTaskCreate(Task2,0,t2stack+24,2);		//Create second task
	mailbox = SpSMboxCreate((void*)0);				//Create mailbox
	SpSStart();										//Start OS kernel
}

void Task1() 			                       
{
	int msg = 0;
	SpSMboxPost(mailbox,&msg);
	while(1) {
		SpSTimeDly(128);							//Delay 128 tick 
		msg = (msg+1)%256;
		SpSMboxPost(mailbox,&msg);					//Send a mail to task 2
	}
}
void Task2()
{
	int msg;
	int * pmsg;
	int err;
	while(1) {
		pmsg = SpSMboxPend(mailbox,0,&err);			//Waiting mail
		msg = *pmsg;								//Copy mail to local variable 
		*P_IOB_BUFFER = msg;							//Write mail value to prot B
	}
}

⌨️ 快捷键说明

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