Hi / Lo
Posted: 05 Oct 2010 07:06
Let's say, hypothetically, that I have the variable, "value" of 800 (Decimal). I wan't to break this value up in 2 x 1 byte values for storage in an EEPROM. 800d is 11 0010 0000b, so theoretically (as far as I know), Hi(value) should return 0000 0011b, and Lo(value) should return 0010 0000b.
Practically I'm using this for storing an ADC-value (10-bit, 0-1023) into my EEPROM, which, of course, is 8-bit. The two variables I need to store are called cal_x_max and cal_y_max, and they're typically in the 800-900d range which is, in fact, a 10-bit value. For breaking them up, and storing them, I use the following code:
For writing:
For reading:
This, however, returns very strange values in the variables, usually in the >50.000d range. For debugging purposes I've tried converting the Hi and Lo parts of the cal_x_max variable, as well as the variable as a whole to strings for display on GLCD, and it seems cal_x_max is roughly around 800d, but Hi(cal_x_max) seems to always return a value around 800d on itself, and Lo(cal_x_max) also returns a number in the 800-900d. range. Anyone have any idea what's going on?
Practically I'm using this for storing an ADC-value (10-bit, 0-1023) into my EEPROM, which, of course, is 8-bit. The two variables I need to store are called cal_x_max and cal_y_max, and they're typically in the 800-900d range which is, in fact, a 10-bit value. For breaking them up, and storing them, I use the following code:
For writing:
Code: Select all
Eeprom_WrSingle(0x04,Lo(cal_x_max));
Eeprom_WrSingle(0x05,Hi(cal_y_max));
Code: Select all
cal_x_max=Eeprom_RdSingle(0x05);
cal_x_max=cal_x_max<<8;
cal_x_max=cal_x_max+Eeprom_RdSingle(0x04);