SHARPメモリ液晶+つぼフォント(GT20L16J1Y) の表示サンプル。 半角カナ(JIS X 0201)と、2バイトUTF-8コード(顔文字に使用)に対応。
Dependencies: GT20L16J1Y_font TFT_fonts mbed sharp_mlcd
Fork of hello_GT20L16J1Y_FONT by
main.cpp
00001 #include "mbed.h" 00002 #include "sharp_mlcd.h" 00003 #include "GT20L16J1Y_font.h" 00004 #include "utf8_table.h" 00005 00006 #include <stdlib.h> 00007 00008 /* 00009 GT20L16J1Y library test program 00010 */ 00011 00012 DigitalOut led(LED1); 00013 00014 #if defined(TARGET_LPC1768) 00015 C12832 lcd(p5, p7, p6, p8, p11); 00016 GT20L16J1Y_FONT font(p11, p12, p13, p10); 00017 #elif defined(TARGET_LPC11U68) 00018 C12832 lcd(D11, D13, D12, D7, D10); 00019 GT20L16J1Y_FONT font(P0_21, P0_22, P1_20, P0_23); 00020 #elif defined(TARGET_KL46Z) || defined(TARGET_KL25Z) 00021 GT20L16J1Y_FONT font(D11, D12, D13, D3); 00022 sharp_mlcd lcd(D11, D13, D2, D4, D5, "LCD"); 00023 #endif 00024 00025 Ticker timer; 00026 00027 void attime() 00028 { 00029 lcd.attime(); 00030 } 00031 00032 #define numOfCharBuffer 40 00033 uint16_t kBuf[numOfCharBuffer]; 00034 00035 void draw_string(int offset_x, int offset_y, int width) 00036 { 00037 int color; 00038 for(int x=0; x<width*2; x++) 00039 { 00040 for(int y=0; y<8; y++) 00041 { 00042 if (font.bitmap[x] & (1<<y)) 00043 color = 1; 00044 else 00045 color = 0; 00046 lcd.pixel(x%width + offset_x, y+(8*(x/width)) + offset_y, color); 00047 } 00048 } 00049 //lcd.copy_to_lcd(); 00050 } 00051 00052 int int_compar(const uint16_t *a, const uint16_t *b) 00053 { 00054 if (*a < *b) 00055 return (-1); 00056 else if (*a > *b) 00057 return (1); 00058 else 00059 return (0); 00060 } 00061 00062 int conv_utf8(char* utfBuffer, uint16_t* kutenBuffer) 00063 { 00064 int ret; 00065 uint16_t key, *index, *pBuf; 00066 char *uBuf; 00067 00068 uBuf = utfBuffer; 00069 pBuf = kutenBuffer; 00070 ret = 0; 00071 00072 while (uBuf[0] != 0) { 00073 if (uBuf[0] >= 0x20 && uBuf[0] < 0x80) { 00074 // in case of ASCII 00075 *pBuf++ = (uint16_t)uBuf[0]; 00076 uBuf += 1; 00077 ret++; 00078 continue; 00079 } 00080 else if ( (uBuf[0]&0xF0) == 0xE0) { 00081 // extract valid bits of UTF-8 00082 key = ((uBuf[0] & 0x000F) << 12) | ((uBuf[1] & 0x003F) << 6) | (uBuf[2] & 0x003F); 00083 uBuf += 3; 00084 } 00085 else if ( (uBuf[0]&0xE0) == 0xC0) { 00086 // extract valid bits of UTF-8 00087 key = ((uBuf[0] & 0x001F) << 6) | (uBuf[1] & 0x003F); 00088 uBuf += 2; 00089 } 00090 else { 00091 uBuf += 1; 00092 continue; 00093 } 00094 00095 // search UTF-8 code from utf8_key[] table to get index of Kuten table 00096 index = (uint16_t *)bsearch(&key, utf8_key, (sizeof(utf8_key) / sizeof(utf8_key[0])), sizeof(uint16_t), (int (*)(const void *, const void *))int_compar); 00097 if (index != 0) { 00098 // get Kuten code 00099 *pBuf = utf8_value[index - utf8_key]; 00100 } else { 00101 *pBuf = 0; 00102 } 00103 00104 pBuf++; 00105 ret++; 00106 } 00107 *pBuf = 0; 00108 00109 return ret; 00110 } 00111 00112 void draw_utf8(int offset_x, int offset_y, char *buf_u) 00113 { 00114 int len = conv_utf8(buf_u, kBuf); 00115 int xpos = 0; 00116 00117 for(int i = 0; i < len; i++) { 00118 int width = font.read_kuten(kBuf[i]); 00119 draw_string(xpos + offset_x, offset_y, width); 00120 xpos += width; 00121 } 00122 } 00123 00124 void draw_test1() 00125 { 00126 char str[11]; 00127 int ypos = 0; 00128 int p = 0x20; 00129 for(int j = 0; j < 14; j++) { 00130 sprintf(str, "%8X:", p); 00131 draw_utf8(0, ypos, str); 00132 int xpos = 80; 00133 for(int i = 0; i < 16; i++) { 00134 int width = font.read_kuten(0x0000 + p++); 00135 draw_string(xpos, ypos, width); 00136 xpos += width; 00137 } 00138 ypos += 16; 00139 if(ypos > 240 - 16) ypos = 0; 00140 lcd.copy_to_lcd(); 00141 } 00142 } 00143 00144 void draw_test2() 00145 { 00146 char str[11]; 00147 int ypos = 0; 00148 unsigned long p = 0x00; 00149 for(int j = 0; j < 150; j++) { 00150 sprintf(str, "%8X:", p); 00151 draw_utf8(0, ypos, str); 00152 int xpos = 80; 00153 for(int i = 0; i < 16; i++) { 00154 font.read_direct(p); 00155 p += 32; 00156 draw_string(xpos, ypos, 16); 00157 xpos += 16; 00158 } 00159 ypos += 16; 00160 if(ypos > 240 - 16) ypos = 0; 00161 lcd.copy_to_lcd(); 00162 } 00163 } 00164 00165 void draw_test3() 00166 { 00167 char str[11]; 00168 int ypos = 0; 00169 unsigned long p = 0x3E7E0; 00170 for(int j = 0; j < 15; j++) { 00171 sprintf(str, "%8X:", p); 00172 draw_utf8(0, ypos, str); 00173 int xpos = 80; 00174 for(int i = 0; i < 32; i++) { 00175 font.read_direct(p); 00176 p += 16; 00177 draw_string(xpos, ypos, 8); 00178 xpos += 8; 00179 } 00180 ypos += 16; 00181 if(ypos > 240 - 16) ypos = 0; 00182 lcd.copy_to_lcd(); 00183 } 00184 } 00185 00186 int main() 00187 { 00188 led = 0; 00189 00190 printf("start\r\n"); 00191 00192 timer.attach(attime, 0.5); 00193 00194 lcd.setmode(NORMAL); 00195 lcd.set_auto_up(0); 00196 00197 lcd.cls(); 00198 00199 draw_utf8(0, 0, "進捗どうですか??"); 00200 draw_utf8(0, 16, "mbedで日本語表示"); 00201 00202 draw_utf8(0, 48, "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソ"); 00203 draw_utf8(0, 64, "タチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚"); 00204 00205 draw_utf8(0, 96, "エンベッド -> エェェェェンベッド!"); 00206 00207 draw_utf8(0, 112, "顔文字1 -> (;´Д`)ゞ"); 00208 draw_utf8(0, 128, "顔文字2 -> (´・ω・`)"); 00209 draw_utf8(0, 144, "顔文字3 -> (∩´∀`)∩"); 00210 draw_utf8(0, 160, "顔文字4 -> (・・)/~"); 00211 00212 lcd.copy_to_lcd(); 00213 00214 wait(5); 00215 00216 lcd.cls(); 00217 draw_test1(); 00218 lcd.copy_to_lcd(); 00219 00220 wait(5); 00221 00222 lcd.cls(); 00223 draw_test2(); 00224 lcd.copy_to_lcd(); 00225 00226 wait(5); 00227 00228 lcd.cls(); 00229 draw_test3(); 00230 lcd.copy_to_lcd(); 00231 00232 printf("end\r\n"); 00233 00234 while(1) { 00235 led = !led; 00236 wait(1.0); 00237 } 00238 }
Generated on Wed Jul 13 2022 18:53:42 by
1.7.2
ban4jp -
