#include "c:\miniide\hcs12.inc" org $1000 org $1500 lds #$1500 ; set up stack pointer ; **************************************************************************** ; The following function reprograms a sector in the EEPROM. Index register X ; contains the address of the EEPROM location to be programmed. Y holds the ; address of the first data word. ; **************************************************************************** eesectormodify movb #ACCERR+PVIOL,ESTAT ; clear error flags brclr ESTAT,CBEIF,cantmod ; command buffer not empty movw 0,Y,0,X ; write data to EEPROM address movb #SectorModify,ECMD ; write sector modify command movb #CBEIF,ESTAT ; launch the erase and check command brclr ESTAT,ACCERR+PVIOL,EEModOK cantmod ldab #1 ; return error code 1 rts EEModOK brclr ESTAT,CBEIF,EEModOK ; wait for command buffer to empty movw 2,Y,2,X ; write second data word to 2nd word of EEPROM movb #Program,ECMD ; write program command movb #CBEIF,ESTAT ; launch the program command brclr ESTAT,ACCERR+PVIOL,EEPR2OK ldab #1 rts EEPR2Ok brclr ESTAT,CCIF,EEPR2OK ; wait for program command completion clrb ; successful program code is 0 rts end