$regfile = "2313def.dat" $crystal = 4000000 Config Sda = Portd.5 Config Scl = Portd.4 Config I2cdelay = 10 Config Pind.6 = Output Const Pcf8574write = &H40 Const Pcf8574read = &H41 Const Shortwait = 50 Const Longwait = 250 Const Switchbit = 0 Dim Ledwait As Byte Dim Pcf8574port As Byte 'Make all Pcf8574 pins high -> input I2cstart I2cwbyte Pcf8574write I2cwbyte 255 I2cstop Do 'Read Pcf8574 port I2cstart I2cwbyte Pcf8574read I2crbyte Pcf8574port , Nack I2cstop 'Determine state of Switchbit bit If Pcf8574port.switchbit = 1 Then Ledwait = Shortwait Else Ledwait = Longwait End If Set Portd.6 Waitms Ledwait Reset Portd.6 Waitms Ledwait Loop End