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

📄 framemodule.c

📁 该程序完成了c8051外围电路的驱动和串口协议的编写。希望能给大家学习51单片机带来帮助
💻 C
📖 第 1 页 / 共 5 页
字号:
		if ((All.Para.Ch[0].uiChEnable == 0) ||(All.Para.Ch[1].uiChEnable == 0))
		{
			SetEnableStatusChannel(1,0x00);
			SetEnableStatusChannel(2,0x00);   
		}								   
		else
		{
			SetEnableStatusChannel(1,0x01);
			SetEnableStatusChannel(2,0x01);
		}
	}
	else
	{
		SetEnableStatusChannel(1,All.Para.Ch[0].uiChEnable); 
		SetEnableStatusChannel(2,All.Para.Ch[1].uiChEnable);
	}

	InitChannelParaVariable();
}

//--------------------------------------------------------------------------------------
//函数名称:void InitADPara(void)
//功    能:初始化AD参数	 
//输入参数:无
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
void InitADPara(void)
{
	unsigned char idata i;
	ADModuleSoftInitialize();
	for(i=0; i<2; i++)
	{
		SetSensorDirection(i+1, (unsigned char)All.Para.Ch[i].uiSensorDirection);
		SetZeroPosition(i+1, All.Para.Ch[i].iZeroPosition);
		SetScaleLow(i+1, UnifyUnit(All.Para.Ch[i].iScaleLow, All.Para.Ch[i].iExponentValue, All.Para.Ch[i].uiMeasureUnit));
		SetScaleHigh(i+1, UnifyUnit(All.Para.Ch[i].iScaleHigh, All.Para.Ch[i].iExponentValue, All.Para.Ch[i].uiMeasureUnit));
		SetSensorSensitive(i+1,SensitiveChange(All.Para.Ch[i].uiSensitive, All.Para.Ch[i].uiMeasureUnit, All.Para.Ch[i].uiChType));		
		SetSampleRateAD(i+1, All.Para.Ch[i].uiSampleRate);		   
		SetACADZero(i+1, All.Para.Channel[i].uiVibADZero);
		SetACADFull(i+1, All.Para.Channel[i].uiVibADFull);
		SetDCADZero(i+1, All.Para.Channel[i].uiDisADZero);
		SetDCADFull(i+1, All.Para.Channel[i].uiDisADFull);
		SetLittleRangeADZero(i+1,All.Para.Channel[i].uiLittleRangeZero);
		SetLittleRangeADFull(i+1,All.Para.Channel[i].uiLittleRangeFull);
		SetChannleType(i+1, All.Para.Ch[i].uiChType);			  
		SetMeasureType(i + 1, All.Para.Ch[i].uiMeasureType);
		SetSampleTypeHW(All.Para.Ch[0].uiChType);			  
		SetGAPADZero(i+1,All.Para.Channel[i].uiGAPADZero);
		SetGAPADFull(i+1,All.Para.Channel[i].uiGAPADFull);
		FeedDog();
//		SetDefaultCentricity(i+1);
	}
}

//--------------------------------------------------------------------------------------
//函数名称:void InitFramemoduleParameters(void)
//功    能:系统参数初始化	 
//输入参数:无
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
void InitFramemoduleParameters(void)
{		
	ReadSystemPara((unsigned char *)&All.Array, 0,PARALENGTH*2);	  //初始化参数之前读取设定的参数
	JudgeChannelPara();		  //20080528
	InitAlarmPara();
	InitChannelStatusPara();
	InitADPara();
	InitSampleType();
	InitDAPara();
	InitCalibrationPara(1);
	InitCalibrationPara(2);	
	InitADSampleModule();	 //must make this function after all the Para Init function 	
	CaculateDataScale();		  //初始化参数后就计算AD模块的计算参数,以节约时间
//	JudgeChannelScale();
	CaculateEnableStatus(1);	
	CaculateEnableStatus(2);
}

