/*-------------------------------------------------------*/ /*------------------5.7-640480---------------------------*/ int TFT_57F_demo(void) { char filename[18] = "5_7_640480WF_"; 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_57F_Init(); TFT_57F_WindowSet(0x0000,0x027f,0x0000,0x01df); TFT_57F_Write_Command(0x2c); filename[13]='\0'; filenumber[0] = image; strncat(filename,filenumber,1); strncat(filename,filetype,4); while(1){ TFT_57F_Init(); 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_57F_WindowSet(0x0000,0x027f,0x0000,0x01df); TFT_57F_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<128;n++){ //read from file 128 times, 7200 bytes each time f_read(&File1, Buff, 7200, &blen); // read line of pixels for(i=0;i<7200;i++){ GPIO_SetBits(GPIOC, nWR); GPIO_Write(GPIOB, Buff[i]); GPIO_ResetBits(GPIOC, nWR); } } //read next 7200 bytes 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 SEL button");UILCD_SetCursor(1,0);UILCD_DisplayString("for next file. "); while(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2)!=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; } /******************************************************************************* * Function Name : TFT_57F_Init * Description : Initializes LCD. * Input : None * Output : None * Return : None *******************************************************************************/ void TFT_57F_Init(void) { GPIO_ResetBits(GPIOC, CS1); GPIO_SetBits(GPIOC, nRD); GPIO_ResetBits(GPIOC, nWR); GPIO_WriteBit(GPIOC, RES, Bit_RESET); TFT_delay(5); GPIO_WriteBit(GPIOC, RES, Bit_SET); TFT_delay(100); TFT_57F_Write_Command(0x01); //Software Reset TFT_57F_Write_Command(0x01); TFT_57F_Write_Command(0x01); TFT_delay(10); TFT_57F_Command_Write(0xe0,0x01); //START PLL TFT_57F_Command_Write(0xe0,0x03); //LOCK PLL TFT_57F_Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(0x0c); //SET TFT MODE & hsync+Vsync+DEN MODE TFT_57F_Write_Data(0x80); //SET TFT MODE & hsync+Vsync+DEN MODE TFT_57F_Write_Data(0x02); //SET horizontal size=640-1 HightByte TFT_57F_Write_Data(0x7f); //SET horizontal size=640-1 LowByte TFT_57F_Write_Data(0x01); //SET vertical size=480-1 HightByte TFT_57F_Write_Data(0xdf); //SET vertical size=480-1 LowByte TFT_57F_Write_Data(0x00); //SET even/odd line RGB seq.=RGB TFT_57F_Command_Write(0xf0,0x00); //SET pixel data I/F format=8bit TFT_57F_Command_Write(0x36,0x09); //SET address mode=flip vertical, BGR TFT_57F_Command_Write(0x3a,0x60); // SET R G B format = 6 6 6 TFT_57F_Write_Command(0xe6); //SET PCLK freq=4.94MHz ; pixel clock frequency GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(0x02); TFT_57F_Write_Data(0xff); TFT_57F_Write_Data(0xff); TFT_57F_Write_Command(0xb4); //SET HBP, GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(0x02); //SET HSYNC Total=760 TFT_57F_Write_Data(0xf8); TFT_57F_Write_Data(0x00); //SET HBP 68 TFT_57F_Write_Data(0x44); TFT_57F_Write_Data(0x0f); //SET VBP 16=15+1 TFT_57F_Write_Data(0x00); //SET Hsync pulse start position TFT_57F_Write_Data(0x00); TFT_57F_Write_Data(0x00); //SET Hsync pulse subpixel start position TFT_57F_Write_Command(0xb6); //SET VBP, GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(0x01); //SET Vsync total TFT_57F_Write_Data(0xf8); TFT_57F_Write_Data(0x00); //SET VBP=19 TFT_57F_Write_Data(0x13); TFT_57F_Write_Data(0x07); //SET Vsync pulse 8=7+1 TFT_57F_Write_Data(0x00); //SET Vsync pulse start position TFT_57F_Write_Data(0x00); TFT_57F_Write_Command(0x2a); //SET column address GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(0x00); //SET start column address=0 TFT_57F_Write_Data(0x00); TFT_57F_Write_Data(0x02); //SET end column address=639 TFT_57F_Write_Data(0x7f); TFT_57F_Write_Command(0x2b); //SET page address GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(0x00); //SET start page address=0 TFT_57F_Write_Data(0x00); TFT_57F_Write_Data(0x01); //SET end page address=479 TFT_57F_Write_Data(0xdf); TFT_57F_Write_Command(0x29); //SET display on } void TFT_57F_Write_Command(unsigned char command) { GPIO_Write(GPIOB, command); GPIO_ResetBits(GPIOC, RS); GPIO_ResetBits(GPIOC, nWR); GPIO_SetBits(GPIOC, nWR); } void TFT_57F_Write_Data(unsigned char data1) { GPIO_Write(GPIOB, data1); GPIO_ResetBits(GPIOC, nWR); GPIO_SetBits(GPIOC, nWR); } void TFT_57F_Command_Write(unsigned char REG,unsigned char VALUE) { TFT_57F_Write_Command(REG); GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data(VALUE); } void TFT_57F_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_57F_WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y) { TFT_57F_Write_Command(0x2a); //SET page address GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data((s_x)>>8); //SET start page address=0 TFT_57F_Write_Data(s_x); TFT_57F_Write_Data((e_x)>>8); //SET end page address=639 TFT_57F_Write_Data(e_x); TFT_57F_Write_Command(0x2b); //SET column address GPIO_SetBits(GPIOC, RS); TFT_57F_Write_Data((s_y)>>8); //SET start column address=0 TFT_57F_Write_Data(s_y); TFT_57F_Write_Data((e_y)>>8); //SET end column address=479 TFT_57F_Write_Data(e_y); } /*-------------------------------------------------------*/