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
Diff: AQM1602.hpp
- Revision:
- 12:21830002e12d
- Parent:
- 11:f650f1e809a9
- Child:
- 13:4975e1c1d743
diff -r f650f1e809a9 -r 21830002e12d AQM1602.hpp --- a/AQM1602.hpp Sat Jul 22 01:56:41 2017 +0000 +++ b/AQM1602.hpp Sat Oct 28 12:57:52 2017 +0000 @@ -1,15 +1,17 @@ //--------------------------------------------------------------- // Class for LCD, AQM1602XA-RN-GBW (Header) -// Use mbed Rev.129 for Nucleo-F401/446/746 and DISCO-F746 // -// Default pin assignments for Nucleo and DISCO-F746 +// Default pin assignments for Nucleo // D14 SDA ---- to pin4 of LCD module // D15 SCL ---- to pin3 of LCD module // -// mbed Rev.130 以降で起こる,割り込み処理での動作不良を修正 -// DISCO-F746 では動作不良は修正できないようだ +// 動作を確認したボード: Nucleo-F401RE, Nucleo-F411RE, Nucleo-F446RE, +// LPC1768 +// 動作が不良なボード: Nucleo-F302R8, Nucle0-F746ZG, Disco-f746NG // -// 2017/07/21, Copyright (c) 2016 MIKAMI, Naoki +// このプログラムを作った際の mbed のリビジョン:Rev.154 +// +// 2017/10/28, Copyright (c) 2017 MIKAMI, Naoki //--------------------------------------------------------------- #ifndef AQM1602I2C_HPP @@ -17,6 +19,7 @@ #include "mbed.h" #include <string> +#include <algorithm> // min() で使用 namespace Mikami { @@ -24,22 +27,13 @@ { public: // Constructor -#if defined(STM32F4) || defined(STM32L0) || defined(__STM32F3xx_H) || \ - defined(STM32F7) -#define STM_USER_BUTTON + // sda, scl のデフォルト値は Nucleo に対応 Aqm1602(PinName sda = D14, // SDA PinName scl = D15, // SCL uint32_t clock = 100000, // clock: 100 kHz bool cursor = false, // cursor: off bool blink = false); // blink: off -// Default constructor is defined for only Nucleo -#else - Aqm1602(PinName sda, // SDA - PinName scl, // SCL - uint32_t clock = 100000, // clock: 100 kHz - bool cursor = false, // cursor: off - bool blink = false); // blink: off -#endif + Aqm1602(I2C &i2c, // Reference of I2C object uint32_t clock = 100000, // clock: 100 kHz bool cursor = false, // cursor: off @@ -52,7 +46,7 @@ bool IsConnected() { return connected_; } // All clear - bool Clear(); + void Clear(); // Send command bool WriteCmd(uint8_t cmd) { return LcdTx(0x00, cmd); } @@ -65,18 +59,15 @@ { WriteCmd(x + y*0x40 | 0x80);} // Write string - void WriteString(const char str[]); - void WriteString(const string str) { WriteString(str.c_str()); } + void WriteString(const string str); // Write string from specified position - void WriteStringXY(const char str[], uint8_t x, uint8_t y); - void WriteStringXY(const string str, uint8_t x, uint8_t y) - { WriteStringXY(str.c_str(), x, y); } + void WriteStringXY(const string str, uint8_t x, uint8_t y); // Write numerical value template <typename T> void WriteValue(const char fmt[], T value) { - char str[17]; + char str[N_CHR+1]; sprintf(str, fmt, value); WriteString(str); } @@ -100,9 +91,9 @@ static const uint8_t LCD_ADDRESS_ = 0x7C; static const uint8_t N_CHR = 16; - I2C *i2cPtr_; // Pointer of I2C object - I2C &i2c_; // Reference of I2C object - bool connected_; // false: LCD is not connected + I2C *i2cPtr_; // Pointer of I2C object + I2C &i2c_; // Reference of I2C object + bool connected_; // false: LCD is not connected void Init(uint32_t clock, bool cursor, bool blink);