//--------------------------------------------------------------------------------------
//函数名称:void JudgeChannelPara(void)
//功    能:判断系统通道配置的参数,如果配置的参数出现致命的错误,则默认一个参数	  
//输入参数:无
//返    回:无
//---------------------------------------------------------------------------------------
void JudgeChannelPara(void)
{
	unsigned char xdata i;

	for (i=0; i<2; i++)
	{
		if(((All.Para.Ch[i].uiChType > 12) && (All.Para.Ch[i].uiChType < 19)) || (All.Para.Ch[i].uiChType == 21)
			|| (All.Para.Ch[i].uiChType == 22) || (All.Para.Ch[i].uiChType == 28)) 
		{
			;	
		}
		else
		{
			All.Para.Ch[i].uiChType = 13;
		}
	}
}

//--------------------------------------------------------------------------------------
//函数名称:void InitFramemoduleVariable(void)
//功    能:系统变量参数初始化	  
//输入参数:无
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
void InitFramemoduleVariable(void)
{
	unsigned char xdata i;	

	MainModule.uchLastChannelAlarm[0] = 0;	
	MainModule.uchLastChannelAlarm[1] = 0;
	MainModule.uchModuleStatus = 1;    //默认运行的状态
	MainModule.uchModuleFlag = 1;
	
	for (i=0; i<2; i++)
	{
		MainModule.uchLastChannelAlarm[i] = 0;
		MainModule.uchChannelAlarm[i] = 0;
//		MainModule.uiReportAlarmEvenStatus[i] = 0;
		MainModule.uchCalibrationStatus[i] = 0xff;	        //默认标定状态为不进行任何操作
		MainModule.iReportCurrentMeasureValue[i] = 0;
		MainModule.iReportCurrentGAPValue[i] = 0;
		MainModule.iPercentValue[i] = 0;
		MainModule.uchChannelOK[i] = 0x00;
		MainModule.uchBypassFlag[i] = 0x00;
	  	MainModule.uchChannelOKBAK[i] = 0x00;
	   	MainModule.uchChannelBypassStatus[i] = 0x00;
		MainModule.uchEnableStatus[i] = 0x01;    //&&&&		  使能默认为有效
	}

	FeedDog();
	MainModule.uchStartReportTimeFlag = 0;	//上报实时值延时的标志位
	MainModule.uchPhaseLoseStatus = 0;    //默认键相没有丢失
	MainModule.uchRAMLostStatus = 0;
	MainModule.uchFlashLostStatus = 0;
	MainModule.uchModuleNewConfigStatus = 0;
	MainModule.uchModuleConfigLostStatus = 0;
	MainModule.uchSelfTestControlStatus = 0xff;		   //自检状态下不执行任何操作,初始化
	MainModule.uchPowerStatus = 0x00;
	MainModule.uchModuleChannelParaStatus = 0x01;
	MainModule.uchHWConfigStatus = 0x00;  //默认硬件CONFIG线为低电平	
//	MainModule.uchSoftBypassTotalStatus = 0x00;		 //默认框架软件全体没有旁路
//	MainModule.uchSoftTripleTotalStatus	= 0x00;	     //默认框架软件全体没有倍增
	MainModule.uchModuleFlagBAK = 0x01;     //默认运行状态
	MainModule.uchPowerFlag = 0x00;			//默认电源状态正常
	MainModule.uchPhaseFlag = 0x00;			//默认键相信号没有丢失
	MainModule.uchRAMLostFlag = 0x00;		//默认RAM没有失效
	MainModule.uchFlashLostFlag = 0x00;		//默认FLASH没有失效
	MainModule.uchModuleNewConfigFlag = 0x00;	//默认模块没有被重新配置
	MainModule.uchModuleConfigLostFlag = 0x00;	   //默认模块配置没有失效
   	MainModule.uchModuleStatusChange = 1;       //默认模块状态在运行状态打开采样中断
	MainModule.uchModuleReportCount = 0;        //模块上报的次数初始化为0
	MainModule.uchSystemOKStatus  = 1;      //默认系统间隙状态处于OK状态
//	SamplePTR0BAK = SamplePTR0;
//	uchRMSFlag = 0;
//	uchRMSFlagBAK = uchRMSFlag;

	MainModule.uchNotOKToOKStatus[0] = 1;
	MainModule.uchNotOKToOKStatus[1] = 1;

	StopHeartBeat();
	uiHeartBeatNumber = uiHeartbeatValue;   //20080322
	StartHeartBeat();

	MainModule.uchReportNumber = 0;


	CaculateEnableStatus(1);	
	CaculateEnableStatus(2);
}

