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
AQM1602.hpp@12:21830002e12d, 2017-10-28 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Oct 28 12:57:52 2017 +0000
- Revision:
- 12:21830002e12d
- Parent:
- 11:f650f1e809a9
- Child:
- 13:4975e1c1d743
13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 10:6e6c0f24e81f | 1 | //--------------------------------------------------------------- |
MikamiUitOpen | 0:f177013dc4fc | 2 | // Class for LCD, AQM1602XA-RN-GBW (Header) |
MikamiUitOpen | 0:f177013dc4fc | 3 | // |
MikamiUitOpen | 12:21830002e12d | 4 | // Default pin assignments for Nucleo |
MikamiUitOpen | 0:f177013dc4fc | 5 | // D14 SDA ---- to pin4 of LCD module |
MikamiUitOpen | 0:f177013dc4fc | 6 | // D15 SCL ---- to pin3 of LCD module |
MikamiUitOpen | 0:f177013dc4fc | 7 | // |
MikamiUitOpen | 12:21830002e12d | 8 | // 動作を確認したボード: Nucleo-F401RE, Nucleo-F411RE, Nucleo-F446RE, |
MikamiUitOpen | 12:21830002e12d | 9 | // LPC1768 |
MikamiUitOpen | 12:21830002e12d | 10 | // 動作が不良なボード: Nucleo-F302R8, Nucle0-F746ZG, Disco-f746NG |
MikamiUitOpen | 11:f650f1e809a9 | 11 | // |
MikamiUitOpen | 12:21830002e12d | 12 | // このプログラムを作った際の mbed のリビジョン:Rev.154 |
MikamiUitOpen | 12:21830002e12d | 13 | // |
MikamiUitOpen | 12:21830002e12d | 14 | // 2017/10/28, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 10:6e6c0f24e81f | 15 | //--------------------------------------------------------------- |
MikamiUitOpen | 0:f177013dc4fc | 16 | |
MikamiUitOpen | 0:f177013dc4fc | 17 | #ifndef AQM1602I2C_HPP |
MikamiUitOpen | 0:f177013dc4fc | 18 | #define AQM1602I2C_HPP |
MikamiUitOpen | 0:f177013dc4fc | 19 | |
MikamiUitOpen | 0:f177013dc4fc | 20 | #include "mbed.h" |
MikamiUitOpen | 1:18cd1c4212c3 | 21 | #include <string> |
MikamiUitOpen | 12:21830002e12d | 22 | #include <algorithm> // min() で使用 |
MikamiUitOpen | 0:f177013dc4fc | 23 | |
MikamiUitOpen | 0:f177013dc4fc | 24 | namespace Mikami |
MikamiUitOpen | 0:f177013dc4fc | 25 | { |
MikamiUitOpen | 0:f177013dc4fc | 26 | class Aqm1602 |
MikamiUitOpen | 0:f177013dc4fc | 27 | { |
MikamiUitOpen | 0:f177013dc4fc | 28 | public: |
MikamiUitOpen | 0:f177013dc4fc | 29 | // Constructor |
MikamiUitOpen | 12:21830002e12d | 30 | // sda, scl のデフォルト値は Nucleo に対応 |
MikamiUitOpen | 0:f177013dc4fc | 31 | Aqm1602(PinName sda = D14, // SDA |
MikamiUitOpen | 0:f177013dc4fc | 32 | PinName scl = D15, // SCL |
MikamiUitOpen | 0:f177013dc4fc | 33 | uint32_t clock = 100000, // clock: 100 kHz |
MikamiUitOpen | 0:f177013dc4fc | 34 | bool cursor = false, // cursor: off |
MikamiUitOpen | 0:f177013dc4fc | 35 | bool blink = false); // blink: off |
MikamiUitOpen | 12:21830002e12d | 36 | |
MikamiUitOpen | 8:854c244a7863 | 37 | Aqm1602(I2C &i2c, // Reference of I2C object |
MikamiUitOpen | 8:854c244a7863 | 38 | uint32_t clock = 100000, // clock: 100 kHz |
MikamiUitOpen | 8:854c244a7863 | 39 | bool cursor = false, // cursor: off |
MikamiUitOpen | 8:854c244a7863 | 40 | bool blink = false); // blink: off |
MikamiUitOpen | 8:854c244a7863 | 41 | |
MikamiUitOpen | 10:6e6c0f24e81f | 42 | virtual ~Aqm1602() |
MikamiUitOpen | 8:854c244a7863 | 43 | { if (NULL != i2cPtr_) delete i2cPtr_; } |
MikamiUitOpen | 8:854c244a7863 | 44 | |
MikamiUitOpen | 3:414f98234c94 | 45 | // Return false if LCD is not connected |
MikamiUitOpen | 3:414f98234c94 | 46 | bool IsConnected() { return connected_; } |
MikamiUitOpen | 3:414f98234c94 | 47 | |
MikamiUitOpen | 0:f177013dc4fc | 48 | // All clear |
MikamiUitOpen | 12:21830002e12d | 49 | void Clear(); |
MikamiUitOpen | 1:18cd1c4212c3 | 50 | |
MikamiUitOpen | 0:f177013dc4fc | 51 | // Send command |
MikamiUitOpen | 3:414f98234c94 | 52 | bool WriteCmd(uint8_t cmd) { return LcdTx(0x00, cmd); } |
MikamiUitOpen | 1:18cd1c4212c3 | 53 | |
MikamiUitOpen | 0:f177013dc4fc | 54 | // Write character (Not 0x80 but 0x40) |
MikamiUitOpen | 3:414f98234c94 | 55 | bool WriteChar(char data) { return LcdTx(0x40, data); } |
MikamiUitOpen | 1:18cd1c4212c3 | 56 | |
MikamiUitOpen | 0:f177013dc4fc | 57 | // Specify display position, x: 0 - 7, y: 0, 1 |
MikamiUitOpen | 0:f177013dc4fc | 58 | void SetXY(uint8_t x = 0, uint8_t y = 0) |
MikamiUitOpen | 0:f177013dc4fc | 59 | { WriteCmd(x + y*0x40 | 0x80);} |
MikamiUitOpen | 1:18cd1c4212c3 | 60 | |
MikamiUitOpen | 0:f177013dc4fc | 61 | // Write string |
MikamiUitOpen | 12:21830002e12d | 62 | void WriteString(const string str); |
MikamiUitOpen | 1:18cd1c4212c3 | 63 | |
MikamiUitOpen | 0:f177013dc4fc | 64 | // Write string from specified position |
MikamiUitOpen | 12:21830002e12d | 65 | void WriteStringXY(const string str, uint8_t x, uint8_t y); |
MikamiUitOpen | 1:18cd1c4212c3 | 66 | |
MikamiUitOpen | 9:74a845df6e7a | 67 | // Write numerical value |
MikamiUitOpen | 9:74a845df6e7a | 68 | template <typename T> void WriteValue(const char fmt[], T value) |
MikamiUitOpen | 9:74a845df6e7a | 69 | { |
MikamiUitOpen | 12:21830002e12d | 70 | char str[N_CHR+1]; |
MikamiUitOpen | 9:74a845df6e7a | 71 | sprintf(str, fmt, value); |
MikamiUitOpen | 9:74a845df6e7a | 72 | WriteString(str); |
MikamiUitOpen | 9:74a845df6e7a | 73 | } |
MikamiUitOpen | 9:74a845df6e7a | 74 | |
MikamiUitOpen | 9:74a845df6e7a | 75 | // Write numerical value from specified position |
MikamiUitOpen | 9:74a845df6e7a | 76 | template <typename T> |
MikamiUitOpen | 9:74a845df6e7a | 77 | void WriteValueXY(const char fmt[], T value, uint8_t x, uint8_t y) |
MikamiUitOpen | 9:74a845df6e7a | 78 | { |
MikamiUitOpen | 9:74a845df6e7a | 79 | SetXY(x, y); |
MikamiUitOpen | 9:74a845df6e7a | 80 | WriteValue(fmt, value); |
MikamiUitOpen | 9:74a845df6e7a | 81 | } |
MikamiUitOpen | 9:74a845df6e7a | 82 | |
MikamiUitOpen | 0:f177013dc4fc | 83 | // Clear of specified line |
MikamiUitOpen | 0:f177013dc4fc | 84 | void ClearLine(uint8_t line); |
MikamiUitOpen | 1:18cd1c4212c3 | 85 | |
MikamiUitOpen | 0:f177013dc4fc | 86 | void SetContrast(uint8_t c); |
MikamiUitOpen | 0:f177013dc4fc | 87 | |
MikamiUitOpen | 0:f177013dc4fc | 88 | private: |
MikamiUitOpen | 3:414f98234c94 | 89 | // Slave address of AQM1602A |
MikamiUitOpen | 0:f177013dc4fc | 90 | // left-justified 7-bit address |
MikamiUitOpen | 0:f177013dc4fc | 91 | static const uint8_t LCD_ADDRESS_ = 0x7C; |
MikamiUitOpen | 0:f177013dc4fc | 92 | static const uint8_t N_CHR = 16; |
MikamiUitOpen | 0:f177013dc4fc | 93 | |
MikamiUitOpen | 12:21830002e12d | 94 | I2C *i2cPtr_; // Pointer of I2C object |
MikamiUitOpen | 12:21830002e12d | 95 | I2C &i2c_; // Reference of I2C object |
MikamiUitOpen | 12:21830002e12d | 96 | bool connected_; // false: LCD is not connected |
MikamiUitOpen | 0:f177013dc4fc | 97 | |
MikamiUitOpen | 8:854c244a7863 | 98 | void Init(uint32_t clock, bool cursor, bool blink); |
MikamiUitOpen | 8:854c244a7863 | 99 | |
MikamiUitOpen | 3:414f98234c94 | 100 | bool LcdTx(uint8_t cmdData, uint8_t data); |
MikamiUitOpen | 0:f177013dc4fc | 101 | |
MikamiUitOpen | 7:5375acc9a74a | 102 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:f177013dc4fc | 103 | Aqm1602(const Aqm1602&); |
MikamiUitOpen | 0:f177013dc4fc | 104 | Aqm1602& operator=(const Aqm1602&); |
MikamiUitOpen | 0:f177013dc4fc | 105 | }; |
MikamiUitOpen | 0:f177013dc4fc | 106 | } |
MikamiUitOpen | 3:414f98234c94 | 107 | #endif // AQM1602I2C_HPP |