AQM1602 library

Dependents:   mbed_AQM1602 CatPot_Main_T_2v00 CatPot_2v10_T_Main CatPot_2v20_T_Main ... more

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

Files at this revision

API Documentation at this revision

Comitter:
yasuyuki
Date:
Fri Mar 06 12:51:41 2015 +0000
Commit message:
release

Changed in this revision

AQM1602.cpp Show annotated file Show diff for this revision Revisions of this file
AQM1602.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4c3df2da124c AQM1602.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AQM1602.cpp	Fri Mar 06 12:51:41 2015 +0000
@@ -0,0 +1,111 @@
+//**********************
+// AQM1602.cpp for mbed
+//
+// AQM1602 lcd(P0_5,P0_4);
+// or
+// I2C i2c(P0_5,P0_4);
+// AQM1602 lcd(i2c);
+//
+// (C)Copyright 2015 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#include "mbed.h"
+#include "AQM1602.h"
+
+AQM1602::AQM1602 (PinName sda, PinName scl) : _i2c(sda, scl) {
+    init();
+}
+AQM1602::AQM1602 (I2C& p_i2c) : _i2c(p_i2c) {
+    init();
+}
+
+void AQM1602::put(unsigned char a, unsigned char b)
+{
+    buf[0]=a;
+    buf[1]=b;
+    _i2c.write(AQM1602_ADDR, buf, 2);
+}
+
+
+void AQM1602::get(unsigned char a)
+{
+    buf[0] = a;
+    _i2c.write(AQM1602_ADDR, buf, 1, true); // no stop, repeated
+    _i2c.read( AQM1602_ADDR, buf, 1);
+
+}
+
+void AQM1602::cls()
+{
+    // Clear Display = 0x01
+    put(CMD, 0x01);
+    // Wait 1.08ms
+    wait_ms(2);
+
+}
+
+void AQM1602::locate(int x, int y)
+{
+
+    // 16x2
+    put(CMD, 0x80 + y*0x40 + x);
+
+}
+
+void AQM1602::print(const char *a)
+{
+
+    while(*a != '\0')
+    {
+        put(DAT, *a);
+        a++;
+    }
+
+}
+
+void AQM1602::init()
+{
+    // Wait 40ms
+    wait_ms(100);
+    // Function set = 0x38
+    put(CMD, 0x38);
+    // Wait 26.3us
+    wait_ms(1);
+    // Function set = 0x39
+    put(CMD, 0x39);
+    // Wait 26.3us
+    wait_ms(1);
+    // Internal OSC frequency = 0x14
+    put(CMD, 0x14);
+    // Wait 26.3us
+    wait_ms(1);
+    // Contrast set = 0x70
+    put(CMD, 0x70);
+    // Wait 26.3us
+    wait_ms(1);
+    // Power/ICON/Contrast control = 0x56
+    put(CMD, 0x56);
+    // Wait 26.3us
+    wait_ms(1);
+    // Follower control = 0x6C
+    put(CMD, 0x6C);
+    // Wait 200ms
+    wait_ms(200);
+    // Function set = 0x38
+    put(CMD, 0x38);
+    // Wait 26.3us
+    wait_ms(1);
+    // Display ON/OFF control = 0x0C
+    put(CMD, 0x0C);
+    // Wait 26.3us
+    wait_ms(1);
+    // Clear Display = 0x01
+    put(CMD, 0x01);
+    // Wait 1.08ms
+    wait_ms(2);
+
+}
+
+
+
diff -r 000000000000 -r 4c3df2da124c AQM1602.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AQM1602.h	Fri Mar 06 12:51:41 2015 +0000
@@ -0,0 +1,42 @@
+//**********************
+// AQM1602.h for mbed
+//
+// (C)Copyright 2015 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#ifndef AQM1602_H_
+#define AQM1602_H_
+
+#define AQM1602_ADDR    0x7c
+#define CMD 0x00
+#define DAT 0x40
+
+#include "mbed.h"
+
+//class AQM1602: public Stream{
+class AQM1602{
+public:
+    AQM1602 (PinName sda, PinName scl);
+    AQM1602 (I2C& p_i2c);
+    void init();
+
+    void put(unsigned char a, unsigned char b);
+    void get(unsigned char a);
+    void cls();
+    void locate (int x, int y);
+    void print (const char* a);
+
+protected:
+    
+    I2C _i2c;
+//    virtual int _putc(int value);
+//    virtual int _getc();
+
+    char buf[2];
+
+};
+
+
+#endif /* AQM1602_H_ */
+