![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
I2C 接続の LCD AQM1602XA-RN-GBW 用のライブラリの使用例. Demo program of library for LCD 1602XA-RN-GBW connected using I2C interface.
Dependencies: mbed UIT_AQM1602
main.cpp@10:8d358c3dfc7a, 2020-02-07 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Feb 07 05:24:49 2020 +0000
- Revision:
- 10:8d358c3dfc7a
- Parent:
- 9:3ccc730c6f1b
- Child:
- 11:a15fc2bc069e
11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 7:3b3317e5f14e | 1 | //---------------------------------------------------------------- |
MikamiUitOpen | 9:3ccc730c6f1b | 2 | // LCD 表示器 AQM1602 用クラスライブラリ Aqm1602 の使用例 |
MikamiUitOpen | 7:3b3317e5f14e | 3 | // |
MikamiUitOpen | 9:3ccc730c6f1b | 4 | // 動作を確認したボード: Nucleo-F401RE, Nucleo-F411RE, Nucleo-F446RE, |
MikamiUitOpen | 9:3ccc730c6f1b | 5 | // LPC1768 |
MikamiUitOpen | 9:3ccc730c6f1b | 6 | // 動作が不良なボード: Nucleo-F302R8, Nucle0-F746ZG, Disco-f746NG |
MikamiUitOpen | 8:ac09e00d2903 | 7 | // |
MikamiUitOpen | 10:8d358c3dfc7a | 8 | // 使用した mbed ライブラリ: Rev.172 |
MikamiUitOpen | 10:8d358c3dfc7a | 9 | // 使用した Aqm1602 用ライブラリ: Rev.13 |
MikamiUitOpen | 9:3ccc730c6f1b | 10 | // |
MikamiUitOpen | 10:8d358c3dfc7a | 11 | // 2020/02/07, Copyright (c) 2020 MIKAMI, Naoki |
MikamiUitOpen | 7:3b3317e5f14e | 12 | //---------------------------------------------------------------- |
MikamiUitOpen | 0:e1b05c7eb023 | 13 | |
MikamiUitOpen | 9:3ccc730c6f1b | 14 | #pragma diag_suppress 870 // マルチバイト文字使用の警告を出ないようにする |
MikamiUitOpen | 0:e1b05c7eb023 | 15 | #include "AQM1602.hpp" |
MikamiUitOpen | 1:6c838e71e330 | 16 | |
MikamiUitOpen | 9:3ccc730c6f1b | 17 | // タイマ割り込みを使う場合は,次の define 文をコメントアウトする |
MikamiUitOpen | 9:3ccc730c6f1b | 18 | #define WITHOUT_TIMER_INTERRUPT |
MikamiUitOpen | 0:e1b05c7eb023 | 19 | |
MikamiUitOpen | 9:3ccc730c6f1b | 20 | using Mikami::Aqm1602; |
MikamiUitOpen | 9:3ccc730c6f1b | 21 | // 以下は Nucleo の場合 |
MikamiUitOpen | 9:3ccc730c6f1b | 22 | Aqm1602 lcd_; // OK, Default, D14: SDA, D15: SCL |
MikamiUitOpen | 4:291e82d910d0 | 23 | //Aqm1602 lcd_(D14, D15, 200000, true, true); // OK |
MikamiUitOpen | 9:3ccc730c6f1b | 24 | //Aqm1602 lcd_(PB_4, PA_8); // OK, PB_4: D5, PA_8: D7 |
MikamiUitOpen | 9:3ccc730c6f1b | 25 | |
MikamiUitOpen | 9:3ccc730c6f1b | 26 | // 以下は Nucleo を使い,既に生成された I2C のオブジェクトを渡す場合 |
MikamiUitOpen | 4:291e82d910d0 | 27 | //I2C i2cObj_(D14, D15); |
MikamiUitOpen | 9:3ccc730c6f1b | 28 | //Aqm1602 lcd_(i2cObj_); // OK |
MikamiUitOpen | 9:3ccc730c6f1b | 29 | |
MikamiUitOpen | 9:3ccc730c6f1b | 30 | // 以下は LPC1768 の場合 |
MikamiUitOpen | 9:3ccc730c6f1b | 31 | //Aqm1602 lcd_(p9, p10); // OK |
MikamiUitOpen | 4:291e82d910d0 | 32 | |
MikamiUitOpen | 9:3ccc730c6f1b | 33 | #ifdef WITHOUT_TIMER_INTERRUPT |
MikamiUitOpen | 9:3ccc730c6f1b | 34 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 9:3ccc730c6f1b | 35 | // タイマ割り込みを使わない場合 |
MikamiUitOpen | 9:3ccc730c6f1b | 36 | int main() |
MikamiUitOpen | 9:3ccc730c6f1b | 37 | { |
MikamiUitOpen | 9:3ccc730c6f1b | 38 | if (lcd_.IsConnected()) printf("\r\nLCD が接続されています.\r\n"); |
MikamiUitOpen | 9:3ccc730c6f1b | 39 | else printf("\r\nLCD が接続されていません.\r\n"); |
MikamiUitOpen | 9:3ccc730c6f1b | 40 | |
MikamiUitOpen | 9:3ccc730c6f1b | 41 | lcd_.Clear(); |
MikamiUitOpen | 9:3ccc730c6f1b | 42 | lcd_.WriteString("Using Wait"); |
MikamiUitOpen | 4:291e82d910d0 | 43 | |
MikamiUitOpen | 9:3ccc730c6f1b | 44 | int count = 0; |
MikamiUitOpen | 9:3ccc730c6f1b | 45 | while (true) |
MikamiUitOpen | 9:3ccc730c6f1b | 46 | { |
MikamiUitOpen | 9:3ccc730c6f1b | 47 | lcd_.WriteValueXY("%d", count, 0, 1); |
MikamiUitOpen | 9:3ccc730c6f1b | 48 | printf("%d\r\n", count++); |
MikamiUitOpen | 9:3ccc730c6f1b | 49 | wait(1); // ここで1秒間待つ |
MikamiUitOpen | 9:3ccc730c6f1b | 50 | } |
MikamiUitOpen | 9:3ccc730c6f1b | 51 | } |
MikamiUitOpen | 0:e1b05c7eb023 | 52 | |
MikamiUitOpen | 9:3ccc730c6f1b | 53 | #else |
MikamiUitOpen | 9:3ccc730c6f1b | 54 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 9:3ccc730c6f1b | 55 | // タイマ割り込みを使う場合 |
MikamiUitOpen | 0:e1b05c7eb023 | 56 | Ticker timer_; |
MikamiUitOpen | 0:e1b05c7eb023 | 57 | |
MikamiUitOpen | 9:3ccc730c6f1b | 58 | // タイマ割り込みに対する割り込みサービスルーチン |
MikamiUitOpen | 0:e1b05c7eb023 | 59 | void TimerIsr() |
MikamiUitOpen | 0:e1b05c7eb023 | 60 | { |
MikamiUitOpen | 9:3ccc730c6f1b | 61 | static int count = 0; |
MikamiUitOpen | 9:3ccc730c6f1b | 62 | lcd_.WriteValueXY("%d", count, 0, 1); |
MikamiUitOpen | 9:3ccc730c6f1b | 63 | printf("%d\r\n", count++); |
MikamiUitOpen | 0:e1b05c7eb023 | 64 | } |
MikamiUitOpen | 0:e1b05c7eb023 | 65 | |
MikamiUitOpen | 0:e1b05c7eb023 | 66 | int main() |
MikamiUitOpen | 0:e1b05c7eb023 | 67 | { |
MikamiUitOpen | 9:3ccc730c6f1b | 68 | if (lcd_.IsConnected()) printf("\r\nLCD は接続されています.\r\n"); |
MikamiUitOpen | 9:3ccc730c6f1b | 69 | else printf("\r\nLCD は接続されていません.\r\n"); |
MikamiUitOpen | 3:fe2f8abf2120 | 70 | |
MikamiUitOpen | 0:e1b05c7eb023 | 71 | lcd_.Clear(); |
MikamiUitOpen | 9:3ccc730c6f1b | 72 | lcd_.WriteString("Using Ticker"); |
MikamiUitOpen | 0:e1b05c7eb023 | 73 | |
MikamiUitOpen | 9:3ccc730c6f1b | 74 | TimerIsr(); // 直ちに "0" を表示するため |
MikamiUitOpen | 9:3ccc730c6f1b | 75 | timer_.attach(&TimerIsr, 1); |
MikamiUitOpen | 0:e1b05c7eb023 | 76 | while (true) {} |
MikamiUitOpen | 0:e1b05c7eb023 | 77 | } |
MikamiUitOpen | 10:8d358c3dfc7a | 78 | #endif |