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

Bittest and bitset in keil mdk5

Dear board
Im writing a driver for HX711 load cell pickup unit.

This has a clock pin which is input to hx711 ic and this clk will be driven by stm32f103
And a Dout pin where for every low to high transition hx711 will out a bit and this goes 24 bit long..

I need to read this serial input and store to a byte which is 24 bit data where i can use array of 3 bytes..

I can easily read input status low or high from input function.

But how can i assign that bit value to a byte at particular position??

Earlier in pic micro.. i have function called bit_set and bit_clear to set or clear particular bit in a byte...

I googled and found there are no code fullfilling my requirements.

Can anyone suggest me please?? I need to read pin and save 24 bit info and convert to
decimal.

Thanks

Parents
  • #include <stdio.h>
    #include <stdint.h>
    
    uint8_t bit_set( uint8_t data, int position )
    {
        data |= (1u<<position);
        return data;
    }
    
    uint8_t bit_clear( uint8_t data, int position )
    {
        data &= ~(1u<<position);
        return data;
    }
    
    void main(void)
    {
        uint8_t Target = 0xC9;
    
        printf( "%X\n", Target );
    
        Target = bit_set( Target, 1 );
        Target = bit_clear( Target, 3 );
    
        printf( "%X\n", Target );
    }
    

Reply
  • #include <stdio.h>
    #include <stdint.h>
    
    uint8_t bit_set( uint8_t data, int position )
    {
        data |= (1u<<position);
        return data;
    }
    
    uint8_t bit_clear( uint8_t data, int position )
    {
        data &= ~(1u<<position);
        return data;
    }
    
    void main(void)
    {
        uint8_t Target = 0xC9;
    
        printf( "%X\n", Target );
    
        Target = bit_set( Target, 1 );
        Target = bit_clear( Target, 3 );
    
        printf( "%X\n", Target );
    }
    

Children
No data