Arduino - Tela LCD Touch Screen 2.4 8bit TFT01-2.4

De TuxTI

Introdução

Este é um módulo de tela LCD de 2.4" de 8bit, sua interface é de 40 pinos.

TFT01_2.4 is a TFT LCD Screen Module , 40pins interface , not just a LCD break but include the Touch , SD card and Flash design. So it’s a powerful extension module for your project.

  • Another useful extension in the TFT01 is the SD Card socket . It use the SPI mode to operate the SD card, the SPI interface include in the 40pins breakout.
  • There is a reserve extension design in the TFT01 , that’s the external flash . It’s leave the pad and the pins out for the SST25VF016B Flash. So when you need , you can easily add a external flash for your project .

The TFT01 layout a 40 pins interface for your project , the interface include LCD bus, SD card bus, Touch screen bus and the Flash bus.

TFT01-2.4-05.jpg

Feature

  • Extensive bus interface
  • Single chip solution for a liquid crystal QVGA TFT LCD display
  • 240RGBx320-dot resolution capable with real 262,144 display color
  • Support MVA (Multi-domain Vertical Alignment) wide view display
  • Internal oscillator and hardware reset
  • Partial drive function, enabling partially driving an LCD panel at positions specified by user
  • Power saving functions
    • 8-color mode
    • standby mode
    • sleep mode
  • Low -power consumption architecture
  • Size:530mm * 750mm

Idéias de Aplicação

  • Quadro de Fotos Digital
  • Terminais de Vídeo
  • Instrumentação
  • GPS
  • Vídeo Games
  • Vídeo Fone ou DVD Portátil

Cautions

  • TFT01 default use the 8bit mode , and if you need the 16 bit mode, you can tear the LCD screen down form the board , and move the R2 resistor to R1 to change the data mode. It’s a hard job , and easy to destroy the screen, so if you need a 16bit mode , you had better tell us before shipping , we will set the data mode for you.
  • When you use the 8bit mode , the DB8-DB15 is used ,please remember to pull the DB0-DB7 to GND.
  • The I/O of the Panel is 3.3v voltage , so you had better not to directly connect it to the 5v voltage I/O .We suggest using the 30K and 20K resistor to reduce voltage.

Esquema

TFT01-2.4-03.jpg

Specification

Pin definition and Rating

TFT01-2.4-04.jpg

The pins named with “D_” is the touch bus , the pins named with “SD_” is SD bus, the pins named with “F_” is Flash bus.

TFT01 is work at 3.3v DC, if you need to connect the module with the 5v voltage I/O , you need to add the 30k and 20k resistors to reduce voltage.

LCD TFT01 3.2 15.jpg

Mechanic Dimensions

TFT01-2.4-01.jpg

TFT01-2.4-02.jpg

Usage

Hardware Installation

Programming

Includes important code snippet.
All of the Demo used TFT01 Shield v1.0, that just support 8 bit mode, because of Arduino Limited IO, You could setting 10 PIN to CS the Touch or SD card function. Download the below code, and run on TFT01 Shield v1.0 . If you want use 16 bit mode and touch function, you could used TFT-01 Mega Shield v1.1, which for Mega1280 or Mega2560 and there are enough IO for Touch and SD card function .


  • Pant Screen

NewTFT4.3-01-LGR.jpg

New controller S6D1121 8 bit Touch Demo

Using TFT2.4 Shield V2.0

/*================================================================
This demo code shows how to use the touch screen in TFT01
The LCD connection is the same as that in “8 Bit Pant Demo“
 
by Elecfreaks
================================================================*/
 
#define LCD_RS   19         
#define LCD_WR   18     
#define LCD_CS   17       
#define LCD_REST 16

#define DCLK     15
#define DIN      14 
#define CS       8  
#define DOUT     9
//#define IRQ      8    
 
unsigned int TP_X,TP_Y;    
unsigned int TouchCount=0;
 int  pacy=0;
 
 
 
