$regfile = "2313def.dat" $crystal = 4000000 Config Sda = Portd.5 Config Scl = Portd.4 Config I2cdelay = 10 Config Pind.6 = Output Config Pind.2 = Input Config Int0 = Falling Const Pcf8574write = &H40 Const Pcf8574read = &H41 Const Shortwait = 50 Const Longwait = 250 Const Switchbit = 0 Dim Ledwait As Byte Dim Pcf8574port As Byte Ledwait = Shortwait On Int0 Pcfint Enable Interrupts Enable Int0 'Make all Pcf8574 pins high -> input I2cstart I2cwbyte Pcf8574write I2cwbyte 255 I2cstop Do Set Portd.6 Waitms Ledwait Reset Portd.6 Waitms Ledwait Loop 'PCF8574 interrupt routine Pcfint: 'debounce wait time Waitms 10 'read the input pins I2cstart I2cwbyte Pcf8574read I2crbyte Pcf8574port , Nack I2cstop 'Determine state of Switchbit bit If Pcf8574port.switchbit = 1 Then Ledwait = Shortwait Else Ledwait = Longwait End If Gifr = 64 Return End