Go Down

Topic: Arduino control the 2.4" TFT LCD (Read 16305 times) previous topic - next topic

ITead

May 10, 2010, 06:56 pm Last Edit: May 11, 2010, 04:14 am by ITead Reason: 1
Useing the 2.4 inch TFT LCD , which is used ILI9325 controller ,  65K color , 320*240 (resolution).

Connect the pins to Arduino
DB0-DB16 to pin D0-D13 , pin A0-A1 of Arduino
RESET to A2
CS to A3
WR to A4
RS to A5

Use the 16 bit data bus which is 2 timer faster than 8 bit. but it used up all the pins of the Arduino.
Code: [Select]
#define LCD_RS 19
#define LCD_REST 16
#define LCD_WR 18
#define LCD_CS 17

void main_Write_COM(int DH)
{
 unsigned char i;
 int temp;
 digitalWrite(LCD_RS,LOW);
 digitalWrite(LCD_CS,LOW);
 for(i=0;i<16;i++)
 {
   temp=(DH&0x01);
   if(temp)
     digitalWrite(i,HIGH);
   else
     digitalWrite(i,LOW);
   DH=DH>>1;
 }
 digitalWrite(LCD_WR,LOW);
 digitalWrite(LCD_WR,HIGH);
 digitalWrite(LCD_CS,HIGH);
}

void main_Write_DATA(int DH)
{
 unsigned char i;
 int temp;
 digitalWrite(LCD_RS,HIGH);
 digitalWrite(LCD_CS,LOW);
 for(i=0;<16;i++)
 {
   temp=(DH&;0x01);
   if(temp)
     digitalWrite(i,HIGH);
   else
     digitalWrite(i,LOW);
   DH=DH>>1;
 }
 digitalWrite(LCD_WR,LOW);
 digitalWrite(LCD_WR,HIGH);
 digitalWrite(LCD_CS,HIGH);
}

void main_W_com_data(int com1,int dat1)
{
 main_Write_COM(com1);
 main_Write_DATA(dat1);
}

void address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
 main_W_com_data(0x0002,x1>>8);     // Column address start2
 main_W_com_data(0x0003,x1);    // Column address start1
 main_W_com_data(0x0004,x2>>8);     // Column address end2
 main_W_com_data(0x0005,x2);    // Column address end1
 main_W_com_data(0x0006,y1>>8);     // Row address start2
 main_W_com_data(0x0007,y1);    // Row address start1
 main_W_com_data(0x0008,y2>>8);     // Row address end2
 main_W_com_data(0x0009,y2);    // Row address end1
 main_Write_COM(0x0022);      

}

