Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to read and write float values in eeprom

Status
Not open for further replies.

mshh

Full Member level 6
Joined
May 30, 2010
Messages
349
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
usa
Activity points
3,871
I want to write float values inn eeprom and read it using codevision,need help to start.
 

I do not have Codevision but I believe it is a standard 'C' compiler.

1. Find out how many bytes it takes to store a floating point number. (probably 4 or 6 bytes)
2. create a union containing the floating point number and single bytes.

As the union shares the same memory addresses as the individual bytes, writing the float value to the union will allow you to read and store it in EEPROM as individual 8-bit values.
This should give you the idea:
Code:
union
{
    float FloatValue;
    char SingleBytes[4];
}un;
Storing the floating point number to un.FloatValue will let you read it's individual bytes as un.SingleBytes[0] to un.SingleBytes[3]. Change the '4' to whatever size Codevision uses to store floating point values. In the same way, if you write to the 'SingleBytes' storage you can read it as 'FloatValue'.

Brian.
 

With the exception of the case of handling internal parameters for math computing (eg. update constants of a digital filter) if the goal is to store a value which represents a measured physical quantity, in that case it would be more plausible to scale the value to an integer/long and then to store it in a raw byte structure, as Brian mentioned.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top