Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 19
' 1 is an input. For example:
'
' %11100000 = Bits 0 - 4 are outputs, bits 5 - 7 are inputs
'
' For the PCF8574 the syntax becomes:
'
' I2CIN pin, ddr_value, [in_byte]
' I2COUT pin, ddr_value, [out_byte]
'
' Special Note: When reading inputs while using the PCF8574 in mixed I/O mode,
' you must refresh the output bits during the read. This is easily accomplished
' by ORing the state of the output pins with the DDR value.
'
' I2CIN pin, (ddr_value | out_bits), [out_byte]
'
' This program uses the bits in mixed mode and will use the syntax described
' immediately above.
'
' I/O Notes:
'
' The input bit is pulled up to Vdd (+5) through 10K. This input is connected
' to Vss (ground) through a N.O. pushbutton switch. The input will read 1 when
' the switch is open, 0 when pressed.
'
' PCF8574 can sink current, but provide almost no source current. Outputs for
' this program are setup as act ive-low. The tilde (~) in front of the variable
' cntr inverts the bits since we're using active low outputs.
' -----[ Revision History ]-----------------------------------------------------
'
' -----[ I/O Definitions ] ------------------------------------------------------
'
I2Cpin CON 8 ' SDA on 8; SCL on 9
' -----[ Constants ]------------------------------------------------------------
'
DevType CON %0100 << 4 ' Device type
DevAddr CON %000 << 1 ' address = %000 -> %111
Wr8574 CON DevType | DevAddr ' write to PCF8574
Rd8574 CON Wr8574 | 1 ' read from PCF8574
MixDDR CON %11111100 ' 1 = input, 0 = output
' -----[ Variables ]------------------------------------------------------------
'
ioByte VAR Byte ' i/o byte for PCF8574
btn VAR ioByte.Bit7 ' button input (0 = pressed)
cntr VAR Nib ' counter
' -----[ EEPROM Data ]----------------------------------------------------------
'
' -----[ Initialization ]-------------------------------------------------------
'
Initialize:
DEBUG CLS