View Single Post
  #4   Spotlight this post!  
Unread 20-06-2008, 12:03
Ian Curtis Ian Curtis is offline
Best Available Data
FRC #1778 (Chill Out!)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Puget Sound
Posts: 2,520
Ian Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond repute
Re: Displaying a 16 bit integer on PIC 16F877?

Quote:
Originally Posted by Joe Ross View Post
More important then knowing the type of PIC is what compiler you are using.

In C18 %ld prints in hex and expects a long (32 bits) while an int is 16 bits
In a compiler for your computer, both an int and a long are 32 bits, and both %d and %ld would print the same thing with both.

Other compilers (especially embedded compilers) will all have small variations like that, that you can only learn about by reading the manual.
I'm using CCS. I ended up solving it by making all of the variables 32 bit integers, which obviously isn't the best solution. I think the problem came when I was doing 8 bit integer math and then set the result equal to a 32 or 16 bit integer. Is there a way to go about doing that?

The piece of code in question was:

angle=angle+instant

Originally, angle was 16 bit integer, and instant was an 8 bit integer. But I couldn't get a useful number, so I changed angle to a 32 bit integer, which I knew I had the syntax right, but it was still a funny number. After I changed instant to a 32 bit number it worked fine. I think I probably have to cast it somehow, but I don't really have a grasp on what casting exactly does, and why it works.
__________________
CHILL OUT! | Aero Stability & Control Engineer
Adam Savage's Obsessions (TED Talk) (Part 2)
It is much easier to call someone else a genius than admit to yourself that you are lazy. - Dave Gingery