//--------------------------------------------------------------------------------------
//函数名称:void CaculateEnableStatus(unsigned char uchChannel)
//功    能:计算两个通道的使能状态
//输入参数:通道号
//返    回:无
//---------------------------------------------------------------------------------------
void CaculateEnableStatus(unsigned char uchChannel)		//&&&&
{
	if (uchChannel == 2)
	{
		if (All.Para.Ch[0].uiChType == 22)	
		{
			if ((All.Para.Ch[0].uiChEnable == 0) || (All.Para.Ch[1].uiChEnable == 0))	  
			{										
			 	MainModule.uchEnableStatus[0] = 0x00;
				MainModule.uchEnableStatus[1] = 0x00;
			}
			else
			{
				MainModule.uchEnableStatus[0] = 0x01;	  
				MainModule.uchEnableStatus[1] = 0x01;
			}
		}
		else
		{
			MainModule.uchEnableStatus[0] = All.Para.Ch[0].uiChEnable;
			MainModule.uchEnableStatus[1] = All.Para.Ch[1].uiChEnable;
		}
	}
	else
	{
		;
	}
} 			   






//--------------------------------------------------------------------------------------
//函数名称:void SetSoftBypassTotalStatus(unsigned char uchSoftBypassTotalFlag)
//功    能:将软件全体Bypass状态设置到框架中
//输入参数:框架软件Bypass状态
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
/*void SetSoftBypassTotalStatus(unsigned char uchSoftBypassTotalFlag)
{
	MainModule.uchSoftBypassTotalStatus = uchSoftBypassTotalFlag;
}*/

//--------------------------------------------------------------------------------------
//函数名称:void SetSoftTripleTotalStatus(unsigned char uchSoftTripleTotalFlag)
//功    能:将软件全体倍增状态设置到框架中
//输入参数:框架软件倍增状态
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
/*void SetSoftTripleTotalStatus(unsigned char uchSoftTripleTotalFlag)
{
	MainModule.uchSoftTripleTotalStatus = uchSoftTripleTotalFlag;
}  */

//--------------------------------------------------------------------------------------
//函数名称:void ClearSelfFlag(void)
//功    能:清除自检标志位
//输入参数:无
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
void ClearSelfFlag(void)
{
	MainModule.uchSelfTestControlStatus = 0x00;
}