void spistar()                                     //SPI Start
{
  digitalWrite(CS,LOW);
  digitalWrite(DCLK,HIGH);
  digitalWrite(DIN,HIGH);
  digitalWrite(DCLK,HIGH);
 
}
//**********************************************************
void WriteCharTo7843(unsigned char num)          //SPI Write Data
{
  unsigned char count=0;
  unsigned char temp;
  unsigned nop;
  temp=num;
  digitalWrite(DCLK,LOW);
  for(count=0;count<8;count++)
  {
    if(temp&0x80)
      digitalWrite(DIN,HIGH);
    else
      digitalWrite(DIN,LOW);
 
    temp=temp<<1; 
 
    digitalWrite(DCLK,LOW);                
    nop++;
    nop++;
    digitalWrite(DCLK,HIGH);
    nop++;
    nop++;
  }
}
 
//**********************************************************
unsigned int ReadFromCharFrom7843()             //SPI Read Data
{ 
  unsigned nop;
  unsigned char count=0;
  unsigned int Num=0;
  for(count=0;count<12;count++)
  {
    Num<<=1;
    digitalWrite(DCLK,HIGH);//DCLK=1; _nop_();_nop_();_nop_();                
    nop++;
    digitalWrite(DCLK,LOW);//DCLK=0; _nop_();_nop_();_nop_();
    nop++;
    if(digitalRead(DOUT)) Num++;
  }
  return(Num);
}
 
 
 
void LCD_Writ_Bus(char VH,char VL)   
{   
  PORTD = VH;
  digitalWrite(LCD_WR,LOW);
  digitalWrite(LCD_WR,HIGH);
  PORTD = VL;
  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 Lcd_Write_Com_Data(int com,int val)		   //发送数据命令
{
    LCD_Write_COM(com>>8,com);
    LCD_Write_DATA(val>>8,val);
}
 
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
  LCD_Write_COM(0x00,0x46);LCD_Write_DATA(x2,x1);	  
  LCD_Write_COM(0x00,0x47);LCD_Write_DATA(y2>>8,y2);  
  LCD_Write_COM(0x00,0x48);LCD_Write_DATA(y1>>8,y1);
  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,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);  
        Lcd_Write_Com_Data(0x11,0x2004);		
        Lcd_Write_Com_Data(0x13,0xCC00);		
        Lcd_Write_Com_Data(0x15,0x2600);	
	Lcd_Write_Com_Data(0x14,0x252A);			
	Lcd_Write_Com_Data(0x12,0x0033);		
	Lcd_Write_Com_Data(0x13,0xCC04);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0xCC06);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0xCC4F);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0x674F);
	Lcd_Write_Com_Data(0x11,0x2003);
	delay(1); 	
	Lcd_Write_Com_Data(0x30,0x2609);		
	Lcd_Write_Com_Data(0x31,0x242C);		
	Lcd_Write_Com_Data(0x32,0x1F23);		
	Lcd_Write_Com_Data(0x33,0x2425);		
	Lcd_Write_Com_Data(0x34,0x2226);		
	Lcd_Write_Com_Data(0x35,0x2523);		
	Lcd_Write_Com_Data(0x36,0x1C1A);		
	Lcd_Write_Com_Data(0x37,0x131D);		
	Lcd_Write_Com_Data(0x38,0x0B11);		
	Lcd_Write_Com_Data(0x39,0x1210);		
	Lcd_Write_Com_Data(0x3A,0x1315);		
	Lcd_Write_Com_Data(0x3B,0x3619);		
	Lcd_Write_Com_Data(0x3C,0x0D00);		
	Lcd_Write_Com_Data(0x3D,0x000D);		
	Lcd_Write_Com_Data(0x16,0x0007);		
	Lcd_Write_Com_Data(0x02,0x0013);		
	Lcd_Write_Com_Data(0x03,0x0003);		
	Lcd_Write_Com_Data(0x01,0x0127);		
	delay(1); 
	Lcd_Write_Com_Data(0x08,0x0303);		
	Lcd_Write_Com_Data(0x0A,0x000B);		
	Lcd_Write_Com_Data(0x0B,0x0003);   
	Lcd_Write_Com_Data(0x0C,0x0000);   
	Lcd_Write_Com_Data(0x41,0x0000);    
	Lcd_Write_Com_Data(0x50,0x0000);   
	Lcd_Write_Com_Data(0x60,0x0005);    
        Lcd_Write_Com_Data(0x70,0x000B);    
	Lcd_Write_Com_Data(0x71,0x0000);    
	Lcd_Write_Com_Data(0x78,0x0000);    
	Lcd_Write_Com_Data(0x7A,0x0000);   
	Lcd_Write_Com_Data(0x79,0x0007);		
	Lcd_Write_Com_Data(0x07,0x0051);   
	delay(1); 	
	Lcd_Write_Com_Data(0x07,0x0053);		
	Lcd_Write_Com_Data(0x79,0x0000);
 
	LCD_Write_COM(0x00,0x22);
  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 AD7843(void)              
{
  digitalWrite(CS,LOW);                    
  WriteCharTo7843(0x90);        
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW); 
  TP_Y=ReadFromCharFrom7843();
  WriteCharTo7843(0xD0);      
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW);
  TP_X=ReadFromCharFrom7843();
  digitalWrite(CS,HIGH);
}
 
 
 
 
void setup()
{
 
  unsigned char p;
  int i,j,k;
  for(p=0;p<20;p++)
  {
    pinMode(p,OUTPUT);
  }
  pinMode(DOUT,INPUT);
//  pinMode(IRQ,INPUT);
 
  LCD_Init();  
  Pant(0x00,0x00);   
}
 
