The DFM does not support the Erase Page operation. However, the DFM can be erased by writing 0xFF to all locations in the memory that need to be erased.
CLRF NVMADRL ; Clear address low byte
CLRF NVMADRH ; Clear address high byte
MOVLW 0x31 ; DFM upper address
MOVWF NVMADRU ; Set address upper byte
SETF NVMDATL ; Load 0xFF to the data register
BCF INTCON0, GIE ; Disable interrupts
MOVLW 0x04 ; write with post increment command
MOVWF NVMCON1
Loop: ; Loop to refresh array
; –––-- Required Sequence –––––––––––-
MOVLW 0x55 ; Initiate unlock sequence
MOVWF NVMLOCK
MOVLW 0xAA
MOVWF NVMLOCK
BSF NVMCON0, GO ; Set GO bit to begin write
; ––––––––––––––––––––––––––-–––––––––––-
BTFSC NVMCON0, GO ; Wait for write to complete
BRA $-2
MOVF NVMADRL, F ; test address low byte
BTFSS STATUS,Z
BRA Loop ; Not zero, do it again
; The following 4 lines of code are not needed if DFM is 256 bytes or less
MOVLW 0x03 ; Move 0x03 to working register
CPFSGT NVMADRH ; Compare address high byte with working register
BRA Loop ; Skip when high address exceeds DFM range
; Else go back to erase loop
CLRF NVMCON1 ; Disable writes
BSF INTCON0, GIE ; Enable interrupts