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

📄 flashmodule.c

📁 该程序完成了c8051外围电路的驱动和串口协议的编写。希望能给大家学习51单片机带来帮助
💻 C
📖 第 1 页 / 共 2 页
字号:
//*******************************************************************************
//Copyright (c) 2007,派利斯电子(北京)有限公司 硬件部
//文件名称: FlahModule.c
//摘    要: 本文件主要包含PT2060程序中Flash参数等操作
//当前版本: D-1 
//作    者:  佟文杰
//完成日期: 4/19/2007
//******************************************************************************* 
#define FLASHMODULE_C
#include "FlashModule.h"
extern xdata unsigned int  uiHeartbeatValue; 
#define  FLASHREMOTIONADRESS     0x0800	 

int code Def_Para_Array[107] = {
//	第一行为数组数据代表的变量名称
//	第二行为数组数据代表的含义
//	第三行为数组数据存入到flash的真实数据
//--------------------------第一通道的参数Channel1Para----------------------------------------
//		uiSampleRate,		uiSamPeriod,		uiMeasureType,		uiMeasureUnit;
//		   4.0K				   250ms			  RMS					mm/s
		    3,				    3,				   3,				    2,
//      uiSensorType,       uiSensitive,        iSensorDirection,   uiAlertType; 
//		TM0180/5m(无前置)	  mv/um				朝向/背向
		   24,				  4000,		           0,				    1,
//      iDangerHigh,        iFallingDangerH,    iDangerLow,         iFallingDangerL;
//
		  3750,					1,					0,				     1,
//		iAlertLow,          iFallingAlertL,     iAlertHigh,		    iFallingAlertH;
//
		 0,					   1,					2500,				 1,
//	    iGapHigh,           iGapLow,		    iGapFalling,        iScaleHigh;	   
//		电压   负数								   范围 1-5
		  17000,			  -2000,				1000,			   5000,		   
//	    uiAlertDelay,       uiDangerDelay,      uiLatch,			uiChEnable;
//		单位:S				   同前				 不自锁					使能
		   3,					 1,				   1,					 1,
//      uiPhaseRef,         uchChType;
//																				  
		   0,				   16,
//      iScaleLow,	        iExponentValue,     iZeroPosition,      iHystersisVolt;  
//												  电压*1000  负数	   电压*100  迟滞
 		   0,   			    0,			/*	8*/  0,				       0,
//      iTriggerVolt;
//																						  
		   0 ,
//	    uiteeth,            iTriggerSelect,       uiAngle,             uiBarrier;
//							0/1 自动选择/用户选择  0/1 	             0/1  无隔离栅/有隔离栅
		   60,					  0,				0,			        1,
//      uiLowCutoff,        uiHighCutOff,       uiChConfig;   
//		 低端截止频率
		   0,					0,				   0,

//--------------------------第二通道的参数Channel2Para----------------------------------------
//		uiSampleRate,		uiSamPeriod,		uiMeasureType,		uiMeasureUnit;
//		   4.0K				   250ms			  RMS					mm/s
		    3,				    3,				   3,				    2,
//      uiSensorType,       uiSensitive,        iSensorDirection,   uiAlertType; 
//		TM0180/5m(无前置)	  mv/um				 0/1 朝向/背向
		   24,				  4000,		           0,				    1,
//      iDangerHigh,        iFallingDangerH,    iDangerLow,         iFallingDangerL;
//
		  3750,					1,					0,				1,
//		iAlertLow,          iFallingAlertL,     iAlertHigh,		    iFallingAlertH;
//
		   0,					1,					2500,				    1,
//	    iGapHigh,           iGapLow,		    iGapFalling,        iScaleHigh;
//		电压 负数								   范围 1-5
		  17000,		   	 -2000,			      1000,					5000,
//	    uiAlertDelay,       uiDangerDelay,      uiLatch,			uiChEnable;
//		单位:S				   同前				 不自锁					使能
		   3,					 1,				   1,					 1,
//      uiPhaseRef,         uchChType;
//
		   0,				   16,
//      iScaleLow,	        iExponentValue,     iZeroPosition,      iHystersisVolt;  
//												  电压*1000  负数	   电压*100  迟滞
 		   0,   			   0,			/*8000*/  0,				  0,
//      iTriggerVolt;
//																							 
		   0 ,
//	    uiteeth,            iTriggerSelect,         uiAngle,          uiBarrier;
//							0/1 自动选择/用户选择  	   0/1  无隔离栅/有隔离栅
		   60,					  0,				   0,			  1,
//      uiLowCutoff,        uiHighCutOff,       uiChConfig;   
//		 低端截止频率
		   0,					0,				   0,

//-----------------------------厂家信息FactoryInfo--------------------------------------------

//       uiSoftwareVer;		   
//
		  403,				          
//	    uiProductSNHigh;	uiProductSNLow                             long型数据分开
//
		   0,					 0 ,
//	    uiCheckerNum,        uiModuleType, 	     uiHardwareVer; 
//
		   0,					5,		          	302,
//----------------------------标定第一通道CalibrationChannel1---------------------------------
//      uiVibADZero,        uiVibADFull,        uiDisADZero,        uiDisADFull;   
//								e09
     	  0x04,				   0x0c8a,			   0x03,				  0x0384,
//
//	uiLittleRangeZero,              uiLittleRangeFull;  
		 7,								 0xb1d,
//	uiGAPADZero,    				uiGAPADFull; 
 	   0xb9,							   0x0b7d,
//	    uiDAZero,           uiDAFull;
//		 4mA				   20mA
		 0x2b1,				  0xd8f,
//----------------------------标定第二通道CalibrationChannel1---------------------------------
//      uiVibADZero,        uiVibADFull,        uiDisADZero,        uiDisADFull;   
//								e09
     	  0x04,				   0x0c8a,			   0x03,				  0x0384,

//
//	uiLittleRangeZero,              uiLittleRangeFull;  
		 7,								0xb1d,
//	uiGAPADZero,    				uiGAPADFull; 
 		0xb9,							   0x0b7d,
//	    uiDAZero,           uiDAFull;
//		 2mA				   23.4mA
		 0x2b1,				  0xd8f,
//----------------------------其他参数--------------------------------------------------------

//      uiDataSpan,    uiTripValue[0],    uiTripValue[0],  uiBypassFlag[0] uiBypassFlag[1];
//
		  16384,			0,	        	   0,		         	0,				 0
																		 
};
//--------------------------------------------------------------------------------------------------
//函数名称:void DelayTimeCount(unsigned int uiTime)
//功    能:由心跳计算延时的时间,心跳为10ms,所以设置的时间必须是10ms的倍数  延时的时间大约为uiTime×10ms 
//输入参数:输入心跳的个数
//返    回:无						 
//完成日期:4/13/2007
//-------------------------------------------------------------------------------------------------
void DelayTimeCount(unsigned int uiTime)
{
	unsigned int xdata uiHeartbeatValueBAK;
	unsigned int xdata uiHeartbeatcount = 0;
	unsigned int xdata uiCurrentHeartBeatNumber;
	StopHeartBeat();
	uiHeartbeatValueBAK = uiHeartbeatValue;
	StartHeartBeat();
	while (1)
	{
		StopHeartBeat();
		uiCurrentHeartBeatNumber = uiHeartbeatValue;
		StartHeartBeat();
		if (uiCurrentHeartBeatNumber >= uiHeartbeatValueBAK)
		{
			uiHeartbeatcount = uiCurrentHeartBeatNumber - uiHeartbeatValueBAK;
			
		}
		else
		{
			uiHeartbeatcount = 65535 - uiHeartbeatValueBAK + uiCurrentHeartBeatNumber;							
		}
		if (uiHeartbeatcount >= uiTime)
		{
			break;
		}
		FeedDog();
	}
}