void loop()
{  TouchCount++; 
  unsigned char flag;
  unsigned char ss[6];	
  unsigned int lx,ly;
   spistar();  
  if(TouchCount==200)
  {
      pacy=random(0, 7);  
      TouchCount=0;
  }
 
//  while(digitalRead(IRQ)==0)
//  {  	
      digitalWrite(LCD_CS,LOW); 
      AD7843();
      lx=240-((TP_X-220)/16);
      ly=320-((TP_Y-400)/11);
      Address_set(lx,ly,lx+2,ly+2);
      switch(pacy)
                                {
                                  case 0: for(int i=0; i<5; i++)  LCD_Write_DATA(0xF8,0x00);  break;   //Red
                                  case 1: for(int i=0; i<5; i++)  LCD_Write_DATA(0xFF,0xE0);  break;   //Yellow
                                  case 2: for(int i=0; i<5; i++)  LCD_Write_DATA(0xFF,0xFF);  break;   //White 
                                  case 3: for(int i=0; i<5; i++)  LCD_Write_DATA(0x05,0x1F);  break;   //Blue
                                  case 4: for(int i=0; i<5; i++)  LCD_Write_DATA(0x00,0x1F);  break;   //Blue-2
                                  case 5: for(int i=0; i<5; i++)  LCD_Write_DATA(0xF8,0x1F);  break;   //Magenta
                                  case 6: for(int i=0; i<5; i++)  LCD_Write_DATA(0x07,0xE0);  break;   //Green
                                  case 7: for(int i=0; i<5; i++)  LCD_Write_DATA(0x7F,0xFF);  break;   //Cyan
                                  defoult:for(int i=0; i<5; i++)  LCD_Write_DATA(0x00,0x00);  break;   //Black
                                }
      digitalWrite(LCD_CS,HIGH); 
//    }
}




Using TFT2.4 Shield V1.4

/*================================================================
This demo code shows how to use the touch screen in TFT01
The LCD connection is the same as that in “8 Bit Pant Demo“
 
by Elecfreaks
================================================================*/
 
