nabla101
Junior Member level 3
HI, I'm using SPI of PIC18F46K80, and I want to write a function to feed it a 6-bit address, and a read/write bit. If I have the address as a UINT8 type, then how can I change the bits of the UINT8 to construct an 8-bit packet (Another UINT8) with the MSB bit set to '0', followed by the 6-bit adress (stored in the 8-bit UINT8) - bits 6-1, followed by the R/W bit (bit 0 - LSB)?
Alternatively, is there a 6-bit variable I can use to store the address (UINT6), and then append the other two bits onto the front/back of this variable to make a UINT8? If not, then can I create such a UINT6 variable myself?....this would be better, since I want to do the same thing with a 10-bit address (Making a 12 bit packet that is transmitted as two address bytes, with the last 4 bits irrelevant).
Thanks
p.s. OK, Its been a while since I've programmed, but just remembered I can use bitwise operators to do this..... still how can I create 6-bit and 10-bit variables? - this way I can avoid addresses that are too large being sent to the function in the first place.
Alternatively, is there a 6-bit variable I can use to store the address (UINT6), and then append the other two bits onto the front/back of this variable to make a UINT8? If not, then can I create such a UINT6 variable myself?....this would be better, since I want to do the same thing with a 10-bit address (Making a 12 bit packet that is transmitted as two address bytes, with the last 4 bits irrelevant).
Thanks
p.s. OK, Its been a while since I've programmed, but just remembered I can use bitwise operators to do this..... still how can I create 6-bit and 10-bit variables? - this way I can avoid addresses that are too large being sent to the function in the first place.