Sample code for NHD-4.3-800480CF with SSD1963 controller (Due).
/* /Program for writing to NHD-4.3-800480CF-ASXP display paired with the NHD-4.3-480272MF Controller Board using the SSD1963 controller. /This code is written for the Arduino Due (Atmel SAM3X8E) using 8-bit Parallel Interface. /This code also interfaces with a Micro SD card Storage Board and provides an example of loading and writing an image to the NHD-4.3-800480CF-ASXP display. / /Newhaven Display invests time and resources providing this open source code, /Please support Newhaven Display by purchasing products from Newhaven Display! * Copyright (c) 2020 Alee Shah - Newhaven Display International, Inc. * * This code is provided as an example only and without any warranty by Newhaven Display. * Newhaven Display accepts no responsibility for any issues resulting from its use. * The developer on the final application incorporating any parts of this * sample code is responsible for ensuring its safe and correct operation * and for any consequences resulting from its use. * See the GNU General Public License for more details. * *****************************************************************************/ #include <SPI.h> #include <SD.h> /**************************************************** * PINOUT: Arduino Due -> 4.3" Controller Board * ****************************************************/ // The 8 bit data bus is connected to PORTD 2-9 of the Arduino Due #define DIS 23 // DISP signal connected to Arduino digital pin (A,14) #define RS 24 // RS signal connected to Arduino digital pin (A,15) #define WR 25 // /WR signal connected to Arduino digital pin (D,0) #define RD 26 // /RD signal connected to Arduino digital pin (D,1) #define RES 27 // /RES signal connected to Arduino digital pin (D,2) #define BL 42 // BACKLIGHT ENABLE signal connected to Arduino digital pin (A,19) // /CS signal tied to GND /***************************************************** * PINOUT: Arduino Uno -> SD card * ****************************************************** * NOTE: * MOSI pin from SD Card Reader -> SPI-4 of Arduino Due * MISO pin from SD Card Reader -> SPI-1 of Arduino Due * SCK pin from SD Card Reader -> SPI-3 of Arduino Due *****************************************************/ const int ChipSelect = 44; File myFile; /**************************************************** * Basic Functions * ****************************************************/ void TFT_Write_Command(unsigned char command) { REG_PIOA_ODSR &= ~0x00008000; //RS = 0 REG_PIOC_ODSR = command << 2; //Shift Left in order to place data from PORTD 0-7 -> PORTD 2-9. REG_PIOD_ODSR &= ~0x00000001; //WR = 0 REG_PIOD_ODSR |= 0x00000001; //WR = 1 } void TFT_Write_Data(unsigned char data) { REG_PIOA_ODSR |= 0x00008000; //RS = 1 REG_PIOC_ODSR = data << 2; //Shift Left in order to place data from PORTD 0-7 -> PORTD 2-9. REG_PIOD_ODSR &= ~0x00000001; //WR = 0 REG_PIOD_ODSR |= 0x00000001; //WR = 1 } void TFT_Command_Write(unsigned char REG,unsigned char VALUE) { TFT_Write_Command(REG); //Command TFT_Write_Data(VALUE); //Data } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Window Set Function //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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); } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Fill Screen (All Red -> All Green -> All Blue) Function //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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 Red pixels { for(j=0;j<800;j++) { TFT_Write_Data(0x00); TFT_Write_Data(0x00); TFT_Write_Data(0xFF); } } 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 Blue pixels { for(j=0;j<800;j++) { TFT_Write_Data(0xFF); TFT_Write_Data(0x00); TFT_Write_Data(0x00); } } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Border and Fill Function (Red Border & Black Interior) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void Border_Fill() { unsigned int i,j; WindowSet(0,799,0,0); //Set start/end column/page address (Bottom Line) TFT_Write_Command(0x2C); //Command to begin writing to frame memory for(i=0;i<800;i++) //Bottom Red Border { for (j=0;j<1;j++) { TFT_Write_Data(0x00); TFT_Write_Data(0x00); TFT_Write_Data(0xFF); } } WindowSet(0,0,0,479); //Set start/end column/page address (Left Line) TFT_Write_Command(0x2C); //Command to begin writing to frame memory for(i=0;i<1;i++) //Left Red Pixel Border { for (j=0;j<480;j++) { TFT_Write_Data(0x00); TFT_Write_Data(0x00); TFT_Write_Data(0xFF); } } WindowSet(0,799,479,479); //Set start/end column/page address (Top Line) TFT_Write_Command(0x2C); //Command to begin writing to frame memory for(i=0;i<800;i++) //Top Red Pixel Border { for (j=0;j<1;j++) { TFT_Write_Data(0x00); TFT_Write_Data(0x00); TFT_Write_Data(0xFF); } } WindowSet(799,799,0,479); //Set start/end column/page address (Right screen) TFT_Write_Command(0x2C); //Command to begin writing to frame memory for(i=0;i<1;i++) //Right Red Pixel Border { for (j=0;j<800;j++) { TFT_Write_Data(0x00); TFT_Write_Data(0x00); TFT_Write_Data(0xFF); } } WindowSet(1,798,1,478); //Set start/end column/page address (Interior of Drawn Border) TFT_Write_Command(0x2C); //Command to begin writing to frame memory for(i=0;i<798;i++) //Fill interior with Black Pixels { for (j=0;j<478;j++) { TFT_Write_Data(0x00); TFT_Write_Data(0x00); TFT_Write_Data(0x00); } } } //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // Draw Image from SD Card Function (2 Images Total) //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void TFT_SDbmp_800480(unsigned char image) { unsigned int i, j; unsigned char dummy; switch(image) { case 1: myFile = SD.open("Image1.bmp"); break; case 2: myFile = SD.open("Image2.bmp"); break; default: break; } WindowSet(0,799,0,479); //Set start/end column/page address (full screen) TFT_Write_Command(0x2C); if(myFile) { for(unsigned int i=0;i<54;i++) //Must read 54 dummy bytes to begin { dummy = myFile.read(); } for(unsigned int i=0;i<384000;i++) //800 x 480 Pixel Resolution { TFT_Write_Data(myFile.read()); TFT_Write_Data(myFile.read()); TFT_Write_Data(myFile.read()); } myFile.close(); } } /***************************************************** * Initialization & Setup Function, to run once * *****************************************************/ void setup() { int k; pinMode(RS, OUTPUT); pinMode(RD, OUTPUT); pinMode(WR, OUTPUT); pinMode(RES, OUTPUT); pinMode(DIS, OUTPUT); pinMode(DIS, OUTPUT); for(k=34;k<=41;k++) { pinMode(k, OUTPUT); } REG_PIOC_OWER |= 0x000FFFFF; REG_PIOD_OWER |= 0x000FFFFF; REG_PIOA_OWER |= 0x000FFFFF; digitalWrite(DIS, HIGH); digitalWrite(RD, HIGH); digitalWrite(WR, LOW); digitalWrite(BL, HIGH); 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(0x1d); 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); //SET HSYNC Total=1056 TFT_Write_Data(0xA0); TFT_Write_Data(0x00); //SET HBP 88 TFT_Write_Data(0x58); TFT_Write_Data(0x80); //SET HSYNC Pulse Width=128=127pixels+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 TFT_Write_Data(0x02); //SET Vsync total 525 TFT_Write_Data(0x0d); TFT_Write_Data(0x00); //SET VBP=32 TFT_Write_Data(0x1F); TFT_Write_Data(0x01); //SET VSYNC Pulse Width= 0=0lines+1 TFT_Write_Data(0x00); //SET Vsync pulse start position 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); SD.begin(ChipSelect); } /***************************************************** * Loop Function, to run repeatedly * *****************************************************/ void loop() { disp(); delay(1000); Border_Fill(); delay(1000); TFT_SDbmp_800480(1); delay(1000); TFT_SDbmp_800480(2); delay(1000); }