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:
13:4975e1c1d743
Parent:
12:21830002e12d
Child:
14:5e1b1de66a7f
--- a/AQM1602.cpp	Sat Oct 28 12:57:52 2017 +0000
+++ b/AQM1602.cpp	Fri Feb 07 05:23:48 2020 +0000
@@ -1,24 +1,18 @@
 //---------------------------------------------------------------
-//  Class for LCD, AQM1602XA-RN-GBW
-//
-//  Default pin assignments for Nucleo
-//      D14  SDA ---- to pin4 of LCD module
-//      D15  SCL ---- to pin3 of LCD module
+//  液晶表示器 AQM1602XA-RN-GBW 用クラス(ヘッダ)
 //
-//  動作を確認したボード: Nucleo-F401RE, Nucleo-F411RE, Nucleo-F446RE,
-//                      LPC1768
-//  動作が不良なボード:  Nucleo-F302R8, Nucle0-F746ZG, Disco-f746NG
+//  Nucleo の場合のデフォルトのピン
+//      D14 ---- 液晶モジュールの SDA ピン
+//      D15 ---- 液晶モジュールの SCL ピン
 //
-//  このプログラムを作った際の mbed のリビジョン:Rev.154
-//
-//  2017/10/28, Copyright (c) 2017 MIKAMI, Naoki
+//  2020/02/07, Copyright (c) 2020 MIKAMI, Naoki
 //---------------------------------------------------------------
 
 #include "AQM1602.hpp"
 
 namespace Mikami
 {
-    // Constructor
+    // コンストラクタ
     Aqm1602::Aqm1602(PinName sda, PinName scl, uint32_t clock,
                      bool cursor, bool blink)
         : i2cPtr_(new I2C(sda, scl)), i2c_(*i2cPtr_)
@@ -29,29 +23,28 @@
             : i2cPtr_(NULL), i2c_(i2c)
     {   Init(clock, cursor, blink); }
 
-    // All clear
+    // 表示のクリア
     void Aqm1602::Clear()
     {
         WriteCmd(0x01);
         wait_ms(50);
     }
 
-    // Write string
+    // 文字列の書込み
     void Aqm1602::WriteString(const string str)
     {
         int length = min(str.length(), (size_t)N_CHR);
         for (int n=0; n<length; n++) WriteChar(str[n]);
     }
 
-    // Write string from specified position
-    void Aqm1602::WriteStringXY(const string str,
-                                uint8_t x, uint8_t y)
+    // 指定した位置から文字列の書込み
+    void Aqm1602::WriteStringXY(const string 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);
@@ -59,19 +52,16 @@
             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);
+        WriteCmd(0x39);                     // To extended command
+        WriteCmd(0x70 | (c & 0x0f));        // Lower 4 bits
+        WriteCmd(0x5C | ((c >> 4) & 0x03)); // Higher 2 bits
+        WriteCmd(0x38);                     // Return to normal command
     }
 
-    //---------------------------------------------------
-    // Following functions: private
-
-    // Initialize
+    // 初期化
     void Aqm1602::Init(uint32_t clock, bool cursor, bool blink)
     {
         if (clock != 100000) i2c_.frequency(clock);
@@ -80,38 +70,38 @@
 
         // 初期化のためのコマンド送信手順は,秋月電子の AE-AQM1602A(KIT) の
         // データシートの記載に従った
-        connected_ = WriteCmd(0x38); // data length:8-bit, 2-line, 5×8 dots
+        connected_ = WriteCmd(0x38); // データ長 8-bit, 2-line, 5×8 dots
         if (!connected_)
         {
             fprintf(stderr, "\r\nLCD AQM1602 not connected\r\n");
             return;
         }
 
-        WriteCmd(0x39);         // To extended command
-        WriteCmd(0x14);         // Internal OSC frequency
-        WriteCmd(0x70 | 0x00);  // Contrast set
+        WriteCmd(0x39);         // 拡張命令モードへ
+        WriteCmd(0x14);         // 内部発信周波数
+        WriteCmd(0x70 | 0x00);  // コントラスト設定
         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(0x01); // clear,これを入れると正常に動作しない
+        WriteCmd(0x38);         // 通常の命令モードへ復帰,
+                                // データ長:8-bit, 2-line, 5×8 dots
+        WriteCmd(0x01);         // クリア
         WriteCmd(0x0C | (cursor << 1) | blink);
 
         Clear();
     }
 
-    // Send command and data
+    // コマンドとデータの送信
     bool Aqm1602::LcdTx(uint8_t cmdData, uint8_t data)
     {
+        // このメンバ関数を割込み処理で使う場合,以下の処理ではうまく動作しない
 /*
-        // mbed Rev.130 以降では割り込み処理でうまく動作しない場合がある
-        char tx[2] = { cmdData, data };
-        int rt = i2c_.write(LCD_ADDRESS_, tx, 2);
+        int rt = i2c_.write(LCD_ADDRESS_, (char []){cmdData, data}, 2);
         wait_us(30);
         return (rt == 0) ? true : false;
 */
-        // 以下は Rev.12 で変更したもの
+        // 以下の処理は割込み処理で使っても大丈夫
         i2c_.start();
         if (1 != i2c_.write(LCD_ADDRESS_)) return false;
         if (1 != i2c_.write(cmdData)) return false;
@@ -120,4 +110,4 @@
         wait_us(30);
         return true;
     }
-}
+}
\ No newline at end of file