Hey,
I am trying to program an i2c controlled TV tuner module.
I have got the actual I2C bit working now I need to tell it what frequency to tune to.
It takes a 16-bit tuning word split over two bytes. I can make the 16 bit tuning word but cant get it into 2 8-bit bytes.
E.g
1010001000110011 (tuning word)
must become:
10100010 (first byte)
00110011 (second byte)
It depends on what level your working. Mathematically:
unsigned int x = 0b1010001000110011;
uint8_t xlow = x & 0xff;
uint8_t xhigh = (x >> 8);
xlow will contain the lower 8 bit of you word, xhigh the high bits. If your inclined that way, you can do it also by casting pointers and accessing the integer as byte array.
If your data isn't a 16-bit number but a collection of bit, you can also create it split up into two bytes from the outset and work either on xlow or xhigh.
These are actually the fragments of two different compiling runs where I exchanged lowByte and highByte. It was a little hard to find the code for the function, as it's usually reduced to loading the right byte from the memory the next time the result is needed.
One could say, to function get executed by reducing the loading code for the variable next time it's needed.