Interfacing with NHD-2.8-240320AF-CSXP-FCT

Comments

2 comments

  • Ted M.
    NHD Staff

    Hi anees,

    Please review this example code where reset is controlled by it's assigned digital I/O pin.
    Also, please check that pin 8 is also connected to ground for 3-wire serial mode.

    /*
    NHD_1_8_128160EF_SSXN-F-Tester.ino
    Program for writing to Newhaven Display 1.8" TFT with ILI9163 controller with Serial Interface

    Alee Shah - 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.
    */


    #include <SPI.h>
    #include <SD.h>

    /*****************************************************
    *         PINOUT: Arduino Uno -> SD card             *
    ******************************************************/

    #define   MOSI  11      // SI signal connected to Arduino digital pin 11
    #define   MISO  12      // D/C signal connected to Arduino digital pin 9
    #define   SCK   13      // SCL signal connected to Arduino digital pin 10
    const int ChipSelect = 4;

    File myFile;

    /****************************************************
    *         PINOUT: Arduino Uno -> 1.8" TFT           *
    *****************************************************/

    ////////////////        // /CS signal tied to ground
    #define   RST   8      // /RST signal connected to Arduino digital pin 8
    #define   DC    9      // D/C signal connected to Arduino digital pin 9
    #define   SCL   7      // SCL signal connected to Arduino digital pin 10
    #define   SI    6      // SI signal connected to Arduino digital pin 11


    /****************************************************
    *                   Functions                       *
    *****************************************************/

    void comm_out(unsigned char c)
    {
      digitalWrite(DC, LOW);
      for (int i=0;i<8;i++)
      {
        if((c & 0x80)== 0x80)             // Send MSB
          digitalWrite(SI, HIGH);
        else
          digitalWrite(SI, LOW);
        c = (c<<1);
        digitalWrite(SCL, LOW);
        digitalWrite(SCL, HIGH);     // Clock in Command
        digitalWrite(SCL, LOW);
      }
    }

    void data_out(unsigned char d)
    {
      digitalWrite(DC, HIGH);
      for (int i=0;i<8;i++)
      {
        if((d & 0x80)== 0x80)             // Send MSB
          digitalWrite(SI, HIGH);
        else
          digitalWrite(SI, LOW);
        d = (d<<1);
        digitalWrite(SCL, LOW);
        digitalWrite(SCL, HIGH);     // Clock in Command
        digitalWrite(SCL, LOW);
      }
    }

    void window_set(unsigned s_x, unsigned e_x, unsigned s_y, unsigned e_y)
    {
      comm_out(0x2a);    //SET column address
      digitalWrite(RST, HIGH);
      data_out((s_x)>>8);     //SET start column address
      data_out(s_x);
      data_out((e_x)>>8);     //SET end column address
      data_out(e_x);
     
      comm_out(0x2b);    //SET page address
      digitalWrite(RST, HIGH);
      data_out((s_y)>>8);     //SET start page address
      data_out(s_y);
      data_out((e_y)>>8);     //SET end page address
      data_out(e_y);
    }


    void disp2()
    {
      //**************Bottom line White************//
      unsigned int i,j;
      window_set(0,127,0,0);
      comm_out(0x2C);
      digitalWrite(RST, HIGH);
      for(i=0;i<128;i++)                 //fill with white pixels
      {
        for (j=0;j<1;j++)               
        {
        data_out(0xFF);
        data_out(0xFF);
        data_out(0xFF);
        }
      }
      delay(600);
      //**************Left line White************//
      window_set(0,0,0,159);
      comm_out(0x2C);
      digitalWrite(RST, HIGH);
      for(i=0;i<1;i++)                  //fill with white pixels
      {
        for (j=0;j<160;j++)               
        {
        data_out(0xFF);
        data_out(0xFF);
        data_out(0xFF);
        }
      }
      delay(600);
      //**************Top line White************//
      window_set(0,127,159,159);
      comm_out(0x2C);
      digitalWrite(RST, HIGH);
      for(i=0;i<128;i++)                 //fill with white pixels
      {
        for (j=0;j<1;j++)               
        {
        data_out(0xFF);
        data_out(0xFF);
        data_out(0xFF);
        }
      }
      delay(600);
      //**************Right line White************//
      window_set(127,127,0,159);
      comm_out(0x2C);
      digitalWrite(RST, HIGH);
      for(i=0;i<1;i++)                   //fill with white pixels
      {
        for (j=0;j<160;j++)               
        {
        data_out(0xFF);
        data_out(0xFF);
        data_out(0xFF);
        }
      }
      delay(600);
      //**************Fill Screen Green************//
      window_set(1,126,1,158);
      comm_out(0x2C);
      digitalWrite(RST, HIGH);
      for(i=0;i<126;i++)                   //fill inside of white border with dark green pixels
      {
        for (j=0;j<158;j++)               
        {
        data_out(0x00);
        data_out(0x38);
        data_out(0x00);
        }
      }
       delay(600);
    }



    void disp3()
    {
      unsigned int i;
      window_set(0,127,0,159);
      comm_out(0x2C);              //command to begin writing to frame memory
      digitalWrite(RST, HIGH);
            for(i=0;i<20480;i++)         //fill screen with black pixels
      {
                data_out(0x00);
                data_out(0x00);
                data_out(0x00);
      }
    }



    void TFT_SDbmp_128160RGB2(unsigned char image)    // function to show bmp from SD card
    {
       unsigned int i, j;
       unsigned char dummy;
       unsigned int incr = 0;
       
       switch(image)
       {
         case 1:
                 myFile = SD.open("AS_1_8_R.bmp");
                 break;
         case 2:
                 myFile = SD.open("rainbow.bmp");
                 break;
         default:
                 break;     
       }
     
       window_set(0,127,0,159);
       comm_out(0x2C);
       
       if(myFile)
       {
        for(unsigned int i=0;i<54;i++)
        {
            dummy = myFile.read();
        }
        //for(unsigned int i=0;i<20480;i++)
        while(myFile.available())
        { 
            data_out(myFile.read());
        }
        myFile.close();
       }
       
    }

    /****************************************************
    *         Initialization and Setup Routine          *
    *****************************************************/

    void setup()
    {
      DDRB = 0xFF;  //Enable All outputs on PortB   
      PORTB = 0x00;
      DDRC = 0xFF;  //Enable All outputs on PortC   
      PORTC = 0x00;
      DDRD = 0xFF;  //Enable All outputs on PortD
      PORTD = 0x00;
     
     
      //digitalWrite(RD, HIGH);
      //digitalWrite(WR, LOW);
      digitalWrite(RST, LOW);
      delay(150);
      digitalWrite(RST, HIGH);
      delay(150);
     
      comm_out(0x11);              //exit SLEEP mode
     
      delay(100);
     
      comm_out(0x28);              //display off
     
      comm_out(0x26);              //select gamma curve
      data_out(0x04);
     
      comm_out(0xB1);              //frame rate control
      data_out(0x0A);
      data_out(0x14);
     
      comm_out(0xC0);              //power control 1
      data_out(0x0A);
      data_out(0x00);
     
      comm_out(0xC1);              //power control 2
      data_out(0x02);
     
      comm_out(0xC5);              //VCOM control 1
      data_out(0x2F);
      data_out(0x3E);
     
      comm_out(0xC7);              //VCOM control 2
      data_out(0x40);
     
      comm_out(0x2A);              //column address set
      data_out(0x00);                 
      data_out(0x00);                  //start 0x0000
      data_out(0x00);
      data_out(0x7F);                  //end 0x007F
     
      comm_out(0x2B);              //page address set
      data_out(0x00);                 
      data_out(0x00);                  //start 0x0000
      data_out(0x00);
      data_out(0x9F);                  //end 0x009F
     
      comm_out(0x36);              //memory access control
      data_out(0xC0);              //C0 = RGB; C8 = BGR
     
      comm_out(0x3A);              //pixel format = 18 bit per pixel
      data_out(0x06);                 
     
      comm_out(0x29);              //display ON

      delay(10);
      SD.begin(ChipSelect); 
    }

    /****************************************************
    *          Loop function to run repeatedly          *
    *****************************************************/

    void loop()
    {
      disp2();
      delay(1000);
      disp3();
      delay(1000);
     
      TFT_SDbmp_128160RGB2(1);
      delay(6000);
      TFT_SDbmp_128160RGB2(2);
      delay(4000);
    }

    Best Regards,

    0
  • anees

    Thanks for the response, modified our board taking into your comments. However even with LED_POWER_ON, TFT_POWER_ON and RESET (LOW HIGH), display doesnt even turn on. I probed these 3 signals and are found to be around 3.3V. attaching a document with relevant portion of the schematic and display initilization code, let me know if any one has any suggestions how to proceed from here?
    I have a  spark fun pro Micro-3.3V board, but looking for an adaptor board to connect this display part, a quick google search didnt turn up anything OTS

     

    Thanks again
    Anees

     

    0

Please sign in to leave a comment.