|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
newb assistance - arrays |
Posted: Fri May 19, 2006 4:00 am |
|
|
I'm having something of a problem using an array.
Basically I've got a 7*5 LED matrix and am using a 16f628 to drive it.
I've written out a charector map to display some numbers/letter/symbols and put then in a large array.
the trouble is that the array seems to be giving me some problems, I have about 90 numbers/letters/symbols
but I only seem to be able to make an array that has 51 spaces in it.
Code: | const char c32[51][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00},
{0x....
...
...
}; |
works fine,
yet
Code: | const char c32[96][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00},
{0x....
...
...
}; |
gives the error
Quote: | Error[45] Matrix.c 38 : Subscript out of range
|
I have version 3.099 (which I know is old).
and am using MPLAB as an IDE
I know that I could split the array in half into 2 arrays and set each a different range of charectors, but that seems a little messy so I though I'd make a post here to see if anyone had any suggestions. |
|
|
Ttelmah Guest
|
|
Posted: Fri May 19, 2006 4:31 am |
|
|
The problem is the total size. Constant array accesses on the 16 chips, are done by adding an offset to the program counter, to 'jump' to a RETLW instruction containing the byte required. The maximum offset possible, is 255. 51*5, just fits into this, but 96*5=480, which can't be handled.
This is a hardware limit of the 16 architecture, not something that is fixed in a latter version. It would be possible for the compiler to do multiple arrays, and 'hide' the problem, but it doesn't.
May I suggest a macro like:
#define c32(x,y) (c32##y[x])
Then if you define five 96 element arrays, c320[n]..c324[n], you can access these as 'c32(n,0)'.
The only 'caveat' with the macro version, is that the second digit has to be a constant text character, rather than a variable. Otherwise just have a function to access the five arrays.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|