Skip to main content
Untitled Document

Large Array

Large Array

Large Array

Introduction

JAL support to type of arrays:
  • 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
The maximum size of the constant data arrays depends on the size of the program memory of the PIC and can at most be 64 kbytes. For an array with variable data there are limitation caused by how a PIC is organized. Data memory in the PIC is stored in banks which are limited in size:
  • 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

In applications that need arrays with the size larger than the bank size of the PIC a library is available. This large array library supports the following:
  • 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

There are four large array libraries present in Jallib so at most four large arrays can be used in one application. The type of array (byte, word, dword) and size are defined using constants. If, for example, library 'large_array_1.jal' is used, the following needs to be defined before including the 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.