This is my first post here so please forgive anything I do wrong :) This is my situation. I am writing a simple data transfer operation for a PIC16F876 using MPLAB and the HI-Tech C compiler.
I have a char called data, I wanted to access the bits in data and send them to portB0, starting with the MSB.
In assembly I would simply do:
PORTB,0 = data,7
// to get the MSB and put it on port B0, I would then do this for all bits.
However in C this seems to be more complicated. I have done some research and have found a function which works:
getBit(char data, int bitNumber)
{
return (data & (1 << bitNumber-1)) != 0;
}
Then I just use:
PORTBbits.RB0 = getBit(data,7);
This is OK, but messy and seems to take longer, I dont know why I need an extra function... So my question is: Is there not a simple method to access a bit in a register? like:
PORTBbits.RB0 = data,7
I cant understand why there would not be as the complier converts it in to assembly anyway??!!!!
Thanks in advance. Regards, Tim.