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

📄 eepromctrlex0205.h

📁 如何使用flash来模拟EEPROM
💻 H
字号:
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  System       : EEPROM emulation
  Module name  : Include file for "EEPROMCtrlEx.c"
  File name    : EEPROMCtrlEx.h
  Version name : 1.00
  Target CPU   : uPD78F0547(78K0/KF2)
  Last updated : 2005/09/08
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/*--- Expanded functions ------------------------------------------*/
#pragma	sfr
#pragma	DI
#pragma	EI
#pragma	nop
#pragma asm

/*--- Type declarations	-------------------------------------------*/
typedef	unsigned char  UCHAR;
typedef	unsigned short USHORT;
typedef	unsigned long  ULONG;
typedef			 char  CHAR;
typedef			 short SHORT;
typedef			 long  LONG;

/*-#- User settings --#--#--#--#--#--#--#--#--#--#--#--#--#--#--#---*/

/********************************************************************/
/* EEPROM瞻晦愝掕弶婜抣                                             */
/********************************************************************/
const UCHAR ucEEPROM_BLOCK[]={9,10};			/* 0x2000-0x27ff       	*/
const UCHAR ucEEPROM_BANK[]={0,0};	 		/* EEPROM 0兽莞傪巊梡  	*/
#define DATALENGTH 	(1)		/* 彂偒崬傒棉袄偺棉袄挿                	*/
#define DATANOMAX 	(4)		/* 巊梡偡傞嵟戝棉袄斣崋                	*/
#define BANKUSE       		/* 矣廿兽莞懳墳惢昳                    	*/
#define WRITENUM 	(1)		/* 彂偒崬傒啬撞夞悢                    	*/
#define ERASENUM 	(0)     /* 徚嫀啬撞夞悢                        	*/
#define AUTOERASE 			/* 剔郫笗蠉X帪偺徚嫀摦嶌桳             	*/

/*-#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#--#-*/
/*--- Constant definitions -----------------------------------------*/
#define	TRUE		(0x00)		/* Normal end                   	*/
#define	NMLBLK		(0x01)		/* Normal end(Block error)      	*/
#define	ERRPRM		(0xF4)		/* Parameter Error              	*/
#define	ERRFULL		(0xF5)		/* Data full                    	*/
#define	ERRWRITE	(0xF6)		/* Data write error             	*/
#define	ERRNODAT	(0xF7)		/* With no read-out data        	*/
#define	ERRNOBLA	(0xF8)		/* With no eraseed block        	*/
#define	ERRNOERS	(0xF9)		/* With no erasable block       	*/
#define	ERRNOUSE	(0xFA)		/* With no effective block      	*/
#define	ERRALL		(0xFB)		/* Prohibition of all block use 	*/
#define	ERRBLK		(0xFC)		/* Block error                  	*/
#define	ERRDEV		(0xFD)		/* Device error                 	*/
#define	ERRINIT		(0xFE)		/* Initialization error         	*/
#define	FALSE		(0xFF)		/* Abnormal end                 	*/

/* Return value from FlashFirm */
#define	LIB_NORMAL_END	(0x00)	/* Normal completion(== Constant definitions: TRUE) */
#define	LIB_BLKCHK_ERR	(0x1B)	/* Blank check error 				*/
#define	LIB_BLANK_ERR	(0x1E)	/* Blank error 						*/
#define	LIB_STATE_INT	(0x1F)	/* State of interruption 			*/

#define WRITE_DATA_LENGTH (((((DATALENGTH+1)>>2)+1)<<2)-1)/* Data length亄Data which buried the insufficiency of a 4-byte boundary亄Delimiter */

#define	BUFLENGTH	WRITE_DATA_LENGTH+1					/* Length of general-purpose buffer */

#define	DATATOP			(8)								/* Top byte of data used as block data */
#define	DATA_NO_MAX 	(DATANOMAX + 1)					/* Amount of data */

#define	EEPROM_BLOCK_NO	sizeof(ucEEPROM_BLOCK)			/* Number of blocks used as EEPROM */

