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

Struct problem

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



Joined: 18 Jan 2006
Posts: 43

View user's profile Send private message

Struct problem
PostPosted: Fri Jul 13, 2007 1:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 13, 2007 1:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 13, 2007 2:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 13, 2007 3:03 pm     Reply with quote

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







PostPosted: Wed Aug 27, 2008 5:01 am     Reply with quote

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







PostPosted: Wed Aug 27, 2008 10:19 am     Reply with quote

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
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