Erasing the DFM

DFM can be erased by writing 0xFF to all locations in the memory that need to be erased.

DFM Erase Routine

        CLRF    NVMADRL             ; Clear address low byte
        CLRF    NVMADRH             ; Clear address high byte
        MOVLW   31h                 ; EEPROM upper address
        MOVWF   NVMADRU             ; Set address upper byte
        SETF    NVMDAT              ; Load 0xFF to data register
        BCF     INTCON, GIE         ; Disable interrupts
        BSF     NVMCON0, NVMEN      ; Enable NVM
Loop:                               ; Loop to refresh array
        MOVLW   0x55                ; Initiate unlock sequence
        MOVWF   NVMCON2             ;
        MOVLW   0xAA                ;
        MOVWF   NVMCON2             ;
        BSF     NVMCON1, WR         ; Set WR bit to begin write
        BTFSC   NVMCON1, WR         ; Wait for write to complete
        BRA     $-2
        INCFSZ  NVMADRL, F          ; Increment address low byte
        BRA     Loop                ; Not zero, do it again
; The following 4 lines of code are not needed if EEPROM is 256 bytes or less
        INCF    NVMADRH, F          ; Decrement address high byte
        MOVLW   0x03                ; Move 0x03 to working register
        CPFSGT  NVMADRH             ; Compare address high byte with working register
        BRA     Loop                ; Skip if greater than working register
                                    ; Else go back to erase loop
        BCF     NVMCON0, NVMEN      ; Disable NVM
        BSF     INTCON, GIE         ; Enable interrupts