#define LCD_RS   19         
#define LCD_WR   18     
#define LCD_CS   17       
#define LCD_REST 16

#define DCLK     15
#define DIN      14 
#define CS       10  
#define DOUT     9
#define IRQ      8    

unsigned int TP_X,TP_Y;    
 
 
 
void spistar()                                     //SPI Start
{
  digitalWrite(CS,LOW);
  digitalWrite(DCLK,HIGH);
  digitalWrite(DIN,HIGH);
  digitalWrite(DCLK,HIGH);
 
}
//**********************************************************
void WriteCharTo7843(unsigned char num)          //SPI Write Data
{
  unsigned char count=0;
  unsigned char temp;
  unsigned nop;
  temp=num;
  digitalWrite(DCLK,LOW);
  for(count=0;count<8;count++)
  {
    if(temp&0x80)
      digitalWrite(DIN,HIGH);
    else
      digitalWrite(DIN,LOW);
 
    temp=temp<<1; 
 
    digitalWrite(DCLK,LOW);                
    nop++;
    nop++;
    digitalWrite(DCLK,HIGH);
    nop++;
    nop++;
  }
}
 
//**********************************************************
unsigned int ReadFromCharFrom7843()             //SPI Read Data
{ 
  unsigned nop;
  unsigned char count=0;
  unsigned int Num=0;
  for(count=0;count<12;count++)
  {
    Num<<=1;
    digitalWrite(DCLK,HIGH);//DCLK=1; _nop_();_nop_();_nop_();                
    nop++;
    digitalWrite(DCLK,LOW);//DCLK=0; _nop_();_nop_();_nop_();
    nop++;
    if(digitalRead(DOUT)) Num++;
  }
  return(Num);
}
 
 
 
void LCD_Writ_Bus(char VH,char VL)   
{   
  PORTD = VH;
  digitalWrite(LCD_WR,LOW);
  digitalWrite(LCD_WR,HIGH);
  PORTD = VL;
  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 Lcd_Write_Com_Data(int com,int val)		   //发送数据命令
{
    LCD_Write_COM(com>>8,com);
    LCD_Write_DATA(val>>8,val);
}
 
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
  LCD_Write_COM(0x00,0x46);LCD_Write_DATA(x2,x1);	  
  LCD_Write_COM(0x00,0x47);LCD_Write_DATA(y2>>8,y2);  
  LCD_Write_COM(0x00,0x48);LCD_Write_DATA(y1>>8,y1);
  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,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);  
        Lcd_Write_Com_Data(0x11,0x2004);		
        Lcd_Write_Com_Data(0x13,0xCC00);		
        Lcd_Write_Com_Data(0x15,0x2600);	
	Lcd_Write_Com_Data(0x14,0x252A);			
	Lcd_Write_Com_Data(0x12,0x0033);		
	Lcd_Write_Com_Data(0x13,0xCC04);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0xCC06);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0xCC4F);		
	delay(1); 
	Lcd_Write_Com_Data(0x13,0x674F);
	Lcd_Write_Com_Data(0x11,0x2003);
	delay(1); 	
	Lcd_Write_Com_Data(0x30,0x2609);		
	Lcd_Write_Com_Data(0x31,0x242C);		
	Lcd_Write_Com_Data(0x32,0x1F23);		
	Lcd_Write_Com_Data(0x33,0x2425);		
	Lcd_Write_Com_Data(0x34,0x2226);		
	Lcd_Write_Com_Data(0x35,0x2523);		
	Lcd_Write_Com_Data(0x36,0x1C1A);		
	Lcd_Write_Com_Data(0x37,0x131D);		
	Lcd_Write_Com_Data(0x38,0x0B11);		
	Lcd_Write_Com_Data(0x39,0x1210);		
	Lcd_Write_Com_Data(0x3A,0x1315);		
	Lcd_Write_Com_Data(0x3B,0x3619);		
	Lcd_Write_Com_Data(0x3C,0x0D00);		
	Lcd_Write_Com_Data(0x3D,0x000D);		
	Lcd_Write_Com_Data(0x16,0x0007);		
	Lcd_Write_Com_Data(0x02,0x0013);		
	Lcd_Write_Com_Data(0x03,0x0003);		
	Lcd_Write_Com_Data(0x01,0x0127);		
	delay(1); 
	Lcd_Write_Com_Data(0x08,0x0303);		
	Lcd_Write_Com_Data(0x0A,0x000B);		
	Lcd_Write_Com_Data(0x0B,0x0003);   
	Lcd_Write_Com_Data(0x0C,0x0000);   
	Lcd_Write_Com_Data(0x41,0x0000);    
	Lcd_Write_Com_Data(0x50,0x0000);   
	Lcd_Write_Com_Data(0x60,0x0005);    
        Lcd_Write_Com_Data(0x70,0x000B);    
	Lcd_Write_Com_Data(0x71,0x0000);    
	Lcd_Write_Com_Data(0x78,0x0000);    
	Lcd_Write_Com_Data(0x7A,0x0000);   
	Lcd_Write_Com_Data(0x79,0x0007);		
	Lcd_Write_Com_Data(0x07,0x0051);   
	delay(1); 	
	Lcd_Write_Com_Data(0x07,0x0053);		
	Lcd_Write_Com_Data(0x79,0x0000);
 
	LCD_Write_COM(0x00,0x22);
  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 AD7843(void)              
{
  digitalWrite(CS,HIGH);                    
  WriteCharTo7843(0x90);        
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW); 
  TP_Y=ReadFromCharFrom7843();
  WriteCharTo7843(0xD0);      
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW);
  TP_X=ReadFromCharFrom7843();
  digitalWrite(CS,LOW);
}
 
 
 
 
void setup()
{
 
  unsigned char p;
  int i,j,k;
  for(p=0;p<20;p++)
  {
    pinMode(p,OUTPUT);
  }
  pinMode(DOUT,INPUT);
  pinMode(IRQ,INPUT);
 
  LCD_Init();  
  Pant(0x00,0x00);   
}
 
