Difference between revisions of "Arduino LCDs"

From ElectroDragon
Jump to: navigation, search
(Created page with "== Shield For Arduino UNO == * Schematic 1.4 * Schematic 2.0 * :File:TFT2.4-Shield-v2.zip|V2...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Shield For Arduino UNO ==
 
* [[:File:TFT01_shield_uno-schematic-1.4.pdf|Schematic 1.4]]
 
* [[:File:Schematic-2.4-v2-uno.pdf|Schematic 2.0]]
 
* [[:File:TFT2.4-Shield-v2.zip|V2 Testing Demo Code]], with a little modification, CS pin is connected to the GND.
 
=== Touch Function Demo Code ===
 
* Allow you draw things on screen
 
<syntaxhighlight lang="Arduino">
 
#define LCD_RS  19      // A5 
 
#define LCD_WR  18      // A4
 
#define LCD_CS  17      // A3
 
#define LCD_REST 16      // A2
 
  
#define DCLK    15      // A1
 
#define DIN      14      // A0
 
#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);
 
//    }
 
}
 
 
</syntaxhighlight>
 
== Shield For Arduino Mega ==
 
=== Touch Function Demo Code for LCD 3'2''===
 
<syntaxhighlight lang="Arduino">
 
#define LCD_RS  38       
 
#define LCD_WR  39   
 
#define LCD_CS  40     
 
#define LCD_REST 41
 
 
#define DCLK    6
 
#define CS      5 
 
#define DIN      4
 
#define DOUT    3
 
#define IRQ      2
 
 
unsigned int TP_X,TP_Y;
 
void spistar()                                    //SPI Start
 
{
 
  digitalWrite(CS,HIGH);
 
  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 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 Lcd_Writ_Bus(char VH,char VL)
 
{
 
  PORTA = VH;
 
  PORTC = 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 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_Data(0x0044,(x2<<8)+x1);
 
      Lcd_Write_Com_Data(0x0045,y1);
 
      Lcd_Write_Com_Data(0x0046,y2);
 
      Lcd_Write_Com_Data(0x004e,x1);
 
      Lcd_Write_Com_Data(0x004f,y1);
 
      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);
 
 
    Lcd_Write_Com_Data(0x0000,0x0001);    delay(1);  //打开晶振
 
    Lcd_Write_Com_Data(0x0003,0xA8A4);    delay(1);  //0xA8A4
 
    Lcd_Write_Com_Data(0x000C,0x0000);    delay(1); 
 
    Lcd_Write_Com_Data(0x000D,0x080C);    delay(1); 
 
    Lcd_Write_Com_Data(0x000E,0x2B00);    delay(1); 
 
    Lcd_Write_Com_Data(0x001E,0x00B7);    delay(1); 
 
    Lcd_Write_Com_Data(0x0001,0x2B3F);    delay(1);  //驱动输出控制320*240  0x6B3F
 
    Lcd_Write_Com_Data(0x0002,0x0600);    delay(1);
 
    Lcd_Write_Com_Data(0x0010,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0011,0x6070);    delay(1);        //0x4030          //定义数据格式  16位色
 
    Lcd_Write_Com_Data(0x0005,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0006,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0016,0xEF1C);    delay(1);
 
    Lcd_Write_Com_Data(0x0017,0x0003);    delay(1);
 
    Lcd_Write_Com_Data(0x0007,0x0233);    delay(1);        //0x0233     
 
    Lcd_Write_Com_Data(0x000B,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x000F,0x0000);    delay(1);        //扫描开始地址
 
    Lcd_Write_Com_Data(0x0041,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0042,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0048,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0049,0x013F);    delay(1);
 
    Lcd_Write_Com_Data(0x004A,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x004B,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0044,0xEF00);    delay(1);
 
    Lcd_Write_Com_Data(0x0045,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0046,0x013F);    delay(1);
 
    Lcd_Write_Com_Data(0x0030,0x0707);    delay(1);
 
    Lcd_Write_Com_Data(0x0031,0x0204);    delay(1);
 
    Lcd_Write_Com_Data(0x0032,0x0204);    delay(1);
 
    Lcd_Write_Com_Data(0x0033,0x0502);    delay(1);
 
    Lcd_Write_Com_Data(0x0034,0x0507);    delay(1);
 
    Lcd_Write_Com_Data(0x0035,0x0204);    delay(1);
 
    Lcd_Write_Com_Data(0x0036,0x0204);    delay(1);
 
    Lcd_Write_Com_Data(0x0037,0x0502);    delay(1);
 
    Lcd_Write_Com_Data(0x003A,0x0302);    delay(1);
 
    Lcd_Write_Com_Data(0x003B,0x0302);    delay(1);
 
    Lcd_Write_Com_Data(0x0023,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0024,0x0000);    delay(1);
 
    Lcd_Write_Com_Data(0x0025,0x8000);    delay(1);
 
    Lcd_Write_Com_Data(0x004f,0);        //行首址0
 
    Lcd_Write_Com_Data(0x004e,0);        //列首址0
 
    Lcd_Write_Com(0x00,0x22);
 
 
}
 
 
void Pant(char VH,char VL)
 