void main_init(void)
{

 digitalWrite(LCD_REST,HIGH);
 delay(5);
 digitalWrite(LCD_REST,LOW);
 delay(10);
 digitalWrite(LCD_REST,HIGH);
 delay(20);

 //  VENDOR
 main_W_com_data(0x0046,0x00A4);
 main_W_com_data(0x0047,0x0053);
 main_W_com_data(0x0048,0x0000);
 main_W_com_data(0x0049,0x0044);
 main_W_com_data(0x004a,0x0004);
 main_W_com_data(0x004b,0x0067);
 main_W_com_data(0x004c,0x0033);
 main_W_com_data(0x004d,0x0077);
 main_W_com_data(0x004e,0x0012);
 main_W_com_data(0x004f,0x004C);
 main_W_com_data(0x0050,0x0046);
 main_W_com_data(0x0051,0x0044);

 //240x320 window setting
 main_W_com_data(0x0002,0x0000); // Column address start2
 main_W_com_data(0x0003,0x0000); // Column address start1
 main_W_com_data(0x0004,0x0000); // Column address end2
 main_W_com_data(0x0005,0x00ef); // Column address end1
 main_W_com_data(0x0006,0x0000); // Row address start2
 main_W_com_data(0x0007,0x0000); // Row address start1
 main_W_com_data(0x0008,0x0001); // Row address end2
 main_W_com_data(0x0009,0x003f); // Row address end1

 // Display Setting
 main_W_com_data(0x0001,0x0006); // IDMON=0, INVON=1, NORON=1, PTLON=0
 main_W_com_data(0x0016,0x00C8); // MY=0, MX=0, MV=0, ML=1, BGR=0, TEON=0   0048
 main_W_com_data(0x0023,0x0095); // N_DC=1001 0101
 main_W_com_data(0x0024,0x0095); // PI_DC=1001 0101
 main_W_com_data(0x0025,0x00FF); // I_DC=1111 1111

 main_W_com_data(0x0027,0x0002); // N_BP=0000 0010
 main_W_com_data(0x0028,0x0002); // N_FP=0000 0010
 main_W_com_data(0x0029,0x0002); // PI_BP=0000 0010
 main_W_com_data(0x002a,0x0002); // PI_FP=0000 0010
 main_W_com_data(0x002C,0x0002); // I_BP=0000 0010
 main_W_com_data(0x002d,0x0002); // I_FP=0000 0010

 main_W_com_data(0x003a,0x0001); // N_RTN=0000, N_NW=001    0001
 main_W_com_data(0x003b,0x0000); // P_RTN=0000, P_NW=001
 main_W_com_data(0x003c,0x00f0); // I_RTN=1111, I_NW=000
 main_W_com_data(0x003d,0x0000); // DIV=00
 delay(1);
 main_W_com_data(0x0035,0x0038); // EQS=38h
 main_W_com_data(0x0036,0x0078); // EQP=78h
 main_W_com_data(0x003E,0x0038); // SON=38h
 main_W_com_data(0x0040,0x000F); // GDON=0Fh
 main_W_com_data(0x0041,0x00F0); // GDOFF

 // Power Supply Setting
 main_W_com_data(0x0019,0x0049); // CADJ=0100, CUADJ=100, OSD_EN=1 ,60Hz
 main_W_com_data(0x0093,0x000F); // RADJ=1111, 100%
 delay(1);
 main_W_com_data(0x0020,0x0040); // BT=0100
 main_W_com_data(0x001D,0x0007); // VC1=111   0007
 main_W_com_data(0x001E,0x0000); // VC3=000
 main_W_com_data(0x001F,0x0004); // VRH=0011

 //VCOM SETTING
 main_W_com_data(0x0044,0x004D); // VCM=101 0000  4D
 main_W_com_data(0x0045,0x000E); // VDV=1 0001   0011
 delay(1);
 main_W_com_data(0x001C,0x0004); // AP=100
 delay(2);

 main_W_com_data(0x001B,0x0018); // GASENB=0, PON=0, DK=1, XDK=0, VLCD_TRI=0, STB=0
 delay(1);
 main_W_com_data(0x001B,0x0010); // GASENB=0, PON=1, DK=0, XDK=0, VLCD_TRI=0, STB=0
 delay(1);
 main_W_com_data(0x0043,0x0080); //set VCOMG=1
 delay(2);

 // Display ON Setting
 main_W_com_data(0x0090,0x007F); // SAP=0111 1111
 main_W_com_data(0x0026,0x0004); //GON=0, DTE=0, D=01
 delay(1);
 main_W_com_data(0x0026,0x0024); //GON=1, DTE=0, D=01
 main_W_com_data(0x0026,0x002C); //GON=1, DTE=0, D=11
 delay(1);
 main_W_com_data(0x0026,0x003C); //GON=1, DTE=1, D=11

 // INTERNAL REGISTER SETTING
 main_W_com_data(0x0057,0x0002); // TEST_Mode=1: into TEST mode
 main_W_com_data(0x0095,0x0001); // SET DISPLAY CLOCK AND PUMPING CLOCK TO SYNCHRONIZE
 main_W_com_data(0x0057,0x0000); // TEST_Mode=0: exit TEST mode
 //main_W_com_data(0x0021,0x0000);
 main_Write_COM(0x0022);  

}

void Pant(unsigned int color)
{
 int i,j;
 address_set(0,0,239,319);

 for(i=0;i<320;i++)
 {
   for (j=0;j<240;j++)
   {
     main_Write_DATA(color);
   }

 }
}

void setup()
{
 unsigned char p;
 for(p=0;p<20;p++)
 {
   pinMode(p,OUTPUT);
 }
 main_init();
}

void loop()
{
 Pant(0xf800); //Red
 delay(1000);
 Pant(0X07E0); //Green
 delay(1000);
 Pant(0x001f); //Blue
 delay(1000);
}




More information about the demo code and the screen :
http://iteadstudio.com/application-note/itdb02-2-4-display-with-arduino

I am going to write a library for this controller , and there are the 2.4 and 3.2 inch LCD use the same controller that can use this library ;)
Itead Studio - Make innovation easier

PaulS

Quote
Useing the 2.4 [glow]inch [/glow]TFT LCD


Rats. Going by the thread title, I was hoping to find a LARGE TFT that I could use in a  project.

mowcius

