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

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Thu Apr 16 04:22:48 2020 +0000
Parent:
14:5e1b1de66a7f
Commit message:
16

Changed in this revision

AQM1602.cpp Show annotated file Show diff for this revision Revisions of this file
AQM1602.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/AQM1602.cpp	Fri Feb 14 07:14:51 2020 +0000
+++ b/AQM1602.cpp	Thu Apr 16 04:22:48 2020 +0000
@@ -1,11 +1,11 @@
 //---------------------------------------------------------------
-//  液晶表示器 AQM1602XA-RN-GBW 用クラス(ヘッダ)
+//  液晶表示器 AQM1602XA-RN-GBW 用クラス,メンバ関数の定義
 //
 //  Nucleo の場合のデフォルトのピン
 //      D14 ---- 液晶モジュールの SDA ピン
 //      D15 ---- 液晶モジュールの SCL ピン
 //
-//  2020/02/14, Copyright (c) 2020 MIKAMI, Naoki
+//  2020/04/16, Copyright (c) 2020 MIKAMI, Naoki
 //---------------------------------------------------------------
 
 #include "AQM1602.hpp"
@@ -20,45 +20,45 @@
 
     Aqm1602::Aqm1602(I2C &i2c, uint32_t clock,
                      bool cursor, bool blink)
-            : i2cPtr_(NULL), i2c_(i2c)
+        : i2cPtr_(NULL), i2c_(i2c)
     {   Init(clock, cursor, blink); }
 
     // 表示のクリア
-    void Aqm1602::Clear()
+    void Aqm1602::Clear() const
     {
         WriteCmd(0x01);
         wait_ms(50);
     }
 
     // 文字列の書込み
-    void Aqm1602::WriteString(const string str)
+    void Aqm1602::WriteString(const string str) const
     {
         int length = min(str.length(), (size_t)N_CHR);
         for (int n=0; n<length; n++) WriteChar(str[n]);
     }
 
     // 指定した位置から文字列の書込み
-    void Aqm1602::WriteStringXY(const string str, uint8_t x, uint8_t y)
+    void Aqm1602::WriteStringXY(const string str,
+                                uint8_t x, uint8_t y) const
     {
         SetXY(x, y);
         WriteString(str);
     }
 
     // 指定した行のクリア
-    void Aqm1602::ClearLine(uint8_t line)
+    void Aqm1602::ClearLine(uint8_t line) const
     {
         SetXY(0, line);
-        for (int n=0; n<N_CHR; n++)
-            WriteString(" ");
+        for (int n=0; n<N_CHR; n++) WriteString(" ");
     }
 
     // コントラストの設定
-    void Aqm1602::SetContrast(uint8_t c)
+    void Aqm1602::SetContrast(uint8_t c) const
     {
-        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
+        WriteCmd(0x39);                     // 拡張コマンドへ
+        WriteCmd(0x70 | (c & 0x0f));        // 下位 4 ビット
+        WriteCmd(0x5C | ((c >> 4) & 0x03)); // 上位 2 ビット
+        WriteCmd(0x38);                     // ノーマル・コマンドへ
     }
 
     // 初期化
@@ -86,14 +86,14 @@
 
         WriteCmd(0x38);         // 通常の命令モードへ復帰,
                                 // データ長:8-bit, 2-line, 5×8 dots
-//        WriteCmd(0x01);         // クリア,これを入れると正常に動作しないようだ
+//        WriteCmd(0x01);         // クリア,これを入れると正常に動作しない
         WriteCmd(0x0C | (cursor << 1) | blink);
 
         Clear();
     }
 
     // コマンドとデータの送信
