![Microchip Technology PIC12F1501 Скачать руководство пользователя страница 16](http://html1.mh-extra.com/html/microchip-technology/pic12f1501/pic12f1501_manual_1785833016.webp)
2011-2015 Microchip Technology Inc.
DS40001609E-page 17
PIC16(L)F1508/9
3.2.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.2.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:
RETLW
INSTRUCTION
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.2.1.2
Indirect Read with FSR
The program memory can be accessed as data by set-
ting bit 7 of the FSRxH register and reading the match-
ing 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 pro-
gram memory via the FSR require one extra instruction
cycle to complete.
demonstrates access-
ing the program memory via an FSR.
The
HIGH
operator will set bit<7> if a label points to a
location in program memory.
EXAMPLE 3-2:
ACCESSING PROGRAM
MEMORY VIA FSR
constants
BRW
;Add Index in W to
;program counter to
;select data
RETLW DATA0
;Index0 data
RETLW DATA1
;Index1 data
RETLW DATA2
RETLW DATA3
my_function
;… LOTS OF CODE…
MOVLW
DATA_INDEX
call constants
;… THE CONSTANT IS IN W
constants
DW DATA0
;First constant
DW DATA1
;Second constant
DW DATA2
DW DATA3
my_function
;… LOTS OF CODE…
MOVLW
DATA_INDEX
ADDLW
LOW constants
MOVWF
FSR1L
MOVLW
HIGH constants;MSb sets
automatically
MOVWF
FSR1H
BTFSC
STATUS, C
;carry from ADDLW?
INCF
FSR1h, f
;yes
MOVIW
0[FSR1]
;THE PROGRAM MEMORY IS IN W
Содержание PIC12F1501
Страница 307: ...PIC16 L F1508 9 DS40001609E page 308 2011 2015 Microchip Technology Inc NOTES...
Страница 392: ...2011 2015 Microchip Technology Inc DS40001609E page 393 PIC16 L F1508 9 1RWH 6 7 7 588 8 7...
Страница 399: ...PIC16 L F1508 9 DS40001609E page 400 2011 2015 Microchip Technology Inc NOTES...