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

📄 list.c

📁 一个流量控制仪器的源码
💻 C
字号:
/************************************************************************************/
/* G7000 V3 列表管理											*/
/* MCU 型号: Philips P89C668														*/
/* 时钟频率: 11.0592 MHz	6 CLOCK														    */
/* 开发环境: Keil C51 V7.06a															*/
/* 开发日期: 2004.02.25													        	*/
/* 程序编写: BaoFang  鲍方															*/
/* 系统版本: V3.00																	*/
/************************************************************************************/
#include <REG668.H>
#include <G7000.H>
#include <Stdio.H>
#include <List.H>

#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long



xdata StateListStruct List_Work;	//1.工作列表
xdata StateListStruct List_Wait;	//2.等待列表
xdata StateListStruct List_Return;	//3.还原列表
xdata StateListStruct List_Nouse;	//4.备用列表
xdata StateListStruct List_Init;	//5.准备列表

xdata StateListStruct *StateList[7] = {
	&List_Work,			//State_X0
	&List_Wait,			//State_X1
	&List_Return,			//State_X2
	&List_Nouse,			//State_X3
	&List_Return,			//State_X4
	NULL,				//State_X5
	&List_Init			//State_XX
};

/*
************************************************************************************************************************
**函数原型:  void List_Init(uchar NodeState);
**参数说明:  初始化清空当前列表。
**返回值:
**
**参数说明:     uchar NodeState		加入的节点状态

************************************************************************************************************************
*/
void ListInit(uchar NodeState)
{
	uchar tempi;
	//队列初始化
	StateList[NodeState]->ucListFirstP = 0;
	StateList[NodeState]->ucListLastP = 0;
	
	StateList[NodeState]->ucListN = 0;
	
	//未使用位置填充0xFF,使得查找数据简单化。
	for(tempi=0;tempi<List_ZMAX;tempi++)
		StateList[NodeState]->List[tempi] = 0xFF;
}
				
				
				
/*
************************************************************************************************************************
**函数原型:  uchar List_AddNode(uchar NodeState,uchar NodeAddress);
**参数说明:  加入一个节点。(判断是否重复)
**返回值:		
**           	返回0xFF表示重复,或者队列满!
		返回NodeAddress表示成功。
**
**参数说明:     uchar NodeState		加入的节点状态
		uchar NodeAddress	加入的节点地址
************************************************************************************************************************
*/
uchar ListAddNode(uchar NodeState,uchar NodeAddress)
{
	uchar tempi;
	
	//查找队列中是否已经有次节点
	for(tempi=0;tempi<List_ZMAX;tempi++)
		if(StateList[NodeState]->List[tempi] == NodeAddress)
			return(0xFF);
	
	tempi = StateList[NodeState]->ucListLastP;		

	tempi = (tempi + 1) % List_ZMAX;
	
	//判断队列满?
	if(tempi == StateList[NodeState]->ucListFirstP)
		return(0xFF);
		
	//节点加入尾部
	StateList[NodeState]->List[tempi] = NodeAddress;
	
	StateList[NodeState]->ucListLastP = tempi;
	
	//队列数+1
	StateList[NodeState]->ucListN++;
	
	return(NodeAddress);
	
}

/*
************************************************************************************************************************
**函数原型:  uchar ListGetFirstNode(uchar NodeState);
**参数说明:  取出一个节点。(最先进入的节点)
**返回值:		
**           	返回0xFF表示失败。
		返回NodeAddress表示成功。
**
**参数说明:     uchar NodeState		加入的节点状态
************************************************************************************************************************
*/
uchar ListGetFirstNode(uchar NodeState)
{
	uchar tempi,tempj;
	
	tempi = StateList[NodeState]->ucListFirstP;
	
	//判断队列是否空
	if(StateList[NodeState]->ucListLastP == tempi)
		return(0xFF);
	
	//节点从头部取出
	tempi = (tempi + 1) % List_ZMAX;
	
	tempj = StateList[NodeState]->List[tempi];
	
	StateList[NodeState]->ucListFirstP = tempi;
	
	StateList[NodeState]->List[tempi] = 0xFF;
	
	//队列数-1
	StateList[NodeState]->ucListN--;
	
	return(tempj);
	
}


/*
************************************************************************************************************************
**函数原型:  uchar ListGetTheNode(uchar NodeState,uchar NodeAddress);
**参数说明:  取出特定节点。(指定的节点)
**返回值:		
**           	返回0xFF表示失败。
		返回NodeAddress表示成功。
**
**参数说明:     uchar NodeState		加入的节点状态
		uchar NodeAddress	取出的节点地址
************************************************************************************************************************
*/
uchar ListGetTheNode(uchar NodeState,uchar NodeAddress)
{
	uchar tempi,tempj,tempii,tempjj;
	
	tempi = StateList[NodeState]->ucListFirstP;
	tempj = StateList[NodeState]->ucListLastP;
	
	//判断队列是否空
	if( tempj == tempi)
		return(0xFF);
		
	//寻找节点位置
	//查找队列中是否已经有次节点
	//从队列头tempi查起直到队尾tempj
	while(tempi != tempj)
	{
		tempii = tempi;	//保存这个头指针
		
		//临时对头前进+1
		tempi = (tempi + 1) % List_ZMAX;
		
		//默认无相同的两个节点在队列中。
		if(StateList[NodeState]->List[tempi] == NodeAddress)
		{
			//发现相同的话,就开始转移数据。删除指定节点地址
			while(tempi!=tempj)
			{
				tempjj = (tempi + 1) % List_ZMAX;
				
				StateList[NodeState]->List[tempi] = StateList[NodeState]->List[tempjj];
				
				tempii = tempi;	//保存这个头指针
				
				tempi = tempjj; 
			}
			
			//把尾指针退回一个位置。
			StateList[NodeState]->List[tempi] = 0xFF;
			
			StateList[NodeState]->ucListLastP = tempii;
	
			//队列数-1
			StateList[NodeState]->ucListN--;
				
			return(NodeAddress);
		}
		
	}
	
	return(0xFF);
	
}

⌨️ 快捷键说明

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