AN2400 Freescale Semiconductor / Motorola, AN2400 Datasheet - Page 38

no-image

AN2400

Manufacturer Part Number
AN2400
Description
HCS12 NVM Guidelines
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2400/D
EEPROM Sector
Erase Command
38
ESTAT.byte = ACCERR|PVIOL;
if(ESTAT.bit.cbeif == 1)
{
}
else
{
}
if((ESTAT.byte & (ACCERR|PVIOL))!= 0)
*sectorAddr = dummy;
ECMD.byte = ERASE;
ESTAT.byte = CBEIF;
{
}
while(ESTAT.bit.ccif != 1)
{
}
return(PASS);
return(FAIL);
return(FAIL);
The following code segment demonstrates how to erase a sector (4 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 sector to be erased
must not be protected, the EEPROM address must be word aligned (bit 0 = 0).
Registers: X contains word aligned EEPROM address within sector to be
erased.
Stack Pointer
C function local variables: UINT16* sectorAddr, UINT16 dummy.
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,eesef Check command buffer is empty
STD
MOVB
MOVB
BRSET $115,#$30,eesef Command failed if either error flag set
BRCLR $115,#$40,*+0
CLRB
BRA
eesef:
LDAB
eesertn:
RTS
Go to: www.freescale.com
HCS12 NVM Guidelines
return address.
eesertn
#$30,$115
0,X
#$40,$116
#$80,$115
#1
Clear error flags
Write any data to EEPROM sector address
Write sector erase 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’
MOTOROLA

Related parts for AN2400