Syntax:
DATA DataSetName [as Byte | Word]
// multiples values, strings etc.
0,1,2,3
END DATACommand Availability:
Available on all PIC microcontrollers with DATA memory.
Explanation:
The DATA construct creates an DATA dataset, or DATA block, for use with the specific microcontroller. A DATA dataset, or DATA block, is a list of values that are stored in the PROGMEM memory of the microcontroller, which then can be accessed using the ProgRead() command or other DATA read operations.
The advantage of an DATA dataset, or DATA block, is that they are memory efficient being loaded directly into the DATA during programming operations.
DATA datasets are defined as follows:
- Byte or Word values,
- Multiple numeric elements on a single line separated by commas,
- Constants and calculations within the single line dataset entries are permitted,
- Decimal values are NOT supported,
- Access is via ProgRead().
Defining DATA datasets
Single data values
A single value on each line with in the dataset. The example dataset, shown below, has the data on different line in within the set.
Simple example: This creates an DATA dataset at the first DATA location, then, the values of 12, 24, … 72 are the consecutive values.
DATA EEDataSet as Byte
12
24
36
48
60
72
End DATAMultiple data values of the same line
The following example creates the DATA dataset at DATA offset address of 0x10.
Multiple elements on a single line separated by commas. The example dataset, shown below, has the data separated by , and on different line in within the dataset.
DATA EEDataSource as Byte
12, 24, 36
48, 60, 72
End DATAData values as constants, and, with data transformation
Constants and calculations within the single line. The example dataset, shown below, uses a defined constant to multiple the data with the dataset.
#define calculation_constant 2
DATA EEDataSource as Word
1 * calculation_constant
2 * calculation_constant
3 * calculation_constant
8 * calculation_constant
4 * calculation_constant
5 * calculation_constant
End DATA
Data values as Strings
Strings can be defined. Strings are delimited by double quotes. The following examples show the methods.
Any ASCII characters between any two " " (double quotes) will be converted to dataset data. Also see ASCII escape codes.
A source string can be one string per line or comma separated strings, therefore, on the same line.
Example:
DATA Test_1 as Byte
"ABCDEFGHIJ"
End DATAASCII Escape code
Accepted escape strings are shown in the dataset below.
| Escape sequence | Meaning |
|---|---|
|
\a |
beep |
|
\b |
backspace |
|
\f |
formfeed |
|
\l or \n |
newline |
|
\r |
carriage return |
|
\t |
tab |
|
\0 |
Null value, equates to ASCII 0. Same as \&000 |
|
\&nnn |
ascii char in decimal |
|
\\ |
backslash |
|
\" |
double quote |
|
\' |
single quote |
Maximum Stored Value
The maximum value that can be stored in a single program memory word location across the PIC families you asked about (PIC10, PIC12, PIC14, PIC16, PIC18), formatted as clean markdown:
|
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 > 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, etc. — i.e., the largest number that fits in one program memory word.
Complete working example program
This example creates several DATA datasets. The example also create a lookup table. The DATA dataset are addressed with the additional parameter to ensure there is no DATA dataset overlap.
#chip 16F886
#option explicit
#DEFINE USART_BAUD_RATE 9600
#DEFINE USART_TX_BLOCKING
#DEFINE USART_DELAY OFF
Dim dataaddress, datavalue as Byte
DATA DataSet1 as Byte
3,2,1
End DATA
DATA VersionData as Byte
" PWM2Laser "
" Fabrice ENGEL "
" Version 1.4 "
" November 2023 "
End DATA
For dataaddress = 0 to 2
ProgramRead ( @DataSet1 + dataaddress , datavalue )
HserPrint datavalue
NextFor more help, see ProgramRead, Creating data from a Lookup Table

