PCF8591 library

Dependents:   mbed_DEMO

See https://developer.mbed.org/users/yasuyuki/notebook/PCF8591/

Files at this revision

API Documentation at this revision

Comitter:
yasuyuki
Date:
Sat Oct 04 12:03:47 2014 +0000
Commit message:
first release

Changed in this revision

PCF8591.cpp Show annotated file Show diff for this revision Revisions of this file
PCF8591.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r e17d7079ee96 PCF8591.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCF8591.cpp	Sat Oct 04 12:03:47 2014 +0000
@@ -0,0 +1,36 @@
+//**********************
+// PCF8591.cpp for mbed
+//
+// PCF8591 lcd(P0_5,P0_4);
+// or
+// I2C i2c(P0_5,P0_4);
+// PCF8591 lcd(i2c);
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#include "mbed.h"
+#include "PCF8591.h"
+
+PCF8591::PCF8591 (PinName sda, PinName scl) : _i2c(sda, scl) {
+}
+PCF8591::PCF8591 (I2C& p_i2c) : _i2c(p_i2c) {
+}
+
+void PCF8591::put(unsigned char a, unsigned char b)
+{
+    buf[0]=a;
+    buf[1]=b;
+    _i2c.write(PCF8591_ADDR, buf, 2);
+}
+
+unsigned char PCF8591::get(unsigned char a)
+{
+    buf[0] = a;
+    _i2c.write(PCF8591_ADDR, buf, 1, true); // no stop, repeated
+    _i2c.read( PCF8591_ADDR, buf, 1);
+    return buf[0];
+}
+
+
diff -r 000000000000 -r e17d7079ee96 PCF8591.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCF8591.h	Sat Oct 04 12:03:47 2014 +0000
@@ -0,0 +1,31 @@
+//**********************
+// PCF8591.h for mbed
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#ifndef PCF8591_H_
+#define PCF8591_H_
+
+#define PCF8591_ADDR    0x92
+
+#include "mbed.h"
+
+class PCF8591{
+public:
+    PCF8591 (PinName sda, PinName scl);
+    PCF8591 (I2C& p_i2c);
+
+    void put(unsigned char a, unsigned char b);
+    unsigned char get(unsigned char a);
+
+protected:
+    
+    I2C _i2c;
+    char buf[2];
+
+};
+
+
+#endif /* PCF8591_H_ */