test program for Sharp memory LCD

Dependencies:   TFT_fonts mbed sharp_mlcd

Sharp のメモリLCD, LS027B4DH01 (秋月電子扱い http://akizukidenshi.com/catalog/g/gP-04944/) 用の表示ライブラリとテストプログラム。この LCD は初期設定が不要です。mbed の GraphicDisplay ライブラリを継承していますからフォントなどについてはそちらを見てください。

この LCD は低消費電力と高コントラストが特徴で、高速表示にはあまり向かないと思います。ライブラリもあまり効率を考慮していません。フレームバッファの自動書き出しはオフ(set_auto_up(0))にして、まとめて表示(copy_to_lcd())するのが良いでしょう。フレーム反転フラグ(EXTCOMIN)の制御はあまりスマートではありません。リフレッシュ等も考慮していません。VDD は 4.8-5.5V となっていますが、3.3V でも動きました。電源が 5V でも信号は 3.3V が推奨値です。

sharp_mlcd.h 内で WIDTH と HEIGHT を 96 にし、sharp_mlcd.cpp 内で SPI クロックを 1MHz にすれば TI の Sharp Memory LCD BoosterPack (LS013B4DN04)でも使えます。その際には main.cpp 内で使用しているフォントやビットマップを適当に変更してください。こちらは 3.3V 動作です。SPI クロックは LS027B4DH01 と同じ 2MHz でも動作しましたが、規格外です。

ビットマップデータの変換にはこれとか使えると思います。 https://code.google.com/p/lcd-image-converter/

pin assign

LS027B4DH01TI Sharp Memory LCD BoosterPackNucleo L152RE
1 SCLK7 SPI CLKD13
2 SI15 SPI SIMOD11
3 SCS6 SPI CSD10
4 EXTCOMIN19 External COM InversionD9
5 DISP5 LCD Enable (R16)D8
6 VDDA-5V
7 VDD-5V
8 EXTMODE1 +3.3V3.3V
9 VSS20 GNDGND
10 VSSA-GND

/media/uploads/masato/ls027b4dh01-1.jpg

大きな"mbed"はビットマップ、その下はテキスト。

/media/uploads/masato/ls013b4dn04.jpg

ディスプレイ面の赤丸は保護シートを剥がしていないため。

/media/uploads/masato/ls027b4dh01-2.jpg

ビットマップのアニメーション。

/media/uploads/masato/ls027b4dh01-3.jpg

直線。

main.cpp

Committer:
masato
Date:
2014-05-11
Revision:
1:443ce3a02a88
Parent:
0:eb868b2d7042

File content as of revision 1:443ce3a02a88:

#include "mbed.h"
#include "sharp_mlcd.h"

#include "Arial12x12.h"

sharp_mlcd lcd("LCD");
Serial pc(USBTX, USBRX);

const static 
char mbedlogo128x48[768]
= {
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc7,0x83,0xe0,0x3c,0x7c,0x00,0x7e,0x00,0x3e,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xdf,0xef,0xf8,0x3d,0xfe,0x01,0xff,0x80,0x7f,0xbc,0x00,0x00,0x00,
   0x00,0x00,0x03,0xff,0xff,0xf8,0x3f,0xff,0x03,0xff,0xc0,0xff,0xfc,0x00,0x00,0x00,
   0x00,0x00,0x03,0xf1,0xfc,0x7c,0x3f,0x0f,0x87,0xc3,0xe1,0xf0,0xfc,0x00,0x00,0x00,
   0x00,0x00,0x03,0xe0,0xf8,0x3c,0x3e,0x07,0x87,0x81,0xe1,0xe0,0x7c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xe3,0xc0,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xf3,0xc0,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0x03,0xc0,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x03,0xcf,0x00,0x03,0xc0,0x7c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x07,0x87,0x80,0x01,0xe0,0x7c,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0x0f,0x87,0xc1,0xc1,0xf0,0xfc,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0xff,0x03,0xff,0xf0,0xff,0xfc,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3d,0xfe,0x01,0xff,0xe0,0x7f,0xbc,0x00,0x00,0x00,
   0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0xfc,0x00,0x7f,0x00,0x3f,0x3c,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};


const static struct Bitmap logo = {
  128,
  48,
  16,
  (char*)mbedlogo128x48,
};

const char target[] = 
#if defined(TARGET_NUCLEO_L152RE)
"STM32 Nucleo L152RE"
#elif defined(TARGET_KL05Z)
"Freescale FRDM-KL05Z"
#else
"????"
#endif
;

Ticker timer;

void attime() {
    lcd.attime();
}

static const unsigned char  logo16_glcd_bmp[] =
{ 0x00, 0xc0, // B00000000, B11000000,
  0x01, 0xc0, // B00000001, B11000000,
  0x01, 0xc0, // B00000001, B11000000,
  0x03, 0xe0, // B00000011, B11100000,
  0xf3, 0xe0, // B11110011, B11100000,
  0xfe, 0xf8, // B11111110, B11111000,
  0x7e, 0xff, // B01111110, B11111111,
  0x33, 0x9f, // B00110011, B10011111,
  0x1f, 0xfc, // B00011111, B11111100,
  0x0d, 0x70, // B00001101, B01110000,
  0x1b, 0xa0, // B00011011, B10100000,
  0x3f, 0xe0, // B00111111, B11100000,
  0x3f, 0xf0, // B00111111, B11110000,
  0x7c, 0xf0, // B01111100, B11110000,
  0x70, 0x70, // B01110000, B01110000,
  0x00, 0x30 }; // B00000000, B00110000 };
  
const static struct Bitmap snow = {
  16,
  16,
  2,
  (char*)logo16_glcd_bmp,
};

#define NUMFLAKES 16
#define XPOS 0
#define YPOS 1
#define DELTAY 2

void testdrawbitmap(struct Bitmap bitmap) {
  uint8_t icons[NUMFLAKES][3];
  srand((unsigned int)time(NULL)); // srandom(666);     // whatever seed
  int i;
 
  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = rand() % lcd.width(); // display.width();
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = rand() % 5 + 1;
#if 0
    Serial.print("x: ");
    Serial.print(icons[f][XPOS], DEC);
    Serial.print(" y: ");
    Serial.print(icons[f][YPOS], DEC);
    Serial.print(" dy: ");
    Serial.println(icons[f][DELTAY], DEC);
#endif
  }
  lcd.setmode(XOR);
  i = 0;
  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      lcd.print_bm(bitmap, icons[f][XPOS], icons[f][YPOS], 1); 
    }
    lcd.copy_to_lcd();
    wait(0.2); // delay(200);
    
    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      lcd.print_bm(bitmap, icons[f][XPOS], icons[f][YPOS], 1); 
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > lcd.height()) { // display.height()) {
        icons[f][XPOS] = rand() % lcd.width(); // display.width();
        icons[f][YPOS] = 0;
        icons[f][DELTAY] = rand() % 5 + 1;
      }
    }
    if (i++ > 100) break;
   }
   lcd.setmode(NORMAL);
}


