this is kazushi's branch of AD128160

Fork of AD128160 by Gingax x

Committer:
akira
Date:
Sun Oct 02 15:02:29 2011 +0000
Revision:
0:6fc03008c3fd

        

Who changed what in which revision?

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