{
 
  int i,j;
 
  digitalWrite(LCD_CS,LOW);
 
  Address_set(0,0,239,319);
 
  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=22;p<42;p++)
 
  {
 
    pinMode(p,OUTPUT);
 
  }
 
  for(int p=2; p<7;p++)
 
      pinMode(p,OUTPUT);
 
  pinMode(DOUT,INPUT);
 
  pinMode(IRQ,INPUT);
 
 
  Lcd_Init();       
 
  Pant(0x00, 0x00);
 
  delay(500);
 
}
 
 
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=((TP_X-340)*10/144);
 
      if(lx>237) lx=237;
 
      ly=320-((TP_Y-320)/11);
 
      if(ly<0) ly=0;
 
      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);
 
    }
 
}
 
</syntaxhighlight>
 
=== Touch Function demo code for LCD 3.2''-W (400*240) ===
 
<syntaxhighlight lang="Arduino">
 
/*
 
This example code is 16bit mode for TFT01 demo.
 
 
The demo used TFT01 Mega Shield and connect the pins to Arduino first :
 
DB0-DB16 to pin 22-29, 30-37
 
 
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 if you haven't TFT01 Mega Shield,the LCM 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 LCD_RS  38       
 
#define LCD_WR  39   
 
#define LCD_CS  40     
 
#define LCD_REST 41
 
 
#define DCLK    6
 
#define CS      5 
 
#define DIN      4
 
#define DOUT    3
 
#define IRQ      2
 
 
 
unsigned int TP_X,TP_Y;
 
void spistar()                                    //SPI Start
 
{
 
  digitalWrite(CS,HIGH);
 
  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 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 Lcd_Writ_Bus(char VH,char VL)
 
{
 
  PORTA = VH;
 
  PORTC = 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 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_Data(0x0003,x1);
 
Lcd_Write_Com_Data(0x0006,y1>>8);
 
Lcd_Write_Com_Data(0x0007,y1);
 
Lcd_Write_Com_Data(0x0005,x2);
 
Lcd_Write_Com_Data(0x0008,y2>>8);
 
        Lcd_Write_Com_Data(0x0009,y2);
 
        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(0x00,0x83);         
 
        Lcd_Write_Data(0x00,0x02);  //TESTM=1
 
 
        Lcd_Write_Com(0x00,0x85); 
 
        Lcd_Write_Data(0x00,0x03);  //VDC_SEL=011
 
        Lcd_Write_Com(0x00,0x8B); 
 
        Lcd_Write_Data(0x00,0x01);
 
        Lcd_Write_Com(0x00,0x8C); 
 
        Lcd_Write_Data(0x00,0x93); //STBA[7]=1,STBA[5:4]=01,STBA[1:0]=11
 
 
        Lcd_Write_Com(0x00,0x91); 
 
        Lcd_Write_Data(0x00,0x01); //DCDC_SYNC=1
 
 
        Lcd_Write_Com(0x00,0x83); 
 
        Lcd_Write_Data(0x00,0x00); //TESTM=0
 
        //Gamma Setting
 
 
        Lcd_Write_Com(0x00,0x3E); 
 
        Lcd_Write_Data(0x00,0xB0);
 
        Lcd_Write_Com(0x00,0x3F); 
 
        Lcd_Write_Data(0x00,0x03);
 
        Lcd_Write_Com(0x00,0x40); 
 
        Lcd_Write_Data(0x00,0x10);
 
        Lcd_Write_Com(0x00,0x41); 
 
        Lcd_Write_Data(0x00,0x56);
 
        Lcd_Write_Com(0x00,0x42); 
 
        Lcd_Write_Data(0x00,0x13);
 
        Lcd_Write_Com(0x00,0x43); 
 
        Lcd_Write_Data(0x00,0x46);
 
        Lcd_Write_Com(0x00,0x44); 
 
        Lcd_Write_Data(0x00,0x23);
 
        Lcd_Write_Com(0x00,0x45); 
 
        Lcd_Write_Data(0x00,0x76);
 
        Lcd_Write_Com(0x00,0x46); 
 
        Lcd_Write_Data(0x00,0x00);
 
        Lcd_Write_Com(0x00,0x47); 
 
        Lcd_Write_Data(0x00,0x5E);
 
        Lcd_Write_Com(0x00,0x48); 
 
        Lcd_Write_Data(0x00,0x4F);
 
        Lcd_Write_Com(0x00,0x49); 
 
        Lcd_Write_Data(0x00,0x40);
 
//**********Power On sequence************
 
 
        Lcd_Write_Com(0x00,0x17); 
 
        Lcd_Write_Data(0x00,0x91);
 
 
        Lcd_Write_Com(0x00,0x2B); 
 
        Lcd_Write_Data(0x00,0xF9);
 
        delay(10);
 
 
        Lcd_Write_Com(0x00,0x1B); 
 
        Lcd_Write_Data(0x00,0x14);
 
 
        Lcd_Write_Com(0x00,0x1A); 
 
        Lcd_Write_Data(0x00,0x11);
 
 
        Lcd_Write_Com(0x00,0x1C); 
 
        Lcd_Write_Data(0x00,0x06);   //0d
 
 
        Lcd_Write_Com(0x00,0x1F); 
 
        Lcd_Write_Data(0x00,0x42);
 
        delay(20);
 
 
        Lcd_Write_Com(0x00,0x19); 
 
        Lcd_Write_Data(0x00,0x0A);
 
 
        Lcd_Write_Com(0x00,0x19); 
 
        Lcd_Write_Data(0x00,0x1A);
 
        delay(40);
 
 
 
        Lcd_Write_Com(0x00,0x19); 
 
        Lcd_Write_Data(0x00,0x12);
 
        delay(40);
 
 
        Lcd_Write_Com(0x00,0x1E); 
 
        Lcd_Write_Data(0x00,0x27);
 
        delay(100);  
 
 
 
      //**********DISPLAY ON SETTING***********
 
 
        Lcd_Write_Com(0x00,0x24); 
 
        Lcd_Write_Data(0x00,0x60);
 
 
        Lcd_Write_Com(0x00,0x3D); 
 
        Lcd_Write_Data(0x00,0x40);
 
 
        Lcd_Write_Com(0x00,0x34); 
 
        Lcd_Write_Data(0x00,0x38);
 
 
        Lcd_Write_Com(0x00,0x35); 
 
        Lcd_Write_Data(0x00,0x38);
 
 
        Lcd_Write_Com(0x00,0x24); 
 
        Lcd_Write_Data(0x00,0x38);
 
      delay(40);
 
 
        Lcd_Write_Com(0x00,0x24); 
 
        Lcd_Write_Data(0x00,0x3C);
 
 
        Lcd_Write_Com(0x00,0x16); 
 
        Lcd_Write_Data(0x00,0x1C);
 
 
        Lcd_Write_Com(0x00,0x01); 
 
        Lcd_Write_Data(0x00,0x06);
 
 
        Lcd_Write_Com(0x00,0x55); 
 
        Lcd_Write_Data(0x00,0x00);
 
 
        Lcd_Write_Com(0x00,0x02);         
 
        Lcd_Write_Data(0x00,0x00);
 
        Lcd_Write_Com(0x00,0x03);         
 
        Lcd_Write_Data(0x00,0x00);
 
          Lcd_Write_Com(0x00,0x04);         
 
        Lcd_Write_Data(0x00,0x00);
 
        Lcd_Write_Com(0x00,0x05);         
 
        Lcd_Write_Data(0x00,0xef);
 
 
        Lcd_Write_Com(0x00,0x06);         
 
        Lcd_Write_Data(0x00,0x00);
 
        Lcd_Write_Com(0x00,0x07);         
 
        Lcd_Write_Data(0x00,0x00);
 
        Lcd_Write_Com(0x00,0x08);         
 
        Lcd_Write_Data(0x00,0x01);
 
        Lcd_Write_Com(0x00,0x09);         
 
        Lcd_Write_Data(0x00,0x8f);
 
 
        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,239,399);
 
  for(i=0;i<400;i++)
 
  {
 
    for (j=0;j<240;j++)
 
    {
 
      Lcd_Write_Data(VH,VL);
 
    }
 
 
  }
 
  digitalWrite(LCD_CS,HIGH); 
 
}
 
 
void setup()
 
{
 
  for(int p=22;p<42;p++)
 
  {
 
    pinMode(p,OUTPUT);
 
  }
 
  for(int p=2; p<7;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=(TP_X- 310)/14;
 
      ly=(TP_Y- 150)/9;
 
      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);
 
}
 
</syntaxhighlight>
 
 
=== Documents ===
 
=== Documents ===
* [[:File:TFT01_Mega_shield_V1.4.pdf|Schematic 1.4]]
+
* [[:File:Schematic-2.4-v2-uno.pdf|Schematic 2.0 UNO Shield]]
* [[:File:TFT_MEGA_V2.0.pdf|Schematic 2.0]]
+
* [[:File:TFT_MEGA_V2.0.pdf|Schematic 2.0 Mega Shield]]
 +
* [https://github.com/Edragon/Arduino/tree/master/Sketchbook/08-LCD Demo code please see at page here.]
 
* [http://www.youtube.com/embed/7wr8uLYX0T0 Demo Video Available here.]
 
* [http://www.youtube.com/embed/7wr8uLYX0T0 Demo Video Available here.]
  
 +
== Old ==
 +
* [[:File:TFT01_shield_uno-schematic-1.4.pdf|Schematic 1.4 UNO Shield]]
 +
* [[:File:TFT01_Mega_shield_V1.4.pdf|Schematic 1.4 mega shield]]
 
[[category: Arduino Shields]]
 
[[category: Arduino Shields]]

Latest revision as of 00:25, 9 March 2018

Documents

Old