Page 176 - Programming Microcontrollers in C
P. 176
Microcontroller Memory 161
/* pragmas to identify EEPROM control registers */
#pragma portrw EEPROM_CTL @ 0x07;
#pragma portrw OPTIONS @ 0x100;
.
.
.
/* EEPROM programming specific defines */
#define E1PGM 0
#define E1LAT 1
#define E1ERA 2
#define PROG_TIME 10
.
.
/* some function prototypes */
void delay(unsigned long);
void program(int ,int);
void erase(int );
.
.
.
int EEPROM[0xff] @ 0x101; /* Identify the EEPROM */
void program(int address,int value)
{
EEPROM_CTL.E1LAT=1; /* set the E1LAT bit */
EEPROM[address]=value;/* put the data and address
in place */
EEPROM_CTL.E1PGM=1; /* turn on the charge pump */
delay(PROG_TIME); /* delay programming time */
EEPROM_CTL.E1LAT=0; /* reset the E1LAT also
resets the E1PGM bit */
} /* return when done */
void erase(int x)
{