Quote:
Originally Posted by Joe Ross
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.