this is kazushi's branch of AD128160
Fork of AD128160 by
s_Lcd.cpp@6:96576c9c7828, 2011-11-24 (annotated)
- Committer:
- akira
- Date:
- Thu Nov 24 14:01:45 2011 +0000
- Revision:
- 6:96576c9c7828
- Parent:
- 5:39b01a6f0f75
- Child:
- 7:227b64bf8fb1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akira | 2:5d8d5291b4cd | 1 | #include "mbed.h" |
akira | 2:5d8d5291b4cd | 2 | |
akira | 6:96576c9c7828 | 3 | #define kanji_file "/local/SHMZN16X.FNT" |
akira | 6:96576c9c7828 | 4 | //#defin kanji_file "/local/k12x10.fnt" |
akira | 6:96576c9c7828 | 5 | |
akira | 6:96576c9c7828 | 6 | Serial device(p9, p10); // tx, rx LCD |
akira | 2:5d8d5291b4cd | 7 | DigitalOut rst(p20); //P20 --> LCD RST (Reset) |
akira | 2:5d8d5291b4cd | 8 | |
akira | 4:1f72df1a88e0 | 9 | LocalFileSystem local("local"); |
akira | 4:1f72df1a88e0 | 10 | |
akira | 6:96576c9c7828 | 11 | int cx = 0; |
akira | 6:96576c9c7828 | 12 | int cy = 0; |
akira | 6:96576c9c7828 | 13 | int offsety = 0; |
akira | 6:96576c9c7828 | 14 | bool kstate = false; |
akira | 6:96576c9c7828 | 15 | unsigned char kbuf; |
akira | 6:96576c9c7828 | 16 | |
akira | 6:96576c9c7828 | 17 | FILE *fp; //File open buffer |
akira | 4:1f72df1a88e0 | 18 | |
akira | 4:1f72df1a88e0 | 19 | unsigned short start[92], end[92]; |
akira | 4:1f72df1a88e0 | 20 | unsigned char font[64]; |
akira | 4:1f72df1a88e0 | 21 | |
akira | 4:1f72df1a88e0 | 22 | char Identifier[6+1]; |
akira | 4:1f72df1a88e0 | 23 | char FontName[8+1]; |
akira | 4:1f72df1a88e0 | 24 | unsigned char XSize; |
akira | 4:1f72df1a88e0 | 25 | unsigned char YSize; |
akira | 4:1f72df1a88e0 | 26 | unsigned char Size; |
akira | 4:1f72df1a88e0 | 27 | unsigned char CodeType; |
akira | 4:1f72df1a88e0 | 28 | unsigned char Tnum; |
akira | 4:1f72df1a88e0 | 29 | |
akira | 4:1f72df1a88e0 | 30 | #define FONT_XBYTE ((XSize + 7) >> 3) |
akira | 4:1f72df1a88e0 | 31 | #define FONT_YBYTE ((YSize + 7) >> 3) |
akira | 4:1f72df1a88e0 | 32 | |
akira | 2:5d8d5291b4cd | 33 | void lcdspeed() |
akira | 2:5d8d5291b4cd | 34 | { |
akira | 2:5d8d5291b4cd | 35 | device.putc(0x55);// UART Speed 115200bps |
akira | 2:5d8d5291b4cd | 36 | device.putc(0x05); |
akira | 2:5d8d5291b4cd | 37 | device.putc(0x8B); |
akira | 2:5d8d5291b4cd | 38 | device.putc(0x00); |
akira | 2:5d8d5291b4cd | 39 | device.putc(0x01); |
akira | 2:5d8d5291b4cd | 40 | device.putc(0xC2); |
akira | 2:5d8d5291b4cd | 41 | device.putc(0x00); |
akira | 2:5d8d5291b4cd | 42 | device.putc(0x4E); |
akira | 2:5d8d5291b4cd | 43 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 44 | } |
akira | 6:96576c9c7828 | 45 | void bmp(int x0,int y0,int bmp_no) |
akira | 6:96576c9c7828 | 46 | { |
akira | 6:96576c9c7828 | 47 | unsigned char x0H; |
akira | 6:96576c9c7828 | 48 | unsigned char x0L; |
akira | 6:96576c9c7828 | 49 | unsigned char y0H; |
akira | 6:96576c9c7828 | 50 | unsigned char y0L; |
akira | 6:96576c9c7828 | 51 | unsigned char rH; |
akira | 6:96576c9c7828 | 52 | unsigned char rL; |
akira | 6:96576c9c7828 | 53 | unsigned char sum; |
akira | 6:96576c9c7828 | 54 | |
akira | 6:96576c9c7828 | 55 | x0H = x0 >> 8; |
akira | 6:96576c9c7828 | 56 | x0L = x0 & 0xFF; |
akira | 6:96576c9c7828 | 57 | y0H = y0 >> 8; |
akira | 6:96576c9c7828 | 58 | y0L = y0 & 0xff; |
akira | 6:96576c9c7828 | 59 | rH = bmp_no >> 8; |
akira | 6:96576c9c7828 | 60 | rL = bmp_no & 0xFF; |
akira | 6:96576c9c7828 | 61 | sum = x0H+x0L+y0H+y0L+rH+rL+0x09; |
akira | 6:96576c9c7828 | 62 | device.putc(0x55); |
akira | 6:96576c9c7828 | 63 | device.putc(0x07); |
akira | 6:96576c9c7828 | 64 | device.putc(0x09);//command |
akira | 6:96576c9c7828 | 65 | device.putc(x0H); |
akira | 6:96576c9c7828 | 66 | device.putc(x0L); |
akira | 6:96576c9c7828 | 67 | device.putc(y0H); |
akira | 6:96576c9c7828 | 68 | device.putc(y0L); |
akira | 6:96576c9c7828 | 69 | device.putc(rH); |
akira | 6:96576c9c7828 | 70 | device.putc(rL); |
akira | 6:96576c9c7828 | 71 | device.putc(sum); |
akira | 6:96576c9c7828 | 72 | device.putc(0xAA); |
akira | 6:96576c9c7828 | 73 | } |
akira | 2:5d8d5291b4cd | 74 | |
akira | 2:5d8d5291b4cd | 75 | void cls() |
akira | 2:5d8d5291b4cd | 76 | { |
akira | 2:5d8d5291b4cd | 77 | device.putc(0x55);// Clear |
akira | 2:5d8d5291b4cd | 78 | device.putc(0x02); |
akira | 2:5d8d5291b4cd | 79 | device.putc(0x80); |
akira | 2:5d8d5291b4cd | 80 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 81 | device.putc(0xD5); |
akira | 2:5d8d5291b4cd | 82 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 83 | } |
akira | 6:96576c9c7828 | 84 | void scroll(void){ |
akira | 6:96576c9c7828 | 85 | |
akira | 6:96576c9c7828 | 86 | } |
akira | 6:96576c9c7828 | 87 | |
akira | 6:96576c9c7828 | 88 | |
akira | 6:96576c9c7828 | 89 | |
akira | 4:1f72df1a88e0 | 90 | |
akira | 4:1f72df1a88e0 | 91 | void lcdputs( char data[98],int x,int y) |
akira | 2:5d8d5291b4cd | 92 | { |
akira | 6:96576c9c7828 | 93 | unsigned char s=0; |
akira | 4:1f72df1a88e0 | 94 | unsigned char x0H; |
akira | 4:1f72df1a88e0 | 95 | unsigned char x0L; |
akira | 4:1f72df1a88e0 | 96 | unsigned char y0H; |
akira | 4:1f72df1a88e0 | 97 | unsigned char y0L; |
akira | 4:1f72df1a88e0 | 98 | unsigned char datalen; |
akira | 4:1f72df1a88e0 | 99 | x0H = x >> 8; |
akira | 4:1f72df1a88e0 | 100 | x0L = x & 0xFF; |
akira | 4:1f72df1a88e0 | 101 | y0H = y >> 8; |
akira | 4:1f72df1a88e0 | 102 | y0L = y & 0xFF; |
akira | 4:1f72df1a88e0 | 103 | datalen = strlen(data)+5; |
akira | 4:1f72df1a88e0 | 104 | device.putc(0x55); |
akira | 4:1f72df1a88e0 | 105 | device.putc(datalen); |
akira | 4:1f72df1a88e0 | 106 | device.putc(0x0B); // command ASCII Print |
akira | 4:1f72df1a88e0 | 107 | device.putc(x0H); //x upper 8bit |
akira | 4:1f72df1a88e0 | 108 | device.putc(x0L); //x low 8bit |
akira | 4:1f72df1a88e0 | 109 | device.putc(y0H); //y upper 8bit |
akira | 4:1f72df1a88e0 | 110 | device.putc(y0L); //y low 8bit |
akira | 4:1f72df1a88e0 | 111 | for(int a=0;a<strlen(data);a++) |
akira | 4:1f72df1a88e0 | 112 | { |
akira | 4:1f72df1a88e0 | 113 | device.putc(data[a]); |
akira | 4:1f72df1a88e0 | 114 | s = s+data[a]; |
akira | 4:1f72df1a88e0 | 115 | } |
akira | 4:1f72df1a88e0 | 116 | s = s+x0H+x0L+y0H+y0L+0x0B; |
akira | 4:1f72df1a88e0 | 117 | device.putc(s);//sumcheck |
akira | 3:f5576943e216 | 118 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 119 | } |
akira | 2:5d8d5291b4cd | 120 | |
akira | 2:5d8d5291b4cd | 121 | void color(int rgb) |
akira | 2:5d8d5291b4cd | 122 | { |
akira | 2:5d8d5291b4cd | 123 | int c1; |
akira | 2:5d8d5291b4cd | 124 | int c2; |
akira | 2:5d8d5291b4cd | 125 | int sum; |
akira | 2:5d8d5291b4cd | 126 | |
akira | 2:5d8d5291b4cd | 127 | c1=(rgb >> 8) & 0xff; |
akira | 2:5d8d5291b4cd | 128 | c2=(rgb & 0xff); |
akira | 2:5d8d5291b4cd | 129 | sum=c1+c2+0x84; |
akira | 2:5d8d5291b4cd | 130 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 131 | device.putc(0x03); |
akira | 2:5d8d5291b4cd | 132 | device.putc(0x84); |
akira | 2:5d8d5291b4cd | 133 | device.putc(c1); |
akira | 2:5d8d5291b4cd | 134 | device.putc(c2); |
akira | 2:5d8d5291b4cd | 135 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 136 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 137 | } |
akira | 2:5d8d5291b4cd | 138 | |
akira | 6:96576c9c7828 | 139 | void newline(void){ |
akira | 6:96576c9c7828 | 140 | cx = 0; |
akira | 6:96576c9c7828 | 141 | cy += 16; |
akira | 6:96576c9c7828 | 142 | if(cy > 160){ |
akira | 6:96576c9c7828 | 143 | scroll(); |
akira | 6:96576c9c7828 | 144 | cy = 0; |
akira | 6:96576c9c7828 | 145 | color(0x001f); |
akira | 6:96576c9c7828 | 146 | cls(); |
akira | 6:96576c9c7828 | 147 | color(0xffff); |
akira | 6:96576c9c7828 | 148 | } |
akira | 6:96576c9c7828 | 149 | } |
akira | 6:96576c9c7828 | 150 | |
akira | 6:96576c9c7828 | 151 | void movecorsor(int a) |
akira | 6:96576c9c7828 | 152 | { |
akira | 6:96576c9c7828 | 153 | cx+=8*a; |
akira | 6:96576c9c7828 | 154 | if(cx>=128) newline(); |
akira | 6:96576c9c7828 | 155 | } |
akira | 6:96576c9c7828 | 156 | |
akira | 6:96576c9c7828 | 157 | |
akira | 2:5d8d5291b4cd | 158 | void pixel(int x0,int y0) |
akira | 2:5d8d5291b4cd | 159 | { |
akira | 2:5d8d5291b4cd | 160 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 161 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 162 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 163 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 164 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 165 | |
akira | 2:5d8d5291b4cd | 166 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 167 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 168 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 169 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 170 | |
akira | 2:5d8d5291b4cd | 171 | sum = x0H+x0L+y0H+y0L+0x01; |
akira | 2:5d8d5291b4cd | 172 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 173 | device.putc(0x05); |
akira | 2:5d8d5291b4cd | 174 | device.putc(0x01);//command |
akira | 2:5d8d5291b4cd | 175 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 176 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 177 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 178 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 179 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 180 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 181 | } |
akira | 2:5d8d5291b4cd | 182 | |
akira | 2:5d8d5291b4cd | 183 | void box(int x0,int y0,int x1,int y1,int paint) |
akira | 2:5d8d5291b4cd | 184 | { |
akira | 2:5d8d5291b4cd | 185 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 186 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 187 | unsigned char x1H; |
akira | 2:5d8d5291b4cd | 188 | unsigned char x1L; |
akira | 2:5d8d5291b4cd | 189 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 190 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 191 | unsigned char y1H; |
akira | 2:5d8d5291b4cd | 192 | unsigned char y1L; |
akira | 2:5d8d5291b4cd | 193 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 194 | unsigned char cmd; |
akira | 2:5d8d5291b4cd | 195 | switch (paint) |
akira | 2:5d8d5291b4cd | 196 | { |
akira | 2:5d8d5291b4cd | 197 | case 1: |
akira | 2:5d8d5291b4cd | 198 | cmd = 0x04; |
akira | 2:5d8d5291b4cd | 199 | break; |
akira | 2:5d8d5291b4cd | 200 | default: |
akira | 2:5d8d5291b4cd | 201 | cmd =0x03; |
akira | 2:5d8d5291b4cd | 202 | break; |
akira | 2:5d8d5291b4cd | 203 | } |
akira | 2:5d8d5291b4cd | 204 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 205 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 206 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 207 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 208 | x1H = x1 >> 8; |
akira | 2:5d8d5291b4cd | 209 | x1L = x1 & 0xFF; |
akira | 2:5d8d5291b4cd | 210 | y1H = y1 >> 8; |
akira | 2:5d8d5291b4cd | 211 | y1L = y1 & 0xff; |
akira | 2:5d8d5291b4cd | 212 | sum = x0H+x0L+y0H+y0L+x1H+x1L+y1H+y1L+cmd; |
akira | 2:5d8d5291b4cd | 213 | device.putc(0x55);//Box |
akira | 2:5d8d5291b4cd | 214 | device.putc(0x09); |
akira | 2:5d8d5291b4cd | 215 | device.putc(cmd);//command |
akira | 2:5d8d5291b4cd | 216 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 217 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 218 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 219 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 220 | device.putc(x1H); |
akira | 2:5d8d5291b4cd | 221 | device.putc(x1L); |
akira | 2:5d8d5291b4cd | 222 | device.putc(y1H); |
akira | 2:5d8d5291b4cd | 223 | device.putc(y1L); |
akira | 2:5d8d5291b4cd | 224 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 225 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 226 | } |
akira | 2:5d8d5291b4cd | 227 | |
akira | 2:5d8d5291b4cd | 228 | void circle(int x0,int y0,int r,int paint) |
akira | 2:5d8d5291b4cd | 229 | { |
akira | 2:5d8d5291b4cd | 230 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 231 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 232 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 233 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 234 | unsigned char rH; |
akira | 2:5d8d5291b4cd | 235 | unsigned char rL; |
akira | 2:5d8d5291b4cd | 236 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 237 | unsigned char cmd; |
akira | 2:5d8d5291b4cd | 238 | switch (paint) |
akira | 2:5d8d5291b4cd | 239 | { |
akira | 2:5d8d5291b4cd | 240 | case 0: |
akira | 2:5d8d5291b4cd | 241 | cmd = 0x05; |
akira | 2:5d8d5291b4cd | 242 | break; |
akira | 2:5d8d5291b4cd | 243 | case 1: |
akira | 2:5d8d5291b4cd | 244 | cmd = 0x06; |
akira | 2:5d8d5291b4cd | 245 | break; |
akira | 2:5d8d5291b4cd | 246 | default: |
akira | 2:5d8d5291b4cd | 247 | cmd =0x05; |
akira | 2:5d8d5291b4cd | 248 | break; |
akira | 2:5d8d5291b4cd | 249 | } |
akira | 2:5d8d5291b4cd | 250 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 251 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 252 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 253 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 254 | rH = r >> 8; |
akira | 2:5d8d5291b4cd | 255 | rL = r & 0xFF; |
akira | 2:5d8d5291b4cd | 256 | sum = x0H+x0L+y0H+y0L+rH+rL+cmd; |
akira | 2:5d8d5291b4cd | 257 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 258 | device.putc(0x07); |
akira | 2:5d8d5291b4cd | 259 | device.putc(cmd);//command |
akira | 2:5d8d5291b4cd | 260 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 261 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 262 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 263 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 264 | device.putc(rH); |
akira | 2:5d8d5291b4cd | 265 | device.putc(rL); |
akira | 2:5d8d5291b4cd | 266 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 267 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 268 | } |
akira | 2:5d8d5291b4cd | 269 | |
akira | 2:5d8d5291b4cd | 270 | void line(int x0,int y0,int x1,int y1) |
akira | 2:5d8d5291b4cd | 271 | { |
akira | 2:5d8d5291b4cd | 272 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 273 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 274 | unsigned char x1H; |
akira | 2:5d8d5291b4cd | 275 | unsigned char x1L; |
akira | 2:5d8d5291b4cd | 276 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 277 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 278 | unsigned char y1H; |
akira | 2:5d8d5291b4cd | 279 | unsigned char y1L; |
akira | 2:5d8d5291b4cd | 280 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 281 | |
akira | 2:5d8d5291b4cd | 282 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 283 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 284 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 285 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 286 | x1H = x1 >> 8; |
akira | 2:5d8d5291b4cd | 287 | x1L = x1 & 0xFF; |
akira | 2:5d8d5291b4cd | 288 | y1H = y1 >> 8; |
akira | 2:5d8d5291b4cd | 289 | y1L = y1 & 0xff; |
akira | 2:5d8d5291b4cd | 290 | sum = x0H+x0L+y0H+y0L+x1H+x1L+y1H+y1L+02; |
akira | 2:5d8d5291b4cd | 291 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 292 | device.putc(0x09); |
akira | 2:5d8d5291b4cd | 293 | device.putc(0x02);//command |
akira | 2:5d8d5291b4cd | 294 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 295 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 296 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 297 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 298 | device.putc(x1H); |
akira | 2:5d8d5291b4cd | 299 | device.putc(x1L); |
akira | 2:5d8d5291b4cd | 300 | device.putc(y1H); |
akira | 2:5d8d5291b4cd | 301 | device.putc(y1L); |
akira | 2:5d8d5291b4cd | 302 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 303 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 304 | } |
akira | 4:1f72df1a88e0 | 305 | void lcdput(unsigned char data,int x,int y) |
akira | 2:5d8d5291b4cd | 306 | { |
akira | 2:5d8d5291b4cd | 307 | unsigned char s; |
akira | 2:5d8d5291b4cd | 308 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 309 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 310 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 311 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 312 | unsigned char datalen; |
akira | 2:5d8d5291b4cd | 313 | x0H = x >> 8; |
akira | 2:5d8d5291b4cd | 314 | x0L = x & 0xFF; |
akira | 2:5d8d5291b4cd | 315 | y0H = y >> 8; |
akira | 2:5d8d5291b4cd | 316 | y0L = y & 0xFF; |
akira | 4:1f72df1a88e0 | 317 | datalen = 6; |
akira | 2:5d8d5291b4cd | 318 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 319 | device.putc(datalen); |
akira | 2:5d8d5291b4cd | 320 | device.putc(0x0B); // command ASCII Print |
akira | 2:5d8d5291b4cd | 321 | device.putc(x0H); //x upper 8bit |
akira | 2:5d8d5291b4cd | 322 | device.putc(x0L); //x low 8bit |
akira | 2:5d8d5291b4cd | 323 | device.putc(y0H); //y upper 8bit |
akira | 2:5d8d5291b4cd | 324 | device.putc(y0L); //y low 8bit |
akira | 4:1f72df1a88e0 | 325 | device.putc(data); |
akira | 4:1f72df1a88e0 | 326 | s = data+x0H+x0L+y0H+y0L+0x0B; |
akira | 2:5d8d5291b4cd | 327 | device.putc(s);//sumcheck |
akira | 2:5d8d5291b4cd | 328 | device.putc(0xAA); |
akira | 4:1f72df1a88e0 | 329 | } |
akira | 4:1f72df1a88e0 | 330 | |
akira | 4:1f72df1a88e0 | 331 | |
akira | 6:96576c9c7828 | 332 | |
akira | 6:96576c9c7828 | 333 | void kanji_init(){ |
akira | 6:96576c9c7828 | 334 | //move cursor |
akira | 6:96576c9c7828 | 335 | fp = fopen(kanji_file , "r"); |
akira | 6:96576c9c7828 | 336 | |
akira | 6:96576c9c7828 | 337 | |
akira | 6:96576c9c7828 | 338 | if(!fp) { |
akira | 6:96576c9c7828 | 339 | printf("File could not be opened!\n"); |
akira | 6:96576c9c7828 | 340 | exit(1); |
akira | 6:96576c9c7828 | 341 | } |
akira | 6:96576c9c7828 | 342 | |
akira | 6:96576c9c7828 | 343 | fgets(Identifier, 6+1, fp); // FONTX2 |
akira | 6:96576c9c7828 | 344 | fgets(FontName, 8+1, fp); |
akira | 6:96576c9c7828 | 345 | fread(&XSize, 1, 1, fp); |
akira | 6:96576c9c7828 | 346 | fread(&YSize, 1, 1, fp); |
akira | 6:96576c9c7828 | 347 | fread(&CodeType, 1, 1, fp); |
akira | 6:96576c9c7828 | 348 | fread(&Tnum, 1, 1, fp); |
akira | 6:96576c9c7828 | 349 | |
akira | 6:96576c9c7828 | 350 | // Table read |
akira | 6:96576c9c7828 | 351 | for(int a=0;a< Tnum ;a++){ |
akira | 6:96576c9c7828 | 352 | fread(&start[a],1,2,fp); |
akira | 6:96576c9c7828 | 353 | fread(&end[a] ,1,2,fp); |
akira | 6:96576c9c7828 | 354 | } |
akira | 6:96576c9c7828 | 355 | } |
akira | 6:96576c9c7828 | 356 | |
akira | 6:96576c9c7828 | 357 | //Kanji puts cr = kanji cord |
akira | 6:96576c9c7828 | 358 | void k_puts(int cr){ |
akira | 6:96576c9c7828 | 359 | //kanji address |
akira | 6:96576c9c7828 | 360 | int c; |
akira | 6:96576c9c7828 | 361 | int adrs; |
akira | 6:96576c9c7828 | 362 | c=0; |
akira | 6:96576c9c7828 | 363 | adrs=0; |
akira | 6:96576c9c7828 | 364 | while(cr>start[c]){ |
akira | 6:96576c9c7828 | 365 | if(cr > end[c]){ |
akira | 6:96576c9c7828 | 366 | adrs += end[c]-start[c]+1; |
akira | 6:96576c9c7828 | 367 | } |
akira | 6:96576c9c7828 | 368 | else{ |
akira | 6:96576c9c7828 | 369 | adrs += cr - start[c]; |
akira | 6:96576c9c7828 | 370 | } |
akira | 6:96576c9c7828 | 371 | c++; |
akira | 6:96576c9c7828 | 372 | } |
akira | 6:96576c9c7828 | 373 | c--; |
akira | 6:96576c9c7828 | 374 | //printf("C=%d,adrs=%d cr=%X ",c,adrs,cr); |
akira | 6:96576c9c7828 | 375 | // Kanji image Read |
akira | 6:96576c9c7828 | 376 | fseek( fp, Tnum*4+18+32*adrs, SEEK_SET ); |
akira | 6:96576c9c7828 | 377 | fread(&font,1,32,fp); |
akira | 6:96576c9c7828 | 378 | // kanji put |
akira | 6:96576c9c7828 | 379 | c=0; |
akira | 6:96576c9c7828 | 380 | for (int y=0;y<16;y++){ |
akira | 6:96576c9c7828 | 381 | for (int x=0;x<8;x++){ |
akira | 6:96576c9c7828 | 382 | if((font[c] & 0x80)==0x80){ |
akira | 6:96576c9c7828 | 383 | pixel(cx+x,cy+y); |
akira | 6:96576c9c7828 | 384 | } |
akira | 6:96576c9c7828 | 385 | font[c] = font[c] << 1; |
akira | 6:96576c9c7828 | 386 | if((font[c+1] & 0x80)==0x80){ |
akira | 6:96576c9c7828 | 387 | pixel(cx+x+8,cy+y); |
akira | 6:96576c9c7828 | 388 | } |
akira | 6:96576c9c7828 | 389 | font[c+1] = font[c+1] << 1; |
akira | 6:96576c9c7828 | 390 | } |
akira | 6:96576c9c7828 | 391 | c+=2; |
akira | 6:96576c9c7828 | 392 | } |
akira | 6:96576c9c7828 | 393 | //move cursor |
akira | 6:96576c9c7828 | 394 | cx+=16; |
akira | 6:96576c9c7828 | 395 | if(cx>=128){ //LF control |
akira | 6:96576c9c7828 | 396 | cx=0; |
akira | 6:96576c9c7828 | 397 | cy+=16; |
akira | 6:96576c9c7828 | 398 | } |
akira | 6:96576c9c7828 | 399 | } |
akira | 6:96576c9c7828 | 400 | |
akira | 6:96576c9c7828 | 401 | void kanji_end(){ |
akira | 6:96576c9c7828 | 402 | fclose(fp); |
akira | 6:96576c9c7828 | 403 | } |
akira | 6:96576c9c7828 | 404 | |
akira | 6:96576c9c7828 | 405 | void drawc(unsigned char c){ |
akira | 6:96576c9c7828 | 406 | if(kstate){ // 2nd byte of shift-jis |
akira | 6:96576c9c7828 | 407 | kstate = false; |
akira | 6:96576c9c7828 | 408 | |
akira | 6:96576c9c7828 | 409 | k_puts(kbuf << 8 | c); |
akira | 6:96576c9c7828 | 410 | } else if((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)){ // 1st byte of shift-jis |
akira | 6:96576c9c7828 | 411 | kstate = true; |
akira | 6:96576c9c7828 | 412 | kbuf = c; |
akira | 6:96576c9c7828 | 413 | } else { // Ascii Out |
akira | 6:96576c9c7828 | 414 | lcdput(c,cx,cy); |
akira | 6:96576c9c7828 | 415 | movecorsor(1); // 1byte Move |
akira | 6:96576c9c7828 | 416 | } |
akira | 6:96576c9c7828 | 417 | } |
akira | 6:96576c9c7828 | 418 | |
akira | 6:96576c9c7828 | 419 | |
akira | 4:1f72df1a88e0 | 420 | void s_Lcdinit() |
akira | 4:1f72df1a88e0 | 421 | { |
akira | 4:1f72df1a88e0 | 422 | // device.baud(9600); |
akira | 4:1f72df1a88e0 | 423 | rst = 0; //Reset |
akira | 4:1f72df1a88e0 | 424 | wait(0.1); |
akira | 4:1f72df1a88e0 | 425 | rst = 1; |
akira | 4:1f72df1a88e0 | 426 | wait(0.1); |
akira | 4:1f72df1a88e0 | 427 | lcdspeed();//speed 115200 |
akira | 4:1f72df1a88e0 | 428 | wait(0.1); |
akira | 4:1f72df1a88e0 | 429 | device.baud(115200); |
akira | 4:1f72df1a88e0 | 430 | device.putc(0x55);//Back light On |
akira | 4:1f72df1a88e0 | 431 | device.putc(0x03); |
akira | 4:1f72df1a88e0 | 432 | device.putc(0x89); |
akira | 4:1f72df1a88e0 | 433 | device.putc(0x01); |
akira | 4:1f72df1a88e0 | 434 | device.putc(0x2C); |
akira | 4:1f72df1a88e0 | 435 | device.putc(0xB6); |
akira | 4:1f72df1a88e0 | 436 | device.putc(0xAA); |
akira | 6:96576c9c7828 | 437 | bmp(0,0,1); |
akira | 6:96576c9c7828 | 438 | lcdputs(" GingaX ",20,140); |
akira | 6:96576c9c7828 | 439 | wait(3); |
akira | 6:96576c9c7828 | 440 | bmp(0,0,0); |
akira | 6:96576c9c7828 | 441 | wait(3); |
akira | 4:1f72df1a88e0 | 442 | cls(); |
akira | 6:96576c9c7828 | 443 | color(0xffff); |
akira | 6:96576c9c7828 | 444 | kanji_init(); |
akira | 4:1f72df1a88e0 | 445 | } |
akira | 4:1f72df1a88e0 | 446 |