//--------------------------------------------------------------------------------------
//函数名称:void MainSignalProcess(void)
//功    能:主框架信号处理,连接各个模块	  
//输入参数:无
//返    回:无
//完成日期:4/16/2007
//---------------------------------------------------------------------------------------
void MainSignalProcess(void)
{
	static unsigned char xdata s_uchCaculateLoop = 0;
	static unsigned char xdata s_uchDACalibrationComplete1 = 0;
	static unsigned char xdata s_uchDACalibrationComplete2 = 0;	  
	unsigned char xdata uchTempData;
	unsigned char xdata uchChannelStatus;  


	JudgeAndReportCommonSystemEvenStatus();	 //普通系统事件
	CaculateStartReportTime();		  //等待延时时间完成的标志位
	RuningLEDControl();
	JudgeModuleStatus();			 //判断模块运行的四种状态
	CaculateHotResetStartReportTime();

	FeedDog();
	
	switch(MainModule.uchModuleStatus)
	{
		case 0x01:			 //运行

			RunChannelParaJudge();		//判断通道参数	重新起机判断一次,以后通道参数有变化则也进行判断
			ClearModuleNewConfigStatus();	
			if (MainModule.uchSamplelCompleteStatus == 1)
			{				 
				if (s_uchCaculateLoop == 0)
				{
					ADModuleSignalProcessing(1);
					if ((All.Para.Ch[0].uiChType == 13) || (All.Para.Ch[0].uiChType == 14) || (All.Para.Ch[0].uiChType == 16)
						|| (All.Para.Ch[0].uiChType == 17) || (All.Para.Ch[0].uiChType == 18))	
					{
						SetGapVoltChannel(1, MainModule.iNOTOKGapVoltage[0]);
					}
					else 
					{
						SetGapVoltChannel(1, MainModule.iGapVoltage[0]);
					}									

					ProcessChannelGaps(1);//调用的通道状态模块的函数 
					JudgeBypassStatus(1);	//判断bypass状态
					SetBypassStatusALM(1,MainModule.uchBypassStatus[0]);
					SetOKStatusALM(1, MainModule.uchChannelOK[0]);  
					SetCurrentValueALM(1, (float)MainModule.iCurrentMeasureValue[0]);	  
					SetPercentValueALM(1, MainModule.iPercentValue[0]);	
					CaculateTripleStatus(1);				
					SetTripleStatusALM(1, MainModule.uchTripleStatus[0]);								  
				}
				else if (s_uchCaculateLoop == 1)
				{
					ADModuleSignalProcessing(2);
					if ((All.Para.Ch[1].uiChType == 13) || (All.Para.Ch[1].uiChType == 14) || (All.Para.Ch[1].uiChType == 16)
						|| (All.Para.Ch[1].uiChType == 17) || (All.Para.Ch[1].uiChType == 18))	
					{
						SetGapVoltChannel(2, MainModule.iNOTOKGapVoltage[1]);
					}
					else
					{
						SetGapVoltChannel(2, MainModule.iGapVoltage[1]);
					}

					ProcessChannelGaps(2);//调用的通道状态模块的函数 
					JudgeBypassStatus(2);  //判断bypass状态
					SetBypassStatusALM(2, MainModule.uchBypassStatus[1]);
					SetOKStatusALM(2, MainModule.uchChannelOK[1]); 
					SetCurrentValueALM(2, (float)MainModule.iCurrentMeasureValue[1]);
					SetPercentValueALM(2, MainModule.iPercentValue[1]);	
					CaculateTripleStatus(2);		
					SetTripleStatusALM(2, MainModule.uchTripleStatus[1]);	
				}
				s_uchCaculateLoop++;
				if (s_uchCaculateLoop >= 2)
				{
					s_uchCaculateLoop = 0;
					MainModule.uchSamplelCompleteStatus = 0;
				}
				uchTempData	= (s_uchCaculateLoop + 1) & 0x01;
				if (MainModule.uchStartReportTimeFlag == 1)
				{
					DelayChannelNotoktoOK(uchTempData + 1);
					AlarmModuleProcess(uchTempData + 1);	  //报警模块处理
					StopHeartBeat();
					if (uiHeartbeatValue >= uiHeartBeatNumber)
					{
						uiHeartbeatcount = uiHeartbeatValue - uiHeartBeatNumber;	
					}
					else
					{
						uiHeartbeatcount = 65535 - uiHeartBeatNumber + uiHeartbeatValue ;							
					}
					StartHeartBeat();
						
					if (uiHeartbeatcount >= 10)
					{
						MainModule.uchReportNumber = (MainModule.uchReportNumber + 1)&0x01;
						StopHeartBeat(); 
						uiHeartBeatNumber = uiHeartbeatValue;	 
						StartHeartBeat();
						CaculateReportMeasureValue(MainModule.uchReportNumber + 1);
						CaculateReportGapValue(MainModule.uchReportNumber + 1);				//计算的数值要从新计算					
						uchChannelStatus = ChannelStatus(MainModule.uchReportNumber + 1);				//以下几行是区分CPU的程序		
						if (MainModule.uchCPUAddressFlag == 0)
						{
							ReportChannelCurrentStatus(MainModule.uchReportNumber + 1,uchChannelStatus,MainModule.iReportCurrentMeasureValue[MainModule.uchReportNumber],MainModule.iReportCurrentGAPValue[MainModule.uchReportNumber]);	  
							JudgeAndReportAlertEvenStatus(MainModule.uchReportNumber + 1);
							JudgeAndReportSpecialSystemEvenStatus(MainModule.uchReportNumber + 1);								
						}
						else if (MainModule.uchCPUAddressFlag == 1)
						{				
							ReportChannelCurrentStatus(MainModule.uchReportNumber + 3,uchChannelStatus,MainModule.iReportCurrentMeasureValue[MainModule.uchReportNumber],MainModule.iReportCurrentGAPValue[MainModule.uchReportNumber]);
							JudgeAndReportAlertEvenStatus(MainModule.uchReportNumber + 3);

⌨️ 快捷键说明

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