this is kazushi's branch of AD128160
Fork of AD128160 by
s_Lcd.cpp@2:5d8d5291b4cd, 2011-10-08 (annotated)
- Committer:
- akira
- Date:
- Sat Oct 08 08:19:31 2011 +0000
- Revision:
- 2:5d8d5291b4cd
- Child:
- 3:f5576943e216
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 | 2:5d8d5291b4cd | 3 | Serial device(p9, p10); // tx, rx |
akira | 2:5d8d5291b4cd | 4 | //Serial pc(USBTX, USBRX); // tx, rx |
akira | 2:5d8d5291b4cd | 5 | DigitalOut rst(p20); //P20 --> LCD RST (Reset) |
akira | 2:5d8d5291b4cd | 6 | |
akira | 2:5d8d5291b4cd | 7 | void lcdspeed() |
akira | 2:5d8d5291b4cd | 8 | { |
akira | 2:5d8d5291b4cd | 9 | device.putc(0x55);// UART Speed 115200bps |
akira | 2:5d8d5291b4cd | 10 | device.putc(0x05); |
akira | 2:5d8d5291b4cd | 11 | device.putc(0x8B); |
akira | 2:5d8d5291b4cd | 12 | device.putc(0x00); |
akira | 2:5d8d5291b4cd | 13 | device.putc(0x01); |
akira | 2:5d8d5291b4cd | 14 | device.putc(0xC2); |
akira | 2:5d8d5291b4cd | 15 | device.putc(0x00); |
akira | 2:5d8d5291b4cd | 16 | device.putc(0x4E); |
akira | 2:5d8d5291b4cd | 17 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 18 | } |
akira | 2:5d8d5291b4cd | 19 | |
akira | 2:5d8d5291b4cd | 20 | void cls() |
akira | 2:5d8d5291b4cd | 21 | { |
akira | 2:5d8d5291b4cd | 22 | device.putc(0x55);// Clear |
akira | 2:5d8d5291b4cd | 23 | device.putc(0x02); |
akira | 2:5d8d5291b4cd | 24 | device.putc(0x80); |
akira | 2:5d8d5291b4cd | 25 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 26 | device.putc(0xD5); |
akira | 2:5d8d5291b4cd | 27 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 28 | } |
akira | 2:5d8d5291b4cd | 29 | |
akira | 2:5d8d5291b4cd | 30 | void lcdprint( char data[98],int x,int y) |
akira | 2:5d8d5291b4cd | 31 | { |
akira | 2:5d8d5291b4cd | 32 | unsigned char s; |
akira | 2:5d8d5291b4cd | 33 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 34 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 35 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 36 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 37 | unsigned char datalen; |
akira | 2:5d8d5291b4cd | 38 | x0H = x >> 8; |
akira | 2:5d8d5291b4cd | 39 | x0L = x & 0xFF; |
akira | 2:5d8d5291b4cd | 40 | y0H = y >> 8; |
akira | 2:5d8d5291b4cd | 41 | y0L = y & 0xFF; |
akira | 2:5d8d5291b4cd | 42 | datalen = strlen(data)+5; |
akira | 2:5d8d5291b4cd | 43 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 44 | device.putc(datalen); |
akira | 2:5d8d5291b4cd | 45 | device.putc(0x0B); // command ASCII Print |
akira | 2:5d8d5291b4cd | 46 | device.putc(x0H); //x upper 8bit |
akira | 2:5d8d5291b4cd | 47 | device.putc(x0L); //x low 8bit |
akira | 2:5d8d5291b4cd | 48 | device.putc(y0H); //y upper 8bit |
akira | 2:5d8d5291b4cd | 49 | device.putc(y0L); //y low 8bit |
akira | 2:5d8d5291b4cd | 50 | for(int a=0;a<strlen(data);a++) |
akira | 2:5d8d5291b4cd | 51 | { |
akira | 2:5d8d5291b4cd | 52 | device.putc(data[a]); |
akira | 2:5d8d5291b4cd | 53 | s = s+data[a]; |
akira | 2:5d8d5291b4cd | 54 | // pc.printf("%x:",data[a]); |
akira | 2:5d8d5291b4cd | 55 | } |
akira | 2:5d8d5291b4cd | 56 | s = s+x0H+x0L+y0H+y0L+0x0B; |
akira | 2:5d8d5291b4cd | 57 | device.putc(s);//sumcheck |
akira | 2:5d8d5291b4cd | 58 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 59 | // pc.printf("print %x %x %x %x %x %d ",x0H,x0L,y0H,y0L,s,datalen); |
akira | 2:5d8d5291b4cd | 60 | } |
akira | 2:5d8d5291b4cd | 61 | |
akira | 2:5d8d5291b4cd | 62 | void color(int rgb) |
akira | 2:5d8d5291b4cd | 63 | { |
akira | 2:5d8d5291b4cd | 64 | int c1; |
akira | 2:5d8d5291b4cd | 65 | int c2; |
akira | 2:5d8d5291b4cd | 66 | int sum; |
akira | 2:5d8d5291b4cd | 67 | |
akira | 2:5d8d5291b4cd | 68 | c1=(rgb >> 8) & 0xff; |
akira | 2:5d8d5291b4cd | 69 | c2=(rgb & 0xff); |
akira | 2:5d8d5291b4cd | 70 | sum=c1+c2+0x84; |
akira | 2:5d8d5291b4cd | 71 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 72 | device.putc(0x03); |
akira | 2:5d8d5291b4cd | 73 | device.putc(0x84); |
akira | 2:5d8d5291b4cd | 74 | device.putc(c1); |
akira | 2:5d8d5291b4cd | 75 | device.putc(c2); |
akira | 2:5d8d5291b4cd | 76 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 77 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 78 | //pc.printf("color %x %x %x ",c1,c2,sum); |
akira | 2:5d8d5291b4cd | 79 | } |
akira | 2:5d8d5291b4cd | 80 | |
akira | 2:5d8d5291b4cd | 81 | void pixel(int x0,int y0) |
akira | 2:5d8d5291b4cd | 82 | { |
akira | 2:5d8d5291b4cd | 83 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 84 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 85 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 86 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 87 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 88 | |
akira | 2:5d8d5291b4cd | 89 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 90 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 91 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 92 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 93 | |
akira | 2:5d8d5291b4cd | 94 | sum = x0H+x0L+y0H+y0L+0x01; |
akira | 2:5d8d5291b4cd | 95 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 96 | device.putc(0x05); |
akira | 2:5d8d5291b4cd | 97 | device.putc(0x01);//command |
akira | 2:5d8d5291b4cd | 98 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 99 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 100 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 101 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 102 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 103 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 104 | } |
akira | 2:5d8d5291b4cd | 105 | |
akira | 2:5d8d5291b4cd | 106 | void box(int x0,int y0,int x1,int y1,int paint) |
akira | 2:5d8d5291b4cd | 107 | { |
akira | 2:5d8d5291b4cd | 108 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 109 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 110 | unsigned char x1H; |
akira | 2:5d8d5291b4cd | 111 | unsigned char x1L; |
akira | 2:5d8d5291b4cd | 112 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 113 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 114 | unsigned char y1H; |
akira | 2:5d8d5291b4cd | 115 | unsigned char y1L; |
akira | 2:5d8d5291b4cd | 116 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 117 | unsigned char cmd; |
akira | 2:5d8d5291b4cd | 118 | switch (paint) |
akira | 2:5d8d5291b4cd | 119 | { |
akira | 2:5d8d5291b4cd | 120 | case 1: |
akira | 2:5d8d5291b4cd | 121 | cmd = 0x04; |
akira | 2:5d8d5291b4cd | 122 | break; |
akira | 2:5d8d5291b4cd | 123 | default: |
akira | 2:5d8d5291b4cd | 124 | cmd =0x03; |
akira | 2:5d8d5291b4cd | 125 | break; |
akira | 2:5d8d5291b4cd | 126 | } |
akira | 2:5d8d5291b4cd | 127 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 128 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 129 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 130 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 131 | x1H = x1 >> 8; |
akira | 2:5d8d5291b4cd | 132 | x1L = x1 & 0xFF; |
akira | 2:5d8d5291b4cd | 133 | y1H = y1 >> 8; |
akira | 2:5d8d5291b4cd | 134 | y1L = y1 & 0xff; |
akira | 2:5d8d5291b4cd | 135 | sum = x0H+x0L+y0H+y0L+x1H+x1L+y1H+y1L+cmd; |
akira | 2:5d8d5291b4cd | 136 | device.putc(0x55);//Box |
akira | 2:5d8d5291b4cd | 137 | device.putc(0x09); |
akira | 2:5d8d5291b4cd | 138 | device.putc(cmd);//command |
akira | 2:5d8d5291b4cd | 139 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 140 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 141 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 142 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 143 | device.putc(x1H); |
akira | 2:5d8d5291b4cd | 144 | device.putc(x1L); |
akira | 2:5d8d5291b4cd | 145 | device.putc(y1H); |
akira | 2:5d8d5291b4cd | 146 | device.putc(y1L); |
akira | 2:5d8d5291b4cd | 147 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 148 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 149 | } |
akira | 2:5d8d5291b4cd | 150 | |
akira | 2:5d8d5291b4cd | 151 | void circle(int x0,int y0,int r,int paint) |
akira | 2:5d8d5291b4cd | 152 | { |
akira | 2:5d8d5291b4cd | 153 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 154 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 155 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 156 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 157 | unsigned char rH; |
akira | 2:5d8d5291b4cd | 158 | unsigned char rL; |
akira | 2:5d8d5291b4cd | 159 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 160 | unsigned char cmd; |
akira | 2:5d8d5291b4cd | 161 | switch (paint) |
akira | 2:5d8d5291b4cd | 162 | { |
akira | 2:5d8d5291b4cd | 163 | case 0: |
akira | 2:5d8d5291b4cd | 164 | cmd = 0x05; |
akira | 2:5d8d5291b4cd | 165 | break; |
akira | 2:5d8d5291b4cd | 166 | case 1: |
akira | 2:5d8d5291b4cd | 167 | cmd = 0x06; |
akira | 2:5d8d5291b4cd | 168 | break; |
akira | 2:5d8d5291b4cd | 169 | default: |
akira | 2:5d8d5291b4cd | 170 | cmd =0x05; |
akira | 2:5d8d5291b4cd | 171 | break; |
akira | 2:5d8d5291b4cd | 172 | } |
akira | 2:5d8d5291b4cd | 173 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 174 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 175 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 176 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 177 | rH = r >> 8; |
akira | 2:5d8d5291b4cd | 178 | rL = r & 0xFF; |
akira | 2:5d8d5291b4cd | 179 | sum = x0H+x0L+y0H+y0L+rH+rL+cmd; |
akira | 2:5d8d5291b4cd | 180 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 181 | device.putc(0x07); |
akira | 2:5d8d5291b4cd | 182 | device.putc(cmd);//command |
akira | 2:5d8d5291b4cd | 183 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 184 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 185 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 186 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 187 | device.putc(rH); |
akira | 2:5d8d5291b4cd | 188 | device.putc(rL); |
akira | 2:5d8d5291b4cd | 189 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 190 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 191 | } |
akira | 2:5d8d5291b4cd | 192 | |
akira | 2:5d8d5291b4cd | 193 | void line(int x0,int y0,int x1,int y1) |
akira | 2:5d8d5291b4cd | 194 | { |
akira | 2:5d8d5291b4cd | 195 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 196 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 197 | unsigned char x1H; |
akira | 2:5d8d5291b4cd | 198 | unsigned char x1L; |
akira | 2:5d8d5291b4cd | 199 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 200 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 201 | unsigned char y1H; |
akira | 2:5d8d5291b4cd | 202 | unsigned char y1L; |
akira | 2:5d8d5291b4cd | 203 | unsigned char sum; |
akira | 2:5d8d5291b4cd | 204 | |
akira | 2:5d8d5291b4cd | 205 | x0H = x0 >> 8; |
akira | 2:5d8d5291b4cd | 206 | x0L = x0 & 0xFF; |
akira | 2:5d8d5291b4cd | 207 | y0H = y0 >> 8; |
akira | 2:5d8d5291b4cd | 208 | y0L = y0 & 0xff; |
akira | 2:5d8d5291b4cd | 209 | x1H = x1 >> 8; |
akira | 2:5d8d5291b4cd | 210 | x1L = x1 & 0xFF; |
akira | 2:5d8d5291b4cd | 211 | y1H = y1 >> 8; |
akira | 2:5d8d5291b4cd | 212 | y1L = y1 & 0xff; |
akira | 2:5d8d5291b4cd | 213 | sum = x0H+x0L+y0H+y0L+x1H+x1L+y1H+y1L+02; |
akira | 2:5d8d5291b4cd | 214 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 215 | device.putc(0x09); |
akira | 2:5d8d5291b4cd | 216 | device.putc(0x02);//command |
akira | 2:5d8d5291b4cd | 217 | device.putc(x0H); |
akira | 2:5d8d5291b4cd | 218 | device.putc(x0L); |
akira | 2:5d8d5291b4cd | 219 | device.putc(y0H); |
akira | 2:5d8d5291b4cd | 220 | device.putc(y0L); |
akira | 2:5d8d5291b4cd | 221 | device.putc(x1H); |
akira | 2:5d8d5291b4cd | 222 | device.putc(x1L); |
akira | 2:5d8d5291b4cd | 223 | device.putc(y1H); |
akira | 2:5d8d5291b4cd | 224 | device.putc(y1L); |
akira | 2:5d8d5291b4cd | 225 | device.putc(sum); |
akira | 2:5d8d5291b4cd | 226 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 227 | } |
akira | 2:5d8d5291b4cd | 228 | void lcdput(unsigned char data,int x,int y) |
akira | 2:5d8d5291b4cd | 229 | { |
akira | 2:5d8d5291b4cd | 230 | unsigned char s; |
akira | 2:5d8d5291b4cd | 231 | unsigned char x0H; |
akira | 2:5d8d5291b4cd | 232 | unsigned char x0L; |
akira | 2:5d8d5291b4cd | 233 | unsigned char y0H; |
akira | 2:5d8d5291b4cd | 234 | unsigned char y0L; |
akira | 2:5d8d5291b4cd | 235 | unsigned char datalen; |
akira | 2:5d8d5291b4cd | 236 | x0H = x >> 8; |
akira | 2:5d8d5291b4cd | 237 | x0L = x & 0xFF; |
akira | 2:5d8d5291b4cd | 238 | y0H = y >> 8; |
akira | 2:5d8d5291b4cd | 239 | y0L = y & 0xFF; |
akira | 2:5d8d5291b4cd | 240 | datalen = 6; |
akira | 2:5d8d5291b4cd | 241 | device.putc(0x55); |
akira | 2:5d8d5291b4cd | 242 | device.putc(datalen); |
akira | 2:5d8d5291b4cd | 243 | device.putc(0x0B); // command ASCII Print |
akira | 2:5d8d5291b4cd | 244 | device.putc(x0H); //x upper 8bit |
akira | 2:5d8d5291b4cd | 245 | device.putc(x0L); //x low 8bit |
akira | 2:5d8d5291b4cd | 246 | device.putc(y0H); //y upper 8bit |
akira | 2:5d8d5291b4cd | 247 | device.putc(y0L); //y low 8bit |
akira | 2:5d8d5291b4cd | 248 | device.putc(data); |
akira | 2:5d8d5291b4cd | 249 | s = data+x0H+x0L+y0H+y0L+0x0B; |
akira | 2:5d8d5291b4cd | 250 | device.putc(s);//sumcheck |
akira | 2:5d8d5291b4cd | 251 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 252 | // pc.printf("print %x %x %x %x %x %d ",x0H,x0L,y0H,y0L,s,datalen); |
akira | 2:5d8d5291b4cd | 253 | } |
akira | 2:5d8d5291b4cd | 254 | |
akira | 2:5d8d5291b4cd | 255 | |
akira | 2:5d8d5291b4cd | 256 | void s_Lcdinit() |
akira | 2:5d8d5291b4cd | 257 | { |
akira | 2:5d8d5291b4cd | 258 | device.baud(9600); |
akira | 2:5d8d5291b4cd | 259 | rst = 0; //Reset |
akira | 2:5d8d5291b4cd | 260 | wait(0.1); |
akira | 2:5d8d5291b4cd | 261 | rst = 1; |
akira | 2:5d8d5291b4cd | 262 | wait(0.5); |
akira | 2:5d8d5291b4cd | 263 | lcdspeed(); |
akira | 2:5d8d5291b4cd | 264 | wait(0.1); |
akira | 2:5d8d5291b4cd | 265 | device.baud(115200); |
akira | 2:5d8d5291b4cd | 266 | device.putc(0x55);//Back light On |
akira | 2:5d8d5291b4cd | 267 | device.putc(0x03); |
akira | 2:5d8d5291b4cd | 268 | device.putc(0x89); |
akira | 2:5d8d5291b4cd | 269 | device.putc(0x01); |
akira | 2:5d8d5291b4cd | 270 | device.putc(0x2C); |
akira | 2:5d8d5291b4cd | 271 | device.putc(0xB6); |
akira | 2:5d8d5291b4cd | 272 | device.putc(0xAA); |
akira | 2:5d8d5291b4cd | 273 | wait(0.1); |
akira | 2:5d8d5291b4cd | 274 | cls(); |
akira | 2:5d8d5291b4cd | 275 | |
akira | 2:5d8d5291b4cd | 276 | } |
akira | 2:5d8d5291b4cd | 277 |