#include "c:\miniide\hcs12.inc" org $1000 org $1500 lds #$1500 ; setup stack pointer ; ****************************************************************************** ; The following function bulk erase the entire flash memory block. Index register ; X contains a word-aligned address within the block to be bulk erased. ; ****************************************************************************** BulkEraseF brset FPROT,FPOPEN+FPHDIS+FPLDIS,doBL ldab #1 ; return error code 1 rts doBL brclr FSTAT,CBEIF,errBL ; bulk erase prohibited if CBEIF == 0 std 0,X ; write any data to sector address movb #BulkErase,FCMD ; write sector erase command movb #CBEIF,FSTAT ; launch the erase command brclr FSTAT,ACCERR+PVIOL,OK2BL ; no error flag? errBL ldab #1 ; return error code of "1" rts OK2BL brclr FSTAT,CCIF,OK2BL ; wait until command is completed ldab #0 ; erase successfully, return code "0" rts end