stamp.peripheral.io
Class PCF8574

java.lang.Object
  |
  +--stamp.peripheral.io.PCF8574

public class PCF8574
extends Object

This class provides an interface to the Philips PCF8574 (8-bit bi- directional port expander). PCF8574 inputs and outputs are active low; pins used as inputs should be pulled-up to Vdd through 10K.

To create a PCF8574 object, the programmer will usually define a [shared] I2C bus object first and pass this object to the PCF8574 constructor.

I2C ioBus = new I2C(CPU.pin0, CPU.pin1); PCF8574 ioPort = new PCF8574(ioBus, 0x00, 0xF0);

If a single PCF8574 is the only I2C device connected to the Javelin, an alternate constructor may be used that creates the necessary I2C bus. Note that this bus is private to the PCF8574 and cannot be shared with any other device.

PCF8574 ioPort = new PCF8574(CPU.pin0, CPU.pin1, 0x00, 0xF0);

For additonal operational details, consult Philips documentation for the PCF8574.


Constructor Summary
PCF8574(I2C bus, int devAddr, int dirs)
          Create PCF8574 object
PCF8574(int sdaPin, int sclPin, int devAddr, int dirs)
          Create PCF8574 object with private I2C bus.
 
Method Summary
 boolean isPresent()
          Check for presence of specific PCF8574 device.
 int read()
          Get PCF8574 inputs (pins masked with dirs value)
 void write(int outData)
          Set PCF8574 outputs (pins masked with dirs value).
 
Methods inherited from class java.lang.Object
equals
 

Constructor Detail

PCF8574

public PCF8574(I2C bus,
               int devAddr,
               int dirs)
Create PCF8574 object
Parameters:
bus - I2C bus object
devAddr - Device address (0 .. 7)
dirs - PCF8574 pin directions (1 = input, 0 = output)

PCF8574

public PCF8574(int sdaPin,
               int sclPin,
               int devAddr,
               int dirs)
Create PCF8574 object with private I2C bus. This method is not recommended unless the PCF8574 is the only I2C device connected to the Javelin.
Parameters:
sdaPin - I2C serial data pin
sclPin - I2C serial clock pin
devAddr - Device address (0 .. 7)
dirs - PCF8574 pin directions (1 = input, 0 = output)
Method Detail

isPresent

public boolean isPresent()
Check for presence of specific PCF8574 device.
Returns:
True if device exists on bus

write

public void write(int outData)
Set PCF8574 outputs (pins masked with dirs value).
Parameters:
outData - Data to write to PCF8574 port

read

public int read()
Get PCF8574 inputs (pins masked with dirs value)
Returns:
Data from PCF8574 inputs