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

📄 eepromcopy.c

📁 一个非常好的微处理器烧录EEPROM的C++ 原代码项目文件,直接可用,一拖一的,成果奉献给广大的底层软件开发者
💻 C
字号:
/***************************************************************************************************************************
* Project:    		EepromCopy Software Part                                                    
*                                                                                                                          
* File:         		EepromCopy.C (Source)                                                                                  
*                                                                                                                          
*Version:      		V0.00                                                                                               
*                                                                                                                          
* Created:      	2006.05.10
* Last Change:      2006.05.10                                                                          
*                                                                                                                          
* Author:       		LaiJun                                                                                         
*							       			   			  	       	    
* Company:		COBY										       	    
*                                                                                                                         
* Compiler:     	KEIL C51 V7.07                                                                              
*                                                                                                                         
* Description:  	
*
* SM5964(@12MHz)                                        	       	                            	    
*
*Copyright (c) COBY Integration Technology, Inc.
*All rights reserved.
*
***************************************************************************************************************************/
#include	"PublicDef.h"
#include	"PublicFunction.h"
//define	Public var
union
	{
		BYTE	 bytes[128];
		WORD	 words[64];
		DWORD	 dwords[32];
	}	GpBuffer;
BYTE	*ptGpBuffer;

BYTE	bDelayTime,Operate_Flag;
WORD	wDelayTime,wDemoDelay;
void	InitMcu(void)
{
#ifdef	MCU_SM5964_SynCmos
	TMOD=0x10;
	TL1=bCOPYTL1;
	TH1=bCOPYTH1;
	SCON=0x50;
	T2CON=0x30;
	PCON=0x00;
	TH2=RCAP2H=0xff;
	TL2=RCAP2L=BAUD_UART;
	IT1 =0;
	ET1=ES=1;
	PT1=0;PS=1;
	TR1=TR2=1;
	EX1=0;
	WDTC=0;
	EA=btENABLE;
	SCONF=0x0E;
	DBANK=0x00;
#endif
}

void	TurnOnOff_Light(BYTE	Light)
{
	switch	(Light)
	{
		case	LIGHT_RED:
				Pin_LIGHT_RED=1;
				Pin_LIGHT_GREEN=0;
				break;
		case	LIGHT_GREEN:
				Pin_LIGHT_RED=0;
				Pin_LIGHT_GREEN=1;
				break;
		case	LIGHT_YELLOW:
				Pin_LIGHT_RED=1;
				Pin_LIGHT_GREEN=1;
				break;
		case	LIGHT_OFF:
				Pin_LIGHT_RED=0;
				Pin_LIGHT_GREEN=0;
				break;
	}
}

BYTE	Chek_Chip(BYTE	Chip_Number)
{
	#define		CHIP_R		1
	#define		CHIP_D		2

	if	(Chip_Number&CHIP_R)
	{
		SetIIC_Type(IIC_AT24CXX_R);
		Reset_Eeprom();
		ptGpBuffer=GpBuffer.bytes;
		if	(EepromRead(0,1)==btIIC_ERROR)
		return		btIIC_ERROR;
	}
	if	(Chip_Number&CHIP_D)
	{
		SetIIC_Type(IIC_AT24CXX_D);
		Reset_Eeprom();
		ptGpBuffer=GpBuffer.bytes;
		if	(EepromRead(0,1)==btIIC_ERROR)
		return		btIIC_ERROR;
	}
	return		btIIC_RIGHT;
}

