6.4.1 NVMREG Read Operation

To read an NVM location using the NVMREG interface, the user must:
  1. Clear the NVMREGS bit of the NVMCON1 register if the user intends to access program memory locations, or set NMVREGS if the user intends to access User ID, EEPROM, or configuration locations.
  2. Write the desired address into the NVMADRH:NVMADRL register pair.
  3. Set the RD bit of the NVMCON1 register 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.

The 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 6-1. Flash Program Memory Read Flowchart

Program Memory Read

* This code block will read one 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