1602 キャラクタディスプレイ データ4bit接続用のテスト STM32F103RB CUCLEOボードでテスト
Dependencies: CharLcd4bit mbed
main.cpp@0:53b69a4c796a, 2017-10-06 (annotated)
- Committer:
- tshl
- Date:
- Fri Oct 06 05:04:58 2017 +0000
- Revision:
- 0:53b69a4c796a
CharLcd4bit?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tshl | 0:53b69a4c796a | 1 | #include "mbed.h" |
tshl | 0:53b69a4c796a | 2 | #include "CharLcd4bit.h" |
tshl | 0:53b69a4c796a | 3 | |
tshl | 0:53b69a4c796a | 4 | // LEDのポート宣言 |
tshl | 0:53b69a4c796a | 5 | DigitalOut Led(LED1); |
tshl | 0:53b69a4c796a | 6 | |
tshl | 0:53b69a4c796a | 7 | // LCDのライブラリ、LCDポート宣言 |
tshl | 0:53b69a4c796a | 8 | CharLcd4bit lcd(A0, A1, A2, D4, D5, D6, D7); |
tshl | 0:53b69a4c796a | 9 | |
tshl | 0:53b69a4c796a | 10 | char message1[][16] = { |
tshl | 0:53b69a4c796a | 11 | "Hello!", |
tshl | 0:53b69a4c796a | 12 | "How are you?", |
tshl | 0:53b69a4c796a | 13 | "I am fine.", |
tshl | 0:53b69a4c796a | 14 | "And you?", |
tshl | 0:53b69a4c796a | 15 | "I am fine too.", |
tshl | 0:53b69a4c796a | 16 | "" |
tshl | 0:53b69a4c796a | 17 | }; |
tshl | 0:53b69a4c796a | 18 | |
tshl | 0:53b69a4c796a | 19 | char message2[][16] = { |
tshl | 0:53b69a4c796a | 20 | "> ", |
tshl | 0:53b69a4c796a | 21 | "-> ", |
tshl | 0:53b69a4c796a | 22 | "--> ", |
tshl | 0:53b69a4c796a | 23 | "---> ", |
tshl | 0:53b69a4c796a | 24 | "----> ", |
tshl | 0:53b69a4c796a | 25 | "-----> ", |
tshl | 0:53b69a4c796a | 26 | "------> ", |
tshl | 0:53b69a4c796a | 27 | "-------> ", |
tshl | 0:53b69a4c796a | 28 | "--------> ", |
tshl | 0:53b69a4c796a | 29 | "---------> ", |
tshl | 0:53b69a4c796a | 30 | "----------> ", |
tshl | 0:53b69a4c796a | 31 | "-----------> ", |
tshl | 0:53b69a4c796a | 32 | "------------> ", |
tshl | 0:53b69a4c796a | 33 | "------------->" |
tshl | 0:53b69a4c796a | 34 | }; |
tshl | 0:53b69a4c796a | 35 | |
tshl | 0:53b69a4c796a | 36 | int main() { |
tshl | 0:53b69a4c796a | 37 | int message1Count = sizeof(message1) / 16; |
tshl | 0:53b69a4c796a | 38 | int message2Count = sizeof(message2) / 16; |
tshl | 0:53b69a4c796a | 39 | int message1Index = 0; |
tshl | 0:53b69a4c796a | 40 | int message2Index = 0; |
tshl | 0:53b69a4c796a | 41 | |
tshl | 0:53b69a4c796a | 42 | // LCD初期化 |
tshl | 0:53b69a4c796a | 43 | lcd.Initialize(); |
tshl | 0:53b69a4c796a | 44 | |
tshl | 0:53b69a4c796a | 45 | lcd.WriteLine(1, "Waiting"); |
tshl | 0:53b69a4c796a | 46 | lcd.WriteLine(2, " for Initialize..."); |
tshl | 0:53b69a4c796a | 47 | wait(3); |
tshl | 0:53b69a4c796a | 48 | |
tshl | 0:53b69a4c796a | 49 | // 表示クリア |
tshl | 0:53b69a4c796a | 50 | lcd.Clear(); |
tshl | 0:53b69a4c796a | 51 | wait(3); |
tshl | 0:53b69a4c796a | 52 | |
tshl | 0:53b69a4c796a | 53 | while(1) { |
tshl | 0:53b69a4c796a | 54 | Led = 0; |
tshl | 0:53b69a4c796a | 55 | lcd.SetPosition(2, 15); |
tshl | 0:53b69a4c796a | 56 | lcd.WriteChar(' '); |
tshl | 0:53b69a4c796a | 57 | wait_ms(500); |
tshl | 0:53b69a4c796a | 58 | |
tshl | 0:53b69a4c796a | 59 | lcd.WriteLine(1, message1[message1Index]); |
tshl | 0:53b69a4c796a | 60 | message1Index++; |
tshl | 0:53b69a4c796a | 61 | if(message1Index >= message1Count) message1Index = 0; |
tshl | 0:53b69a4c796a | 62 | |
tshl | 0:53b69a4c796a | 63 | Led = 1; |
tshl | 0:53b69a4c796a | 64 | lcd.SetPosition(2, 15); |
tshl | 0:53b69a4c796a | 65 | lcd.WriteChar(0xA5); |
tshl | 0:53b69a4c796a | 66 | wait_ms(500); |
tshl | 0:53b69a4c796a | 67 | |
tshl | 0:53b69a4c796a | 68 | lcd.SetPosition(2, 0); |
tshl | 0:53b69a4c796a | 69 | lcd.WriteStr(message2[message2Index]); |
tshl | 0:53b69a4c796a | 70 | message2Index++; |
tshl | 0:53b69a4c796a | 71 | if(message2Index >= message2Count) message2Index = 0; |
tshl | 0:53b69a4c796a | 72 | } |
tshl | 0:53b69a4c796a | 73 | } |