Example code for 5.0" TFT - SSD1963 controller.
//---------------------------------------------------------
/*
Program snippet for writing to Newhaven Display 5.0" TFT
(c)2012 Newhaven Display International, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//---------------------------------------------------------
/*-------------------------------------------------------*/
/*------------------5.0-800480---------------------------*/
void TFT_delay(int time)
{
int i,j;
for(i=0;i<(time^1000);i++){
for(j=0;j<(time^1000);j++){;}}
}
int TFT_5_demo(void)
{
char filename[18] = "5_0_800480TF_";
char filetype[4] = ".bmp";
char filenumber[1] = "0";
int i,n,result;
char image = 0x30;
BYTE Buff[48*1024] __attribute__ ((aligned (4))) ; /* Working buffer */
UINT blen = sizeof(Buff);
memset(Buff,3,sizeof(Buff));
TFT_5_Init();
filename[13]='\0';
filenumber[0] = image;
strncat(filename,filenumber,1);
strncat(filename,filetype,4);
while(1){
UILCD_SetCursor(0,0);UILCD_DisplayString("Reading SD Card ");UILCD_SetCursor(1,0);UILCD_DisplayString(" ");
UILCD_SetCursor(1,0);UILCD_DisplayString(filename);
if(openSD(filename)==0x30)
{while(1);}
seekSD(108);
TFT_5_WindowSet(0x0000,0x031f,0x0000,0x01df);
TFT_5_Write_Command(0x2c);
GPIO_SetBits(GPIOC, RS);
for(n=0;n<54;n++){GPIO_SetBits(GPIOC, nWR);GPIO_Write(GPIOB,0x00);GPIO_ResetBits(GPIOC, nWR);}
for(n=0;n<480;n++){ //read from file 32 times, 36,000 bytes each time
f_read(&File1, Buff, 2400, &blen); // read line of pixels
for(i=0;i<2400;i++){
GPIO_SetBits(GPIOC, nWR);
GPIO_Write(GPIOB, Buff[i]);
GPIO_ResetBits(GPIOC, nWR);
}
}
result = f_close(&File1); // close file
if (result != FR_OK) {
UILCD_SetCursor(0,0);UILCD_DisplayString("File not Closed ");while(1);
return result;}
UILCD_SetCursor(0,0);UILCD_DisplayString("Press UP button ");UILCD_SetCursor(1,0);UILCD_DisplayString("for next file. ");
while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)!=0){;}
image++;
if(image==0x3A){image=0x41;}
filename[13]='\0';
filenumber[0] = image;
strncat(filename,filenumber,1);
strncat(filename,filetype,4);
if(openSD(filename)==0x30)
{image=0x30;}
filename[13]='\0';
filenumber[0] = image;
strncat(filename,filenumber,1);
strncat(filename,filetype,4);
}
return 1;
}
void TFT_5_Init(void)
{
GPIO_ResetBits(GPIOC, CS1);
GPIO_SetBits(GPIOC, DISP);
GPIO_SetBits(GPIOC, nRD);
GPIO_ResetBits(GPIOC, nWR);
GPIO_WriteBit(GPIOC, RES, Bit_RESET);
delay(5);
TFT_delay(10);
GPIO_WriteBit(GPIOC, RES, Bit_SET);
delay(100);
TFT_delay(10);
TFT_5_Write_Command(0x01); //Software Reset
delay(10);
TFT_delay(10);
TFT_5_Write_Command(0x01); //Software Reset
delay(10);
TFT_delay(10);
TFT_5_Command_Write(0xe0,0x01); //START PLL
TFT_5_Command_Write(0xe0,0x03); //LOCK PLL
TFT_5_Write_Command(0xb0); //SET LCD MODE (7 parameters)
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x08); //18-bit, TFT FRC enable, dithering off
TFT_5_Write_Data(0x80); //LCD panel mode
TFT_5_Write_Data(0x03); //SET horizontal size=800-1 HightByte
TFT_5_Write_Data(0x1f); //SET horizontal size=800-1 LowByte
TFT_5_Write_Data(0x01); //SET vertical size=480-1 HightByte
TFT_5_Write_Data(0xdf); //SET vertical size=480-1 LowByte
TFT_5_Write_Data(0x00); //SET even/odd line RGB seq.=RGB
TFT_5_Command_Write(0xf0,0x00); //SET pixel data I/F format=8bit
TFT_5_Command_Write(0x36,0x09); //SET address mode=flip vertical
TFT_5_Command_Write(0x3a,0x60); // SET R G B format = 6 6 6
TFT_5_Write_Command(0xe2); //SET PCLK freq=9.5MHz ; pixel clock frequency
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x1d);
TFT_5_Write_Data(0x02);
TFT_5_Write_Data(0x54);
TFT_5_Write_Command(0xe6); //SET PCLK freq=9.5MHz ; pixel clock frequency
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x02);
TFT_5_Write_Data(0xff);
TFT_5_Write_Data(0xff);
TFT_5_Write_Command(0xb4); //SET Horizontal Period (8 parameters)
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x04); //SET HSYNC Total=1056
TFT_5_Write_Data(0x20);
TFT_5_Write_Data(0x00); //SET HSYNC Start Position=88
TFT_5_Write_Data(0x58);
TFT_5_Write_Data(0x80); //SET HSYNC Pulse Width=128=127pixels+1
TFT_5_Write_Data(0x00); //SET HSYNC pulse start position=0
TFT_5_Write_Data(0x00);
TFT_5_Write_Data(0x00); //SET HSYNC pulse subpixel start position
TFT_5_Write_Command(0xb6); //SET Vertical Period (7 parameters),
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x02); //SET Vsync total=525
TFT_5_Write_Data(0x0d);
TFT_5_Write_Data(0x00); //SET VSYNC Pulse Start Position=32
TFT_5_Write_Data(0x20);
TFT_5_Write_Data(0x01); //SET VSYNC Pulse Width= 0=0lines+1
TFT_5_Write_Data(0x00); //SET VSYNC Pulse Start Position=0
TFT_5_Write_Data(0x00);
TFT_5_Write_Command(0x2a); //SET column address
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x00); //SET start column address=0
TFT_5_Write_Data(0x00);
TFT_5_Write_Data(0x03); //SET end column address=799
TFT_5_Write_Data(0x1f);
TFT_5_Write_Command(0x2b); //SET page address
GPIO_SetBits(GPIOC, RS);
TFT_5_Write_Data(0x00); //SET start page address=0
TFT_5_Write_Data(0x00);
TFT_5_Write_Data(0x01); //SET end page address=479
TFT_5_Write_Data(0xdf);
TFT_5_Write_Command(0x13); //SET normal mode
TFT_5_Write_Command(0x38); //SET normal mode
TFT_5_Write_Command(0x29); //SET display on
}
void TFT_5_Write_Command(unsigned char command)
{
GPIO_Write(GPIOB, command);
GPIO_ResetBits(GPIOC, RS);
GPIO_ResetBits(GPIOC, nWR);
GPIO_SetBits(GPIOC, nWR);
TFT_delay(10);
}
void TFT_5_Write_Data(unsigned char data1)
{
GPIO_SetBits(GPIOC, RS);
GPIO_Write(GPIOB, data1);
GPIO_ResetBits(GPIOC, nWR);
GPIO_SetBits(GPIOC, nWR);
TFT_delay(10);
}
void TFT_5_Command_Write(unsigned char REG,unsigned char VALUE)
{
TFT_5_Write_Command(REG);
TFT_5_Write_Data(VALUE);
}
void TFT_5_SendData(unsigned long color)
{
GPIO_SetBits(GPIOC, RS);
GPIO_Write(GPIOB, (color>>16));
GPIO_ResetBits(GPIOC, nWR);
GPIO_SetBits(GPIOC, nWR);
GPIO_Write(GPIOB, (color>>8));
GPIO_ResetBits(GPIOC, nWR);
GPIO_SetBits(GPIOC, nWR);
GPIO_Write(GPIOB, (color));
GPIO_ResetBits(GPIOC, nWR);
GPIO_SetBits(GPIOC, nWR);
}
void TFT_5_WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y)
{
TFT_5_Write_Command(0x2a); //SET page address
TFT_5_Write_Data((s_x)>>8); //SET start page address
TFT_5_Write_Data(s_x);
TFT_5_Write_Data((e_x)>>8); //SET end page address
TFT_5_Write_Data(e_x);
TFT_5_Write_Command(0x2b); //SET column address
TFT_5_Write_Data((s_y)>>8); //SET start column address
TFT_5_Write_Data(s_y);
TFT_5_Write_Data((e_y)>>8); //SET end column address
TFT_5_Write_Data(e_y);
}