You need to convert your number to a floating point number first, then save it using the code that Erik posted or something similar. Floating point numbers are represented as a long in memory with the first bit set.
You need to know what 123.456 actually is. If it is a floating point number, it occupies 4 bytes. You have 2 options to writing it to eeprom. First is to write 4 bytes, that is the floating point number. The other is to convert it to a string representation and then write the string, 8 bytes with a $00 byte added to terminate the string. If this is data you pulled off the GPS, it may already be a string.
Another way to do it is to use BCD encoding where each digit is 4 bits, or 2 numbers per byte. Valid digits are 0-9, you can encode the decimal point as one of the unused values (say $A), then to indicate the end of the number you can use another unused value (like $F). This scheme maintains the simplicity of strings but encodes it at double the density. The number 123.456 would be stored as $12, $3A, $45, $6F.
You can go even fancier by assigning other unused values, like - to $B and E to $E. So a scientific number like -1.74E-6 would be $B1, $A7, $4E, $B6, $F0. The last digit is a "don't care", it's just padding to make the number take 8 bits.
I hate to be noobish, but I'm still a little confused. Anyone want to hold my hand through it using basic_i2c_driver and the example value 123.456? (Thanks to everyone who has posted above, I certainly don't mean to say that you haven't been helpful).
You haven't said yet what form the number is in. Is it a string of characters? If so, what marks the end of the string. Is there a zero byte or carriage return (13) or do you have a known length for the string? Is it a floating point number (stored in a long)? First you have to specify what you have, then we can suggest a way to get it copied to an EEPROM.
In that case, the value fits in a long variable and you can use the read/write long methods in the Basic_I2C_Driver. I don't have a copy of the driver handy, but you'll see simplified read/write routines for words and longs. Important things to remember:
1) The 4 bytes of the long have to fit in an EEPROM "page". The best way to do this is simply to require the EEPROM address to be a multiple of 4.
2) A write operation takes roughly 5ms. You can put in a 5ms wait like WAITCNT(CLKFREQ/200+CNT) or you can use the test for completion of the write that's shown in the comments at the beginning of the driver.
3) The pin # of the SCL signal can be specified separately or combined with the EEPROM address as described in the comments. The pin # of the SDA signal is always the next pin.
Var
LONG GPS_DATA
Obj
EEPROM : "BS2_Function"
Pub Main
EEprom.Start(31,30)
GPS_DATA := 123.325
StoreEEProm
Pub StoreEEProm
'Write_HighMem(address, value, size) This will write to the Variable called GPS_DAta to an address
EEprom.Write_HighMem(10,GPS_DATA , 4)
Post Edited (grasshopper) : 1/7/2009 8:47:20 PM GMT
Comments
The above examples require some modification when used with James code. In my code the 8 stands for the number of bytes to send.
I probably haven't answered your question directly but this is a way to store two longs in memory.
John Abshier
You can go even fancier by assigning other unused values, like - to $B and E to $E. So a scientific number like -1.74E-6 would be $B1, $A7, $4E, $B6, $F0. The last digit is a "don't care", it's just padding to make the number take 8 bits.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Post Edited (Paul Baker) : 1/7/2009 1:39:58 AM GMT
Carl Lawhon
1) The 4 bytes of the long have to fit in an EEPROM "page". The best way to do this is simply to require the EEPROM address to be a multiple of 4.
2) A write operation takes roughly 5ms. You can put in a 5ms wait like WAITCNT(CLKFREQ/200+CNT) or you can use the test for completion of the write that's shown in the comments at the beginning of the driver.
3) The pin # of the SCL signal can be specified separately or combined with the EEPROM address as described in the comments. The pin # of the SDA signal is always the next pin.
object is at link
obex.parallax.com/objects/30/
Post Edited (grasshopper) : 1/7/2009 8:47:20 PM GMT