![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
markleman Guest
|
Array of more the 256 bytes not accessed properly by index v |
Posted: Thu Apr 10, 2003 7:34 am |
|
|
<font face="Courier New" size=-1>I have an array of 512 constant bytes, accessing this using a variable as the index fails for index values of >255. Works if the index is constant but then that’s probably the compiler optimising the look up out. Compiler = PCM Version 3.105
Any thoughts?
Mark Leman
#include<16c711.h>
#device *=16 // use 16 bit pointers
const unsigned int8 ConvertTable[]=
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, // 00-0F
....480 more values....
0xFC, 0xFC, 0xFC, 0xFD, 0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF //1f0-1FF
};
main()
{
long i = 0xaabb; // fill with random value
int c = 0xcc; // fill with random value
c= ConvertTable[0x0080]; //works
i=0x0080;
c = ConvertTable[i]; //works
c= ConvertTable[0x00ff]; //works
i= 0x00ff; // test 8 bit index limit, works
c = ConvertTable[i];
c= ConvertTable[0x0100]; //works
i = 0x0100; //fails - fetches value at index 0x0000
c = ConvertTable[i];
c= ConvertTable[0x1aa]; //works
i = 0x01aa;
c = ConvertTable[i]; // fails - fetches value at index 0x00aa
while (1)
{
output_high(PIN_B0);
output_low(PIN_B0);
}
}</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13576 |
|
![](templates/subSilver/images/spacer.gif) |
markleman Guest
|
And the answer is..... |
Posted: Thu Apr 10, 2003 9:02 am |
|
|
Having spoken to CCS support, the CCS C compiler is unable to use constant tables bigger than 256 bytes with the PIC16xx family.
I solved my problem by splitting the 512 byte table in to two halves and selecting a byte from one or other using an IF statement on the high index byte. For larger tables a switch on the high index byte could be used.
Pity the compiler (PCM C Compiler, Version 3.105) did not produce an error message (only faulty code) and the only mention of this restriction in the manual is on P.167 :
"Subscript out of range. A subscript to a RAM array must be at least 1 and not more than 128 elements. Note that large arrays might not fit in a bank. ROM arrays may not occupy more than 256 locations."
Still problem solved and answer shared....
Mark Leman
___________________________
This message was ported from CCS's old forum
Original Post ID: 13580 |
|
![](templates/subSilver/images/spacer.gif) |
Mother Guest
|
Re: Array of more the 256 bytes not accessed properly by ind |
Posted: Thu Apr 10, 2003 9:02 am |
|
|
Maybe this is re-visiting stuff you've tried, but what happens with something like this?
i = 0x00ff;
i += 1;
c = ConvertTable[i];
This should prove whether its the assignment or the indexing arithmetic that's the problem.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13581 |
|
![](templates/subSilver/images/spacer.gif) |
Yashu Guest
|
The daily double... |
Posted: Fri Apr 11, 2003 10:00 pm |
|
|
:=Having spoken to CCS support, the CCS C compiler is unable to use constant tables bigger than 256 bytes with the PIC16xx family.
:=
:=I solved my problem by splitting the 512 byte table in to two halves and selecting a byte from one or other using an IF statement on the high index byte. For larger tables a switch on the high index byte could be used.
:=
:=Pity the compiler (PCM C Compiler, Version 3.105) did not produce an error message (only faulty code) and the only mention of this restriction in the manual is on P.167 :
:=
:="Subscript out of range. A subscript to a RAM array must be at least 1 and not more than 128 elements. Note that large arrays might not fit in a bank. ROM arrays may not occupy more than 256 locations."
:=
:=Still problem solved and answer shared....
:=
:=Mark Leman
___________________________
This message was ported from CCS's old forum
Original Post ID: 13625 |
|
![](templates/subSilver/images/spacer.gif) |
Thomas Blake Guest
|
Re: And the answer is..... |
Posted: Tue Apr 15, 2003 12:38 pm |
|
|
Well, it helped me anyhow ... I was under the impression that both RAM and ROM were limited to 128 ....
:=
:="Subscript out of range. A subscript to a RAM array must be at least 1 and not more than 128 elements. Note that large arrays might not fit in a bank. ROM arrays may not occupy more than 256 locations."
___________________________
This message was ported from CCS's old forum
Original Post ID: 13694 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|