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.
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'.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.