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

addition format

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







addition format
PostPosted: Tue Feb 07, 2006 2:51 pm     Reply with quote

Hi
I have this configuration in eeprom (18f458)
Code:

............
#define  EEPROM_INT  #ROM 0x00F00000
............
#define SOGLIA1      0x22
#define EUR_GET1   SOGLIA1+9
#define SOGLIA2    SOGLIA1+15
#define EUR_GET2   SOGLIA2+9
#define SOGLIA3    SOGLIA2+15
#define EUR_GET3   SOGLIA3+9
#define RESULT        0x80
EEPROM_INT+SOGLIA1 = {"       0"}
EEPROM_INT+EUR_GET1 = {" 0,05"} //** in hex 0x20 0x30 0x2C 0x30 0x35
EEPROM_INT+SOGLIA2 = {"       0"}
EEPROM_INT+EUR_GET2 = {" 1,00"}
EEPROM_INT+SOGLIA3 = {"       0"}
EEPROM_INT+EUR_GET3 = {" 2,10"}
............
static float fAdd;  // (RAM) is ok float?


How I can add EUR_GET1 + EUR_GET2 + EUR_GET3 and put the result in fAdd and with the same format ** in RESULT (eeprom_int)?

Thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Feb 07, 2006 4:32 pm     Reply with quote

First a remark: are you sure you want to use float variables? Floating point arithmetic has the disadvantage of requiring a lot of program memory space and you will create strange rounding errors like '1 + 1 = 1.99999999'.
There is another technique that doesn't have these problems, it is called 'scaled integers'. With this technique you are always calculating in integers which is much easier to the processor. For your problem this means you are not going to calculate in Euro's but in Euro cents, only at the times you are showing the result to the user you are adding the decimal point to the output.

Another suggestion to make life easier on yourself is by not storing the values in EEPROM as a text string but as integer values. Only do the conversion to text strings when showing the results to the user.
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