' -----[ Title ]---------------------------------------------------------------- ' ' File...... PCF8574.BSP ' Purpose... PCF8574 Demonstation -- for Rev C BS2p ' Author.... Jon Williams ' E-mail.... jwilliams@parallax.com ' Started... ' Updated... 08 MAR 2002 ' {$STAMP BS2p} ' {$PBASIC 2.5} ' -----[ Program Description ]-------------------------------------------------- ' ' This program works only with the Rev C BS2p ' -----[ Revision History ]----------------------------------------------------- ' ' -----[ I/O Definitions ]------------------------------------------------------ ' SDA PIN 8 ' SDA on 8; SCL on 9 ' -----[ Constants ]------------------------------------------------------------ ' MixDDR CON %10000000 ' 1 = input for mixed I/O PCF8574 CON %01000000 ' device address 0 ' -----[ Variables ]------------------------------------------------------------ ' ioByte VAR Byte cntr VAR Nib ' counter ' -----[ EEPROM Data ]---------------------------------------------------------- ' ' -----[ Initialization ]------------------------------------------------------- ' Init: DEBUG CLS, "PCF8574 Demo. Press button to advance counter." ioByte = MixDDR | 0 I2COUT SDA, PCF8574, [ioByte, ioByte] ' -----[ Main Code ]------------------------------------------------------------ ' ' This demo looks at remote I/O pin 7 and increments a counter when ' the button is pressed. Remote I/O pin 7 should be pulled up to Vdd ' through a 10K resistor. Connect a N.O. switch between remote I/O ' pin 7 and Ground. ' ' Remote I/O pins 0 - 3 are connected to LEDs through 1.2K resistors Main: I2CIN SDA, PCF8574, [ioByte] IF (ioByte.BIT7) THEN Main cntr = cntr + 1 DEBUG HOME, 10, BIN4 cntr ioByte = MixDDR | cntr ' mask input pin[s] I2COUT SDA, PCF8574, [ioByte, ioByte] ' force output to pins now PAUSE 250 GOTO Main