2.4" TFT - ILI9328 controller sample code.
//--------------------------------------------------------- /* 2.4in_TFT.c Program for writing to Newhaven Display 2.4" TFT with ILI9328 controller (c) 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. */ //--------------------------------------------------------- #include <at89x51.h> /**************** I/O Setting **********************/ /* [DB7..DB0] = [P0_7..P0_0] [DB15..DB8] = [P1_7..P1_0] /CS = P3_4 RS = P3_5 /WR = P3_6 /RD = P3_7 /RESET = P3_0 */ #define CS P3_4 #define RS P3_5 #define WR P3_6 #define RD P3_7 #define RESET P3_0 /***************************************************/ void data_out(unsigned char i,unsigned char j) //Data Output 16-bit Bus Interface { RS = 1; RD = 1; WR = 0; P1 = i; P0 = j; WR = 1; } void comm_out(unsigned char j) //Command Output 16-bit Bus Interface { RS = 0; RD = 1; WR = 0; P1 = 0x00; P0 = j; WR = 1; } void data_put(unsigned char i,unsigned char j) { CS = 0; RS = 1; RD = 1; P1 = i; P0 = j; } /****************************************************/ void delay(unsigned int n) { unsigned int i,j; for (i=0;i<n;i++) for (j=0;j<350;j++) {;} } void delay1(unsigned int i) { while(i--); } /****************************************************/ void dispPic(unsigned char *picture) { int i,j; CS = 0; RS = 1; for(i=0;i<320;i++) { for(j=0;j<240;j++) { P1 = *picture; P0 = *(++picture); WR = 0; picture++; WR = 1; } } } void Fulldisplay(unsigned char d1,unsigned char d2) { int i,j; data_put(d1,d2); for(i=0;i<320;i++) { for(j=0;j<240;j++) { WR = 0; WR = 1; } } } /**************************************************** * Initialization For ILI9328 * *****************************************************/ void resetLCD() { RESET = 0; delay(100); RESET = 1; delay(100); } void init_LCD() { CS = 0; comm_out(0x00); data_out(0x00,0x01); comm_out(0x01); data_out(0x01,0x00); comm_out(0x02); data_out(0x07,0x00); comm_out(0x03); data_out(0x10,0x30); comm_out(0x04); data_out(0x00,0x00); comm_out(0x08); data_out(0x02,0x02); comm_out(0x09); data_out(0x00,0x00); comm_out(0x0A); data_out(0x00,0x00); comm_out(0x0C); data_out(0x00,0x00); comm_out(0x0D); data_out(0x00,0x00); comm_out(0x0F); data_out(0x00,0x00); comm_out(0x10); data_out(0x00,0x00); comm_out(0x11); data_out(0x00,0x00); comm_out(0x12); data_out(0x00,0x00); comm_out(0x13); data_out(0x00,0x00); delay(200); comm_out(0x10); data_out(0x17,0xB0); comm_out(0x11); data_out(0x01,0x37); delay(50); comm_out(0x12); data_out(0x01,0x3B); delay(50); comm_out(0x13); data_out(0x19,0x00); comm_out(0x29); data_out(0x00,0x07); comm_out(0x2B); data_out(0x00,0x20); delay(50); comm_out(0x20); data_out(0x00,0x00); comm_out(0x21); data_out(0x00,0x00); comm_out(0x30); data_out(0x00,0x07); comm_out(0x31); data_out(0x05,0x04); comm_out(0x32); data_out(0x07,0x03); comm_out(0x35); data_out(0x00,0x02); comm_out(0x36); data_out(0x07,0x07); comm_out(0x37); data_out(0x04,0x06); comm_out(0x38); data_out(0x00,0x06); comm_out(0x39); data_out(0x04,0x04); comm_out(0x3C); data_out(0x07,0x00); comm_out(0x3D); data_out(0x0A,0x08); comm_out(0x50); data_out(0x00,0x00); comm_out(0x51); data_out(0x00,0xEF); comm_out(0x52); data_out(0x00,0x00); comm_out(0x53); data_out(0x01,0x3F); comm_out(0x60); data_out(0x27,0x00); comm_out(0x61); data_out(0x00,0x01); comm_out(0x6A); data_out(0x00,0x00); comm_out(0x90); data_out(0x00,0x10); comm_out(0x92); data_out(0x00,0x00); comm_out(0x95); data_out(0x01,0x10); comm_out(0x97); data_out(0x00,0x00); comm_out(0x07); data_out(0x01,0x73); delay(10); comm_out(0x22); } /*************************************************** * Main Program * ***************************************************/ void main(void) { P0 = 0; P1 = 0; P2 = 0; resetLCD(); init_LCD(); while(1) { Fulldisplay(0xF8,0x00); delay(500); Fulldisplay(0x07,0xE0); delay(500); Fulldisplay(0x00,0x1F); delay(500); Fulldisplay(0xFF,0xFF); delay(500); Fulldisplay(0x00,0x00); delay(500); dispPic(pic); delay(100); } }