Hardware Reference
In-Depth Information
Example 14.11
Write a function that performs bulk erasure to the EEPROM. Index register X contains a
word-aligned EEPROM address.
Solution: The assembly function that performs EEPROM bulk erasure is as follows:
bulkeraseEE movb
#ACCERR 1 PVIOL,ESTAT
; clear error flags
brclr
ESTAT,CBEIF,EEBEErr
; command buffer not empty, return
std
0,X
; write any data to EEPROM
movb
#BulkErase,ECMD
; write bulk-erase command
movb
#CBEIF,ESTAT
; launch bulk-erase command
brclr
ESTAT,ACCERR 1 PVIOL,EEBROK ; check error ; no error?
EEBEErr
ldab
#1
; error code set to 1
rts
EEBROK
brclr
ESTAT,CCIF,EEBROK
; wait until command completion
clrb
rts
The C language version of the function is straightforward and hence is left as an exercise.
Example 14.12
Write a function that bulk-erases the EEPROM and verifies if the whole EEPROM is blank.
The index register X contains a valid word-aligned address to the EEPROM.
Solution: The assembly function that performs the specified operation is as follows:
eeraseverify movb
#ACCERR 1 PVIOL,ESTAT
; clear error flags
brclr
ESTAT,CBEIF,cantEE
; command buffer not empty
std
0,x
; write any data to EEPROM address
movb
#EraseVerify,ECMD
; write the command
movb
#CBEIF,ESTAT
; launch the erase and check command
brclr
ESTAT,ACCERR 1 PVIOL,EEEVOK
ldab
#1
; return error code 1
rts
EEEVOK
brclr
ESTAT,CCIF,EEEVOK
; wait until command is done
brset
ESTAT,BLANK,EVEOK
; successful erase and verify?
cantEE
ldab
#1
; EEPROM is not blank
rts
EVEOK
clrb
rts
The C language version of the function is straightforward and is left as an exercise.
Example 14.13
Write a function that programs a word to the EEPROM. X contains the address of
the EEPROM location to be programmed, and double accumulator D holds the data to be
Search WWH ::




Custom Search