PIC16F7X
3.3
Reading the FLASH Program
Memory
3.4
Operation During Code Protect
FLASH program memory has its own code protect
mechanism. External Read and Write operations by
programmers are disabled if this mechanism is
enabled.
A program memory location may be read by writing two
bytes of the address to the PMADR and PMADRH reg-
isters and then setting control bit RD (PMCON1<0>).
Once the read control bit is set, the microcontroller will
use the next two instruction cycles to read the data. The
data is available in the PMDATA and PMDATH regis-
ters after the second NOPinstruction. Therefore, it can
be read as two bytes in the following instructions. The
PMDATA and PMDATH registers will hold this value
until the next read operation.
The microcontroller can read and execute instructions
out of the internal FLASH program memory, regardless
of the state of the code protect configuration bits.
EXAMPLE 3-1:
FLASH PROGRAM READ
BSF
BCF
STATUS, RP1
STATUS, RP0
ADDRH, W
PMADRH
ADDRL, W
PMADR
;
; Bank 2
;
MOVF
MOVWF
MOVF
MOVWF
BSF
; MSByte of Program Address to read
;
; LSByte of Program Address to read
; Bank 3 Required
STATUS, RP0
Required
Sequence
BSF
NOP
NOP
PMCON1, RD
; EEPROM Read Sequence
; memory is read in the next two cycles after BSF PMCON1,RD
;
BCF
MOVF
MOVF
STATUS, RP0
PMDATA, W
PMDATH, W
; Bank 2
; W = LSByte of Program PMDATA
; W = MSByte of Program PMDATA
TABLE 3-1:
REGISTERS ASSOCIATED WITH PROGRAM FLASH
Value on:
POR,
BOR
Value on
all other
RESETS
Address
Name
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
10Dh
10Fh
10Ch
10Eh
18Ch
PMADR Address Register Low Byte
PMADRH
PMDATA Data Register Low Byte
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
xxxx xxxx uuuu uuuu
1--- ---0 1--- ---0
—
—
—
Address Register High Byte
PMDATH
PMCON1
—
—
—
Data Register High Byte
(1)
—
—
—
—
—
—
RD
Legend: x= unknown, u= unchanged, r = reserved, -= unimplemented read as '0'. Shaded cells are not used during FLASH access.
Note 1: This bit always reads as a ‘1’.
DS30325B-page 30
2002 Microchip Technology Inc.