Large Array
Introduction
- Arrays with constant data. Data is stored in program memory of the PIC
- Arrays with variable data. Data is stored in data memory of the PIC
- For PIC12F and PIC16F, banks are 80 bytes
- For PIC18F banks are 256 bytes
The total data memory of a PIC is a total of all banks that are present in the PIC.
Working with large data arrays
- For controllers with PIC14 core (labeled PIC16(l)f... or
PIC12(l)f...)
- Supports byte array with up to 4800 entries
- Supports word array with up to 2400 entries
- Supports dword array with up to 1200 entries
- For controllers with PIC16 core (labeled PIC18(l)f...)
- Supports byte array with up to 14848 entries
- Supports word array with up to 7424 entries
- Supports dword array with up to 3712 entries
The total size of a large array cannot be larger than the available - remaining - data memory. The JAL compiler will generate an error when the program runs out of data memory.
Defining the large array library
- const LARGE_ARRAY_1_SIZE defining the number of entries in the array
- const LARGE_ARRAY_1_VARIABLE_SIZE defining the
type of array, where:
- A value of 1 gives a byte array
- A value of 2 gives a word array
- A value of 3 gives a dword array
Unlike the standard arrays in JAL, there is no range checking available for large arrays. This means that when an entry is written which lies outside of the maximum size of the array, the user is not warned. So the user has to be extra careful to make sure this does not happen since it may result in unwanted side effects.
Using a large array in your application
The following - part of a - sample program shows how to include the array in your application. Usage of the array is the same as the use of a standard array of the JAL programming language. In this example we skip the include of the device file the pragmas and other libraries. Instead we focus only on the definition and use of the large array. Here we use large array 4.
-- Setup the large array const LARGE_ARRAY_4_SIZE = 400 -- choose number of array variables const LARGE_ARRAY_4_VARIABLE_SIZE = 4 -- choose size of variables (byte*4) include large_array_4 -- include the array library alias test is large_array_4 -- rename/alias the array to test
Now we store some data and print it the computer.
-- store some values test[50] = 0x1111_1111 test[200] = 0x2222_2222 test[26] = 0x3333_3333 test[27] = 0x4444_4444 test[00] = 0x5555_5555 -- This is the first byte of the array. test[57] = 0x6666_6666 test[300] = 0x7777_7777 test[LARGE_ARRAY_4_SIZE - 1] = 0x8888_8888 -- This is the last byte of the array. -- read some values and print them print_dword_hex(serial, test[50]) print_dword_hex(serial, test[200]) print_dword_hex(serial, test[26]) print_dword_hex(serial, test[27]) print_dword_hex(serial, test[00]) print_dword_hex(serial, test[57]) print_dword_hex(serial, test[300]) print_dword_hex(serial, test[LARGE_ARRAY_4_SIZE - 1])
There output printed to the serial port should look something like this:
There are many large array sample files in the Jallib sample directory.