#define	DATA_OF_BLOCK	((0x0400-DATATOP)/(WRITE_DATA_LENGTH+1))

#define	DATA_END_OFFSET	((DATA_OF_BLOCK*(WRITE_DATA_LENGTH+1))+DATATOP)

/* Processing flag definition */
#define	FL_BLKERR	0x80								/* Block error                  */
#define	FL_DOERS	0x08								/* It is necessary to erase     */

/* Macro definition */
#define	BLOCK_TO_ADDRESS( x )	usBlockToAddress( x )
#define	BLOCK_IS_PROHIBIT( x )	ucUseProhibitionBlock( x )
#define	BLOCK_IS_EFFECTIVE( x )	ucEffectiveBlock( x )
#define	BLOCK_IS_BLANK( x )		ucBlankBlock( x )
#define	PARAM_OK				ucParamCheck()

#ifdef	BANKUSE
		#define	SET_BANK(x)				(BANK=x)
#else
		#define	SET_BANK(x)	
#endif

/*--- RAM declarations --------------------------------------------*/

UCHAR	ucDataBuf[ BUFLENGTH ];							/* Buffer for EEPROM data manipulation */

struct	stWordAddress{
	USHORT	WriteAddress;
	UCHAR	WriteBank;
}WordAddr;

sreg	UCHAR	ucEntryRAM[100];


/*--- Prototype declarations --------------------------------------*/
UCHAR  ucEEPROMInitEx( void );
UCHAR  ucEEPROMReadEx( UCHAR ucDataNo , UCHAR *pDataAddress );
UCHAR  ucEEPROMWriteEx( UCHAR ucDataNo, UCHAR *pDataAddress );
UCHAR  ucEEPROMChangeEx( void );
UCHAR  ucEEPROMEraseEx( void );
UCHAR  ucEEPROMGetRemainEx( void );

UCHAR  ucEEPROMUseBlockSearchEx( void );
USHORT usEEPROMWriteTopSearchEx( UCHAR ucBlockTBLNo );
USHORT usEEPROMDataSearchEx( UCHAR ucDataNo, UCHAR ucBlockTBLNo );
UCHAR  ucEEPROMUnableEx( UCHAR ucBlockTBLNo );

void   SelfFlashModeOn( void );
void   SelfFlashModeOff( void );
UCHAR  ucSelfFlashInitialize( void );
UCHAR  ucSelfFlashBlockErase( UCHAR ucBank, UCHAR ucBlock );
UCHAR  ucSelfFlashEEPROMWrite( UCHAR ucBank, USHORT usAddr, UCHAR ucNum );
UCHAR  ucSelfFlashWordWrite( UCHAR ucBank, USHORT usSetAdr, UCHAR ucNum );

USHORT usBlockToAddress( USHORT usBlock );
UCHAR  ucUseProhibitionBlock( UCHAR *p );
UCHAR  ucEffectiveBlock( UCHAR *p );
UCHAR  ucBlankBlock( UCHAR *p );
UCHAR  ucParamCheck( void );

extern	void   FlashStart( void );
extern	void   FlashEnd( void );
extern	void   FlashEnv( USHORT EntryRAM );
extern	UCHAR  FlashBlockErase( UCHAR EraseBank, UCHAR EraseBlock );
extern	UCHAR  FlashWordWrite( struct stWordAddress *ptr, UCHAR WordNumber, USHORT DataBufferAddress);
/* extern	UCHAR  FlashBlockVerify( UCHAR VerifyBank, UCHAR VerifyBlock );*/
extern	UCHAR  FlashBlockBlankCheck( UCHAR BlankCheckBank, UCHAR BlankCheckBlock );
/* extern	UCHAR  FlashGetInfo( struct stGetInfo *ptr, USHORT DataBufferAddress );*/
/* extern	UCHAR  FlashSetInfo( UCHAR SetInfoData );*/
extern	UCHAR  CheckFLMD( void );
extern	UCHAR  EEPROMWrite( struct stWordAddress *ptr, UCHAR WordNumber, USHORT DataBufferAddress);

⌨️ 快捷键说明

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