AD-128160-UART制御用のライブラリ http://www.aitendo.co.jp/product/3119 gingaxさんのプログラムを参考に作らせてもらっています。 http://mbed.org/users/akira/libraries/AD128160/m159hi
Dependents: AD128160_HelloWorld
AD128160.cpp
- Committer:
- nucho
- Date:
- 2011-12-12
- Revision:
- 0:2e2f3b389d8a
- Child:
- 2:6f2db745808e
File content as of revision 0:2e2f3b389d8a:
#include "AD128160.h" AD128160::AD128160(PinName tx,PinName reset):_device(tx,NC),_rst(reset) { init(); } int AD128160::_putc(int c) { if (c == '\n') { newline(); } else { int x = _column * 8; // FIXME: Char sizes int y = _row * 16; unsigned char sum; unsigned char x0H; unsigned char x0L; unsigned char y0H; unsigned char y0L; unsigned char datalen; x0H = x >> 8; x0L = x & 0xFF; y0H = y >> 8; y0L = y & 0xFF; datalen = 6; _device.putc(0x55); _device.putc(datalen); _device.putc(0x0B); // command ASCII Print _device.putc(x0H); //x upper 8bit _device.putc(x0L); //x low 8bit _device.putc(y0H); //y upper 8bit _device.putc(y0L); //y low 8bit _device.putc(c); sum = c+x0H+x0L+y0H+y0L+0x0B; _device.putc(sum);//sumch _device.putc(0xAA); _column++; if (_column >= LCD_COLS) { _row++; _column = 0; } if (_row >= LCD_ROWS) { _row = 0; } } return c; } void AD128160::init() { reset(); brightness(300); cls(); locate(0,0); color(0xffff); } void AD128160::brightness(int value){ unsigned char sum=0; unsigned char byte[2]; byte[0] = (value & 0xff00)>>8; byte[1] = value & 0x00ff; sum+=byte[0]+byte[1]+0x89; _device.putc(0x55);//Back light On _device.putc(0x03); _device.putc(0x89); _device.putc(byte[0]); _device.putc(byte[1]); _device.putc(sum); _device.putc(0xAA); } void AD128160::reset(){ _rst = 0; //Reset wait(0.1); _rst = 1; wait(0.1); } void AD128160::speed(int baud) { unsigned char sum=0; unsigned char byte[4]; byte[0] = (baud&0xff000000)>>24; byte[1] = (baud&0x00ff0000)>>16; byte[2] = (baud&0x0000ff00)>>8; byte[3] = baud&0x000000ff; sum += byte[0]+byte[1]+byte[2]+byte[3]+0x8B; _device.putc(0x55); _device.putc(0x05); _device.putc(0x8B); _device.putc(byte[0]); _device.putc(byte[1]); _device.putc(byte[2]); _device.putc(byte[3]); _device.putc(sum); _device.putc(0xAA); wait(0.1); _device.baud(baud); } void AD128160::bmp(int x0,int y0,int bmp_no) { unsigned char x0H; unsigned char x0L; unsigned char y0H; unsigned char y0L; unsigned char rH; unsigned char rL; unsigned char sum; x0H = x0 >> 8; x0L = x0 & 0xFF; y0H = y0 >> 8; y0L = y0 & 0xff; rH = bmp_no >> 8; rL = bmp_no & 0xFF; sum = x0H+x0L+y0H+y0L+rH+rL+0x09; _device.putc(0x55); _device.putc(0x07); _device.putc(0x09);//command _device.putc(x0H); _device.putc(x0L); _device.putc(y0H); _device.putc(y0L); _device.putc(rH); _device.putc(rL); _device.putc(sum); _device.putc(0xAA); } void AD128160::cls() { _device.putc(0x55);// Clear _device.putc(0x02); _device.putc(0x80); _device.putc(0x55); _device.putc(0xD5); _device.putc(0xAA); locate(0,0); } void AD128160::locate(int column, int row) { _column = column; _row = row; } void AD128160::puts( char s[98]) { unsigned char sum=0; unsigned char x0H; unsigned char x0L; unsigned char y0H; unsigned char y0L; unsigned char datalen; x0H = _column >> 8; x0L = _column & 0xFF; y0H = _row >> 8; y0L = _row & 0xFF; datalen = strlen(s)+5; _device.putc(0x55); _device.putc(datalen); _device.putc(0x0B); // command ASCII Print _device.putc(x0H); //x upper 8bit _device.putc(x0L); //x low 8bit _device.putc(y0H); //y upper 8bit _device.putc(y0L); //y low 8bit for (int a=0; a<strlen(s); a++) { _device.putc(s[a]); sum = sum+s[a]; } sum = sum+x0H+x0L+y0H+y0L+0x0B; _device.putc(sum);//sumcheck _device.putc(0xAA); } void AD128160::color2(int c1,int c2) { //int c1; //int c2; int sum; //c1=(rgb >> 8) & 0xff; //c2=(rgb & 0xff); sum=c1+c2+0x84; _device.putc(0x55); _device.putc(0x03); _device.putc(0x84); _device.putc(c1); _device.putc(c2); _device.putc(sum); _device.putc(0xAA); } void AD128160::backgroudColor(int rgb) { int c1; int c2; int sum; int mode=1; c1=(rgb >> 8) & 0xff; c2=(rgb & 0xff); sum=mode+c1+c2+0x85; _device.putc(0x55); _device.putc(0x04); _device.putc(0x85); _device.putc(mode); _device.putc(c1); _device.putc(c2); _device.putc(sum); _device.putc(0xAA); } void AD128160::color(int rgb) { int c1; int c2; int sum; c1=(rgb >> 8) & 0xff; c2=(rgb & 0xff); sum=c1+c2+0x84; _device.putc(0x55); _device.putc(0x03); _device.putc(0x84); _device.putc(c1); _device.putc(c2); _device.putc(sum); _device.putc(0xAA); } void AD128160::newline(void) { _column = 0; _row++; if (_row >= LCD_ROWS) { _row = 0; } } void AD128160::pixel(int x0,int y0) { unsigned char x0H; unsigned char x0L; unsigned char y0H; unsigned char y0L; unsigned char sum; x0H = x0 >> 8; x0L = x0 & 0xFF; y0H = y0 >> 8; y0L = y0 & 0xff; sum = x0H+x0L+y0H+y0L+0x01; _device.putc(0x55); _device.putc(0x05); _device.putc(0x01);//command _device.putc(x0H); _device.putc(x0L); _device.putc(y0H); _device.putc(y0L); _device.putc(sum); _device.putc(0xAA); } void AD128160::box(int x0,int y0,int x1,int y1,int paint) { unsigned char x0H; unsigned char x0L; unsigned char x1H; unsigned char x1L; unsigned char y0H; unsigned char y0L; unsigned char y1H; unsigned char y1L; unsigned char sum; unsigned char cmd; switch (paint) { case 1: cmd = 0x04; break; default: cmd =0x03; break; } x0H = x0 >> 8; x0L = x0 & 0xFF; y0H = y0 >> 8; y0L = y0 & 0xff; x1H = x1 >> 8; x1L = x1 & 0xFF; y1H = y1 >> 8; y1L = y1 & 0xff; sum = x0H+x0L+y0H+y0L+x1H+x1L+y1H+y1L+cmd; _device.putc(0x55);//Box _device.putc(0x09); _device.putc(cmd);//command _device.putc(x0H); _device.putc(x0L); _device.putc(y0H); _device.putc(y0L); _device.putc(x1H); _device.putc(x1L); _device.putc(y1H); _device.putc(y1L); _device.putc(sum); _device.putc(0xAA); } void AD128160::circle(int x0,int y0,int r,int paint) { unsigned char x0H; unsigned char x0L; unsigned char y0H; unsigned char y0L; unsigned char rH; unsigned char rL; unsigned char sum; unsigned char cmd; switch (paint) { case 0: cmd = 0x05; break; case 1: cmd = 0x06; break; default: cmd =0x05; break; } x0H = x0 >> 8; x0L = x0 & 0xFF; y0H = y0 >> 8; y0L = y0 & 0xff; rH = r >> 8; rL = r & 0xFF; sum = x0H+x0L+y0H+y0L+rH+rL+cmd; _device.putc(0x55); _device.putc(0x07); _device.putc(cmd);//command _device.putc(x0H); _device.putc(x0L); _device.putc(y0H); _device.putc(y0L); _device.putc(rH); _device.putc(rL); _device.putc(sum); _device.putc(0xAA); } void AD128160::line(int x0,int y0,int x1,int y1) { unsigned char x0H; unsigned char x0L; unsigned char x1H; unsigned char x1L; unsigned char y0H; unsigned char y0L; unsigned char y1H; unsigned char y1L; unsigned char sum; x0H = x0 >> 8; x0L = x0 & 0xFF; y0H = y0 >> 8; y0L = y0 & 0xff; x1H = x1 >> 8; x1L = x1 & 0xFF; y1H = y1 >> 8; y1L = y1 & 0xff; sum = x0H+x0L+y0H+y0L+x1H+x1L+y1H+y1L+02; _device.putc(0x55); _device.putc(0x09); _device.putc(0x02);//command _device.putc(x0H); _device.putc(x0L); _device.putc(y0H); _device.putc(y0L); _device.putc(x1H); _device.putc(x1L); _device.putc(y1H); _device.putc(y1L); _device.putc(sum); _device.putc(0xAA); }