SHARPメモリ液晶+つぼフォント(GT20L16J1Y) の表示サンプル。 半角カナ(JIS X 0201)と、2バイトUTF-8コード(顔文字に使用)に対応。
Dependencies: GT20L16J1Y_font TFT_fonts mbed sharp_mlcd
Fork of hello_GT20L16J1Y_FONT by
Diff: main.cpp
- Revision:
- 4:ad167108200d
- Parent:
- 3:b095be7ec287
--- 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);
ban4jp -
