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:
- 8:6f28524bcb29
- Parent:
- 7:fd23d2941f36
- Child:
- 10:49e6a8f8fe4f
- Child:
- 11:bbf31054cfd8
diff -r fd23d2941f36 -r 6f28524bcb29 ACM1602NI.cpp --- a/ACM1602NI.cpp Sat Jan 17 09:59:57 2015 +0000 +++ b/ACM1602NI.cpp Thu Mar 26 01:34:27 2015 +0000 @@ -1,7 +1,7 @@ //------------------------------------------------------- // Class for LCD, ACM1602Ni // -// 2015/01/17, Copyright (c) 2015 MIKAMI, Naoki +// 2015/03/26, Copyright (c) 2015 MIKAMI, Naoki //------------------------------------------------------- #include "ACM1602NI.hpp" @@ -65,9 +65,15 @@ // Send command and data bool Acm1602Ni::LcdTx(uint8_t cmdData, uint8_t data) { - if (!Start()) return false; + // Generate start condition + i2c_.start(); + + // Send slave address + TxDR(LCD_ADDRESS_); + + if (!IsTxMode()) return false; - // defines kind of "data" in next statement + // Define kind of "data" in next statement TxDR(cmdData); TxDR(data); wait_us(500); // indispensable @@ -78,26 +84,18 @@ return true; } - // Preparation for send of command and data - bool Acm1602Ni::Start() + // Check on transmitter mode + bool Acm1602Ni::IsTxMode() { - const uint8_t LENGTH = 10; - - // Generate start condition - i2c_.start(); - - // Send slave address - TxDR(LCD_ADDRESS_); - // Confirm on transmit mode - for (int n=0; n<LENGTH; n++) + for (int n=0; n<10; n++) { wait_us(10); if (CheckSR12(I2C_SR1_TXE | I2C_SR1_ADDR, I2C_SR2_MSL | I2C_SR2_BUSY - | I2C_SR2_TRA)) break; - if (n == LENGTH-1) return false; + | I2C_SR2_TRA)) + return true; } - - return true; + + return false; } }