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

using jb of a unsigned char in c

hello,
I would like to do a bit test of a unsigned char variable. It's like a jb in assembler.

here is my code in c.


unsigned char displ;
unsigned char display3 = 0xA8;
unsigned char i;
sbit display_data = P1^0;

displ = display3;
for (i=0; i<7; i++) {
        if (displ^0 == 1){
        display_data = 0;
        }
        else {
        display_data = 1;
        }
        displ>>=1;
}


I don't have any warning or error, but the result of test is wrong.
is it possible to do in c?

tkx.

Parents
  • I don't have any warning or error, but the result of test is wrong.

    As Andy said - the ^ operator has special meaning only in sbit declarations. In all other cases, it is an XOR operator.

    is it possible to do in c?

    Yes, as long as the unsigned char is located in bdata memory and the appropriate bit within the char is declared with a sbit declaration. Refer to the compiler documentation, especially the chapter "Bit-Addressable Objects".

Reply
  • I don't have any warning or error, but the result of test is wrong.

    As Andy said - the ^ operator has special meaning only in sbit declarations. In all other cases, it is an XOR operator.

    is it possible to do in c?

    Yes, as long as the unsigned char is located in bdata memory and the appropriate bit within the char is declared with a sbit declaration. Refer to the compiler documentation, especially the chapter "Bit-Addressable Objects".

Children