LCD TFT for ssd0139 driver 8 bit mode - using portout for max speed
Fork of LCDTFT_ssd0139 by
Diff: LCDTFT.cpp
- Revision:
- 2:ebedda77b33b
- Parent:
- 1:1085b6177f6e
- Child:
- 3:f999653c1069
--- a/LCDTFT.cpp Tue Mar 15 01:47:35 2011 +0000 +++ b/LCDTFT.cpp Tue Sep 02 09:02:18 2014 +0000 @@ -14,8 +14,8 @@ //// //// //// //// //// (C) Copyright 2011 www.micros-designs.com.ar //// -//// Este código puede ser usado, modificado y distribuido libremente //// -//// sin eliminar esta cabecera y sin garantía de ningún tipo. //// +//// Este c�digo puede ser usado, modificado y distribuido libremente //// +//// sin eliminar esta cabecera y sin garant�a de ning�n tipo. //// //// //// //// //// /////////////////////////////////////////////////////////////////////////// @@ -31,8 +31,62 @@ _Alto=1; _Color=0x0000; } +// global variable for screen orientation set by init +bool orient=0; -void LCDTFT::vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color){ + static const unsigned short regValues[] = { + 0x0000, 0x0001, // start oscillation + 0x00FF, 0x0010, // wait 16 ms + 0x0007, 0x0000, //display control - zeros everything ??? + 0x0013, 0x0000, // power control 3 setting = all zero + 0x0011, 0x2604, //power control 2 seting = gvd voltage 0x26 vci1 voltage 0x04 + 0x0014, 0x0015, // power contrlol 4 setting vcmr=0 vcomh=0 vml=13 = amplitude of vcom voltage + 0x0010, 0x3C00, // power control 1 bt3=0 sap=7 (0b111) bt=4 (0b100) + 0x0013, 0x0040, //power control 3 PON=1 PON1=0 AON=0 + 0x00FF,0x0010, // wait 16ms + 0x0013, 0x0060, // power control 3 PON=1 PON1=1 AON=0 + 0x00FF, 0x0032, // wait 50ms + 0x0013, 0x0070, //power control 3 PON=1 PON1=1 AON=1 + 0x00FF, 0x0028, // wait 40ms + + 0x0001, 0x0127, // driver ouptut control + 0x0002, 0x0700, //LCD driving waveform settings + 0x0003, 0x1030, // entry mode settingtri=0 dfm=0 bgr=1 id1:id0=11 + 0x0007, 0x0000, // display control 1 pt1-0=0 vle2-1=0 spt=0 gon=0 rev=0 d1-0=0 + 0x0008, 0x0404, //black period control fp3-0=4 bp3-0=4 + 0x000B, 0x0200, //frame cycle setting nd1-0=0 sdt1-0=2 ecs2-0=0 div1-0=0 dcr_ex=0 dcr2-0=0 rtn1-0=0 + 0x000C, 0x0000, //external interface controlrm=0 dm1-0=0 rim1-0=0 + 0x00015,0x0000, //sub panel control sub_im1-0=0 stn_en=0 mpu_mode=0 fcv_en=0 + + //gamma setting + 0x0030, 0x0000, + 0x0031, 0x0606, + 0x0032, 0x0006, + 0x0033, 0x0403, + 0x0034, 0x0107, + 0x0035, 0x0101, + 0x0036, 0x0707, + 0x0037, 0x0304, + 0x0038, 0x0A00, + 0x0039, 0x0706, + // end of gamma settings + 0x0040, 0x0000, // gate scan position (start g1 scan) scn5-0=0 + 0x0041, 0x0000, // vertical scroll setting vl8-0=0 + 0x0042, 0x013F, // screen end position se18-10=0x13F + 0x0043, 0x0000, // screen_start position ss28-20=0 + 0x0044, 0x0000, // 2nd screen driving position end 00 + 0x0045, 0x0000, //2nd screen driving position start =00 + 0x0046, 0xEF00, //window addre horizontal ram for x0,x1 HEA=0xEF HSA=00 ie x=0 and x=239 + 0x0047, 0x013F, //vertical ram address end vea=0x13F ie y=319 + 0x0048, 0x0000, //vertical ram address start=00 ie y=0 + 0x0007, 0x0011, //dispaly control 1 + 0x00FF, 0x0028, //wait 40ms + 0x0007, 0x0017, //display control 1 + +}; + + +void LCDTFT::vLCDTFTSetParametersPrintf(unsigned short Xo,unsigned short Yo,unsigned short Xmin,unsigned short Xmax,unsigned char Alto, unsigned short Color,unsigned short BackColor){ X=Xo; Y=Yo; @@ -40,6 +94,7 @@ X_max=Xmax; _Alto=Alto; _Color=Color; + _Background=BackColor; } int LCDTFT::_putc(int value){ @@ -47,13 +102,13 @@ if(value=='\n'){ X=X_min; - Y+=7*_Alto + 1; + Y+=8*_Alto + 1; }else{ - vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color); + vLCDTFTText(X,Y,(const char *)&Fmt[0],&ARIAL[0],_Alto,_Color,_Background); X+=5*_Alto+1; if(X >= X_max){ X = X_min; - Y += 7*_Alto + 1; + Y += 8*_Alto + 1; } } return(value); @@ -67,16 +122,23 @@ LCD_PIN_RS=0; LCD_PIN_CS=0; - LCD_PORT->write(Data); + LCD_PORT->write(Data>>8); // MSB so with an 8 bit port we need to write here the high and ,low bytes successively LCD_PIN_WR=0; LCD_PIN_WR=1; + LCD_PORT->write(Data & 0x00FF); // LSB + LCD_PIN_WR=0; + LCD_PIN_WR=1; + LCD_PIN_CS=1; } void LCDTFT::vLCDTFTWriteData(unsigned short Data){ LCD_PIN_RS=1; LCD_PIN_CS=0; - LCD_PORT->write(Data); + LCD_PORT->write(Data>>8); // MSB so with an 8 bit port we need to write here the high and ,low bytes successively + LCD_PIN_WR=0; + LCD_PIN_WR=1; + LCD_PORT->write(Data & 0x00FF); // LSB LCD_PIN_WR=0; LCD_PIN_WR=1; LCD_PIN_CS =1; @@ -100,23 +162,59 @@ void LCDTFT::vLCDTFTAddressSetPoint(unsigned short x,unsigned short y){ - vLCDTFTWriteCommandData(0x004e,x); - vLCDTFTWriteCommandData(0x004f,y); - vLCDTFTWriteCommand(0x0022); +// CGRAM addresses are given by (x+y*256) - for some reason the y cordinate +// addresses require 17 bits +// equiv if y is given by 0xYYY and x by 0xXX +// then address of point x,y is 0xYYYXXX + int add; + int adl,adh; + if(orient==0){ // portrait + add=x+y*256; //240 x 320 y but 256 bytes for each x row + + } + else{ + add=(239-y)+x*256; + } + adl=add & 0x00FF; // selects the 8 low bits + adh=(add >>8); // the 9 high bits + vLCDTFTWriteCommandData(0x0020,adl); // 8 lsb of address + vLCDTFTWriteCommandData(0x0021,adh); //9 msb of address + vLCDTFTWriteCommand(0x0022); // prepare to send rgb data } -void LCDTFT::vLCDTFTInit(void){ +void LCDTFT::vLCDTFTInit(bool format){ + int i; + unsigned short address,data; + orient=format; LCD_PIN_RESET=1; - wait_ms(5); + wait_ms(5); // must hold for at least 1ms after reset LCD_PIN_RESET=0; - wait_ms(10); + wait_ms(10); // wait for stable R-C oscillation LCD_PIN_RESET=1; + wait_ms(5); // final wait for rest to be acitvated LCD_PIN_CS=1; LCD_PIN_RD=1; LCD_PIN_WR=1; wait_ms(20); + + for(i=0;i<sizeof(regValues)/4;i++) + { + address=regValues[i*2]; + data=regValues[i*2+1]; + + if(address==0xFF) + { + wait_ms(data); + } + else { + vLCDTFTWriteCommandData(address,data); + } + } + wait_ms(1); + +/* vLCDTFTWriteCommandData(0x0000,0x0001); wait_ms(1); vLCDTFTWriteCommandData(0x0003,0xA8A4); wait_ms(1); vLCDTFTWriteCommandData(0x000C,0x0000); wait_ms(1); @@ -159,11 +257,15 @@ vLCDTFTWriteCommandData(0x004f,0); vLCDTFTWriteCommandData(0x004e,0); vLCDTFTWriteCommand(0x0022); + */ } void LCDTFT::vLCDTFTFillScreen(unsigned short Color){ unsigned short i,j; - vLCDTFTAddressSet(0,0,239,319); + + vLCDTFTWriteCommandData(0x0020,00); //set x=0 + vLCDTFTWriteCommandData(0x0021,00); // set y=0 + vLCDTFTWriteCommand(0x0022); for(i=0;i<320;i++){ for (j=0;j<240;j++){ @@ -178,7 +280,7 @@ vLCDTFTWriteData(Color); } -void LCDTFT::vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color){ +void LCDTFT::vLCDTFTText(unsigned short x,unsigned short y,const char *PtrText,const char (*Fuente)[5],unsigned char Alto,unsigned short Color,unsigned short BackColor){ unsigned short i, j, k, l, m, temp; char DataPunto[5]; const char *Ptr; @@ -205,9 +307,16 @@ for(l=0; l < Alto; ++l){ for(m=0; m < Alto; ++m){ vLCDTFTPoint(x+m,y+k*Alto+l,Color); - } - } - } + }//endform + }//endforl + }//endif + else{ + for(l=0; l < Alto; ++l){ + for(m=0; m < Alto; ++m){ + vLCDTFTPoint(x+m,y+k*Alto+l,BackColor); + }//endform + }//endforl + } } } x++; @@ -271,11 +380,11 @@ void LCDTFT::vLCDTFTRectangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,bool Filled,unsigned short Color){ if(Filled){ - int Lenght=((int)(x2-x1+1)*(y2-y1+1)); + int Lenght=(int)(x2-x1); - vLCDTFTAddressSet(x1,y1,x2,y2); + for(int i=0;i<Lenght;i++){ - vLCDTFTWriteData(Color); + vLCDTFTLine(x1,y1+i,x2,y1+i,Color); } }else{ vLCDTFTLine(x1, y1, x2, y1, Color); @@ -313,7 +422,7 @@ else P += 5 + 2 * (a++ - b--); }while(a <= b); } - +/* void LCDTFT::vDrawImageBMP24Bits(const char *NameImagen){ #define OffsetWidthPixel 18 @@ -391,7 +500,7 @@ } fclose(Imagen); } - +*/ void LCDTFT::vLCDTFTDrawImage(unsigned short x,unsigned short y, unsigned short Width, unsigned short Heigh, unsigned int Lenght, const unsigned short *Imagen){ vLCDTFTAddressSet(x,y,x+Width-1,y+Heigh-1);