Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Sep 20, 2003 5:34 pm |
|
|
See below:
Code: |
int address;
long number, finally;
byte topbyte, botbyte, topback, botback;
number = 2280;
// No need and with 0xFF since botbyte ins 8 bits
//botbyte = number & 0xFF;
botbyte = number;
topbyte = number >> 8;
address = 0;
write_eeprom(1l, topbyte);
write_eeprom(2l, botbyte);
address = 1;
topback = read_eeprom(1); // or 0
botback = read_eeprom(2); // or 1
// This is incorrect since topbyte is 8 bits multiplying by 256 will result in 0
//finally = (topback * 256) + botback;
finally = make16(topback, botback);
|
Here's how I would do it:
Code: |
long address;
long number;
union
{
struct
{
UINT8 lowbyte;
UINT8 highbyte;
};
UINT16 word;
}data;
number = 2280;
address = 0;
write_eeprom(address, number>>8);
write_eeprom(address+1, number);
// now to test
data.lowbyte = read_eeprom(address);
data.highbyte = read_eeprom(address+1);
// data.word contain the 16 bit number
|
|
|