Author Topic: Code for NHD-2.8-240320AF-CSXP-FCTP  (Read 159 times)

rrubiocastil

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Code for NHD-2.8-240320AF-CSXP-FCTP
« on: October 21, 2019, 11:19:26 PM »
Hello, I recently purchased a NHD-2.8-240320AF-CSXP-FCTP display. I want to make it work using a PIC24F curiosity board or an Arduino Due. Where can I find libraries? 

Sergio_M

  • Administrator
  • Jr. Member
  • *****
  • Posts: 22
  • Karma: 0
    • View Profile
Re: Code for NHD-2.8-240320AF-CSXP-FCTP
« Reply #1 on: December 31, 2019, 01:51:38 PM »
Hi rrubiocastil,

Please see our example 2.4" Arduino code, the same code can be used for the 2.8" TFT however you must add the Display Inversion ON (0x21) command in your software.

Hope this helps!

Code: [Select]
//---------------------------------------------------------
/*
NHD_2_4_240320CF_CTXI_mega.ino
Program for writing to Newhaven Display 2.4" TFT with ST7789S controller

(c)2016 Paul Bartek - 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.
*/
//---------------------------------------------------------

// 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);
        }
       
        for(i=0;i<38400;i++)         //fill screen with red pixels
{
    data_out(0xF8);
            data_out(0x00);
            data_out(0xF8);
            data_out(0x00);
        }
       
         for(i=0;i<38400;i++)         //fill screen with black pixels
{
    data_out(0x00);
            data_out(0x00);
            data_out(0x00);
            data_out(0x00);
        }
       
         for(i=0;i<38400;i++)         //fill screen with white pixels
{
    data_out(0xFF);
            data_out(0xFF);
            data_out(0xFF);
            data_out(0xFF);
        }
}

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
  delay(100);
 
  comm_out(0x36);  //MADCTL: memory data access control
  data_out(0x80);
 
  //comm_out(0x3A);  //COLMOD: Interface Pixel format *** 262K-colors in 18bit/pixel format when using 8-bit interface to allow 3-bytes per pixel
  //data_out(0x66);
 
  comm_out(0x3A);    //COLMOD: Interface Pixel format  *** 65K-colors in 16bit/pixel (5-6-5) format when using 16-bit interface to allow 1-byte per pixel
  data_out(0x55);
 
  comm_out(0xB2);  //PORCTRK: Porch setting
  data_out(0x0C);
  data_out(0x0C);
  data_out(0x00);
  data_out(0x33);
  data_out(0x33);
 
  comm_out(0xB7);  //GCTRL: Gate Control
  data_out(0x35);
 
  comm_out(0xBB);  //VCOMS: VCOM setting
  data_out(0x2B);
 
  comm_out(0xC0);  //LCMCTRL: LCM Control
  data_out(0x2C);
 
  comm_out(0xC2);  //VDVVRHEN: VDV and VRH Command Enable
  data_out(0x01);
  data_out(0xFF);
 
  comm_out(0xC3);  //VRHS: VRH Set
  data_out(0x11);
 
  comm_out(0xC4);  //VDVS: VDV Set
  data_out(0x20);
 
  comm_out(0xC6);  //FRCTRL2: Frame Rate control in normal mode
  data_out(0x0F);
 
  comm_out(0xD0);  //PWCTRL1: Power Control 1
  data_out(0xA4);
  data_out(0xA1);
 
  comm_out(0xE0);  //PVGAMCTRL: Positive Voltage Gamma control
  data_out(0xD0);
  data_out(0x00);
  data_out(0x05);
  data_out(0x0E);
  data_out(0x15);
  data_out(0x0D);
  data_out(0x37);
  data_out(0x43);
  data_out(0x47);
  data_out(0x09);
  data_out(0x15);
  data_out(0x12);
  data_out(0x16);
  data_out(0x19);
 
  comm_out(0xE1);  //NVGAMCTRL: Negative Voltage Gamma control
  data_out(0xD0);
  data_out(0x00);
  data_out(0x05);
  data_out(0x0D);
  data_out(0x0C);
  data_out(0x06);
  data_out(0x2D);
  data_out(0x44);
  data_out(0x40);
  data_out(0x0E);
  data_out(0x1C);
  data_out(0x18);
  data_out(0x16);
  data_out(0x19);
 
  comm_out(0x2A);  //X address set
  data_out(0x00);
  data_out(0x00);
  data_out(0x00);
  data_out(0xEF);

  comm_out(0x2B);  //Y address set
  data_out(0x00);
  data_out(0x00);
  data_out(0x01);
  data_out(0x3F);
  delay(10);
 
  comm_out(0x29);  //display ON
  delay(10);
}

void loop()
{
  disp();
  delay(1000);
}

 

Sample Code Question for NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM LCD

Started by SteveCBoard Character LCDs

Replies: 2
Views: 7954
Last post July 31, 2014, 08:44:29 PM
by SteveC
NHD‐0420CW‐AG3 + I2C + PIC assembly code: trouble getting started

Started by RichardRBoard OLEDs

Replies: 4
Views: 9643
Last post December 17, 2015, 03:12:49 AM
by RichardR
Korean Hex GB code for OLED multi font display NHD-2.7-12864UMY3

Started by newhavenuserBoard OLEDs

Replies: 0
Views: 5865
Last post May 05, 2017, 01:17:45 PM
by newhavenuser
Demo code for NHD-0216K3Z-FS(RGB)-FBW-V3 module on an ATMEL ATtiny 2313A

Started by swulfBoard Customer Projects

Replies: 1
Views: 6806
Last post December 11, 2017, 07:56:43 AM
by Paul_B
Arduino demo code for running the NHD-0420DZW-AB5 OLED display via SPI

Started by llameroBoard OLEDs

Replies: 1
Views: 5384
Last post May 21, 2018, 11:28:30 AM
by Ted_M