void loop()
{
  unsigned char flag;
  unsigned char ss[6];	
  unsigned int lx,ly;
  spistar();  
  int pacy=random(0, 7);  
  while(digitalRead(IRQ)==0)
  {  	
      digitalWrite(LCD_CS,LOW); 
      AD7843();
      lx=240-((TP_X-220)/16);
      ly=320-((TP_Y-400)/11);
      Address_set(lx,ly,lx+2,ly+2);
      switch(pacy)
                                {
                                  case 0: for(int i=0; i<5; i++)  LCD_Write_DATA(0xF8,0x00);  break;   //Red
                                  case 1: for(int i=0; i<5; i++)  LCD_Write_DATA(0xFF,0xE0);  break;   //Yellow
                                  case 2: for(int i=0; i<5; i++)  LCD_Write_DATA(0xFF,0xFF);  break;   //White 
                                  case 3: for(int i=0; i<5; i++)  LCD_Write_DATA(0x05,0x1F);  break;   //Blue
                                  case 4: for(int i=0; i<5; i++)  LCD_Write_DATA(0x00,0x1F);  break;   //Blue-2
                                  case 5: for(int i=0; i<5; i++)  LCD_Write_DATA(0xF8,0x1F);  break;   //Magenta
                                  case 6: for(int i=0; i<5; i++)  LCD_Write_DATA(0x07,0xE0);  break;   //Green
                                  case 7: for(int i=0; i<5; i++)  LCD_Write_DATA(0x7F,0xFF);  break;   //Cyan
                                  defoult:for(int i=0; i<5; i++)  LCD_Write_DATA(0x00,0x00);  break;   //Black
                                }
      digitalWrite(LCD_CS,HIGH); 
    }
}


