Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- tontoko
- Date:
- 2019-06-08
- Revision:
- 3:d4b979f6f27e
- Parent:
- 2:d2d66ce72529
- Child:
- 4:0f29c512e03d
File content as of revision 3:d4b979f6f27e:
#include "mbed.h"
#include "TextLCD.h"
#define LED_TIME  0.2
DigitalOut myled(P0_22);
Serial pc(USBTX, USBRX);
// TextLCDの使用宣言
TextLCD lcd(p15,p16,p17,p18,p19,p20);  //接続ポートの設定(rs,e,d4,d5,d6,d7)
int main()
{
    
    lcd.init(); //各種設定を初期値に。画面も消去。カーソル位置(0,0)
    
    //  単純な文字列表示
    lcd.printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    
    wait(1);
    // カーソル位置を(0,1)に指定
    lcd.locate(0,1);
    lcd.printf("abcdefghijklmnopqrstuvwxyz");
    
    //表示内容はそのままで、カーソル位置を0,0に。画面のシフトも初期位置に
    lcd.home();
    wait(1);
    lcd.noDisplay(); //ディスプレイ表示OFF
    
    lcd.printf("0123");//表示OFFのままprint
    wait(1);
    lcd.display();  //ディスプレイ表示ON(画面OFFのままprintしても反映されている)
    
    wait(1);
    lcd.cursor();   //カーソル表示ON
    
    lcd.blink();    //カーソルブリンクON
    
    wait(5);
    
    lcd.noBlink();    //カーソルブリンクOFF
    
    lcd.noCursor();   //カーソル表示OFF
    //表示内容はそのままで、画面を左にシフト 4回
    for (int i = 0; i < 4; i++) {
        lcd.shiftDisplayLeft();
        wait(1);
        }
    //表示内容はそのままで、画面を右にシフト 4回
    for (int i = 0; i< 4; i++) {
        lcd.shiftDisplayRight();
        wait(1);
        }
    lcd.cls(); //画面消去、カーソルは(0,0)へ
    
    //カーソル位置を10,0へ
    lcd.locate(10,0);
    
    //表示位置をカーソルから右方向へ設定(デフォルト)
    lcd.leftToRight();
    lcd.printf("5678");
    wait(1);
    //カーソル位置を4,0へ
    lcd.locate(4,0);
    
    //表示位置をカーソル位置から左方向へ設定
    lcd.rightToLeft();
    lcd.printf("1234");      //画面上では "4321"とカーソル位置から左方向に表示される
    wait(1);
    
    //表示位置をカーソルから右方向へ設定(デフォルト
    lcd.leftToRight();
    lcd.cls();
    lcd.home();
    wait(1);
    
    //オートスクロール カーソル位置に文字を表示する度に、設定した方向に画面をシフト
    lcd.AutoScroll();
    lcd.locate(8,0);
    lcd.printf("1");  //わかりやすく1文字ずつ描画
    wait(1);
    lcd.printf("2");
    wait(1);
    lcd.printf("3");
    wait(1);
    lcd.printf("4");
    wait(1);
   
    lcd.init();
    // 表示する最大桁数を設定  1 〜 40(画面は16文字まで。DDRAMは最大40文字×2行)
    lcd.set_max_cols(12);  //12文字で折返しになる設定
    lcd.locate(4,0);
    lcd.rightToLeft();
    lcd.printf("1234567890123456789012");
    wait(5);
    
    lcd.init();
    // CGRAM(外字)の設定 bitを設定した配列を用意
    char bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
    char note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
    char clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
    char heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
    char duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
    char check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
    char cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
    char retarrow[8] = {0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
    
    //CGRAMに格納  0番〜7番までの8文字
    lcd.createChar(0, bell);
    lcd.createChar(1, note);
    lcd.createChar(2, clock);
    lcd.createChar(3, heart);
    lcd.createChar(4, duck);
    lcd.createChar(5, check);
    lcd.createChar(6, cross);
    lcd.createChar(7, retarrow);
    lcd.home();
    
    //設定した外字を表示
    for (int j=0; j<8; j++) {
      lcd.putc(j);
    }
    
    
   while(1) {
        myled = 1;
        wait(LED_TIME);
        myled = 0;
        wait(LED_TIME);
    }
}