This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

passing carry bit to a function as parameter in C

Dear all,

I have a small keyboard in my application and I poll all the keys periodically. I can read all the key values with 2 bytes. Next, I check the bits of these bytes for specific keys.

In my program, I have function (check_button()) which gets the byte value and the bit index of the required key. It extracts the bit using '>>' and '<<', and interprets the value.

for (button_index=0; button_index<8; button_index++)
   check_button(button_port_1, button_index);

:
:
:

void check_button(unsigned char buttons, unsigned char button_index) {
   get the bit using << and >>
   process it
}

However, since this button checks are performed reqularly, I'm trying to re-engineer them for higher performance.

I'm not much familier with assembly, but following seems as a better way to do keyboard check:

for (button_index=0; button_index<8; button_index++) {
   button_port_1 >>= 1; (I need to get the carry bit)
   check_button(carry_bit_taken_above, button_index);
}

Finally, my question is: Is it possible to get the carry bit as above in some way, and pass it as bit parameter to a function in C?

Thanks for reading,

0