Quote
Rats. Going by the thread title, I was hoping to find a LARGE TFT that I could use in a  project.

Haha I didn't notice the 2.4 foot in the title!  ;D

Well at least there are a load of these 2.4" displays hanging around now to choose from.
This place looks pretty cheap though. I wonder how much international shipping to UK is...

Mowcius

retrolefty

The fact that is uses up every I/O pin on a standard Arduino kind of limits it's application doesn't it?  ;)

Plan on using a Mega board if you are going to the trouble of writing a library for it, otherwise it's kind of useless, no?

Lefty

mowcius

meh

I would use an rDuino LEDhead which is standard arduino form factor but has extra pin pads on the board as it uses an 644 chip :)

Mowcius

ITead

#5
May 11, 2010, 04:05 am Last Edit: May 11, 2010, 04:19 am by ITead Reason: 1
Quote
Rats. Going by the thread title, I was hoping to find a LARGE TFT that I could use in a  project.


It's a Low-level errors... 2.4" GLCD  ;)
Itead Studio - Make innovation easier

ITead

#6
May 11, 2010, 04:12 am Last Edit: May 11, 2010, 01:58 pm by ITead Reason: 1
Quote
The fact that is uses up every I/O pin on a standard Arduino kind of limits it's application doesn't it?  

Plan on using a Mega board if you are going to the trouble of gifwriting a library for it, otherwise it's kind of useless, no?

Arduino really with a pool resources of I/O .. so 16bit will use up all the pins of Arduino , if you want to use the touch and the SD card , then just can choose the 8bit mode -- which more slower than you can imagine  :( Mega has enough I/O for the LCD ,touch , SDcard even the external flash .

Even in the 16bit mode work in 16M , the refresh rate is not faster than 1 frame per second ... so you can used the arduino to show the UI menu or a static image , but the video beyond its capacity -- STM32 is a good choice, I like the DMA ;)

Code: [Select]
#define LCD_RS 8        
#define LCD_WR 9      
#define LCD_CS 10      
#define LCD_REST 11


void LCD_Writ_Bus(char VH,char VL)  
{  
   unsigned char i,temp,data;
   data=VH;
    for(i=0;i<8;i++)
   {
      temp=(data&0x01);
      if(temp)
      digitalWrite(i,HIGH);
      else
      digitalWrite(i,LOW);
      data=data>>1;
   }
   digitalWrite(LCD_WR,LOW);
   digitalWrite(LCD_WR,HIGH);
   data=VL;
   for(i=0;i<8;i++)
   {
      temp=(data&0x01);
      if(temp)
      digitalWrite(i,HIGH);
      else
      digitalWrite(i,LOW);
      data=data>>1;
   }            
   digitalWrite(LCD_WR,LOW);
   digitalWrite(LCD_WR,HIGH);
}


void LCD_Write_COM(char VH,char VL)  
{  
   digitalWrite(LCD_RS,LOW);
   LCD_Writ_Bus(VH,VL);
}


void LCD_Write_DATA(char VH,char VL)    
{
   digitalWrite(LCD_RS,HIGH);
   LCD_Writ_Bus(VH,VL);
}

void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
   LCD_Write_COM(0x00,0x20);LCD_Write_DATA(x1>>8,x1);    
   LCD_Write_COM(0x00,0x21);LCD_Write_DATA(y1>>8,y1);  
   LCD_Write_COM(0x00,0x50);LCD_Write_DATA(x1>>8,x1);  
   LCD_Write_COM(0x00,0x52);LCD_Write_DATA(y1>>8,y1);  
   LCD_Write_COM(0x00,0x51);LCD_Write_DATA(x2>>8,x2);  
   LCD_Write_COM(0x00,0x53);LCD_Write_DATA(y2>>8,y2);  
   LCD_Write_COM(0x00,0x22);                                   
}

