//--------------------------------------------------------- /* Program excerpt for: NHDev with NHD-1.8-128160Z (c)2010 Curt Lagerstam - 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. */ //--------------------------------------------------------- int TFT_18Z_demo(void) { char filename[18] = "1_8_128160ZF_"; //****NHDev code omitted**** TFT_18Z_Init(); seekSD(54); //skip the 54byte bmp header for (i=0;i<20480;i++) //for each 24-bit pixel...128*160=20480 { f_read(&File1, &blue, 1, &blen); //read the blue 8-bits f_read(&File1, &green, 1, &blen); //read the green 8-bits f_read(&File1, &red, 1, &blen); //read the red 8-bits red=red>>3; //shift down to 5-bits green=green>>2; //shift down to 6-bits blue=blue>>3; //shift down to 5-bits RGB16[i]= (RGB16[i] | red); //put red 5-bits into int RGB16[i]= (RGB16[i] << 6); //move red bits over, make room for green RGB16[i]= (RGB16[i] | green); //put green 6-bits into int RGB16[i]= (RGB16[i] << 5); //move red and green bits over, make room for blue RGB16[i]= (RGB16[i] | blue); //put blue 5-bits into int } GPIO_SetBits(GPIOC, RS); for(i=0;i<20480;i++){ // 128*160 / 2 GPIO_Write(GPIOB, (RGB16[i]>>8)); GPIO_ResetBits(GPIOC, nWR); //clock in the first byte GPIO_SetBits(GPIOC, nWR); GPIO_Write(GPIOB, (RGB16[i])); GPIO_ResetBits(GPIOC, nWR); //clock in the 2nd byte GPIO_SetBits(GPIOC, nWR); } //****NHDev code omitted**** return 1; } /******************************************************************************* * Function Name : TFT_18Z_Init * Description : Initializes LCD. * Input : None * Output : None * Return : None *******************************************************************************/ void TFT_18Z_Init(void) { GPIO_ResetBits(GPIOC, CS1); 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_18Z_Write_Command(0x11); TFT_delay(100); TFT_18Z_Write_Command(0x26);TFT_18Z_Write_Data(0x04); TFT_18Z_Write_Command(0xF2);TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Command(0xB1);TFT_18Z_Write_Data(0x0A);TFT_18Z_Write_Data(0x14); TFT_18Z_Write_Command(0xC0);TFT_18Z_Write_Data(0x0A);TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Command(0xC1);TFT_18Z_Write_Data(0x02); TFT_18Z_Write_Command(0xC5);TFT_18Z_Write_Data(0x2F);TFT_18Z_Write_Data(0x3E); TFT_18Z_Write_Command(0xC7);TFT_18Z_Write_Data(0x40); TFT_18Z_Write_Command(0x2A); TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Data(0x7F); TFT_18Z_Write_Command(0x2B); TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Data(0x00); TFT_18Z_Write_Data(0x9F); TFT_18Z_Write_Command(0x36);TFT_18Z_Write_Data(0x40); TFT_18Z_Write_Command(0x3A);TFT_18Z_Write_Data(0xC5); TFT_18Z_Write_Command(0x29); TFT_18Z_Write_Command(0x2C); } void TFT_18Z_Write_Command(unsigned char command) { GPIO_ResetBits(GPIOC, RS); GPIO_Write(GPIOB, command); GPIO_ResetBits(GPIOC, nWR); GPIO_SetBits(GPIOC, nWR); } void TFT_18Z_Write_Data(unsigned char data1) { GPIO_SetBits(GPIOC, RS); GPIO_Write(GPIOB, data1); GPIO_ResetBits(GPIOC, nWR); GPIO_SetBits(GPIOC, nWR); }