-    bool Aqm1602::LcdTx(uint8_t cmdData, uint8_t data)
+    bool Aqm1602::LcdTx(uint8_t cmdData, uint8_t data) const
     {
         // このメンバ関数を割込み処理で使う場合,以下の処理ではうまく動作しない
 /*
@@ -101,7 +101,7 @@
         wait_us(30);
         return (rt == 0) ? true : false;
 */
-        // 以下の処理は割込み処理で使っても大丈夫
+        // 以下の処理の場合は,このメンバ関数を割込み処理で使っても大丈夫
         i2c_.start();
         if (1 != i2c_.write(LCD_ADDRESS_)) return false;
         if (1 != i2c_.write(cmdData)) return false;
--- a/AQM1602.hpp	Fri Feb 14 07:14:51 2020 +0000
+++ b/AQM1602.hpp	Thu Apr 16 04:22:48 2020 +0000
@@ -1,11 +1,14 @@
 //---------------------------------------------------------------
-//  液晶表示器 AQM1602XA-RN-GBW 用クラス(ヘッダ)
+//  液晶表示器 AQM1602XA-RN-GBW 用クラス,ヘッダ
 //
 //  Nucleo の場合のデフォルトのピン
 //      D14 ---- 液晶モジュールの SDA ピン
 //      D15 ---- 液晶モジュールの SCL ピン
 //
-//  2020/02/07, Copyright (c) 2020 MIKAMI, Naoki
+//  割込みサービス・ルーチン内に記述した場合でも動作する
+//  このプログラムを作った際の mbed のリビジョン:Rev.172
+//
+//  2020/04/16, Copyright (c) 2020 MIKAMI, Naoki
 //---------------------------------------------------------------
 
 #include "mbed.h"
@@ -25,40 +28,41 @@
                 PinName scl = D15,          // SCL
                 uint32_t clock = 100000,    // クロック: 100 kHz
                 bool cursor = false,        // カーソル:  off
-                bool blink = false);        // 点滅:     off
+                bool blink = false);        // 点滅:      off
 
         Aqm1602(I2C &i2c,                   // I2C オブジェクトの参照
                 uint32_t clock = 100000,    // クロック: 100 kHz
                 bool cursor = false,        // カーソル:  off
-                bool blink = false);        // 点滅:     off
+                bool blink = false);        // 点滅:      off
 
         virtual ~Aqm1602()
         {   if (NULL != i2cPtr_) delete i2cPtr_;    }
 
         // 液晶表示器が接続されていない場合 false を返す
-        bool IsConnected() { return connected_; }
+        bool IsConnected() const { return connected_; }
         
         // 表示のクリア
-        void Clear();
+        void Clear() const;
         
         // コマンドの送信
-        bool WriteCmd(uint8_t cmd) { return LcdTx(0x00, cmd); }
+        bool WriteCmd(uint8_t cmd) const { return LcdTx(0x00, cmd); }
         
         // 1文字の書込み
-        bool WriteChar(char data) { return LcdTx(0x40, data); }
+        bool WriteChar(char data) const { return LcdTx(0x40, data); }
         
         // 表示位置の設定, x: 0 ~ 15, y: 0, 1
-        void SetXY(uint8_t x = 0, uint8_t y = 0)
+        void SetXY(uint8_t x = 0, uint8_t y = 0) const
         { WriteCmd(x + y*0x40 | 0x80);}
         
         // 文字列の書込み
-        void WriteString(const string str);
+        void WriteString(const string str) const;
         
         // 指定した位置から文字列の書込み
-        void WriteStringXY(const string str, uint8_t x, uint8_t y);
+        void WriteStringXY(const string str, uint8_t x, uint8_t y) const;
 
         // 数値の書込み
-        template <typename T> void WriteValue(const char fmt[], T value)
+        template <typename T>
+        void WriteValue(const char fmt[], T value) const
         {
             char str[N_CHR+1];
             sprintf(str, fmt, value);
@@ -67,17 +71,18 @@
 
         // 指定した位置から数値の書込み
         template <typename T>
-        void WriteValueXY(const char fmt[], T value, uint8_t x, uint8_t y)
+        void WriteValueXY(const char fmt[], T value,
+                          uint8_t x, uint8_t y) const
         {
             SetXY(x, y);
             WriteValue(fmt, value);
         }
 
         // 指定した行のクリア
-        void ClearLine(uint8_t line);
+        void ClearLine(uint8_t line) const;
 
         // コントラストの設定
-        void SetContrast(uint8_t c);
+        void SetContrast(uint8_t c) const;
 
     private:
         // AQM1602A のアドレス
@@ -85,15 +90,15 @@
         static const uint8_t LCD_ADDRESS_ = 0x7C;
         static const uint8_t N_CHR = 16;
 
-        I2C *i2cPtr_;       // I2C オブジェクトのポインタ
+        I2C *const i2cPtr_; // I2C オブジェクトのポインタ
         I2C &i2c_;          // I2C オブジェクトの参照
-        bool connected_;    // false: 液晶表示器は接続されていないnected
+        bool connected_;    // false: 液晶表示器は接続されていない
 
         // 初期化
         void Init(uint32_t clock, bool cursor, bool blink);
         
         // コマンドとデータの送信
-        bool LcdTx(uint8_t cmdData, uint8_t data);
+        bool LcdTx(uint8_t cmdData, uint8_t data) const;
 
         // コピー・コンストラクタと代入演算子関数の禁止
         Aqm1602(const Aqm1602&);