Class library for LCD character display ACM1602NI using I2C on Nucleo. Nucleo 用 I2C 接続の LCD キャラクタ・ディスプレー ACM1602Ni 用のクラス・ライブラリ.
Dependents: UIT2_VariableFIR_LPFHPF UIT2_VariableFIR_LPF UIT2_InputSW_LCD ADDA_Prototype_PollingSW ... more
Diff: ACM1602NI.cpp
- Revision:
- 1:7c6b2df4e60b
- Parent:
- 0:d8048b36d982
- Child:
- 2:0936ba74019a
--- a/ACM1602NI.cpp Mon Oct 20 03:01:24 2014 +0000 +++ b/ACM1602NI.cpp Sat Nov 08 09:28:45 2014 +0000 @@ -1,7 +1,7 @@ //------------------------------------------------------- -// Class for LCD, ACM1602NI +// Class for LCD, ACM1602Ni // -// 2014/09/13, Copyright (c) 2014 MIKAMI, Naoki +// 2014/10/14, Copyright (c) 2014 MIKAMI, Naoki //------------------------------------------------------- #include "ACM1602NI.hpp" @@ -23,8 +23,11 @@ myI2c_ = (I2C_TypeDef*)I2C_3; // I2C3 will be used connected_ = Clear(); // Clear display - if (!connected_) return; - + if (!connected_) + { + fprintf(stderr, "\r\nLCD device not connected\r\n"); + return; + } if (clock != 100000) i2c_.frequency(clock); WriteCmd(0x38); // data length:8-bit, 2-line, 5×8 dots @@ -41,13 +44,19 @@ } // Write string from specified position - void Acm1602Ni::WriteString(const char str[], + void Acm1602Ni::WriteString(const char str[]) + { + for (int n=0; n<16; n++) + if (str[n] == 0) break; + else WriteChar(str[n]); + } + + // Write string from specified position + void Acm1602Ni::WriteStringXY(const char str[], uint8_t x, uint8_t y) { SetXY(x, y); - for (int n=0; n<16; n++) - if (str[n] == 0) break; - else WriteChar(str[n]); + WriteString(str); } //--------------------------------------------------- @@ -76,7 +85,7 @@ for (int n=0; n<LENGTH; n++) { wait_us(WAIT); - if (!Check(myI2c_->SR2, I2C_SR2_BUSY)) break; + if (!CheckSR2(I2C_SR2_BUSY)) break; if (n == LENGTH-1) return false; } @@ -85,10 +94,9 @@ // Confirm start condition and master mode for (int n=0; n<LENGTH; n++) { - wait_us(WAIT); - if (Check(myI2c_->SR1, I2C_SR1_SB) && - Check(myI2c_->SR2, I2C_SR2_MSL | - I2C_SR2_BUSY)) break; + wait_us(WAIT); + if (CheckSR12(I2C_SR1_SB, I2C_SR2_MSL | + I2C_SR2_BUSY)) break; if (n == LENGTH-1) return false; } @@ -98,14 +106,13 @@ for (int n=0; n<LENGTH; n++) { wait_us(WAIT); - if (Check(myI2c_->SR1, I2C_SR1_TXE | - I2C_SR1_ADDR) && - Check(myI2c_->SR2, I2C_SR2_MSL | - I2C_SR2_BUSY | - I2C_SR2_TRA)) break; + if (CheckSR12(I2C_SR1_TXE | I2C_SR1_ADDR, + I2C_SR2_MSL | I2C_SR2_BUSY + | I2C_SR2_TRA)) break; if (n == LENGTH-1) return false; } return true; } } +