void	Copy_Eeprom(void)
{
	WORD	Eeprom_Pages;
	#if	SELECT_TYPE_METHOD==SELECT_BY_SOFT
	Eeprom.bType_Eeprom=EEPROM_TYPE;
	#else
	Eeprom.bType_Eeprom=Pin_Type_Select&0x0f;
	#endif
	switch	(Eeprom.bType_Eeprom)
	{
		case	EEPROM_24C01:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C01;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C02;
				break;
		case	EEPROM_24C02:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C02;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C02;
				break;
		case	EEPROM_24C04:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C04;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C16;
				break;
		case	EEPROM_24C08:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C08;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C16;
				break;
		case	EEPROM_24C16:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C16;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C16;
				break;
		case	EEPROM_24C32:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C32;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C64;
				break;
		case	EEPROM_24C64:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C64;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C64;
				break;
		case	EEPROM_24C128:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C128;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C256;
				break;
		case	EEPROM_24C256:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C256;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C256;
				break;
		case	EEPROM_24C512:
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C512;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C512;
				break;
		default:	
				Eeprom.wPages_Eeprom=EEPROM_PAGES_24C08;
				Eeprom.bBytes_PerPage=PAGEBYTES_24C16;
				break;
	}
	TurnOnOff_Light(LIGHT_YELLOW);
	wDelayTime=100;
	while	(wDelayTime);
	for	(Eeprom_Pages=0;Eeprom_Pages<Eeprom.wPages_Eeprom;Eeprom_Pages++)
	{
		TurnOnOff_Light(LIGHT_YELLOW);
		SetIIC_Type(IIC_AT24CXX_R);
		ptGpBuffer=GpBuffer.bytes;
		if  (EepromRead(Eeprom_Pages*Eeprom.bBytes_PerPage,Eeprom.bBytes_PerPage))
		{
			Operate_Flag=OPERATE_ER;
			break;
		}
		TurnOnOff_Light(LIGHT_OFF);
		SetIIC_Type(IIC_AT24CXX_D);
		ptGpBuffer=GpBuffer.bytes;
		if  (EepromWrite(Eeprom_Pages*Eeprom.bBytes_PerPage,Eeprom.bBytes_PerPage))
		{
			Operate_Flag=OPERATE_ER;
			break;
		}
	}
	if	(Eeprom_Pages==Eeprom.wPages_Eeprom)
	Operate_Flag=OPERATE_OK;	
}

void	Operate_Eeprom(void)
{
	if	(Chek_Chip(3))
	Operate_Flag=OPERATE_ER;
	else
	Copy_Eeprom();
	if	(Operate_Flag==OPERATE_OK)
	TurnOnOff_Light(LIGHT_GREEN);
	else
	TurnOnOff_Light(LIGHT_RED);
	wDelayTime=500;
	while	(wDelayTime);
	Key_Func=KEY_NO_KEY;
	while	(1)
	{
		Chek_key();
		if	(Key_Func==KEY_NO_KEY)
		break;	
	}
}
void main(void)
{
	BYTE	Loop_Counter,Chip_Stau_R,Chip_Stau_D;
	InitMcu();
	TurnOnOff_Light(LIGHT_OFF);
	wDelayTime=1000;
	while (wDelayTime);
	Operate_Flag=OPERATE_NO;
	wDemoDelay=400;
	Loop_Counter=0;
	while	(1)
	{
		Chek_key();
		if	(Key_Func==KEY_START)
		Operate_Eeprom();		
		switch	(Operate_Flag)
		{
			case	OPERATE_NO:
					if	(wDemoDelay==0)
					{
						Chip_Stau_R=Chek_Chip(1);
						Chip_Stau_D=Chek_Chip(2);
						if	(Chip_Stau_R&&Chip_Stau_D)
						Loop_Counter=INC(Loop_Counter,0,2);	
						else   if	(Chip_Stau_R&&!Chip_Stau_D)	
						Loop_Counter=INC(Loop_Counter,1,2);	
						else   if	(!Chip_Stau_R&&Chip_Stau_D)	
						Loop_Counter=INCx(Loop_Counter,0,2,2);	
						else
						Loop_Counter=LIGHT_YELLOW;
						TurnOnOff_Light(Loop_Counter);
						wDemoDelay=400;
					}
					break;
			case	OPERATE_ER:
					if	(Chek_Chip(3))
					Operate_Flag=OPERATE_NO;
					else
					{
						if	(wDemoDelay==0)
						{
							Loop_Counter=INCx(Loop_Counter,0,3,3);
							TurnOnOff_Light(Loop_Counter);
							wDemoDelay=400;
						}
					}
					break;
			case	OPERATE_OK:
					if	(Chek_Chip(3))
					Operate_Flag=OPERATE_NO;
					break;
		}
	}
}

⌨️ 快捷键说明

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