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 CCS Technical Support

Compiler won't allow array[10][10]

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



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

Compiler won't allow array[10][10]
PostPosted: Sun May 04, 2008 1:40 am     Reply with quote

i have a simple question.....


how can i create a 10x10 byte matrix? my compiler does not allow me to create an array with that size and instead goes into error that says:

NOT ENOUGH RAM AVAILABLE or DATA ITEM TOO BIG

my compiler version is CCS C 4.057....and my PIC is 16F877A...

thanks!
Ttelmah
Guest







PostPosted: Sun May 04, 2008 2:25 am     Reply with quote

On the 16 chips, arrays _must_ fit into a single bank. On the 16F877, there are no 'full size' banks. Instead, it has 96 bytes in the first bank, 80 bytes in the second, and 96 bytes each, in the third and fourth banks. As such, even an array of 100 integers, won't ever fit on this chip.
You need to use two smaller arrays (2*50 byte arrays will potentially fit), or upgrade to a larger chip. If the array contains anything 'larger' than int8 values, the position gets even worse.

Best Wishes
elizabeth ann



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Sun May 04, 2008 2:32 am     Reply with quote

Ttelmah wrote:
On the 16 chips, arrays _must_ fit into a single bank. On the 16F877, there are no 'full size' banks. Instead, it has 96 bytes in the first bank, 80 bytes in the second, and 96 bytes each, in the third and fourth banks. As such, even an array of 100 integers, won't ever fit on this chip.
You need to use two smaller arrays (2*50 byte arrays will potentially fit), or upgrade to a larger chip. If the array contains anything 'larger' than int8 values, the position gets even worse.

Best Wishes


thanks for the immediate response

however we have tried resizing the array into 2X50, the same error still occurs..

on upgrading to a larger chip we fear that we might have problems migrating the code..do you have any idea on how to move the code into a different chip,say PIC18 series?

is it really difficult to migrate the code? never had any experience on this...

thank you...
Ttelmah
Guest







PostPosted: Sun May 04, 2008 4:33 am     Reply with quote

Have you got #device *=16 selected?. If not, the compiler can _only_ access the 96 bytes in the first bank, and then memory will run out very quickly...
If these are arrays of 8bit integers, and you haven't got much else in use, it should work, with two 50 element arrays.

Best Wishes
elizabeth ann



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Sun May 04, 2008 5:10 am     Reply with quote

tried inserting that line:

#device *=16

but still can't create a 2x50-sized array...

how about migrating the code to some PIC18 chip? would that be too troublesome or not at all.............?

thanks!
Ttelmah
Guest







PostPosted: Sun May 04, 2008 7:39 am     Reply with quote

Obviously the ability to create 2* 50 byte arrays, will still depend totally on how much RAM is left. As for migration, it depends completely on how your core is written. If you only use standard CCS functions, then with the header redefined to suit the larger chip, and a few 'extras' (obviously for example, you need to do extra 'setup' commands for any extra peripherals present), translation can be a matter of only a few minutes work. However if you perform your own direct I/O to byte/bit values, or have assembler sections, then these take longer. The 18F4520, is normally a good upgrade route from the 16F877, and also brings the advantage that if you are running off a crystal below 10MHz, you can get an immediate *4 speed gain, by using the H4 fuse as we4ll, to give internal 4* clock multiplication.

Best Wishes
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Sun May 04, 2008 1:43 pm     Reply with quote

Hi i've successfully implemented at least five 10x10 int8 arrays on a 16f877, as constant. Not sure what you wanna do but defining it as constant will write it in internal program flash and be read-only, i used it as an look up table.

Regards

PS. if memory serves me correct i saw an old post regarding the combination of smaller arrays to form one large array, not sure what it was used for but recall a discussion on such a topic.
elizabeth ann



Joined: 16 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Mon May 05, 2008 4:02 am     Reply with quote

really? how come i can't compile a simple code as that? Crying or Very sad Crying or Very sad
it always halts with the same error..

by read-only you do mean that everything is lost on a power failure, am i right? but i need something that is permanent...stays even after power loss, that is. Smile

nevertheless, would you be kind enough to show an example to start with for a newbie like me ? Very Happy thanks!
Matro
Guest







PostPosted: Mon May 05, 2008 4:18 am     Reply with quote

"Read-only" means that the array is ... readable only. You can't write (chage) any value.
You need something non-volatile so you have to use either program memory or EEPROM memory.
The best in your case is probably to use the following method :
Code:

int8 const array_name [10][10] = {0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9,
                                  0,1,2,3,4,5,6,7,8,9};


Matro+
Ttelmah
Guest







PostPosted: Mon May 05, 2008 6:57 am     Reply with quote

Attached below, is a demo program, to show how to access two arrays as if they were one, on this chip. This compiles, works, and only uses just over 30% RAM, on your compiler version. It is setup to use a 20MHz crystal, and output on the serial.
Code:

#include <16F877A.h>
#device adc=8
#device *=16

#FUSES NOWDT,HS,PUT,NOPROTECT,NODEBUG,BROWNOUT,NOLVP,NOCPD,NOWRT

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

int8 array1[5][10];
int8 array2[5][10];

int8 read_array(int x, int y) {
   if (x>4) return (array2[x-5][y]);
   else return (array1[x][y]);
}

void write_array(int x, int y, int val) {
   if (x>4) array2[x-5][y]=val;
   else array1[x][y]=val;
}

void main()
{
   int8 dummy,x,y;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   dummy=0;
   for (x=0;x<10;x++) {
      for (y=0;y<10;y++) {
         write_array(x,y,dummy++);
      }
   }
   for (x=0;x<10;x++) {
      for (y=0;y<10;y++) {
        printf("value at %d,%d is %d\n\r",x,y,read_array(x,y));
      }
   }
   
   while (TRUE) ;     
}


Best Wishes
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Mon May 05, 2008 10:05 am     Reply with quote

Matro has done the honors of supplying the code, this array is stored as hardcoded stuff, always same after power up/ not possible to change during normal program execution. unless you use routine to alter program memory...

Regards
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