//////////////////////////////////////////////////////////////////////////////////////// /////// Old Controller Demo code ///////////// ////////////////////////////////////////////////////////////////////////////////////////

16 bit Pant Demo code

/*
 This example code is 16bit mode for TFT01 demo.
 
Connect the pins to Arduino first :
DB0-DB16 to pin D0-D13 , pin A0-A1 of Arduino
RESET to A2
CS to A3
WR to A4
RS to A5
 
All the data pins of Arduino is used ….So , we just can connect the RD to 3.3V.
We don’t used it because we don’t need to read back the data from the screen.
Connect the power pins : LCD-A to 3.3V , VCC to 5V , GND to GND
 
Note that the LCD is use the 3.3V voltage level , so if you want to connect the 5V Arduino pins to it , 
you need add a resister about 20K to reduce voltage. We use the 3.3V Arduino Pro which work in 8M , 
so we connect the pins directly — this is why we used 16 bit mode, 8 bit mode is too slow to refresh the screen.
 
*/
 
#define Bus_16   
#define LCD_RS   19         
#define LCD_WR   18     
#define LCD_CS   17       
#define LCD_REST 16

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;
  }	 
  data=VL; 
  for(i=8;i<16;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 Lcd_Write_Com_Data(int com,int dat)
{
     Lcd_Write_Com(com>>8,com);
     Lcd_Write_Data(dat>>8,dat);
}
 
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);	  //setting X
      Lcd_Write_Com(0x00,0x21);
      Lcd_Write_Data(y1>>8,y1);   //setting Y
      Lcd_Write_Com(0x00,0x50);
      Lcd_Write_Data(x1>>8,x1);   //starting X
      Lcd_Write_Com(0x00,0x52);
      Lcd_Write_Data(y1>>8,y1);	  //starting Y
      Lcd_Write_Com(0x00,0x51);
      Lcd_Write_Data(x2>>8,x2);   //ending X
      Lcd_Write_Com(0x00,0x53);
      Lcd_Write_Data(y2>>8,y2);   //ending Y
      Lcd_Write_Com(0x00,0x22);							 
}
 
