Ryu Anzawa / Mbed OS AQM0802A

Dependencies:   aqm0802

Files at this revision

API Documentation at this revision

Comitter:
piroro4560
Date:
Sun Jan 19 09:24:06 2020 +0000
Child:
1:0f68a8a42a12
Commit message:
class for aqm0802

Changed in this revision

aqm0802/aqm0802.cpp Show annotated file Show diff for this revision Revisions of this file
aqm0802/aqm0802.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-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aqm0802/aqm0802.cpp	Sun Jan 19 09:24:06 2020 +0000
@@ -0,0 +1,75 @@
+#include "aqm0802.h"
+
+aqm0802::aqm0802(PinName sda, PinName scl)
+    : i2c_(sda, scl)
+{
+    wait_ms(40);
+    // LCD initialize
+    cmd(0x39); // function set
+    cmd(0x14); // interval osc
+    cmd(0x70); // contrast Low
+    cmd(0x56); // contast High/icon/power
+    cmd(0x6C); // follower control
+    wait_ms(200);
+    cmd(0x38); // function set
+    cmd(0x0C); // Display On
+    cmd(0x01); // Clear Display
+    wait_ms(200);
+}
+
+void aqm0802::cmd(char x)
+{
+    char data[2];
+    data[0] = 0x00; // CO = 0,RS = 0
+    data[1] = x;
+    i2c_.write(AQCM0802_addr, data, 2);
+}
+
+void aqm0802::contdata(char x)
+{
+    char data[2];
+    data[0] = 0xC0; //0b11000000 CO = 1, RS = 1
+    data[1] = x;
+    i2c_.write(AQCM0802_addr, data, 2);
+}
+
+void aqm0802::lastdata(char x)
+{
+    char data[2];
+    data[0] = 0x40; //0b11000000 CO = 0, RS = 1
+    data[1] = x;
+    i2c_.write(AQCM0802_addr, data, 2);
+}
+
+void aqm0802::printStr(const char *s)
+{
+    while(*s) {
+    if (*(s + 1)) {
+        contdata(*s);
+    } else {
+        lastdata(*s);
+    }
+        s++;
+    }
+}
+
+void aqm0802::setCursor(uint8_t x,uint8_t y)
+{
+    cmd(0x80 | (y*0x40 + x));
+}
+
+void aqm0802::setCG(int src,int dst,int len)
+{
+    cmd(0x38);
+    cmd(0x40 + dst);
+
+    for (int i = 0;i < len;i++) contdata(cg[src + i] * (src>=0));
+}
+
+void aqm0802::setContrast(uint8_t c)
+{
+    cmd(0x39);
+    cmd(0x70 | (c & 0x0f)); // contrast Low
+    cmd(0x5C | ((c >> 4) & 0x03)); // contast High/icon/power
+    cmd(0x38);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aqm0802/aqm0802.h	Sun Jan 19 09:24:06 2020 +0000
@@ -0,0 +1,67 @@
+//-------------------------------------------------------
+//  Class for LCD, AQM0802A (Header)
+//
+//  Default pin assignments
+//      D14  SDA ---- to pin4 of LCD module
+//      D15  SCL ---- to pin3 of LCD module
+//
+//  Assignment of I2C ports
+//                SDA                SCL
+//      I2C1   PB_7 or PB_9(D14)  PB_6(D10) or PB_8(D15)
+//      I2C2   PB_3(D3)           PB_10(D6)
+//      I2C3   PB_4(D5) or PC_9   PA_8(D7)
+//
+//-------------------------------------------------------
+
+#ifndef AQM0802_H
+#define AQM0802_H
+
+#include "mbed.h"
+
+class aqm0802 {
+public :
+    // Constructor
+    aqm0802(PinName sda, PinName scl);
+
+    // Send command
+    void cmd(char x);
+
+    // Write string
+    void printStr(const char *s);
+
+    // Set cursol
+    void setCursor(uint8_t x,uint8_t y);
+
+    // Set contrast
+    void setContrast(uint8_t c);
+
+    void contdata(char x);
+
+    void lastdata(char x);
+
+    void setCG(int src,int dst,int len);
+
+//private :
+    const int AQCM0802_addr = 0x7C;
+    
+    I2C i2c_;
+    unsigned char cg[13 * 8] = {
+
+0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E,0x00, // S
+0x11,0x11,0x11,0x15,0x15,0x15,0x0A,0x00, // W
+0x0E,0x04,0x04,0x04,0x04,0x04,0x0E,0x00, // I
+0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x00, // T
+0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C
+0x11,0x11,0x11,0x1F,0x11,0x11,0x11,0x00, // H
+  
+0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E,0x00, // S
+0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C
+0x0E,0x04,0x04,0x04,0x04,0x04,0x0E,0x00, // I
+0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F,0x00, // E
+0x11,0x11,0x19,0x15,0x13,0x11,0x11,0x00, // N
+0x0E,0x11,0x10,0x10,0x10,0x11,0x0E,0x00, // C
+0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F,0x00  // E
+};
+
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jan 19 09:24:06 2020 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "aqm0802.h"
+
+aqm0802 aqm(PB_9, PB_8);
+
+int main() {
+    uint8_t   mode, contrast=0, contrastFlag=false;
+    int       CGcounter, FADEcounter, a=1;
+    
+    while(1) {
+        switch(mode) {
+        case 0:  // init
+            aqm.cmd(0x01);
+            wait_ms(50);
+            mode++;
+            wait(1);
+            break;
+        case 1:  // SWITCH
+            aqm.setCursor(0, 0);
+            aqm.printStr("SWITCH");
+            mode++;
+            wait(1);
+            break;
+        case 2:  // SCI
+            aqm.setCursor(1, 1);
+            aqm.printStr("SCI");
+            mode++;
+            wait(1);
+            break;
+        case 3:
+            aqm.setCursor(4, 1);
+            aqm.printStr("ENCE");
+            FADEcounter = 0;
+            mode++;
+            wait(1);
+            mode=0;
+            break;
+            /*
+        case 4:
+            if (contrastFlag == false) {
+                if (++contrast >= 54) contrastFlag = true;
+            } else {
+                if (--contrast <= 17) {
+                    contrastFlag = false;
+                    if(++FADEcounter >= 2) {
+                        mode = 0;
+                    }
+                }
+            }
+            aqm.setContrast(contrast);
+            break;
+            */
+        }
+        wait(0.05);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Sun Jan 19 09:24:06 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9