Library for LCD ACM1602NI connected using I2C on Nucleo F401 is not to be found. Using I2C class offered by mbed, I cannot program for this LCD on Nucleo F401. So I programmed for this LCD to control by direct accsessing registors for I2C in STM32F401RE. Nucleo F401 で使用できる,I2C 接続の LCD ACM1602NI 用のライブラリ.このライブラリでは,I2C クラスのコンストラクタとクロック周波数設定のメンバ関数は使っているが,その他のメンバ関数などは使っていない.その理由は,タイミングの関係だと思うが,I2C クラスのメンバ関数では正常に動くプログラムを,どうしても作れないことによる.しょうがないので,MCU の I2C 関係のレジスタに直接アクセスするようなプログラムを作ったたところ,動くようになった.Nucleo の F401RE 以外については確認していない.動かない場合は,I2C 用のレジスタのアドレスを,使っている MCU に応じて書きかえる必要がある.

Dependents:   ACM1602NI_Nucleo_Demo

Revision:
2:edf345c86b3b
diff -r cace20837286 -r edf345c86b3b AQM0802A.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AQM0802A.cpp	Sun Nov 30 06:10:19 2014 +0000
@@ -0,0 +1,76 @@
+//-------------------------------------------------------
+//  Class for LCD, AQM0802A
+//
+//  2014/11/30, Copyright (c) 2014 MIKAMI, Naoki
+//-------------------------------------------------------
+
+#include "AQM0802A.hpp"
+
+namespace Mikami
+{
+    // Constructor
+    Aqm0802A::Aqm0802A(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 Aqm0802A::Clear()
+    {
+        WriteCmd(0x01);
+        wait_ms(50);
+    }
+
+    // Write string
+    void Aqm0802A::WriteString(const char str[])
+    {
+        for (int n=0; n<8; n++)
+            if (str[n] == 0) break;
+            else             WriteChar(str[n]);
+    }
+
+    // Write string from specified position
+    void Aqm0802A::WriteStringXY(const char str[],
+                                 uint8_t x, uint8_t y)
+    {
+        SetXY(x, y);
+        WriteString(str);
+    }
+
+    // Set contrast
+    void Aqm0802A::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 Aqm0802A::LcdTx(uint8_t cmdData, uint8_t data)
+    {
+        char tx[2];
+        tx[0] = cmdData;
+        tx[1] = data;
+        i2c_.write(LCD_ADDRESS_, tx, 2);
+    }
+}
+
+