void testdrawline() {  
  for (int16_t i=0; i<lcd.width(); i+=4) {
    lcd.line(0, 0, i, lcd.height()-1, 1);
    lcd.copy_to_lcd();
  }
  for (int16_t i=0; i<lcd.height(); i+=4) {
    lcd.line(0, 0, lcd.width()-1, i, 1);
    lcd.copy_to_lcd();
  }
  wait(0.25); // delay(250);
#if 0
  lcd.cls();
  for (int16_t i=0; i<lcd.width(); i+=4) {
    lcd.line(0, lcd.height()-1, i, 0, 1);
    lcd.copy_to_lcd();
  }
  for (int16_t i=lcd.height()-1; i>=0; i-=4) {
    lcd.line(0, lcd.height()-1, lcd.width()-1, i, 1);
    lcd.copy_to_lcd();
  }
  wait(0.25); // delay(250);
  
  lcd.cls();
  for (int16_t i=lcd.width()-1; i>=0; i-=4) {
    lcd.line(lcd.width()-1, lcd.height()-1, i, 0, 1);
    lcd.copy_to_lcd();
  }
  for (int16_t i=lcd.height()-1; i>=0; i-=4) {
    lcd.line(lcd.width()-1, lcd.height()-1, 0, i, 1);
    lcd.copy_to_lcd();
  }
  wait(0.25); // delay(250);

  lcd.cls();
  for (int16_t i=0; i<lcd.height(); i+=4) {
    lcd.line(lcd.width()-1, 0, 0, i, 1);
    lcd.copy_to_lcd();
  }
  for (int16_t i=0; i<lcd.width(); i+=4) {
    lcd.line(lcd.width()-1, 0, i, lcd.height()-1, 1); 
    lcd.copy_to_lcd();
  }
  wait(0.25);
#endif
}

int main() {
    pc.printf("%s\r\n", target);
    timer.attach(attime, 0.5);
    lcd.setmode(NORMAL);
    // lcd.set_font((unsigned char*)Arial24x23);
    lcd.set_font((unsigned char*)Arial12x12);
    lcd.set_auto_up(0);
    while (1) {
        lcd.cls();
        lcd.locate(0,0);
        pc.printf("\r\n %s!\r\n This is Sharp Memory LCD demo.", target);
        lcd.printf("\r\n %s!\r\n This is Sharp Memory LCD demo.", target);
        wait(1);
        lcd.cls();
        testdrawline();
        wait(1);
        lcd.cls();
        testdrawbitmap(snow);
        wait(1);
        lcd.cls();
        wait(1);
        lcd.print_bm(logo, 0, 0, 1);
        lcd.copy_to_lcd();
        lcd.printf("\r\n\r\n  %s", target);
        lcd.copy_to_lcd();
        
        wait(10);
    }
}