Programming EEPROM

Started by xjmikab November 28, 2002
We would like to know if anyone can help us with the c-code for
programing
the EEPROM of a 9S12DP256 device. I'm using IAR ICC6812 compiler.
The oscillator cristal frekvens is 16 MHz.

Thanks in advance.. Peter and Martin

Below is my function for programming thats not working.

#include "r912dp256.h"

program_2byte_in_EEPROM(char a, char b, char adress_c);

main(void)
{
program_2byte_in_EEPROM(0x11,0x22,0x00);
program_2byte_in_EEPROM(0x33,0x44,0x02);
while(1)
{
;
}
}

void program_2byte_in_EEPROM(char a, char b, char adress_c)
{
char *pointer_c;

if ((ECLKDIV & 0x80) != 1) /* Bit EDIVLD(Clock Divider Loaded) set?
*/
{
ECLKDIV = 0x4A;
/* 0 1 0 0 1 0 1 0 EEPROM Clock Divider Register
| | | | | | | |
| | | | | | | \____ EDIV[0] - Clock Divider
Bits bit 0
| | | | | | \______ EDIV[1] - Clock Divider
Bits bit 1
| | | | | \________ EDIV[2] - Clock Divider
Bits bit 2
| | | | \__________ EDIV[3] - Clock Divider
Bits bit 3
| | | \____________ EDIV[4] - Clock Divider
Bits bit 4
| | \______________ EDIV[5] - Clock Divider
Bits bit 5
| \________________ PRDIV8 - Enable Prescaler
by 8
\__________________ EDIVLD - Clock Divider
Loaded
*/
}

ESTAT &= ~0x20; /* Clear PVIOL(Protection Violation) */
ESTAT &= ~0x10; /* Clear ACCERR(EEPROM Access Error) */
while((ESTAT & 0x80) == 1); /* wait until CBEIF(Command Buffer
Empty Interrupt Flag) clear? */

pointer_c = &E2PROM; /* Point to the first adress in EEPROM.
(=0x800) */
pointer_c += adress_c; /* Add the adress. */

*pointer_c = a;
pointer_c++;
*pointer_c = b;

ECMD = 0x20; /* Program a word (2 byte) */
ESTAT &= ~0x80; /* Clear CBEIF(Command Buffer Empty Interrupt Flag)
*/

while((ESTAT & 0x80) == 1); /* wait until CBEIF(Command Buffer
Empty Interrupt Flag) clear? */
while((ESTAT & 0x40) == 0); /* wait until CCIF(Command Complete
Interrupt Flag) set? */
}