
function call with "pipe"
[...]
Quote:
> data =((unsigned int) _i2c_read() << 8) & 0xff00; // read high 8 bits
> data |= (unsigned int) (_i2c_read()&0xff); // read low 4 bits (high nibble)
> what does the << 8 and the & bit do?!? also |= ??
You need a book that discusses the C programming language. It will
explain the meaning and usage of C's basic operators. A newsgroup is
a very inefficient way to learn these.
The '<<' operator is C's bitwise left shift operator. Thus, if
_i2c_read() returns 0x12, then _i2c_read() << 8 becomes 0x1200, because
it's shifted left 8 bits.
The '&' operator is C's bitwise AND operator. The AND operator takes
two inputs, and returns 1 only if both inputs are 1. Since this is a
bitwise operator, corresponding bits from each input integer are taken
as inputs. In this case, the & 0xff00 is commonly referred to as a
mask. For example, if _i2c_read() returns 0x1234, << 8 will yield
0x123400, and & 0xff00 will yield 0x3400.
The '|=' operator is a shorthand, because in C, 'a = a | b' is almost
equivalent to 'a |= b'. The '|' operator is C's bitwise OR operator,
which is similar to the AND operator above, except that it returns 1
if either or both inputs are 1.
Quote:
> also a function defined as taking input variable unsigned char is
> called with
> _i2c_write(A2D_ADDRESS | 0x01); // write slave address (read)
> what does the pipe do??
Logical OR, as explained above.
Quote:
> all help appreciated! i'm completely stumped!!
You need a good book on C. The comp.lang.c FAQ at
http://www.eskimo.com/~scs/C-faq/top.html
suggests several. You are doing yourself a disservice if you think my
explanation (or indeed most anybody's explanation) in a newsgroup would
substitute for a real discussion on these operators.