#include "c:\miniide\hcs12.inc" ;Program equ $20 ; program a flash or EEPROM word ;EraseVerify equ $05 ; Erase and verify flash and EEPROM, BLANK bit will be set ;SectorErase equ $40 ; Erase a sector of flash or EEPROM ;BulkErase equ $41 ; Bulk erase the flash or EEPROM ;SectorModify equ $60 ; Erase a sector (4 bytes), program a word (2 bytes) org $1500 lds #$1500 ; set stack pointer ; *************************************************************************************** ; This function program a block of data into the flash memory. The word count, the start ; address of the destination, and the start of the block of data to be program are ; passed in B, X, and Y, r espectively. The caller of this function ; *************************************************************************************** feProgBlok tstb ; check word count bne doFLprog ; word count is valid rts ; return if word count is zero doFLprog pshb ; save the word count in stack fepwait1 brclr FSTAT,CBEIF,fepwait1 ; wait until command buffer is empty movw 2,y+,2,x+ ; write data word to flash address movb #Program,FCMD ; write program command movb #CBEIF,FSTAT ; launch the command brclr FSTAT,ACCERR+PVIOL,progOK ; is there any error? pulb ldab #1 ; return error code 1 rts progOK dec 0,SP ; one word less to be programmed bne fepwait1 ; more words to be programmed pulb clrb ; return error code 0 rts end