This program is for writing to PCA9532 on the LPCXpresso Base Board.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Lerche
Date:
Sat Feb 06 06:32:14 2010 +0000
Commit message:

Changed in this revision

PCA9532.cpp Show annotated file Show diff for this revision Revisions of this file
PCA9532.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCA9532.cpp	Sat Feb 06 06:32:14 2010 +0000
@@ -0,0 +1,21 @@
+#include "PCA9532.h"
+#include "mbed.h"
+using namespace mbed;
+PCA9532::PCA9532(PinName sda, PinName scl, int addr)
+    : _i2c(sda,scl) {
+    _addr = addr;
+    }   
+
+int PCA9532::read(void) {
+    char foo[1];
+    _i2c.read(_addr,foo,1); 
+    return (foo[0]);
+ }
+
+void PCA9532::write(int command, int data) {
+    char foo[2];
+    foo[0] = command;
+    foo[1] = data;
+    _i2c.write(_addr,foo,2);
+    return;
+ }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCA9532.h	Sat Feb 06 06:32:14 2010 +0000
@@ -0,0 +1,55 @@
+/* MIDI class for mbed Microcontroller
+ * Copyright (c) 2008, cstyles -- Modified by Lerche for PCA9532
+ */ 
+#include "mbed.h"
+#ifndef MBED_PCA9532_H
+#define MBED_PCA9532_H
+#define INPUT0 0x00
+#define INPUT1 0x01
+#define PSC0   0x02
+#define PWM0   0x03
+#define PSC1   0x04
+#define PWM1   0x05
+#define LS0    0x06
+#define LS1    0x07
+#define LS2    0x08
+#define LS3    0x09
+
+/* Class: PCA9532
+ *  Abstraction for the LED dimmer on LPCXpresso Base Board
+ */ 
+ 
+namespace mbed {
+class PCA9532 {
+  public:
+     /* Constructor: PCA9532
+      *  Create an instance of the PCA9532 connected to specfied I2C pins, with the specified address.
+      *
+      * Variables:
+      *  sda - The I2C data pin (p28)
+      *  scl - The I2C clock pin (p27)
+      *  addr - The address of this instance (0xC0) 
+      */   
+    PCA9532 (PinName sda, PinName scl, int addr);
+     /* Function: read
+      *  Read the IO pin level
+      *
+      * Variables:
+      *  none
+      */ 
+    int read (void);
+     /* Function: write
+      *  Write the IO pin levels / Turn on LEDs
+      *
+      * Variables:
+      *  data - An in, though only the bottom 8 bits are used
+      *  command - Where to put the data. 
+      */ 
+    void write (int command, int data);
+   
+  private :   
+    I2C _i2c;
+    int _addr;
+  };
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 06 06:32:14 2010 +0000
@@ -0,0 +1,11 @@
+#include "PCA9532.h"        // First try making header files. Maybe it works?
+#include "mbed.h"
+
+PCA9532 LED(p28, p27, 0xC0);    // sda, scl, addr
+DigitalOut l1(LED1);            
+
+int main() {
+    LED.write(LS0, 0x55);     // Control register (First four LEDs)
+    wait(1);
+    l1=1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Feb 06 06:32:14 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0