• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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...
 

Mike - K8LH

Well-Known Member
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
 

nusry

New Member
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.

EE World Online Articles

Loading
Top