SHARPメモリ液晶+つぼフォント(GT20L16J1Y) の表示サンプル。 半角カナ(JIS X 0201)と、2バイトUTF-8コード(顔文字に使用)に対応。

Dependencies:   GT20L16J1Y_font TFT_fonts mbed sharp_mlcd

Fork of hello_GT20L16J1Y_FONT by Toyomasa Watarai

Files at this revision

API Documentation at this revision

Comitter:
ban4jp
Date:
Sun Sep 21 14:20:23 2014 +0000
Parent:
3:b095be7ec287
Commit message:
Changed Display SHARP Memory LCD.; Added JIS X 0201 Support.

Changed in this revision

C12832.lib Show diff for this revision Revisions of this file
GT20L16J1Y_font.lib Show annotated file Show diff for this revision Revisions of this file
TFT_fonts.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
sharp_mlcd.lib Show annotated file Show diff for this revision Revisions of this file
utf8_table.h Show annotated file Show diff for this revision Revisions of this file
--- a/C12832.lib	Thu Sep 04 06:55:37 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/teams/components/code/C12832/#03069e3deaa4
--- a/GT20L16J1Y_font.lib	Thu Sep 04 06:55:37 2014 +0000
+++ b/GT20L16J1Y_font.lib	Sun Sep 21 14:20:23 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/MACRUM/code/GT20L16J1Y_font/#aed20a7685b9
+http://mbed.org/users/ban4jp/code/GT20L16J1Y_font/#48c4a173bdab
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TFT_fonts.lib	Sun Sep 21 14:20:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/TFT_fonts/#76774250fcec
--- a/main.cpp	Thu Sep 04 06:55:37 2014 +0000
+++ b/main.cpp	Sun Sep 21 14:20:23 2014 +0000
@@ -1,5 +1,5 @@
 #include "mbed.h"
-#include "C12832.h"
+#include "sharp_mlcd.h"
 #include "GT20L16J1Y_font.h"
 #include "utf8_table.h"
 
@@ -17,8 +17,18 @@
 #elif defined(TARGET_LPC11U68)
 C12832 lcd(D11, D13, D12, D7, D10);
 GT20L16J1Y_FONT font(P0_21, P0_22, P1_20, P0_23);
+#elif defined(TARGET_KL46Z) || defined(TARGET_KL25Z)
+GT20L16J1Y_FONT font(D11, D12, D13, D3);
+sharp_mlcd lcd(D11, D13, D2, D4, D5, "LCD");
 #endif
 
+Ticker timer;
+
+void attime()
+{
+    lcd.attime();
+}
+
 #define numOfCharBuffer 40
 uint16_t kBuf[numOfCharBuffer];
 
@@ -36,7 +46,7 @@
             lcd.pixel(x%width + offset_x, y+(8*(x/width)) + offset_y, color);
         }
     }
-    lcd.copy_to_lcd();
+    //lcd.copy_to_lcd();
 }
 
 int int_compar(const uint16_t *a, const uint16_t *b)
@@ -67,21 +77,30 @@
             ret++;
             continue;
         }
-        else if ( (uBuf[0]&0xF0) != 0xE0) {
+        else if ( (uBuf[0]&0xF0) == 0xE0) {
+            // extract valid bits of UTF-8
+            key = ((uBuf[0] & 0x000F) << 12) | ((uBuf[1] & 0x003F) << 6) | (uBuf[2] & 0x003F);
+            uBuf += 3;
+        }
+        else if ( (uBuf[0]&0xE0) == 0xC0) {
+            // extract valid bits of UTF-8
+            key = ((uBuf[0] & 0x001F) << 6) | (uBuf[1] & 0x003F);
+            uBuf += 2;
+        }
+        else {
             uBuf += 1;
             continue;
         }
-        // extract valid bits of UTF-8 
-        key = ((uBuf[0] & 0x000F) << 12) | ((uBuf[1] & 0x003F) << 6) | (uBuf[2] & 0x003F);
         
         // search UTF-8 code from utf8_key[] table to get index of Kuten table
         index = (uint16_t *)bsearch(&key, utf8_key, (sizeof(utf8_key) / sizeof(utf8_key[0])), sizeof(uint16_t), (int (*)(const void *, const void *))int_compar);
         if (index != 0) {
             // get Kuten code
             *pBuf = utf8_value[index - utf8_key];
+        } else {
+            *pBuf = 0;
         }
 
-        uBuf += 3;
         pBuf++;
         ret++;
     }
