Syntax:
ProgramRead (location, store) or for the 18FxxQ41 family of chips use: PFMRead (location, store)
Command Availability:
Available on all Microchip PIC microcontrollers with self-write capability. Not currently available on Atmel AVR.
Explanation:
ProgramRead reads information from the program memory on chips that support this feature. location and store are both word variables, meaning that they can store values over 255.
The largest value possible for location depends on the amount of program memory on the Microchip PIC microcontroller, given in the datasheet. The range of store is explained in the next section.
Maximum Stored Value
The maximum value that can be stored in a single program-memory word location across the PIC families:
|
Family |
Instruction Word Size |
Program Memory Word Width |
Maximum Value per Word (unsigned decimal) |
Hex Range |
Can store full 16-bit value (0-65535) in one word? |
|
PIC10 |
12-bit |
12 bits |
4095 |
0x000 - 0xFFF |
No |
|
PIC12 (baseline) |
12-bit |
12 bits |
4095 |
0x000 - 0xFFF |
No |
|
PIC12 (enhanced mid-range) |
14-bit |
14 bits |
16383 |
0x0000 - 0x3FFF |
No |
|
PIC14 |
14-bit |
14 bits |
16383 |
0x0000 - 0x3FFF |
No |
|
PIC16 (mid-range) |
14-bit |
14 bits |
16383 |
0x0000 - 0x3FFF |
No |
|
PIC16 (enhanced mid-range) |
14-bit |
14 bits |
16383 |
0x0000 - 0x3FFF |
No |
|
PIC18 |
16-bit |
16 bits |
65535 |
0x0000 - 0xFFFF |
Yes |
Quick Summary Table (Most Common Cases)
|
Family group |
Typical word size |
Max value you can store in one program memory word |
Equivalent to storing a full 16-bit number? |
|
PIC10 / baseline PIC12 |
12 bits |
4095 (0xFFF) |
No |
|
PIC14 / PIC16 / enhanced PIC12 |
14 bits |
16383 (0x3FFF) |
No |
|
PIC18 |
16 bits |
65535 (0xFFFF) |
Yes |
Important Notes
- PIC18 is the only 8-bit PIC family where you can directly store any 16-bit value (0-0xFFFF) in a single program-memory word location.
- On all earlier families (PIC10, PIC12 baseline, PIC14, PIC16, enhanced mid-range), you must split any value greater than 0x3FFF (16383) across two words if you need the full 16-bit range.
- The values above apply when storing constants, lookup table entries,
retlwliterals,data/dbdirectives, and so on — that is, the largest number that fits in one program-memory word.
Addressing Notes
- PIC18F family:
locationis a byte address (TBLPTR is byte-oriented). For reading 16-bit words,locationmust be even (the word starts on an even byte boundary). Reading odd locations may return misaligned or garbage data. - Non-18F families (mid-range, baseline):
locationis a word address (consecutive integers indexing 12/14-bit words). - Special variant: on some newer chips (e.g., 18FxxQ41 family), use
PFMRead (location, store)instead.
See DATA for examples of storing and reading byte/word values in program memory.
Example:
#chip 18F26K22, 16
Dim ReadLocation As Word
Dim ReadValue As Word
ReadLocation = 0x1000
ProgramRead ( ReadLocation, ReadValue ) ' <<< the ProgramRead instruction
HSerPrint ReadValueKey line: ProgramRead ( ReadLocation, ReadValue ) — reads the program-memory word at ReadLocation back into ReadValue.
See Also:
- ProgramErase — erasing a block before writing to it
- ProgramWrite — writing the value this page reads back
- PFMRead — the equivalent command on 18FxxQ41-family chips
- DATA — defining fixed program-memory datasets

