Message Edited by Alban on 01-26-2006 11:58 AM
/* ROM Resident Routines Pointer Definitions */
#define PRGRNGE 0x1009 /* Program a range of FLASH locations */
#define ERARNGE 0x1006 /* Erase a page or a whole array of FLASH */
#define RDVRRNG 0x1003 /* Reads/Verifies a range of locations in FLASH */
#define GETBYTE 0x1000 /* Gets a byte of data from comm port */
#define DELNUS 0X100C /* Generate a delay */
void FLASHProgram(void);
void FLASHErase(void);
/* RAM Data Block */
unsigned char CTRLBYT @0x0048; /* Select between mass/page erase */
unsigned char CPUSPD @0x0049; /* CPU value equals 4x Bus speed */
unsigned int LADDR @0x004A; /* Last address of FLASH to manipulate */
unsigned char DATA[4] @0x004C; /* Data to program into FLASH */
unsigned int FADDR = 0xFB43; /* First Address to store data in FLASH */
unsigned char DataSize = 4; /* Variable to calculate Last Address */
const byte FLBPR_INIT @0x0000FF7E = 0xFF; /* Initialize Flash Block Protection */
/*
* FLASHProgram: Calls ROM-Resident Routine PRGRNGE.
* Locations starting from address specified by FADDR will be
* programmed. The range size is calculated depending on LADDR
*
* Parameters: None
*
* Return : None
*/
void FLASHProgram(void){
asm(LDHX FADDR); /* Load address of RAM Data Block to H:X */
asm(JSR PRGRNGE); /* Call PRGRNGE ROM Subroutine */
}
/*
* FLASHErase: Calls ROM-Resident Routine ERARNGE.
* In the case mass bit (CTRLBYT bit 6) is set, calling ERARNGE
* will perform a mass erase. If the mass bit is cleared (0), a
* page erase will be performed. FADDR may be any address in the
* range to be erased.
*
* Parameters: None
*
* Return : None
*/
void FLASHErase(void){
asm(LDHX FADDR); /* Load to H:X address in FLASH range to be erased */
asm(JSR ERARNGE); /* Call ERARNGE ROM Subroutine */
}
/* RAM DATA Initialization */
CTRLBYT = 0; /* Page erase (clear bit-6) */
CPUSPD = 40; /* 9.8304MHz * 4 = 39.3 = 40 (using external OSC) */
LADDR = FADDR + DataSize - 1; /* Last address in FLASH to program */
/* DATA Buffer Initialization */
DATA[0] = 0xAA;
DATA[1] = 0xBB;
DATA[2] = 0xCC;
DATA[3] = 0xDD;
FLASHErase(); /* Erase the page in FLASH specified by FADDR */
/*
* NOTE: FLASH locations must be blank before
* trying to write data into them.
*/
FLASHProgram(); /* Program DATA into FLASH location starting at FADDR */
Hello Ozelo,
I would suspect that the simulator would not simulate the ROM-based routines since there is really no reason for it to do so. So you will probably need to test EEPROM emulation using actual hardware. For the simulator, "implemented ROM" would actually refer to flash memory.
For simulation purposes, you might replace the ROM routine calls with dummy functions that do nothing, to be used during simulation only. This will at least allow the program to compile and link.
Regards,
Mac