//------------------------------------------------------------------------------------------------------------------
/*
Program for writing to Newhaven Display NHD-3.5-320240JF-ASXP with SSD1963 Controller Board and Arduino MEGA.
Link: https://newhavendisplay.com/3-5-inch-ips-tft-without-touchscreen/
Logic level shifters are required to convert the Arduino 5V logic to 3.3V logic.
External SD card module is used.
See Header.h file for wiring description
(c)2025 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 "Header.h"
#include <SPI.h>
#include <SD.h>
void setup()
{
Init_ports();
digitalWrite(P3,HIGH);
digitalWrite(RD, HIGH);
digitalWrite(WR, LOW);
digitalWrite(RES, LOW);
delay(120);
digitalWrite(RES, HIGH);
delay(120);
TFT_Write_Command(0x01); //Software reset
delay(120);
TFT_Write_Command(0xe2); //set multiplier and divider of PLL
digitalWrite(RS, HIGH);
TFT_Write_Data(0x1d);
TFT_Write_Data(0x02);
TFT_Write_Data(0x04);
TFT_Command_Write(0xe0,0x01); //START PLL
TFT_Command_Write(0xe0,0x03); //LOCK PLL
TFT_Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE
digitalWrite(RS,HIGH);
TFT_Write_Data(0x0C); //SET TFT MODE & hsync+Vsync+DEN MODE
TFT_Write_Data(0x80); //SET TFT MODE & hsync+Vsync+DEN MODE
TFT_Write_Data(0x01); //SET horizontal size=320-1 HightByte
TFT_Write_Data(0x3f); //SET horizontal size=320-1 LowByte
TFT_Write_Data(0x00); //SET vertical size=240-1 HightByte
TFT_Write_Data(0xef); //SET vertical size=240-1 LowByte
TFT_Write_Data(0x00); //SET even/odd line RGB seq.=RGB
TFT_Command_Write(0xf0,0x00); //SET pixel data I/F format=8bit
TFT_Command_Write(0x36,0x09); // SET Address Mode; RGB->BGR, flip vertical
TFT_Command_Write(0x3a,0x60); // SET R G B format = 6 6 6
TFT_Write_Command(0xe6); //SET PCLK freq=4.94MHz ; pixel clock frequency
digitalWrite(RS,HIGH);
TFT_Write_Data(0x01);
TFT_Write_Data(0xb4);//e7
TFT_Write_Data(0xe7);//4f
TFT_Write_Command(0xb4); //SET HBP,
digitalWrite(RS,HIGH);
TFT_Write_Data(0x01); //SET HSYNC Total=371
TFT_Write_Data(0x73);
TFT_Write_Data(0x00); //SET HBP 68
TFT_Write_Data(0x2B);
TFT_Write_Data(0x07); //SET HBP 16=15+1
TFT_Write_Data(0x00); //SET Hsync pulse start position
TFT_Write_Data(0x00);
TFT_Write_Data(0x00); //SET Hsync pulse subpixel start position
TFT_Write_Command(0xb6); //SET VBP,
digitalWrite(RS,HIGH);
TFT_Write_Data(0x01); //SET Vsync Total=260
TFT_Write_Data(0x04); //
TFT_Write_Data(0x00); //SET VBP=19
TFT_Write_Data(0x0C);
TFT_Write_Data(0x07); //SET Vsync pulse 8=7+1
TFT_Write_Data(0x00); //SET Vsync pulse start position
TFT_Write_Data(0x00);
TFT_Write_Command(0x2a); //SET column address
digitalWrite(RS,HIGH);
TFT_Write_Data(0x00); //SET start column address=0
TFT_Write_Data(0x00);
TFT_Write_Data(0x01); //SET end column address=319
TFT_Write_Data(0x3f);
TFT_Write_Command(0x2b); //SET page address
digitalWrite(RS,HIGH);
TFT_Write_Data(0x00); //SET start page address=0
TFT_Write_Data(0x00);
TFT_Write_Data(0x00); //SET end page address=239
TFT_Write_Data(0xef);
TFT_Write_Command(0x13); //SET normal mode
TFT_Write_Command(0x29); //SET display on
delay(10);
SD.begin(10);
TFT_SDbmp_320240RGB2(1);
}
void loop()
{
}