PCF8574 port expansion as output

Currently using a PCF8574 module as a output pins for a switch case.

case 17 makes P0 HIGH, P1-P7 LOW
case 18 makes P1 HIGH, P0 P2-P7 LOW
case 19 makes P2 HIGH, the rest LOW
and so on.

Would like to find out how should i change in order to retain the previous outputs, which means i want to control the output pins individually instead of controlling all 8 pins.

For example,
1>select case 17 -> P0 HIGH
2>select case 19 -> P2 HIGH, P0 HIGH (from first selection)
3>select case 23 -> P6 HIGH, P2 HIGH(from 2nd selection), P0 HIGH (from 1st selection)

Thank you!

1 Like

Save your output in a byte variable, call it currentOutput.

  • To clear a bit, use AND with a Mask

  • To set a bit use OR.

Say currentOutput was b10101010

We want to set bit 2
 76543210
b10101010  currentOutput
b00000100  OR  ||
b10101110  result

we want to clear bit 7
 76543210
b10101010  currentOutput
b01111111  AND &
b00101010  result

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.