I am making baby steps in programming and I am starting to love it.
Hope to get some help setting and clearing bits.
Somehow I made IO expander (TCA9535-16 bit) working properly but I have no idea how to set/clear bit without disturbing other bits.
I understand general idea of doing it but not using I2C protocol.
Also, I use IO expander in inverted output mode only so to clear entire byte I use 0xFF.
Here is a part of the code to test the outputs:
void Exp_Test (uint16_t data)
TWI_write_address(0x40); //device address
So, I have 2 rows of 8 LED's. By sending 0xFF to the port 1 of IO expander I have 1 on outputs which turns OFF 8 LED's.
if ((PINC & (1<<1))==0) //Button1
Exp_Test (0xFF); // 8 bits in PORT1 are set - LED's are OFF
else if ((PINC & (1<<2))==0) //Button2
Exp_Test (0x00); // 8 bits are clear- LED's are ON
I need to set /clear bits one at the time.
Any help would be very appreciated.