void LCD_Init(void)
{

   digitalWrite(LCD_REST,HIGH);
   delay(5);
   digitalWrite(LCD_REST,LOW);
   delay(5);
   digitalWrite(LCD_REST,HIGH);
   delay(5);

   digitalWrite(LCD_CS,LOW);  
   //************* Start Initial Sequence **********//
   LCD_Write_COM(0x00,0xE5); LCD_Write_DATA(0x78,0xF0); // set SRAM internal timing
   LCD_Write_COM(0x00,0x01); LCD_Write_DATA(0x01,0x00); // set SS and SM bit
   LCD_Write_COM(0x00,0x02); LCD_Write_DATA(0x07,0x00); // set 1 line inversion
   LCD_Write_COM(0x00,0x03); LCD_Write_DATA(0x10,0x30); // set GRAM write direction and BGR=1.
   LCD_Write_COM(0x00,0x04); LCD_Write_DATA(0x00,0x00); // Resize register
   LCD_Write_COM(0x00,0x08); LCD_Write_DATA(0x02,0x07); // set the back porch and front porch
   LCD_Write_COM(0x00,0x09); LCD_Write_DATA(0x00,0x00); // set non-display area refresh cycle ISC[3:0]
   LCD_Write_COM(0x00,0x0A); LCD_Write_DATA(0x00,0x00); // FMARK function
   LCD_Write_COM(0x00,0x0C); LCD_Write_DATA(0x00,0x00); // RGB interface setting
   LCD_Write_COM(0x00,0x0D); LCD_Write_DATA(0x00,0x00); // Frame marker Position
   LCD_Write_COM(0x00,0x0F); LCD_Write_DATA(0x00,0x00); // RGB interface polarity
   //*************Power On sequence ****************//
   LCD_Write_COM(0x00,0x10); LCD_Write_DATA(0x00,0x00); // SAP, BT[3:0], AP, DSTB, SLP, STB
   LCD_Write_COM(0x00,0x11); LCD_Write_DATA(0x00,0x07); // DC1[2:0], DC0[2:0], VC[2:0]
   LCD_Write_COM(0x00,0x12); LCD_Write_DATA(0x00,0x00); // VREG1OUT voltage
   LCD_Write_COM(0x00,0x13); LCD_Write_DATA(0x00,0x00); // VDV[4:0] for VCOM amplitude
   LCD_Write_COM(0x00,0x07); LCD_Write_DATA(0x00,0x01);
   delay(50); // Dis-charge capacitor power voltage
   LCD_Write_COM(0x00,0x10); LCD_Write_DATA(0x10,0x90); // 1490//SAP, BT[3:0], AP, DSTB, SLP, STB
   LCD_Write_COM(0x00,0x11); LCD_Write_DATA(0x02,0x27); // DC1[2:0], DC0[2:0], VC[2:0]
   delay(50); // Delay 50ms
   LCD_Write_COM(0x00,0x12); LCD_Write_DATA(0x00,0x1F); //001C// Internal reference voltage= Vci;
   delay(50); // Delay 50ms
   LCD_Write_COM(0x00,0x13); LCD_Write_DATA(0x15,0x00); //0x1000//1400   Set VDV[4:0] for VCOM amplitude  1A00
   LCD_Write_COM(0x00,0x29); LCD_Write_DATA(0x00,0x27); //0x0012 //001a  Set VCM[5:0] for VCOMH  //0x0025  0034
   LCD_Write_COM(0x00,0x2B); LCD_Write_DATA(0x00,0x0D); // Set Frame Rate   000C
   delay(50); // Delay 50ms
   LCD_Write_COM(0x00,0x20); LCD_Write_DATA(0x00,0x00); // GRAM horizontal Address
   LCD_Write_COM(0x00,0x21); LCD_Write_DATA(0x00,0x00); // GRAM Vertical Address
   // ----------- Adjust the Gamma Curve ----------//
   LCD_Write_COM(0x00,0x30); LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x31); LCD_Write_DATA(0x07,0x07);
   LCD_Write_COM(0x00,0x32); LCD_Write_DATA(0x03,0x07);
   LCD_Write_COM(0x00,0x35); LCD_Write_DATA(0x02,0x00);
   LCD_Write_COM(0x00,0x36); LCD_Write_DATA(0x00,0x08);//0207
   LCD_Write_COM(0x00,0x37); LCD_Write_DATA(0x00,0x04);//0306
   LCD_Write_COM(0x00,0x38); LCD_Write_DATA(0x00,0x00);//0102
   LCD_Write_COM(0x00,0x39); LCD_Write_DATA(0x07,0x07);//0707
   LCD_Write_COM(0x00,0x3C); LCD_Write_DATA(0x00,0x02);//0702
   LCD_Write_COM(0x00,0x3D); LCD_Write_DATA(0x1D,0x04);//1604
   
   //------------------ Set GRAM area ---------------//
   LCD_Write_COM(0x00,0x50); LCD_Write_DATA(0x00,0x00); // Horizontal GRAM Start Address
   LCD_Write_COM(0x00,0x51); LCD_Write_DATA(0x00,0xEF); // Horizontal GRAM End Address
   LCD_Write_COM(0x00,0x52); LCD_Write_DATA(0x00,0x00); // Vertical GRAM Start Address
   LCD_Write_COM(0x00,0x53); LCD_Write_DATA(0x01,0x3F); // Vertical GRAM Start Address
   LCD_Write_COM(0x00,0x60); LCD_Write_DATA(0xA7,0x00); // Gate Scan Line
   LCD_Write_COM(0x00,0x61); LCD_Write_DATA(0x00,0x01); // NDL,VLE, REV
   LCD_Write_COM(0x00,0x6A); LCD_Write_DATA(0x00,0x00); // set scrolling line
   //-------------- Partial Display Control ---------//
   LCD_Write_COM(0x00,0x80); LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x81); LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x82); LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x83); LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x84); LCD_Write_DATA(0x00,0x00);
   LCD_Write_COM(0x00,0x85); LCD_Write_DATA(0x00,0x00);
   //-------------- Panel Control -------------------//
   LCD_Write_COM(0x00,0x90); LCD_Write_DATA(0x00,0x10);
   LCD_Write_COM(0x00,0x92); LCD_Write_DATA(0x06,0x00);
   LCD_Write_COM(0x00,0x07); LCD_Write_DATA(0x01,0x33); // 262K color and display ON
   digitalWrite(LCD_CS,HIGH);  

}

