English
Language : 

PIC16F1847_13 Datasheet, PDF (18/440 Pages) Microchip Technology – 18/20/28-Pin Flash Microcontrollers with XLP Technology
PIC16(L)F1847
FIGURE 3-1:
PROGRAM MEMORY MAP
AND STACK FOR
PIC16(L)F1847
PC<14:0>
CALL, RETURN
RETFIE, RETLW
15
Stack (16 Levels)
Reset Vector
0000h
Interrupt Vector
Page 0
Page 1
Page 2
Page 3
Rollover Page 0(1)
0004h
0005h-
07FFh
0800h-
0FFFh
1000h
17FFh
1800h
1FFFh
2000h
Rollover Page 3(1)
7FFFh
Note 1: Reserved. Shadows to 0000h-1FFFh.
3.1.1
READING PROGRAM MEMORY AS
DATA
There are two methods of accessing constants in
program memory. The first method is to use tables of
RETLW instructions. The second method is to set an
FSR to point to the program memory.
3.1.1.1 RETLW Instruction
The RETLW instruction can be used to provide access
to tables of constants. The recommended way to create
such a table is shown in Example 3-1.
EXAMPLE 3-1:
constants
BRW
RETLW DATA0
RETLW DATA1
RETLW DATA2
RETLW DATA3
RETLW INSTRUCTION
;Add Index in W to
;program counter to
;select data
;Index0 data
;Index1 data
my_function
;… LOTS OF CODE…
MOVLW
DATA_INDEX
CALL constants
;… THE CONSTANT IS IN W
The BRW instruction makes this type of table very
simple to implement. If your code must remain portable
with previous generations of microcontrollers, then the
BRW instruction is not available so the older table read
method must be used.
3.1.1.2 Indirect Read with FSR
The program memory can be accessed as data by
setting bit 7 of the FSRxH register and reading the
matching INDFx register. The MOVIW instruction will
place the lower eight bits of the addressed word in the
W register. Writes to the program memory cannot be
performed via the INDF registers. Instructions that
access the program memory via the FSR require one
extra instruction cycle to complete. Example 3-2
demonstrates accessing the program memory via an
FSR.
The HIGH directive will set bit<7> if a label points to a
location in program memory.
EXAMPLE 3-2:
ACCESSING PROGRAM
MEMORY VIA FSR
constants
RETLW DATA0
;Index0 data
RETLW DATA1
;Index1 data
RETLW DATA2
RETLW DATA3
my_function
;… LOTS OF CODE…
MOVLW LOW constants
MOVWF FSR1L
MOVLW HIGH constants
MOVWF FSR1H
MOVIW 0[FSR1]
;THE PROGRAM MEMORY IS IN W
DS40001453D-page 18
Preliminary
 2011-2013 Microchip Technology Inc.