Here is the same code as last reply except formatted (newbie here):
equal to:Code:int set_PORTB_bit(int position, int value) { // Sets or clears the bit in position 'position' // either high or low (1 or 0) to match 'value'. // Leaves all other bits in PORTB unchanged. if (value == 0) { PORTB &= ~(1 << position); // Set bit position low } else { PORTB |= (1 << position); // Set high, leave others alone } return 1; }
Code:int set_PORTB_bit(int position, int value) { PORTB ^= (1 << pos); // Set binary digit at index of 'position' with 'value', leave others unaltered }




Reply With Quote