PCA9672 Library (I2C IO Expander Interface)
Simple output port toggling with PCA9672
#include "mbed.h" #include "PCA9672.h" PCA9672 ioxp(P0_10, P0_11); //I2C connected to PCA9672 in LPC800-MAX int main() { ioxp.frequency(100000); while (1) { ioxp.write(0xFF); wait(.250); ioxp.write(0x00); wait(.250); } }
PCA9672.h@0:27125e4cf941, 2013-09-21 (annotated)
- Committer:
- viswesr
- Date:
- Sat Sep 21 05:28:44 2013 +0000
- Revision:
- 0:27125e4cf941
PCA9672 Library (I2C IO Expander Interface) : First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
viswesr | 0:27125e4cf941 | 1 | /* mbed PCA9672 I2C I/O Expander Library |
viswesr | 0:27125e4cf941 | 2 | * Copyright (c) 2013 viswesr |
viswesr | 0:27125e4cf941 | 3 | * |
viswesr | 0:27125e4cf941 | 4 | * MIT License |
viswesr | 0:27125e4cf941 | 5 | * |
viswesr | 0:27125e4cf941 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
viswesr | 0:27125e4cf941 | 7 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
viswesr | 0:27125e4cf941 | 8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
viswesr | 0:27125e4cf941 | 9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
viswesr | 0:27125e4cf941 | 10 | * furnished to do so, subject to the following conditions: |
viswesr | 0:27125e4cf941 | 11 | * |
viswesr | 0:27125e4cf941 | 12 | * The above copyright notice and this permission notice shall be included in all copies or |
viswesr | 0:27125e4cf941 | 13 | * substantial portions of the Software. |
viswesr | 0:27125e4cf941 | 14 | * |
viswesr | 0:27125e4cf941 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
viswesr | 0:27125e4cf941 | 16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
viswesr | 0:27125e4cf941 | 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
viswesr | 0:27125e4cf941 | 18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
viswesr | 0:27125e4cf941 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
viswesr | 0:27125e4cf941 | 20 | */ |
viswesr | 0:27125e4cf941 | 21 | |
viswesr | 0:27125e4cf941 | 22 | #ifndef PCA9672_H |
viswesr | 0:27125e4cf941 | 23 | #define PCA9672_H |
viswesr | 0:27125e4cf941 | 24 | |
viswesr | 0:27125e4cf941 | 25 | #include "mbed.h" |
viswesr | 0:27125e4cf941 | 26 | |
viswesr | 0:27125e4cf941 | 27 | // PCA9672 IIC slave address |
viswesr | 0:27125e4cf941 | 28 | #define PCA9672_ADDR 0x46 |
viswesr | 0:27125e4cf941 | 29 | |
viswesr | 0:27125e4cf941 | 30 | |
viswesr | 0:27125e4cf941 | 31 | //!Library for the PCA9672 I/O expander. |
viswesr | 0:27125e4cf941 | 32 | /*! |
viswesr | 0:27125e4cf941 | 33 | The PCA9672 is an I2C I/O expander. It has 8 I/O pins. |
viswesr | 0:27125e4cf941 | 34 | */ |
viswesr | 0:27125e4cf941 | 35 | class PCA9672 |
viswesr | 0:27125e4cf941 | 36 | { |
viswesr | 0:27125e4cf941 | 37 | public: |
viswesr | 0:27125e4cf941 | 38 | /*! |
viswesr | 0:27125e4cf941 | 39 | Connect PCA9672 to I2C port pins sda and scl. |
viswesr | 0:27125e4cf941 | 40 | */ |
viswesr | 0:27125e4cf941 | 41 | PCA9672(PinName sda, PinName scl); |
viswesr | 0:27125e4cf941 | 42 | |
viswesr | 0:27125e4cf941 | 43 | /*! |
viswesr | 0:27125e4cf941 | 44 | Set the frequency of the I2C interface. |
viswesr | 0:27125e4cf941 | 45 | */ |
viswesr | 0:27125e4cf941 | 46 | void frequency(int hz); |
viswesr | 0:27125e4cf941 | 47 | |
viswesr | 0:27125e4cf941 | 48 | /*! |
viswesr | 0:27125e4cf941 | 49 | Write the value to the IO Expander (pins XP0-XP7 output) |
viswesr | 0:27125e4cf941 | 50 | */ |
viswesr | 0:27125e4cf941 | 51 | void write(char value); |
viswesr | 0:27125e4cf941 | 52 | |
viswesr | 0:27125e4cf941 | 53 | /*! |
viswesr | 0:27125e4cf941 | 54 | Read the value of the IO Expander (pins XP0-XP7 input) |
viswesr | 0:27125e4cf941 | 55 | */ |
viswesr | 0:27125e4cf941 | 56 | int read(void); |
viswesr | 0:27125e4cf941 | 57 | |
viswesr | 0:27125e4cf941 | 58 | /*! |
viswesr | 0:27125e4cf941 | 59 | Destroys instance. |
viswesr | 0:27125e4cf941 | 60 | */ |
viswesr | 0:27125e4cf941 | 61 | ~PCA9672(); |
viswesr | 0:27125e4cf941 | 62 | |
viswesr | 0:27125e4cf941 | 63 | private: |
viswesr | 0:27125e4cf941 | 64 | |
viswesr | 0:27125e4cf941 | 65 | I2C _i2c; |
viswesr | 0:27125e4cf941 | 66 | |
viswesr | 0:27125e4cf941 | 67 | }; |
viswesr | 0:27125e4cf941 | 68 | |
viswesr | 0:27125e4cf941 | 69 | #endif |