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

migrating serial communication code from 16F877A to 18F4620

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



Joined: 12 Jul 2008
Posts: 18
Location: Canada

View user's profile Send private message

PostPosted: Tue Feb 24, 2009 5:43 pm     Reply with quote

I just tried the program without the interrupt and it still doesn't work. Both chips were tested with the same 10MHz crystal. With the picbaud program I noticed the error in the 19200 baud rate is much lower at 40MHz, so I tried running the 18F4620 at that speed. But no luck, the new PIC still refuses to talk to the servo motors.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 24, 2009 7:18 pm     Reply with quote

I finally figured out what your problem is. It's because starting
with vs. 4.021, CCS decided to do pointer arithmetic correctly.
Here's the note from the old versions page:
Quote:

4.021 The & unary operator by default no longer returns a generic (int8 *)


Quote:
int16 angle;

AX_SendByte(*(&angle+1)); //high byte of angle

This code is actually increasing the address by 2 bytes, because 'angle'
is declared as an 'int16'. This is how it works starting with vs. 4.021.

But you just want to get the MSB of 'angle', so you need to cast it to
an int8 pointer before you add 1 to it. Example:
Quote:
AX_SendByte(*((int8 *)&angle+1));

You need to do this everywhere in your code where you're adding 1
to a 16-bit pointer. Be careful, because it's easy to make a mistake
when doing this mod.
Robotan



Joined: 12 Jul 2008
Posts: 18
Location: Canada

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 7:22 am     Reply with quote

Wow, thanks! I being an amateur programmer would never have caught that. I don't fully understand pointer arithmetic, but that method of accessing the high or low byte of an integer was lifted from a CCS code example. It seemed like a more direct way of doing things rather than copying the high and low bytes to new variables before sending them. I use several serial devices, and in each case I find myself having to split up multi byte variables before sending them, and then re-assembling them on the other side. Are there other ways of doing this that I should be aware of?
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