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
- Committer:
- MikamiUitOpen
- Date:
- 2017-07-22
- Revision:
- 11:f650f1e809a9
- Parent:
- 10:6e6c0f24e81f
- Child:
- 12:21830002e12d
File content as of revision 11:f650f1e809a9:
//--------------------------------------------------------------- // 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 // D14 SDA ---- to pin4 of LCD module // D15 SCL ---- to pin3 of LCD module // // mbed Rev.130 以降で起こる,割り込み処理での動作不良を修正 // DISCO-F746 では動作不良は修正できないようだ // // 2017/07/21, Copyright (c) 2016 MIKAMI, Naoki //--------------------------------------------------------------- #ifndef AQM1602I2C_HPP #define AQM1602I2C_HPP #include "mbed.h" #include <string> namespace Mikami { class Aqm1602 { public: // Constructor #if defined(STM32F4) || defined(STM32L0) || defined(__STM32F3xx_H) || \ defined(STM32F7) #define STM_USER_BUTTON 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 bool blink = false); // blink: off virtual ~Aqm1602() { if (NULL != i2cPtr_) delete i2cPtr_; } // Return false if LCD is not connected bool IsConnected() { return connected_; } // All clear bool Clear(); // Send command bool WriteCmd(uint8_t cmd) { return LcdTx(0x00, cmd); } // Write character (Not 0x80 but 0x40) bool WriteChar(char data) { return LcdTx(0x40, data); } // Specify display position, x: 0 - 7, y: 0, 1 void SetXY(uint8_t x = 0, uint8_t y = 0) { WriteCmd(x + y*0x40 | 0x80);} // Write string void WriteString(const char str[]); void WriteString(const string str) { WriteString(str.c_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); } // Write numerical value template <typename T> void WriteValue(const char fmt[], T value) { char str[17]; sprintf(str, fmt, value); WriteString(str); } // Write numerical value from specified position template <typename T> void WriteValueXY(const char fmt[], T value, uint8_t x, uint8_t y) { SetXY(x, y); WriteValue(fmt, value); } // Clear of specified line void ClearLine(uint8_t line); void SetContrast(uint8_t c); private: // Slave address of AQM1602A // left-justified 7-bit address 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 void Init(uint32_t clock, bool cursor, bool blink); bool LcdTx(uint8_t cmdData, uint8_t data); // disallow copy constructor and assignment operator Aqm1602(const Aqm1602&); Aqm1602& operator=(const Aqm1602&); }; } #endif // AQM1602I2C_HPP