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

pointer error on PIC18F452

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



Joined: 19 Nov 2005
Posts: 5
Location: Devon, England

View user's profile Send private message Send e-mail

pointer error on PIC18F452
PostPosted: Sat Nov 19, 2005 4:55 am     Reply with quote

Hi There.

New user, so may be lacking in forum etiquette.

I have a problem with a pointer using CCS compiler 3.163 and PIC18F452.
We are using the Progressive Learning Resources code for SD/MMC control.

In that code a pointer is delared char* fp->fpntr;

Later the pointer is incremented to point inside a 512 byte buffer.
After 2 days of digging deeper and deeper into the code I find that the statement fp->fpntr++; works fine until 0x2ff when it rolls over to 0x200 not 0x300 !! This then points to another area of memory and trashes everything.

Is this a known compiler problem?
Aren't all PIC18F pointers 16-bit ? I tried #device *=16 but made no difference

I considered upgrading the compiler, but am waiting for DSPIC suport. Does anyone know if I am better or worse off to upgrade compiler now and then upgrade to DSPIC later or should I wait and do it all inone go?

Thanks for any help.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: pointer error on PIC18F452
PostPosted: Sat Nov 19, 2005 12:29 pm     Reply with quote

vetinaspin wrote:
char* fp->fpntr;
fp->fpntr++; works fine until 0x2ff when it rolls over to 0x200 not 0x300 !!


Why did you declare the pointer variable as a Char? Thats only a byte. Your not trying to point to a byte your trying to point to an address.For more than 256 addresses you need the pointer to be 2 bytes. I seldom seen the use of -> in embeded code. You can reach any RAM address with a 16bit pointer.
vetinaspin



Joined: 19 Nov 2005
Posts: 5
Location: Devon, England

View user's profile Send private message Send e-mail

Re: pointer error on PIC18F452
PostPosted: Sun Nov 20, 2005 10:15 am     Reply with quote

Hi Neutone

Thanks for your reply.

Quote:
Why did you declare the pointer variable as a Char? Thats only a byte.


I didn't. That's the code from Progressive Learning. Anyway shouldn't all pointers be 16 bit by default? - but they need to know whether they are pointing to an 8-bit, 16-bit or 32-bit value, so I think the declaration is valid. Despite that, I did try changing the code to a 16-bit value, with no effect.

Quote:
Your not trying to point to a byte your trying to point to an address.

But it's a 16-bit pointer, pointing to an 8-bit value.
Quote:
For more than 256 addresses you need the pointer to be 2 bytes.


My point (excuse the pun) is that I thought the compiler determined the pointer size, not the declaration, or have I got this horribly wrong? If I have an array of char starting at say, location 0x300 (determined by the compiler) I would declare this as char my_array[10] = "ABCDEFGHI" or char* my_array; and then populate my_array. But my_array would be the address which would be 16-bit, and my_array+3 would be 0x303 which would point to "D".
If I dereference the pointer by e.g. x = *my_array then x will be "A", an 8-bit value as this was the original declaration type.

I'll go back and look at their code again to see if I can find the error.
I wondered if anybody else had come across this with CCS version 3.163?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: pointer error on PIC18F452
PostPosted: Sun Nov 20, 2005 10:21 am     Reply with quote

vetinaspin wrote:

I considered upgrading the compiler, but am waiting for DSPIC suport. Does anyone know if I am better or worse off to upgrade compiler now and then upgrade to DSPIC later or should I wait and do it all inone go?


I doubt very seriously that upgrading is going to get you dspic support. That will be another compiler. CCS already has PCB, PCM, PCH for the different PICs so it seems to reason they would have a separate one for the DSPIC.


As for your problem, post a small test program showing the error.
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