15.3.1 NVMREG Read Operation

To read a NVM location using the NVMREG interface, the user must:
  1. Clear the NVMREGS bit if the user intends to access program memory locations, or set NMVREGS if the user intends to access User ID or configuration locations.
  2. Write the desired address into the NVMADRH:NVMADRL register pair.
  3. Set the RD bit to initiate the read.

Once the read control bit is set, the CPU operation is suspended during the read, and resumes immediately after. The data is available in the very next cycle, in the NVMDATH:NVMDATL register pair; therefore, it can be read as two bytes in the following instructions.

NVMDATH:NVMDATL register pair will hold this value until another read or until it is written to by the user.

Upon completion, the RD bit is cleared by hardware.

Figure 15-1. Program Flash Memory Read Sequence

Program Memory read


* This code block will read 1 word of program
* memory at the memory address:
    PROG_ADDR_HI : PROG_ADDR_LO
*   data will be returned in the variables:
*   PROG_DATA_HI, PROG_DATA_LO

   BANKSEL    NVMADRL             ; Select Bank for NVMCON registers
   MOVLW      PROG_ADDR_LO
   MOVWF      NVMADRL             ; Store LSB of address  
   MOVLW      PROG_ADDR_HI
   MOVWF      NVMADRH             ; Store MSB of address

   BCF        NVMCON1,NVMREGS     ; Do not select Configuration Space
   BSF        NVMCON1,RD          ; Initiate read

   MOVF       NVMDATL,W           ; Get LSB of word
   MOVWF      PROG_DATA_LO        ; Store in user location
   MOVF       NVMDATH,W           ; Get MSB of word
   MOVWF      PROG_DATA_HI        ; Store in user location