An I2C text LCD library for Displaytronic ACM1602NI-FLW-FBW-M01

Dependents:   ACM1602NI_Demo ROBOT_v01 ROBOT_v02 Boku-Transmit ... more

Revision:
0:aac87cbfc229
Child:
1:84527dcd3fcc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ACM1602NI.h	Mon May 13 12:50:42 2013 +0000
@@ -0,0 +1,87 @@
+/* mbed Text LCD Library for Displaytronic ACM1602NI-FLW-FBW-M01
+ * Copyright (c) 2013, wtakuo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ 
+#ifndef ACM1602NI_H
+#define ACM1602NI_H
+
+#include "mbed.h"
+
+/** An I2C Text LCD interface for driving Displaytronic ACM1602NI-FLW-FBW-M01
+ * The interface is basically the same as TextLCD by Simon Ford.
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "ACM1602NI.h"
+ * 
+ * I2C i2c(p9, p10);
+ * ACM1602NI lcd(i2c);
+ *
+ * int main() {
+ *     lcd.printf("Hello, World!\n");
+ * }
+ * @endcode
+ */
+class ACM1602NI : public Stream
+{
+public:
+    /** Create an ACM1602NI object connected to the specified I2C port.
+     *
+     * @param i2c     The I2C port to connect to
+     */
+    ACM1602NI(I2C &i2c);
+
+    /** Locate to a screen column and row
+     *
+     * @param column  The horizontal position from the left, indexed from 0
+     * @param row     The vertical position from the top, indexed from 0
+     */
+    void locate(int column, int row);
+    
+    /** Clear the screen and locate to 0,0 */
+    void cls();
+
+    int rows();
+    int columns();
+
+protected:
+    virtual int _putc(int value);
+    virtual int _getc();
+
+    void init();
+    int address(int column, int raw);
+    void character(int column, int row, int c);
+    int writeBytes(const char *data, int length, bool repeated = false);
+    void writeCommand(int command);
+    void writeData(int data);
+
+    static const int i2c_addr = 0x50 << 1;
+    static const int i2c_bit_wait_us = 20;
+    static const int i2c_command_wait_ms = 4;
+
+    static const int display_columns = 16;
+    static const int display_rows = 2;
+
+    I2C &_i2c;
+    int _column, _row;
+};
+
+#endif