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 support@ccsinfo.com

2 lines of code greedy on ROM

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



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

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

2 lines of code greedy on ROM
PostPosted: Fri Oct 09, 2009 10:45 pm     Reply with quote

Pic 16f716

Before adding these 2 lines ROm usage is 78%

Code:

dist=dist + (atof(temp)/3600);
printf("%1.2fkm  ", dist);
 


After "Out of ROM" Error mesage.

How can I fix this? Any help appreciated.
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 09, 2009 11:46 pm     Reply with quote

Floating point code takes up a lot of space. Stick to integer math wherever possible.

From the code you've given, you're only needing to track distance in kilometers to 2 decimal places, i.e. to 10m. So count in multiples of 10m.
Code:
dist = dist + temp / 36;
printf("%ld0m", dist);

There are other things to try. You could shift the "/36" to the printf to maintain precision. You could print to a buffer (see sprintf), allowing you to shuffle characters around and insert a decimal place for kms before displaying.
_________________
Andrew
uni_student



Joined: 01 Aug 2007
Posts: 38
Location: AUckland, NEW ZEALAND

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

PostPosted: Sat Oct 10, 2009 12:18 am     Reply with quote

andrewg

I used a less precise measurement in conjunction with atoi instead of atof which has certainly fixed the problem.

Cheers
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