Menu

Translating C to GCB

Help
MBB
2023-09-18
2023-09-19
  • MBB

    MBB - 2023-09-18

    Does anyone know what this code does?

    static const uint8_t REG_CNTRL1 = 0x00;

    // Set enable bit
    WriteReg(REG_CNTRL1, 0x40 );

    uint8_t val;
    
      val = ReadReg(REG_CNTRL1);
      val &= ~0x40;
      WriteReg(REG_CNTRL1, val);
    
     
  • Anobium

    Anobium - 2023-09-18

    Is this the I2C discovery program from MCU FRIEND ?

    it calls a method called ReadReg() passing the parameter 0x00 storing result in val.
    then, it ANDs val with the 1's compliment of 0x40, clearing bit 6
    calls a method called WriteReg pasking two parameters.

    Corrected after Jerry Messina posted. i had it totally wrong initially as I overlooked the apersand. Thank you Jerry!

     

    Last edit: Anobium 2023-09-19
  • Jerry Messina

    Jerry Messina - 2023-09-18

    val &= ~0x40;
    That statement ANDs val with the 1's compliment of 0x40, clearing bit 6

    Same as

    val = val AND 0xBF
    
     
  • MBB

    MBB - 2023-09-19

    Thanks!

     

Log in to post a comment.