View previous topic :: View next topic |
Author |
Message |
DonWare
Joined: 18 Jan 2006 Posts: 43
|
Struct problem |
Posted: Fri Jul 13, 2007 1:33 pm |
|
|
Hi, I'm having trouble defining a struct. The code below compiles OK but complains about subscript range errors if I increase the numbers to ~10 or more. I'm using a PIC16F877.
struct setup{
int8 pname[5];
int8 seq_cnt;
int8 sname[5];
int8 sdata[5];
}MyData[5];
I didn't do the math but is it really just purely an 'out of memory' problem ?
Also, hows does using a 'union' differ. I can't find much into on it within CCS.
Thanks. Don |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 13, 2007 1:39 pm |
|
|
In a 16F877, the largest available block of user RAM within a single RAM
bank is 96 bytes. A structure must contained within one RAM bank.
It can't span two or more banks. That's the reason for the error message.
To remove this limitation, use an 18F PIC with the PCH compiler. |
|
|
DonWare
Joined: 18 Jan 2006 Posts: 43
|
|
Posted: Fri Jul 13, 2007 2:47 pm |
|
|
OK thanks. That example I gave only totaled 80 bytes (I think). But I'll keep it in mind.
Don |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 13, 2007 3:03 pm |
|
|
Right, but you said the problem was not with the posted structure, but
rather with another one (not shown) that had the array size(s) increased
to 10. If you still have a problem, post the structure that is causing the
error. |
|
|
ferdem Guest
|
|
Posted: Wed Aug 27, 2008 5:01 am |
|
|
PCM programmer wrote: | To remove this limitation, use an 18F PIC with the PCH compiler. |
I have 18F4520 and I want to span banks to use large arrays. How can i do this in CCS? I have searched the word "RAM" in CCS C help and i have read almost all results but i couldnt find releated subject. Thanks |
|
|
Ttelmah Guest
|
|
Posted: Wed Aug 27, 2008 10:19 am |
|
|
Just define the array.
On the 18 chips, the limit is the amount of RAM you have available.
On the original question, regarding the 'union', this is a way of making _two_ (or more) different 'types' of variable use the same memory area. So if (for instance), you create a union as:
Code: |
union {
int8 b[4];
float f;
} val;
|
Then 'val.f' is a floating point variable, and val.b[0] to val.b[3] are four int8 variables _stored in the same area of memory_. You can then write a float into the area, and read it out as bytes, or vice versa.
Best Wishes |
|
|
|