CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

newb assistance - arrays

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








newb assistance - arrays
PostPosted: Fri May 19, 2006 4:00 am     Reply with quote

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







PostPosted: Fri May 19, 2006 4:31 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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