I2C 接続の LCD AQM1602XA-RN-GBW 用のライブラリ. Library for LCD 1602XA-RN-GBW connected using I2C interface.

Dependents:   UIT2_MovingAv_Intr UIT2_VariableFIR UIT2_VowelSynthesizer UIT2_ALE_LeakyLMS ... more

Revision:
0:f177013dc4fc
Child:
1:18cd1c4212c3
diff -r 000000000000 -r f177013dc4fc AQM1602.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AQM1602.cpp	Fri Jun 05 06:43:51 2015 +0000
@@ -0,0 +1,81 @@
+//-------------------------------------------------------
+//  Class for LCD, AQM1602XA-RN-GBW
+//
+//  2014/05/30, Copyright (c) 2015 MIKAMI, Naoki
+//-------------------------------------------------------
+
+#include "AQM1602.hpp"
+
+namespace Mikami
+{
+    // Constructor
+    Aqm1602::Aqm1602(PinName sda, PinName scl, uint32_t clock,
+                     bool cursor, bool blink)
+        : i2c_(sda, scl)
+    {
+        if (clock != 100000) i2c_.frequency(clock);
+
+        wait_ms(40);
+        WriteCmd(0x39); // To extended command
+        WriteCmd(0x14); // Internal OSC frequency
+        WriteCmd(0x70 | 0x00); // Contrast set
+        WriteCmd(0x54 | 0x02); // Power/ICON/Contrast control
+        WriteCmd(0x6C); // Follower control
+        wait_ms(200);
+
+        WriteCmd(0x38); // data length:8-bit, 2-line, 5×8 dots
+        WriteCmd(0x0C | (cursor << 1) | blink);
+        Clear();      // Clear display
+    }
+
+    // All clear
+    void Aqm1602::Clear()
+    {
+        WriteCmd(0x01);
+        wait_ms(50);
+    }
+
+    // Write string
+    void Aqm1602::WriteString(const char str[])
+    {
+        for (int n=0; n<N_CHR; n++)
+            if (str[n] == 0) break;
+            else             WriteChar(str[n]);
+    }
+
+    // Write string from specified position
+    void Aqm1602::WriteStringXY(const char str[],
+                                 uint8_t x, uint8_t y)
+    {
+        SetXY(x, y);
+        WriteString(str);
+    }
+    
+    // Clear of specified line
+    void Aqm1602::ClearLine(uint8_t line)
+    {
+        SetXY(0, line);
+        for (int n=0; n<N_CHR; n++)
+            WriteString(" ");
+    }
+
+    // Set contrast
+    void Aqm1602::SetContrast(uint8_t c)
+    {
+        WriteCmd(0x39);
+        WriteCmd(0x70 | (c & 0x0f));         // Lower 4 bits
+        WriteCmd(0x5C | ((c >> 4) & 0x03));  // Higher 2 bits
+        WriteCmd(0x38);
+    }
+
+    //---------------------------------------------------
+    // Following functions: private
+
+    // Send command and data
+    void Aqm1602::LcdTx(uint8_t cmdData, uint8_t data)
+    {
+        char tx[2] = { cmdData, data };
+        i2c_.write(LCD_ADDRESS_, tx, 2);
+    }
+}
+