//---------------------------------------------------------
/*
Program for writing to Newhaven Display NHD-7.0-800480AF with NHD-4.3-800480TF-20 Controller Board (SSD1963, 8-bit)
R45 on controller board has been replaced with 1.1Ω to provide 180mA backlight current
This program is written for Arduino Due
(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.
*/
//---------------------------------------------------------
const int DATA_PINS[8] = {22, 23, 24, 25, 26, 27, 28, 29};
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
int DIS = 34; // DISP signal connected to Arduino digital pin 34
// /CS signal tied to GND
//;******************************************************************************
void TFT_Write_Command(unsigned char command)
{
digitalWrite(RS, LOW);
for (int i = 0; i < 8; i++) {
digitalWrite(DATA_PINS[i], (command >> i) & 0x01);
}
digitalWrite(WR, LOW);
digitalWrite(WR, HIGH);
}
//;******************************************************************************
void TFT_Write_Data(unsigned char data)
{
digitalWrite(RS, HIGH);
for (int i = 0; i < 8; i++) {
digitalWrite(DATA_PINS[i], (data >> i) & 0x01);
}
digitalWrite(WR, LOW);
digitalWrite(WR, HIGH);
}
//====================================================
void TFT_Command_Write(unsigned char REG,unsigned char VALUE)
{
TFT_Write_Command(REG);
TFT_Write_Data(VALUE);
}
//======================================================
void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y)
{
TFT_Write_Command(0x2a); //SET column address
TFT_Write_Data((s_x)>>8); //SET start column address
TFT_Write_Data(s_x);
TFT_Write_Data((e_x)>>8); //SET end column address
TFT_Write_Data(e_x);
TFT_Write_Command(0x2b); //SET page address
TFT_Write_Data((s_y)>>8); //SET start page address
TFT_Write_Data(s_y);
TFT_Write_Data((e_y)>>8); //SET end page address
TFT_Write_Data(e_y);
}
void disp()
{
unsigned int i, j;
WindowSet(0,799,0,479); //set start/end column/page address (full screen)
TFT_Write_Command(0x2C); //command to begin writing to frame memory
for(i=0;i<480;i++) //fill screen with blue pixels
{
for(j=0;j<800;j++)
{
TFT_Write_Data(0xFF);
TFT_Write_Data(0x00);
TFT_Write_Data(0x00);
}
}
WindowSet(0,799,0,479); //set start/end column/page address (full screen)
TFT_Write_Command(0x2C); //command to begin writing to frame memory
for(i=0;i<480;i++) //fill screen with green pixels
{
for(j=0;j<800;j++)
{
TFT_Write_Data(0x00);
TFT_Write_Data(0xFF);
TFT_Write_Data(0x00);
}
}
WindowSet(0,799,0,479); //set start/end column/page address (full screen)
TFT_Write_Command(0x2C); //command to begin writing to frame memory
for(i=0;i<480;i++) //fill screen with red pixels
{
for(j=0;j<800;j++)
{
TFT_Write_Data(0x00);
TFT_Write_Data(0x00);
TFT_Write_Data(0xFF);
}
}
}
//======================================================
void setup()
{
PIOA->PIO_OER = 0xFFFFFFFF;
PIOA->PIO_CODR = 0xFFFFFFFF;
PIOB->PIO_OER = 0xFFFFFFFF;
PIOB->PIO_CODR = 0xFFFFFFFF;
PIOC->PIO_OER = 0xFFFFFFFF;
PIOC->PIO_CODR = 0xFFFFFFFF;
PIOD->PIO_OER = 0xFFFFFFFF;
PIOD->PIO_CODR = 0xFFFFFFFF;
digitalWrite(DIS, 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
TFT_Write_Data(0x18);
TFT_Write_Data(0x02);
TFT_Write_Data(0x04);
TFT_Command_Write(0xe0,0x01); //Enable PLL
delay(1);
TFT_Command_Write(0xe0,0x03); //Lock PLL
TFT_Write_Command(0x01); //Software reset
delay(120);
TFT_Write_Command(0xb0); //SET LCD MODE SET TFT 18Bits MODE
TFT_Write_Data(0x08); //SET TFT MODE & hsync+Vsync+DEN MODE
TFT_Write_Data(0x80); //SET TFT MODE & hsync+Vsync+DEN MODE
TFT_Write_Data(0x03); //SET horizontal size=800-1 HightByte
TFT_Write_Data(0x1f); //SET horizontal size=800-1 LowByte
TFT_Write_Data(0x01); //SET vertical size=480-1 HightByte
TFT_Write_Data(0xdf); //SET vertical size=480-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=flip vertical
TFT_Write_Command(0xe6); //SET PCLK freq
TFT_Write_Data(0x0f);
TFT_Write_Data(0xff);
TFT_Write_Data(0xff);
TFT_Write_Command(0xb4); //SET HBP
TFT_Write_Data(0x03);
TFT_Write_Data(0x30);
TFT_Write_Data(0x00);
TFT_Write_Data(0x08);
TFT_Write_Data(0x04);
TFT_Write_Data(0x00);
TFT_Write_Data(0x00);
TFT_Write_Data(0x00);
TFT_Write_Command(0xb6); //SET VBP
TFT_Write_Data(0x02);
TFT_Write_Data(0x00);
TFT_Write_Data(0x00);
TFT_Write_Data(0x10);
TFT_Write_Data(0x04);
TFT_Write_Data(0x00);
TFT_Write_Data(0x00);
TFT_Write_Command(0x13); //SET display on
TFT_Write_Command(0x38); //SET display on
TFT_Write_Command(0x29); //SET display on
delay(10);
}
void loop()
{
disp();
}