PCF8574 I2C IO Expander Interface

Dependents:   PCF8574_HelloWorld PCF8574_I2C_4x4_Keypad PCF8574_I2C_4x4_Keypad_interface PCF8574_ButtonPress

Committer:
simon
Date:
Thu Jun 03 13:00:49 2010 +0000
Revision:
1:ec8da0c59403
Parent:
0:ab4e14b911ee

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:ab4e14b911ee 1 /* mbed PCF8574 Library, for driving the I2C I/O Expander
simon 0:ab4e14b911ee 2 * Copyright (c) 2008-2010, cstyles, sford
simon 0:ab4e14b911ee 3 *
simon 0:ab4e14b911ee 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:ab4e14b911ee 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:ab4e14b911ee 6 * in the Software without restriction, including without limitation the rights
simon 0:ab4e14b911ee 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:ab4e14b911ee 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:ab4e14b911ee 9 * furnished to do so, subject to the following conditions:
simon 0:ab4e14b911ee 10 *
simon 0:ab4e14b911ee 11 * The above copyright notice and this permission notice shall be included in
simon 0:ab4e14b911ee 12 * all copies or substantial portions of the Software.
simon 0:ab4e14b911ee 13 *
simon 0:ab4e14b911ee 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:ab4e14b911ee 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:ab4e14b911ee 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:ab4e14b911ee 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:ab4e14b911ee 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:ab4e14b911ee 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:ab4e14b911ee 20 * THE SOFTWARE.
simon 0:ab4e14b911ee 21 */
simon 0:ab4e14b911ee 22
simon 0:ab4e14b911ee 23 #include "PCF8574.h"
simon 0:ab4e14b911ee 24 #include "mbed.h"
simon 0:ab4e14b911ee 25
simon 0:ab4e14b911ee 26 PCF8574::PCF8574(PinName sda, PinName scl, int address)
simon 0:ab4e14b911ee 27 : _i2c(sda, scl) {
simon 0:ab4e14b911ee 28 _address = address;
simon 0:ab4e14b911ee 29 }
simon 0:ab4e14b911ee 30
simon 0:ab4e14b911ee 31 int PCF8574::read() {
simon 0:ab4e14b911ee 32 char foo[1];
simon 1:ec8da0c59403 33 _i2c.read(_address, foo, 1);
simon 0:ab4e14b911ee 34 return foo[0];
simon 0:ab4e14b911ee 35 }
simon 0:ab4e14b911ee 36
simon 0:ab4e14b911ee 37 void PCF8574::write(int data) {
simon 0:ab4e14b911ee 38 char foo[1];
simon 0:ab4e14b911ee 39 foo[0] = data;
simon 1:ec8da0c59403 40 _i2c.write(_address, foo, 1);
simon 0:ab4e14b911ee 41 }