AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 37

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
EEPROM Program
and Erase Routines
EEPROM Program
Command
ESTAT.byte = ACCERR|PVIOL;
if(ESTAT.bit.cbeif == 1)
{
}
else
{
}
MOTOROLA
*progAddr = data;
ECMD.byte = PROG;
ESTAT.byte = CBEIF;
if((ESTAT.byte & (ACCERR|PVIOL))!= 0)
{
}
while(ESTAT.bit.ccif != 1)
{
}
return(PASS);
return(FAIL);
return(FAIL);
The following code segment demonstrates how to program a word (2 bytes) of
EEPROM.
The leftmost column contains C code (variable definitions in
Variable
assuming the register base address is $0000, and the rightmost column
contains comments.
Prerequisites: ECLKDIV must be configured correctly, the EEPROM word to be
programmed must be erased and not protected, the EEPROM address must
be word aligned (bit 0 = 0).
Registers: X contains word aligned EEPROM address to be programmed, D
contains new data value.
Stack Pointer
C function local variables: UINT16* progAddr, UINT16 data.
On return, accumulator B contains 0 if the command executed correctly, or 1 if
the command failed.
Freescale Semiconductor, Inc.
For More Information On This Product,
Definitions), the centre column contains equivalent assembly code
MOVB
BRCLR $115,#$80,eepwf Check command buffer is empty
STD
MOVB
MOVB
BRSET $115,#$30,eepwf Command failed if either error flag set
BRCLR $115,#$40,*+0
CLRB
BRA
eepwf:
LDAB
eepwrtn:
RTS
Go to: www.freescale.com
HCS12 NVM Guidelines
return address.
eepwrtn
#$30,$115
0,X
#$20,$116
#$80,$115
#1
Clear error flags
Write data to EEPROM aligned word address
Write program command
Write '1' to CBEIF to launch the command
Wait for command to finish: this is
optional, but the EEPROM cannot be
accessed until CCIF is set.
Successful, return
Fail, return
Appendix A ‘C’
AN2400/D
EEPROM
37

Related parts for AN2400