Have you used our example code for your program? The initialization there is good, as well as the write command/data routines.
See below:
//---------------------------------------------------------
/*
NHD_2_4_240320SF_CTXI_mega.ino
Program for writing to Newhaven Display 2.4” TFT with ILI9341 controller
(c)2013 Mike LaVine - Newhaven Display International, LLC.
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.
*/
//---------------------------------------------------------
// The 8 bit data bus is connected to PORTA of the Arduino Mega2560
// 5V voltage regulator on Arduino Mega has been replaced with a 3.3V regulator to provide 3.3V logic
int RS = 30; // RS signal connected to Arduino digital pin 30
int WR = 31; // /WR signal connected to Arduino digital pin 31
int RD = 32; // /RD signal connected to Arduino digital pin 32
int RES = 33; // /RES signal connected to Arduino digital pin 33
// /CS signal tied to GND
// IM0 signal tied to VDD
void comm_out(unsigned char c)
{
digitalWrite(RS, LOW);
PORTA = c;
digitalWrite(WR, LOW);
digitalWrite(WR, HIGH);
}
void data_out(unsigned char d)
{
digitalWrite(RS, HIGH);
PORTA = d;
digitalWrite(WR, LOW);
digitalWrite(WR, HIGH);
}
void disp()
{
unsigned int i;
comm_out(0x2C); //command to begin writing to frame memory
for(i=0;i<38400;i++) //fill screen with blue pixels
{
data_out(0x00);
data_out(0x1F);
data_out(0x00);
data_out(0x1F);
}
for(i=0;i<38400;i++) //fill screen with green pixels
{
data_out(0x07);
data_out(0xE0);
data_out(0x07);
data_out(0xE0);
}
}
void setup()
{
DDRC = 0xFF;
PORTC = 0x00;
DDRA = 0xFF;
PORTA = 0x00;
digitalWrite(RD, HIGH);
digitalWrite(WR, LOW);
digitalWrite(RES, LOW);
delay(250);
digitalWrite(RES, HIGH);
delay(250);
comm_out(0x28); //display off
comm_out(0x11); //exit SLEEP mode
comm_out(0xCB); //power control A
data_out(0x39);
data_out(0x2C);
data_out(0x00);
data_out(0x34);
data_out(0x02);
comm_out(0xCF); //power control B
data_out(0x00);
data_out(0x81);
data_out(0x30);
comm_out(0xC0);
data_out(0x26); //power control 1
data_out(0x04); //second parameter for ILI9340 (ignored by ILI9341)
comm_out(0xC1);
data_out(0x11); //power control 2
comm_out(0xC5);
data_out(0x35);
data_out(0x3E); //VCOM control 1
comm_out(0x36);
data_out(0x88); //memory access control = BGR
comm_out(0xB1);
data_out(0x00);
data_out(0x18); //frame rate control
comm_out(0xB6);
data_out(0x0A);
data_out(0xA2); //display function control
comm_out(0xC7);
data_out(0xBE); //VCOM control 2
comm_out(0x3A);
data_out(0x55); //pixel format = 16 bit per pixel
/*comm_out(0xE0);
data_out(0x1F); //positive gamma correction
data_out(0x1B);
data_out(0x18);
data_out(0x0B);
data_out(0x0F);
data_out(0x09);
data_out(0x46);
data_out(0xB5);
data_out(0x37);
data_out(0x0A);
data_out(0x0C);
data_out(0x07);
data_out(0x07);
data_out(0x05);
data_out(0x00);
comm_out(0xE1);
data_out(0x00); //negative gamma correction
data_out(0x24);
data_out(0x27);
data_out(0x04);
data_out(0x10);
data_out(0x06);
data_out(0x39);
data_out(0x74);
data_out(0x48);
data_out(0x05);
data_out(0x13);
data_out(0x38);
data_out(0x38);
data_out(0x3A);
data_out(0x1F);*/
comm_out(0xF2); //3g damma control
data_out(0x02); //off
comm_out(0x26); //gamma curve 3
data_out(0x01);
comm_out(0x2A);
data_out(0x00); //column address set
data_out(0x00); //start 0x0000
data_out(0x00);
data_out(0xEF); //end 0x00EF
comm_out(0x2B);
data_out(0x00); //page address set
data_out(0x00); //start 0x0000
data_out(0x01);
data_out(0x3F); //end 0x003F
comm_out(0x29); //display ON
delay(10);
}
void loop()
{
disp();
delay(1000);
}