void Pant(char VH,char VL)
{
   int i,j;
   digitalWrite(LCD_CS,LOW);
   Address_set(0,0,240,320);
   for(i=0;i<320;i++)
    {
     for (j=0;j<240;j++)
            {
            LCD_Write_DATA(VH,VL);
       }

     }
    digitalWrite(LCD_CS,HIGH);  
}

void setup()
{
 unsigned char p;
 int i,j,k;
 for(p=0;p<20;p++)
 {
   pinMode(p,OUTPUT);
 }
 
   LCD_Init();          
                                                 
   
}

void loop()
{
  Pant(0xf8,0x00);
  delay(1000);
  Pant(0x07,0xE0);
  delay(1000);
  Pant(0x00,0x1f);
  delay(1000);
 
}


The code for 8 bit mode~ connect the DB9-DB16 to the Arduino D0-D7 . pull the DB1-DB8 to GND.

The same effect as the 16bit mode , but slower than 16bit mode , if you use the 8M 3.3V Arduino Pro , about 3 seconds one frame.... but now you have the pins for SD card and the Touch.

Itead Studio - Make innovation easier

ITead

Update :
now we release a library for the 2.4"LCD module , now the beta version just support the LCD display and not powerful enough ,the V1.0 will include more GUI functions and will support touch screen.

Google Code project :
http://code.google.com/p/itdb02
Itead Studio - Make innovation easier

blueblur22

This is awesome! Nice work! [smiley=thumbsup.gif] It's over $120 less than the liquidware touchscreen slide, even if it is less developed/supported.  :)

:question I just ordered the 3.2" screen for my own development. You said that one was supported as well with your library, correct? :question

blueblur22: You could also take a look at my libraries for these modules: http://www.henningkarlsen.com/electronics/a_l_itdb02_graph16.php

/Henning

blueblur22

#10
Oct 25, 2010, 06:47 am Last Edit: Oct 25, 2010, 06:53 am by blueblur22 Reason: 1
Looks interesting. I'll give this one a try when the screen shows up in the mail. Thanks!

EDIT:
Wait... no support for the SD and the Flash? I will be needing both of these for my project as i need to use many graphics. Large storage will be needed. Any way to make this happen? Does anybody else have another library that supports both?

mowcius

Quote
Wait... no support for the SD and the Flash? I will be needing both of these for my project as i need to use many graphics. Large storage will be needed. Any way to make this happen? Does anybody else have another library that supports both?

Not really unless you switch to a Mega. The arduino does not really have the resources.

blueblur22

Sorry, I thought I mentioned it. I am using the Mega1280. Forgot that bit.

I am working on support for the SD as well, but it is a long way away from being finished. My libraries does not stop you from using SD or flash in any way, so you still can use other libraries.

I am not sure if my modules even has flash on them  :-?

/Henning

blueblur22

"As of v2.0 there are NO support for the SD card-slot or Flash-memory."

Since you specificly mentioned there was no support for flash, I only assumed they all had it. What ever. I'm new to Arduino. I have experience for the Dragon board (RS232 chip set) and am basing everything off of that.

I don't know why I assumed I could only use one library  [smiley=embarassed.gif]

Go Up