Maker Pro
Maker Pro

function to send data

Hello
I need help to understand this function. This function is use to send 8 bit serial data (8051 MCU, embedded c, I2C)
Code:
unsigned char I2CSend(unsigned char Data)
{
     unsigned char i, ack_bit;
     for (i = 0; i < 8; i++) {
        if ((Data & 0x80) == 0)
            SDA = 0;
        else
            SDA = 1;
        SCL = 1;
         SCL = 0;
        Data<<=1;
     }
     SDA = 1;
     SCL = 1;
     ack_bit = SDA;
     SCL = 0;
     return ack_bit;
}
what is meaning of this line if ((Data & 0x80) == 0) ?
 
vODy4Y8.png


If ((the result from the first paranthesis) is 0))
{
Do stuff
}
 
I didn't understand what is the 0x80. is it address of low bit?

Not sure I understand, but..

0x80 translates to '1000 0000' in binary, because the eigth(0-7 from right to left) position has the weight of 128..

This is the most significant bit. (or sign bit)
 
Last edited:
0x80 = HEX80 = decimal 128
trying to understand what the meaning of this condition if ((Data & 0x80) == 0)
This is the bitwise & operator. It does an and-operation of these two Data , 0x80
Code:
bit7 bit6 bit5 bit4  bit3 bit2 bit1 bit0
 x     x   x     x     x   x    x   x

x mean 0 or 1 digit

Data = xxxx xxxx;
0x80 = 1000 0000;
---------------------  &
          = xxxx xxxx

I am confused on 0x80. it could be anything like 0x60 or 0x55. why there is only 0x80. any specific reason?
 
Last edited:
Top