sainsmart
Fork of ST7735_TFT by
www.sainsmart.com ST7735 1.8"TFT LCD 128x160 Pixel setting chenge
Revision 2:7a251cc3d679, committed 2014-06-20
- Comitter:
- mihanada
- Date:
- Fri Jun 20 09:25:28 2014 +0000
- Parent:
- 1:967235e6fd48
- Commit message:
- www.sainsmart.com ST7735 1.8"TFT LCD 128x160 Pixel; setting chenge
Changed in this revision
ST7735_TFT.cpp | Show annotated file Show diff for this revision Revisions of this file |
ST7735_TFT.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 967235e6fd48 -r 7a251cc3d679 ST7735_TFT.cpp --- a/ST7735_TFT.cpp Sun Dec 11 21:18:21 2011 +0000 +++ b/ST7735_TFT.cpp Fri Jun 20 09:25:28 2014 +0000 @@ -1,4 +1,5 @@ - /* mbed library for 128*160 pixel display TFT based on ST7735 LCD Controller + +/* mbed library for 128*160 pixel display TFT based on ST7735 LCD Controller * ST7735 specific routines (initialization, window addressing, pixel output) * Copyright (c) 2011 Jonne Valola * @@ -47,16 +48,20 @@ orientation = o; switch (orientation) { case 0: - wr_reg(ST7735_MADCTL, 0x0008); +// wr_reg(ST7735_MADCTL, 0x0008); + wr_reg(ST7735_MADCTL, 0x0000); break; case 1: - wr_reg(ST7735_MADCTL, 0x0068); +// wr_reg(ST7735_MADCTL, 0x0068); + wr_reg(ST7735_MADCTL, 0x0060); break; case 2: - wr_reg(ST7735_MADCTL, 0x00C8); +// wr_reg(ST7735_MADCTL, 0x00C8); + wr_reg(ST7735_MADCTL, 0x00C0); break; case 3: - wr_reg(ST7735_MADCTL, 0x00A8); +// wr_reg(ST7735_MADCTL, 0x00A8); + wr_reg(ST7735_MADCTL, 0x00A0); break; } } @@ -259,6 +264,42 @@ /* Gamma settings -----------------------------------------------------------*/ + wr_cmd(0xE0); // GMCTRP1 + wr_dat(0x0f); + wr_dat(0x1a); + wr_dat(0x0f); + wr_dat(0x18); + wr_dat(0x2f); + wr_dat(0x28); + wr_dat(0x20); + wr_dat(0x22); + wr_dat(0x1f); + wr_dat(0x1b); + wr_dat(0x23); + wr_dat(0x37); + wr_dat(0x00); + wr_dat(0x07); + wr_dat(0x02); + wr_dat(0x10); + wr_cmd(0xE1); // GMCTRN1 + wr_dat(0x0f); + wr_dat(0x1b); + wr_dat(0x0f); + wr_dat(0x17); + wr_dat(0x33); + wr_dat(0x2c); + wr_dat(0x29); + wr_dat(0x2e); + wr_dat(0x30); + wr_dat(0x30); + wr_dat(0x39); + wr_dat(0x3f); + wr_dat(0x00); + wr_dat(0x07); + wr_dat(0x03); + wr_dat(0x10); + +/* wr_cmd(0xE0); // GMCTRP1 wr_dat(0x02); wr_dat(0x1c); @@ -293,6 +334,8 @@ wr_dat(0x00); wr_dat(0x02); wr_dat(0x10); +*/ + wr_cmd(ST7735_DISPON); // display ON wait_ms(100); @@ -302,15 +345,19 @@ switch (orientation) { case 0: +// wr_reg(0xC8, 0x0008); wr_reg(0xC8, 0x0008); break; case 1: +// wr_reg(0xC8, 0x0068); wr_reg(0xC8, 0x0068); break; case 2: +// wr_reg(0xC8, 0x00C8); wr_reg(0xC8, 0x00C8); break; case 3: +// wr_reg(0xC8, 0x00A8); wr_reg(0xC8, 0x00A8); break; } @@ -326,13 +373,16 @@ // setup for data _rs = 1; _cs = 0; - _spi.format(16,3); - _spi.write(color); - _cs = 1; - _spi.format(8,3); + _spi.write(color >> 8); + _spi.write(color); + _cs = 1; + + + } void ST7735_TFT::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { +/* wr_cmd(ST7735_CASET); // column addr set wr_dat(0x00); wr_dat(x+2); // XSTART @@ -344,7 +394,20 @@ wr_dat(y+1); // YSTART wr_dat(0x00); wr_dat(y+h+1); // YEND +*/ + wr_cmd(ST7735_CASET); // column addr set + wr_dat(0x00); + wr_dat(x); // XSTART + wr_dat(0x00); + wr_dat(x+w-1); // XEND + + wr_cmd(ST7735_RASET); // row addr set + wr_dat(0x00); + wr_dat(y); // YSTART + wr_dat(0x00); + wr_dat(y+h); // YEND + wr_cmd(ST7735_RAMWR); // write to RAM } @@ -358,11 +421,10 @@ unsigned int i; WindowMax(); wr_dat_start(); - _spi.format(16,3); for (i = 0; i < ( (width()+1) * (height()+3)); i++) { - _spi.write(_background); + _spi.write(_background >>8); + _spi.write(_background); } - _spi.format(8,3); wr_dat_stop(); } @@ -489,8 +551,8 @@ wr_cmd(0x2C); wr_dat_start(); for (int x=0; x<w; x++) { + _spi.write(color >>8); _spi.write(color); - _spi.write(color >> 8); } wr_dat_stop(); return; @@ -505,8 +567,8 @@ wr_cmd(0x2C); wr_dat_start(); for (int y=0; y<h; y++) { + _spi.write(color >>8); _spi.write(color); - _spi.write(color >> 8); } wr_dat_stop(); return; @@ -615,8 +677,8 @@ wr_cmd(0x2C); wr_dat_start(); for (int p=0; p<pixel; p++) { + _spi.write(color >>8); _spi.write(color); - _spi.write(color >> 8); } wr_dat_stop(); return; @@ -685,20 +747,20 @@ wr_dat_start(); zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap w = zeichen[0]; // width of actual char - _spi.format(16,3); // pixel are 16 bit for (j=0; j<vert; j++) { // vert line for (i=0; i<hor; i++) { // horz line z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); if (( z & b ) == 0x00) { - _spi.write(_background); + _spi.write(_background >>8); + _spi.write(_background); } else { - _spi.write(_foreground); + _spi.write(_foreground >>8); + _spi.write(_foreground); } } } - _spi.format(8,3); // 8 bit wr_dat_stop(); if ((w + 2) < hor) { // x offset to next char char_x += w + 2; @@ -724,14 +786,14 @@ for (j = 0; j < h; j++) { //Lines for (i = 0; i < w; i++) { // copy pixel data to TFT _spi.write(*bitmap_ptr); // one line - _spi.write(*bitmap_ptr >> 8); + _spi.write(*bitmap_ptr >>8); bitmap_ptr++; } } wr_dat_stop(); } - +/* int ST7735_TFT::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) { // BEWARE ! // NOT TESTED @@ -811,4 +873,6 @@ free (line); fclose(Image); return(1); -} \ No newline at end of file +} +*/ +
diff -r 967235e6fd48 -r 7a251cc3d679 ST7735_TFT.h --- a/ST7735_TFT.h Sun Dec 11 21:18:21 2011 +0000 +++ b/ST7735_TFT.h Fri Jun 20 09:25:28 2014 +0000 @@ -268,7 +268,7 @@ * */ - int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); +// int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); /** Read an area from the LCD RAM to MCU RAM *