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

Variable and IF

i m working in C using Keil 3.55a

how can i define a one bit variable

and how can i compare two bits using if

how can i set or clear Bit

and how can i get the compliment of one byte or one bit, like in ASM CPL A or CPL c

Parents
  • 1.how can i define a one bit variable
    A:

    Use #define

    #define glcd_SCK        4
    #define glcd_SDIN       3
    #define glcd_DC         2
    #define glcd_SCE        1
    #define glcd_RST        0
    

    2.How can i compare two bits using if
    A:

    if(bit1 operator bit2)

    3.How can i set or clear Bit
    A:

       bit=0; // for clearing
       bit=1; // for setting
    

    4.How can i get the compliment of one byte or one bit, like in ASM CPL A or CPL c
    A: Use ^ operator.

    byte^=(1<<bit_pos);  // complements the bit in the "bit_pos" bit position.
    bit=(~bit);          // complements the bit
    

Reply
  • 1.how can i define a one bit variable
    A:

    Use #define

    #define glcd_SCK        4
    #define glcd_SDIN       3
    #define glcd_DC         2
    #define glcd_SCE        1
    #define glcd_RST        0
    

    2.How can i compare two bits using if
    A:

    if(bit1 operator bit2)

    3.How can i set or clear Bit
    A:

       bit=0; // for clearing
       bit=1; // for setting
    

    4.How can i get the compliment of one byte or one bit, like in ASM CPL A or CPL c
    A: Use ^ operator.

    byte^=(1<<bit_pos);  // complements the bit in the "bit_pos" bit position.
    bit=(~bit);          // complements the bit
    

Children