this is kazushi's branch of AD128160

Fork of AD128160 by Gingax x

Committer:
akira
Date:
Sat Oct 08 23:51:33 2011 +0000
Revision:
3:f5576943e216
Parent:
2:5d8d5291b4cd
Child:
4:1f72df1a88e0

        

Who changed what in which revision?

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