//--------------------------------------------------------------------------------------------------
//函数名称:unsigned int CaculateCheckSum(unsigned char xdata *Source, unsigned int uiLength)
//功    能:根据长度将源地址的数据累加    
//输入参数:源地址、数据长度 
//返    回:累加和
//完成日期:4/13/2007
//-------------------------------------------------------------------------------------------------
unsigned int CaculateCheckSum(unsigned char xdata *Source, unsigned int uiLength)
{
	unsigned int xdata uiL;
	unsigned int xdata uiTempVariable = 0;

	uiTempVariable = 0;
	for (uiL=0; uiL<uiLength; uiL++)
	{
		uiTempVariable = uiTempVariable + *Source;
		Source++;
	}

	return uiTempVariable;
}


//--------------------------------------------------------------------------------------------------
//函数名称:void WriteSystemPara(unsigned char xdata *destination,unsigned char xdata *Source,unsigned int uchLength)
//功    能:根据长度将目的地址的内容写入到28C64存储器中的各个不同地址中     
//输入参数:目的地址、源地址、数据长度 
//返    回:无
//完成日期:4/13/2007
//-------------------------------------------------------------------------------------------------
void WriteSystemPara(unsigned char xdata *destination,unsigned char xdata *Source,unsigned int uiLength)
{
	WriteExternFlash(destination, Source, uiLength);
	WriteExternFlash(destination + FLASHREMOTIONADRESS, Source, uiLength);
}

//--------------------------------------------------------------------------------------------------
//函数名称:void ReadSystemPara(unsigned char xdata *destination, unsigned int xdata *source,unsigned char uchLength)
//功    能:根据长度并进行校验和判断后将28C64存储器中的不同地址的内容读到目的数组中     
//输入参数:数据目的地址,数据源地址,数据长度 (不包括校验和位的数据)
//返    回:无
//完成日期:4/13/2007
//-------------------------------------------------------------------------------------------------
void ReadSystemPara(unsigned char xdata *destination, unsigned char xdata *source,unsigned int uiLength)
{
	unsigned char xdata uchTempArray[220];	  //数组临时设定,维数要与实际情况为准
	unsigned int  xdata uiTempVariable;
	unsigned int  xdata uiFirstCheckSum;
	unsigned int  xdata uiSecondCheckSum;
	unsigned int  xdata uiL;
	unsigned char xdata uchCountNumber;			   
	
	uchCountNumber = 0;			
	ReadExternFlash(destination,source,(uiLength+2));	
	uiFirstCheckSum = CaculateCheckSum(destination, uiLength);
	uiTempVariable = *(destination + uiLength) << 8 ;
	uiTempVariable = uiTempVariable + *(destination + uiLength + 1);
	FeedDog();
	if (uiFirstCheckSum == uiTempVariable)
	{		
		source = source + FLASHREMOTIONADRESS;
		ReadExternFlash(uchTempArray, source, (uiLength + 2));

		uiSecondCheckSum = CaculateCheckSum(uchTempArray, uiLength);
		uiTempVariable = *(uchTempArray + uiLength) << 8; 
		uiTempVariable = uiTempVariable + *(uchTempArray + uiLength +1);
		while (uiSecondCheckSum != uiTempVariable)
		{
			ReadExternFlash(uchTempArray, source, (uiLength + 2));

			uiSecondCheckSum = CaculateCheckSum(uchTempArray, uiLength);
			uiTempVariable = *(uchTempArray + uiLength) << 8; 
			uiTempVariable = uiTempVariable + *(uchTempArray + uiLength +1);
			uchCountNumber++;

⌨️ 快捷键说明

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