void Lcd_Init(void)
{
       digitalWrite(LCD_REST,HIGH);
       delay(5); 
       digitalWrite(LCD_REST,LOW);
       delay(15);
       digitalWrite(LCD_REST,HIGH);
       delay(15);
 
        digitalWrite(LCD_CS,LOW);
        Lcd_Write_Com_Data(0x0001, 0x0100); // set SS and SM bit
	Lcd_Write_Com_Data(0x0002, 0x0200); // set 1 line inversion
	Lcd_Write_Com_Data(0x0003, 0x1030); // set GRAM write direction and BGR=1.
	Lcd_Write_Com_Data(0x0004, 0x0000); // Resize register
	Lcd_Write_Com_Data(0x0008, 0x0207); // set the back porch and front porch
	Lcd_Write_Com_Data(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0]
	Lcd_Write_Com_Data(0x000A, 0x0000); // FMARK function
	Lcd_Write_Com_Data(0x000C, 0x0000); // RGB interface setting
	Lcd_Write_Com_Data(0x000D, 0x0000); // Frame marker Position
	Lcd_Write_Com_Data(0x000F, 0x0000); // RGB interface polarity
	//*************Power On sequence ****************//
	Lcd_Write_Com_Data(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
	Lcd_Write_Com_Data(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
	Lcd_Write_Com_Data(0x0012, 0x0000); // VREG1OUT voltage
	Lcd_Write_Com_Data(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
	Lcd_Write_Com_Data(0x0007, 0x0001);
	delay(200); // Dis-charge capacitor power voltage
	Lcd_Write_Com_Data(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB
	Lcd_Write_Com_Data(0x0011, 0x0227); // Set DC1[2:0], DC0[2:0], VC[2:0]
	delay(50); // Delay 50ms
	Lcd_Write_Com_Data(0x0012, 0x000D); // 0012
	delay(50); // Delay 50ms
	Lcd_Write_Com_Data(0x0013, 0x1200); // VDV[4:0] for VCOM amplitude
	Lcd_Write_Com_Data(0x0029, 0x000A); // 04  VCM[5:0] for VCOMH
	Lcd_Write_Com_Data(0x002B, 0x000D); // Set Frame Rate
	delay(50); // Delay 50ms
	Lcd_Write_Com_Data(0x0020, 0x0000); // GRAM horizontal Address
	Lcd_Write_Com_Data(0x0021, 0x0000); // GRAM Vertical Address
	// ----------- Adjust the Gamma Curve ----------//
	Lcd_Write_Com_Data(0x0030, 0x0000);
	Lcd_Write_Com_Data(0x0031, 0x0404);
	Lcd_Write_Com_Data(0x0032, 0x0003);
	Lcd_Write_Com_Data(0x0035, 0x0405);
	Lcd_Write_Com_Data(0x0036, 0x0808);
	Lcd_Write_Com_Data(0x0037, 0x0407);
	Lcd_Write_Com_Data(0x0038, 0x0303);
	Lcd_Write_Com_Data(0x0039, 0x0707);
	Lcd_Write_Com_Data(0x003C, 0x0504);
	Lcd_Write_Com_Data(0x003D, 0x0808);
	//------------------ Set GRAM area ---------------//
	Lcd_Write_Com_Data(0x0050, 0x0000); // Horizontal GRAM Start Address
	Lcd_Write_Com_Data(0x0051, 0x00EF); // Horizontal GRAM End Address
	Lcd_Write_Com_Data(0x0052, 0x0000); // Vertical GRAM Start Address
	Lcd_Write_Com_Data(0x0053, 0x013F); // Vertical GRAM Start Address
	Lcd_Write_Com_Data(0x0060, 0xA700); // Gate Scan Line
	Lcd_Write_Com_Data(0x0061, 0x0001); // NDL,VLE, REV
 
	Lcd_Write_Com_Data(0x006A, 0x0000); // set scrolling line
	//-------------- Partial Display Control ---------//
	Lcd_Write_Com_Data(0x0080, 0x0000);
	Lcd_Write_Com_Data(0x0081, 0x0000);
	Lcd_Write_Com_Data(0x0082, 0x0000);
	Lcd_Write_Com_Data(0x0083, 0x0000);
	Lcd_Write_Com_Data(0x0084, 0x0000);
	Lcd_Write_Com_Data(0x0085, 0x0000);
	//-------------- Panel Control -------------------//
	Lcd_Write_Com_Data(0x0090, 0x0010);
	Lcd_Write_Com_Data(0x0092, 0x0000);
	Lcd_Write_Com_Data(0x0007, 0x0133); // 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()
{
  for(int p=0;p<20;p++)
  {
    pinMode(p,OUTPUT);
  }
  Lcd_Init();          
}
 
void loop()
{
   Pant(0x0, 0x0);
   delay(500);
   Pant(0xff, 0x00);
   delay(500);
   Pant(0x00, 0xff);
   delay(500);
   Pant(0xff, 0xff);
   delay(500);
}

8 bit Touch Demo

/*================================================================
This demo code shows how to use the touch screen in TFT01
The LCD connection is the same as that in “8 Bit Pant Demo“
 
by Elecfreaks
================================================================*/
 
#define LCD_RS   19         
#define LCD_WR   18     
#define LCD_CS   17       
#define LCD_REST 16

#define DCLK     15
#define DIN      14 
#define CS       10  
#define DOUT     9
#define IRQ      8    

unsigned int TP_X,TP_Y;    
 
 
 
void spistar()                                     //SPI Start
{
  digitalWrite(CS,LOW);
  digitalWrite(DCLK,HIGH);
  digitalWrite(DIN,HIGH);
  digitalWrite(DCLK,HIGH);
 
}
//**********************************************************
void WriteCharTo7843(unsigned char num)          //SPI Write Data
{
  unsigned char count=0;
  unsigned char temp;
  unsigned nop;
  temp=num;
  digitalWrite(DCLK,LOW);
  for(count=0;count<8;count++)
  {
    if(temp&0x80)
      digitalWrite(DIN,HIGH);
    else
      digitalWrite(DIN,LOW);
 
    temp=temp<<1; 
 
    digitalWrite(DCLK,LOW);                
    nop++;
    nop++;
    digitalWrite(DCLK,HIGH);
    nop++;
    nop++;
  }
}
 
//**********************************************************
unsigned int ReadFromCharFrom7843()             //SPI Read Data
{ 
  unsigned nop;
  unsigned char count=0;
  unsigned int Num=0;
  for(count=0;count<12;count++)
  {
    Num<<=1;
    digitalWrite(DCLK,HIGH);//DCLK=1; _nop_();_nop_();_nop_();                
    nop++;
    digitalWrite(DCLK,LOW);//DCLK=0; _nop_();_nop_();_nop_();
    nop++;
    if(digitalRead(DOUT)) Num++;
  }
  return(Num);
}
 
 
 
void LCD_Writ_Bus(char VH,char VL)   
{   
  PORTD = VH;
  digitalWrite(LCD_WR,LOW);
  digitalWrite(LCD_WR,HIGH);
  PORTD = VL;
 
  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 AD7843(void)              
{
  digitalWrite(CS,HIGH);                    
  WriteCharTo7843(0x90);        
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW); 
  TP_Y=ReadFromCharFrom7843();
  WriteCharTo7843(0xD0);      
  digitalWrite(DCLK,HIGH);
  digitalWrite(DCLK,LOW);
  TP_X=ReadFromCharFrom7843();
  digitalWrite(CS,LOW);
}
 
 
 
 
void setup()
{
 
  unsigned char p;
  int i,j,k;
  for(p=0;p<20;p++)
  {
    pinMode(p,OUTPUT);
  }
  pinMode(DOUT,INPUT);
  pinMode(IRQ,INPUT);
 
  LCD_Init();  
  Pant(0xff,0xff);   
}
 
void loop()
{
  unsigned char flag;
  unsigned char ss[6];	
  unsigned int lx,ly;
  spistar();  
  int pacy=random(0, 7);  
  while(digitalRead(IRQ)==0)
  {  	
      digitalWrite(LCD_CS,LOW); 
      AD7843();
      lx=240-((TP_X-220)/16);
      ly=320-((TP_Y-400)/11);
      Address_set(lx,ly,lx+2,ly+2);
      switch(pacy)
                                {
                                  case 0: for(int i=0; i<5; i++)  LCD_Write_DATA(0xF8,0x00);  break;   //Red
                                  case 1: for(int i=0; i<5; i++)  LCD_Write_DATA(0xFF,0xE0);  break;   //Yellow
                                  case 2: for(int i=0; i<5; i++)  LCD_Write_DATA(0xFF,0xFF);  break;   //White 
                                  case 3: for(int i=0; i<5; i++)  LCD_Write_DATA(0x05,0x1F);  break;   //Blue
                                  case 4: for(int i=0; i<5; i++)  LCD_Write_DATA(0x00,0x1F);  break;   //Blue-2
                                  case 5: for(int i=0; i<5; i++)  LCD_Write_DATA(0xF8,0x1F);  break;   //Magenta
                                  case 6: for(int i=0; i<5; i++)  LCD_Write_DATA(0x07,0xE0);  break;   //Green
                                  case 7: for(int i=0; i<5; i++)  LCD_Write_DATA(0x7F,0xFF);  break;   //Cyan
                                  defoult:for(int i=0; i<5; i++)  LCD_Write_DATA(0x00,0x00);  break;   //Black
                                }
      digitalWrite(LCD_CS,HIGH); 
    } 
}


Arquivos Úteis