@@ -102,12 +121,116 @@
     }
 }
 
+void draw_test1()
+{
+    char str[11];
+    int ypos = 0;
+    int p = 0x20;
+    for(int j = 0; j < 14; j++) {
+        sprintf(str, "%8X:", p);
+        draw_utf8(0, ypos, str);
+        int xpos = 80;
+        for(int i = 0; i < 16; i++) {
+            int width = font.read_kuten(0x0000 + p++);
+            draw_string(xpos, ypos, width);
+            xpos += width;
+        }
+        ypos += 16;
+        if(ypos > 240 - 16) ypos = 0;
+        lcd.copy_to_lcd();
+    }
+}
+
+void draw_test2()
+{
+    char str[11];
+    int ypos = 0;
+    unsigned long p = 0x00;
+    for(int j = 0; j < 150; j++) {
+        sprintf(str, "%8X:", p);
+        draw_utf8(0, ypos, str);
+        int xpos = 80;
+        for(int i = 0; i < 16; i++) {
+            font.read_direct(p);
+            p += 32;
+            draw_string(xpos, ypos, 16);
+            xpos += 16;
+        }
+        ypos += 16;
+        if(ypos > 240 - 16) ypos = 0;
+        lcd.copy_to_lcd();
+    }
+}
+
+void draw_test3()
+{
+    char str[11];
+    int ypos = 0;
+    unsigned long p = 0x3E7E0;
+    for(int j = 0; j < 15; j++) {
+        sprintf(str, "%8X:", p);
+        draw_utf8(0, ypos, str);
+        int xpos = 80;
+        for(int i = 0; i < 32; i++) {
+            font.read_direct(p);
+            p += 16;
+            draw_string(xpos, ypos, 8);
+            xpos += 8;
+        }
+        ypos += 16;
+        if(ypos > 240 - 16) ypos = 0;
+        lcd.copy_to_lcd();
+    }
+}
+
 int main()
 {
     led = 0;
+
+    printf("start\r\n");
+
+    timer.attach(attime, 0.5);
+
+    lcd.setmode(NORMAL);
+    lcd.set_auto_up(0);
+
     lcd.cls();
+
     draw_utf8(0, 0,  "進捗どうですか??");
     draw_utf8(0, 16, "mbedで日本語表示");
+
+    draw_utf8(0, 48, "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソ");
+    draw_utf8(0, 64, "タチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚");
+
+    draw_utf8(0, 96, "エンベッド -> エェェェェンベッド!");
+
+    draw_utf8(0, 112, "顔文字1 -> (;´Д`)ゞ");
+    draw_utf8(0, 128, "顔文字2 -> (´・ω・`)");
+    draw_utf8(0, 144, "顔文字3 -> (∩´∀`)∩");
+    draw_utf8(0, 160, "顔文字4 -> (・・)/~");
+
+    lcd.copy_to_lcd();
+
+    wait(5);
+
+    lcd.cls();
+    draw_test1();
+    lcd.copy_to_lcd();
+
+    wait(5);
+
+    lcd.cls();
+    draw_test2();
+    lcd.copy_to_lcd();
+
+    wait(5);
+
+    lcd.cls();
+    draw_test3();
+    lcd.copy_to_lcd();
+
+    printf("end\r\n");
+
     while(1) {
         led = !led;
         wait(1.0);
--- a/mbed.bld	Thu Sep 04 06:55:37 2014 +0000
+++ b/mbed.bld	Sun Sep 21 14:20:23 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sharp_mlcd.lib	Sun Sep 21 14:20:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ban4jp/code/sharp_mlcd/#d2aed1df064c
--- a/utf8_table.h	Thu Sep 04 06:55:37 2014 +0000
+++ b/utf8_table.h	Sun Sep 21 14:20:23 2014 +0000
@@ -1,4 +1,130 @@
 const uint16_t utf8_key[] = {
+92 ,
+162 ,
+163 ,
+167 ,
+168 ,
+172 ,
+176 ,
+177 ,
+180 ,
+182 ,
+215 ,
+247 ,
+913 ,
+914 ,
+915 ,
+916 ,
+917 ,
+918 ,
+919 ,
+920 ,
+921 ,
+922 ,
+923 ,
+924 ,
+925 ,
+926 ,
+927 ,
+928 ,
+929 ,
+931 ,
+932 ,
+933 ,
+934 ,
+935 ,
+936 ,
+937 ,
+945 ,
+946 ,
+947 ,
+948 ,
+949 ,
+950 ,
+951 ,
+952 ,
+953 ,
+954 ,
+955 ,
+956 ,
+957 ,
+958 ,
+959 ,
+960 ,
+961 ,
+963 ,
+964 ,
+965 ,
+966 ,
+967 ,
+968 ,
+969 ,
+1025 ,
+1040 ,
+1041 ,
+1042 ,
+1043 ,
+1044 ,
+1045 ,
+1046 ,
+1047 ,
+1048 ,
+1049 ,
+1050 ,
+1051 ,
+1052 ,
+1053 ,
+1054 ,
+1055 ,
+1056 ,
+1057 ,
+1058 ,
+1059 ,
+1060 ,
+1061 ,
+1062 ,
+1063 ,
+1064 ,
+1065 ,
+1066 ,
+1067 ,
+1068 ,
+1069 ,
+1070 ,
+1071 ,
+1072 ,
+1073 ,
+1074 ,
+1075 ,
+1076 ,
+1077 ,
+1078 ,
+1079 ,
+1080 ,
+1081 ,
+1082 ,
+1083 ,
+1084 ,
+1085 ,
+1086 ,
+1087 ,
+1088 ,
+1089 ,
+1090 ,
+1091 ,
+1092 ,
+1093 ,
+1094 ,
+1095 ,
+1096 ,
+1097 ,
+1098 ,
+1099 ,
+1100 ,
+1101 ,
+1102 ,
+1103 ,
+1105 ,
 8208 ,
 8213 ,
 8214 ,
@@ -3360,11 +3486,200 @@
 65371 ,
 65372 ,
 65373 ,
+65377 ,
+65378 ,
+65379 ,
+65380 ,
+65381 ,
+65382 ,
+65383 ,
+65384 ,
+65385 ,
+65386 ,
+65387 ,
+65388 ,
+65389 ,
+65390 ,
+65391 ,
+65392 ,
+65393 ,
+65394 ,
+65395 ,
+65396 ,
+65397 ,
+65398 ,
+65399 ,
+65400 ,
+65401 ,
+65402 ,
+65403 ,
+65404 ,
+65405 ,
+65406 ,
+65407 ,
+65408 ,
+65409 ,
+65410 ,
+65411 ,
+65412 ,
+65413 ,
+65414 ,
+65415 ,
+65416 ,
+65417 ,
+65418 ,
+65419 ,
+65420 ,
+65421 ,
+65422 ,
+65423 ,
+65424 ,
+65425 ,
+65426 ,
+65427 ,
+65428 ,
+65429 ,
+65430 ,
+65431 ,
+65432 ,
+65433 ,
+65434 ,
+65435 ,
+65436 ,
+65437 ,
+65438 ,
+65439 ,
 65507 ,
 65509 ,
 };
 
 const uint16_t utf8_value[] = {
+0x120 ,
+0x151 ,
+0x152 ,
+0x158 ,
+0x10f ,
+0x22c ,
+0x14b ,
+0x13e ,
+0x10d ,
+0x259 ,
+0x13f ,
+0x140 ,
+0x601 ,
+0x602 ,
+0x603 ,
+0x604 ,
+0x605 ,
+0x606 ,
+0x607 ,
+0x608 ,
+0x609 ,
+0x60a ,
+0x60b ,
+0x60c ,
+0x60d ,
+0x60e ,
+0x60f ,
+0x610 ,
+0x611 ,
+0x612 ,
+0x613 ,
+0x614 ,
+0x615 ,
+0x616 ,
+0x617 ,
+0x618 ,
+0x621 ,
+0x622 ,
+0x623 ,
+0x624 ,
+0x625 ,
+0x626 ,
+0x627 ,
+0x628 ,
+0x629 ,
+0x62a ,
+0x62b ,
+0x62c ,
+0x62d ,
+0x62e ,
+0x62f ,
+0x630 ,
+0x631 ,
+0x632 ,
+0x633 ,
+0x634 ,
+0x635 ,
+0x636 ,
+0x637 ,
+0x638 ,
+0x707 ,
+0x701 ,
+0x702 ,
+0x703 ,
+0x704 ,
+0x705 ,
+0x706 ,
+0x708 ,
+0x709 ,
+0x70a ,
+0x70b ,
+0x70c ,
+0x70d ,
+0x70e ,
+0x70f ,
+0x710 ,
+0x711 ,
+0x712 ,
+0x713 ,
+0x714 ,
+0x715 ,
+0x716 ,
+0x717 ,
+0x718 ,
+0x719 ,
+0x71a ,
+0x71b ,
+0x71c ,
+0x71d ,
+0x71e ,
+0x71f ,
+0x720 ,
+0x721 ,
+0x731 ,
+0x732 ,
+0x733 ,
+0x734 ,
+0x735 ,
+0x736 ,
+0x738 ,
+0x739 ,
+0x73a ,
+0x73b ,
+0x73c ,
+0x73d ,
+0x73e ,
+0x73f ,
+0x740 ,
+0x741 ,
+0x742 ,
+0x743 ,
+0x744 ,
+0x745 ,
+0x746 ,
+0x747 ,
+0x748 ,
+0x749 ,
+0x74a ,
+0x74b ,
+0x74c ,
+0x74d ,
+0x74e ,
+0x74f ,
+0x750 ,
+0x751 ,
+0x737 ,
 0x11e ,
 0x11d ,
 0x122 ,
@@ -6726,6 +7041,69 @@
 0x130 ,
 0x123 ,
 0x131 ,
+0xa1 ,
+0xa2 ,
+0xa3 ,
+0xa4 ,
+0xa5 ,
+0xa6 ,
+0xa7 ,
+0xa8 ,
+0xa9 ,
+0xaa ,
+0xab ,
+0xac ,
+0xad ,
+0xae ,
+0xaf ,
+0xb0 ,
+0xb1 ,
+0xb2 ,
+0xb3 ,
+0xb4 ,
+0xb5 ,
+0xb6 ,
+0xb7 ,
+0xb8 ,
+0xb9 ,
+0xba ,
+0xbb ,
+0xbc ,
+0xbd ,
+0xbe ,
+0xbf ,
+0xc0 ,
+0xc1 ,
+0xc2 ,
+0xc3 ,
+0xc4 ,
+0xc5 ,
+0xc6 ,
+0xc7 ,
+0xc8 ,
+0xc9 ,
+0xca ,
+0xcb ,
+0xcc ,
+0xcd ,
+0xce ,
+0xcf ,
+0xd0 ,
+0xd1 ,
+0xd2 ,
+0xd3 ,
+0xd4 ,
+0xd5 ,
+0xd6 ,
+0xd7 ,
+0xd8 ,
+0xd9 ,
+0xda ,
+0xdb ,
+0xdc ,
+0xdd ,
+0xde ,
+0xdf ,
 0x111 ,
 0x14f ,
 };