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

📄 flashmodule.c

📁 该程序完成了c8051外围电路的驱动和串口协议的编写。希望能给大家学习51单片机带来帮助
💻 C
📖 第 1 页 / 共 2 页
字号:
			if (uchCountNumber == 10)
			{
				WriteExternFlash(FLASHREMOTIONADRESS, destination, uiLength);
				break;	
			}	
		}			
	}
	else if (uiFirstCheckSum != uiTempVariable)
	{
		uchCountNumber = 0;			 
		ReadExternFlash(destination,source,(uiLength+2));	
		uiFirstCheckSum = CaculateCheckSum(destination, uiLength);
		uiTempVariable = *(destination + uiLength) << 8 ;
		uiTempVariable = uiTempVariable + *(destination + uiLength + 1);
		while(uiFirstCheckSum != uiTempVariable)
		{
			ReadExternFlash(destination,source,(uiLength+2));	
			uiFirstCheckSum = CaculateCheckSum(destination, uiLength);
			uiTempVariable = *(destination + uiLength) << 8 ;
			uiTempVariable = uiTempVariable + *(destination + uiLength + 1);
			uchCountNumber++;
			if (uchCountNumber == 9)
			{
				break;
			}
		}
		if (uiFirstCheckSum == uiTempVariable)
		{
			source = source + FLASHREMOTIONADRESS;
			ReadExternFlash(uchTempArray, source, (uiLength + 2));
			FeedDog();
			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++;
				if (uchCountNumber == 10)
				{
					WriteExternFlash(FLASHREMOTIONADRESS, destination, uiLength);
					break;	
				}	
			}			
			return;
		}
		source = source + FLASHREMOTIONADRESS;
		ReadExternFlash(uchTempArray, source, (uiLength + 2));
		uiSecondCheckSum = CaculateCheckSum(uchTempArray, uiLength);
		uiTempVariable = *(uchTempArray + uiLength) << 8; 
		uiTempVariable = uiTempVariable + *(uchTempArray + uiLength +1);
		FeedDog();
		uchCountNumber = 0;
		while (uiSecondCheckSum != uiTempVariable)
		{
			ReadExternFlash(uchTempArray, source, (uiLength + 2));

			uiSecondCheckSum = CaculateCheckSum(uchTempArray, uiLength);
			uiTempVariable = *(uchTempArray + uiLength) << 8; 
			uiTempVariable = uiTempVariable + *(uchTempArray + uiLength +1);
			uchCountNumber++;
			if (uchCountNumber == 10)
			{
				break;	
			}	
		}
		if (uiSecondCheckSum == uiTempVariable)					 
		{
			for (uiL=0; uiL<uiLength; uiL++)
			{
				*(destination + uiL) = uchTempArray[uiL];				
			}
			WriteExternFlash(0, uchTempArray, uiLength);
		}
		else
		{
			ReadFlashDefaultPara(destination,(char code *)&Def_Para_Array, uiLength);
			WriteSystemPara(0, destination, uiLength);
		}	
	}
	else
	{
		return;
	}
	return;		  
}

//--------------------------------------------------------------------------------------------------
//函数名称:void CheckSystemRAMInvalidation(void)
//功    能:检测系统RAM是否失效     
//输入参数:无 
//返    回:无
//完成日期:4/13/2007
//-------------------------------------------------------------------------------------------------

void CheckSystemRAMInvalidation(void)
{
	unsigned char xdata uchDataCheck[13] = {0xff, 0x94, 0xC0, 0x25, 0x04, 0xf3, 
	 											0xb0, 0x07, 0x5D, 0x07, 0x06, 0x00, 0x00};
	unsigned int  xdata uiDataResult;
	unsigned int  xdata uiTempDataRCR = 0xffff;
	unsigned char xdata uchDataCheckLength = 11;
	unsigned char xdata *p_uchDataCheck = &uchDataCheck; 
	unsigned int  xdata uiTempData;
    
	while(uchDataCheckLength > 0)
    {
        uiTempDataRCR = ((unsigned char)(uiTempDataRCR)) ^ uchDataCheck[((unsigned char)(uiTempDataRCR >> 8) ^ *p_uchDataCheck)];
        uchDataCheckLength--;
        p_uchDataCheck++;

    }
    uiDataResult = uiTempDataRCR;
	uchDataCheck[11] = uiDataResult;
    uchDataCheck[12] = (uiDataResult >> 8);    
	uchDataCheckLength = 11;
	uiTempDataRCR = 0xffff;
	p_uchDataCheck = &uchDataCheck;

	while(uchDataCheckLength > 0)
    {
 		uiTempDataRCR = ((unsigned char)(uiTempDataRCR)) ^ uchDataCheck[((unsigned char)(uiTempDataRCR >> 8) ^ *p_uchDataCheck)];
        uchDataCheckLength--;
        p_uchDataCheck++;

    }
	
	uiDataResult = uiTempDataRCR;	
	uiTempData = uchDataCheck[11] + (uchDataCheck[12] << 8);
	
	if (uiTempDataRCR == uiTempData)
	{
		SetRAMLostStatusMain(0);	
	}	
	else if (uiTempDataRCR != uiTempData)
	{
		SetRAMLostStatusMain(1);	
	}		
}


//--------------------------------------------------------------------------------------------------
//函数名称:void CheckSystemFLASHInvalidation(void)
//功    能:检测系统FLASH是否失效     
//输入参数:无 
//返    回:无
//完成日期:4/13/2007
//-------------------------------------------------------------------------------------------------
void CheckSystemFLASHInvalidation(void)
{
	unsigned char code uchDataCheck[11] = {0xff, 0x94, 0xCc, 0x25, 0x04, 0xf3, 
	 											0xb0, 0x07, 0x5D, 0x07, 0xf6};
	unsigned int  xdata uiDataResult;
	unsigned int  xdata uiTempDataRCR = 0xffff;
	unsigned char xdata uchDataCheckLength = 11;
	unsigned char xdata *p_uchDataCheck = &uchDataCheck; 
    
	while(uchDataCheckLength > 0)
    {
        uiTempDataRCR = ((unsigned char)(uiTempDataRCR)) ^ uchDataCheck[((unsigned char)(uiTempDataRCR >> 8) ^ *p_uchDataCheck)];
        uchDataCheckLength--;
        p_uchDataCheck++;
    }
    uiDataResult = uiTempDataRCR;    
	uchDataCheckLength = 11;
	uiTempDataRCR = 0xffff;
	p_uchDataCheck = &uchDataCheck;

	while(uchDataCheckLength > 0)
    {
 		uiTempDataRCR = ((unsigned char)(uiTempDataRCR)) ^ uchDataCheck[((unsigned char)(uiTempDataRCR >> 8) ^ *p_uchDataCheck)];
        uchDataCheckLength--;
        p_uchDataCheck++;
    }	
	if (uiTempDataRCR == uiDataResult)
	{
		SetFLASHLostStatusMain(0);	
	}	
	else if (uiTempDataRCR != uiDataResult)
	{
		SetFLASHLostStatusMain(1);	
	}			
}





















































⌨️ 快捷键说明

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