PIC12F1516 MICROCHIP [Microchip Technology], PIC12F1516 Datasheet - Page 23

no-image

PIC12F1516

Manufacturer Part Number
PIC12F1516
Description
28/40/44-Pin Flash Microcontrollers with nanoWatt XLP Technology
Manufacturer
MICROCHIP [Microchip Technology]
Datasheet
3.1.1
There are two methods of accessing constants in pro-
gram 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
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:
The BRW instruction makes this type of table very sim-
ple 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
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 8 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.
ing the program memory via an FSR.
The HIGH directive will set bit<7> if a label points to a
location in program memory.
 2011 Microchip Technology Inc.
constants
my_function
BRW
RETLW DATA0
RETLW DATA1
RETLW DATA2
RETLW DATA3
;… LOTS OF CODE…
MOVLW
CALL constants
;… THE CONSTANT IS IN W
READING PROGRAM MEMORY AS
DATA
RETLW Instruction
Indirect Read with FSR
DATA_INDEX
Example 3-2
RETLW INSTRUCTION
Example
;Add Index in W to
;program counter to
;select data
;Index0 data
;Index1 data
demonstrates access-
3-1.
Preliminary
EXAMPLE 3-2:
constants
my_function
;THE PROGRAM MEMORY IS IN W
PIC16(L)F1516/7/8/9
RETLW DATA0
RETLW DATA1
RETLW DATA2
RETLW DATA3
;… LOTS OF CODE…
MOVLW
MOVWF
MOVLW
MOVWF
MOVIW 0[FSR1]
LOW constants
FSR1L
HIGH constants
FSR1H
ACCESSING PROGRAM
MEMORY VIA FSR
;Index0 data
;Index1 data
DS41452B-page 23

Related parts for PIC12F1516