i need to know...

Status
Not open for further replies.

nusry

New Member
void HMC5843(void)
{
uint8_t xh, xl, yh, yl, zh, zl;
long xo, yo, zo;

i2cSendStart();
i2cWaitForComplete();
i2cSendByte(0x3C); //write to HMC
i2cWaitForComplete();
i2cSendByte(0x02); //mode register
i2cWaitForComplete();
i2cSendByte(0x00); //continuous measurement mode
i2cWaitForComplete();
i2cSendStop();

//must read all six registers plus one to move the pointer back to 0x03
i2cSendStart();
i2cWaitForComplete();
i2cSendByte(0x3D); //read from HMC
i2cWaitForComplete();
i2cReceiveByte(TRUE);
i2cWaitForComplete();
xh = i2cGetReceivedByte(); //x high byte
i2cWaitForComplete();
//printf(" %d", xh);

i2cReceiveByte(TRUE);
i2cWaitForComplete();
xl = i2cGetReceivedByte(); //x low byte
i2cWaitForComplete();
xo = xl|(xh << 8);

i need to know what is happening in the last line (xo = xl|(xh << 8)
i mean, the operation of the last line
if it shifts 8bits left, then xh will be '0' and 'xo' will be xl

i don't understand!
please help...
 
That line converts a 16 bit number in the form of two bytes, a "high" byte and a "low" byte, back into a 16 bit number. It's pretty much the same as the following line;

xo = xh * 256 + xl
 
That line converts a 16 bit number in the form of two bytes, a "high" byte and a "low" byte, back into a 16 bit number. It's pretty much the same as the following line;

xo = xh * 256 + xl

yah,
i got it
thanks
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…