Go to Post I know that it's often dangerous to use common sense in a YMTC thread... - Kris Verdeyen [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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,521
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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pic: Feeling a bit Blue Steve W Extra Discussion 3 28-10-2007 23:54
pic: A "Bit" of a problem. Herodotus Extra Discussion 26 11-10-2007 01:53
16 bit math on PIC sciguy125 Programming 17 07-10-2005 02:57
integer division ImmortalAres Programming 5 11-07-2005 21:19
Integer Number powercat Programming 2 18-02-2003 11:26


All times are GMT -5. The time now is 19:26.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi