NHD-0420DZW-AG5 parallel interface

Comments

2 comments

  • Michael_L

    I actually have some code I can share with you.  It is written for an Arduino Uno and uses the parallel interface.  See below:

    //---------------------------------------------------------
    /*
    NHD_0420DZW_uno.ino
    Program for writing to Newhaven Display 4 x 20 Character OLED (6800 mode)

    (c)2014 Mike LaVine - 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.
    */
    //---------------------------------------------------------

    // The 8 bit data bus is connected to PORTD of the Arduino Uno R3

    int RS =  8;    // RS signal connected to digital pin 8 of Arduino Uno R3
    int RW =  9;    // R/W signal connected to digital pin 9 of Arduino Uno R3
    int  E = 10;    // E signal connected to digital pin 10 of Arduino Uno R3

    const char text1[] = {"  Newhaven Display  "};
    const char text2[] = {"   Character OLED   "};
    const char text3[] = {"  4 Line x 20 Char  "};
    const char text4[] = {"0123456789!@#$%^&*()"};

    const char text5[] = {"Line 1"};
    const char text6[] = {"Line 2"};
    const char text7[] = {"Line 3"};
    const char text8[] = {"Line 4"};

    void command(char c)

       digitalWrite(RS, LOW);
       PORTD = c;
       digitalWrite(E, HIGH);
       digitalWrite(E, LOW);
    }

    void data(char d)
    {
       digitalWrite(RS, HIGH);
       PORTD = d;
       digitalWrite(E, HIGH);
       digitalWrite(E, LOW);
    }

    void disp1()
    {
       int i;
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
       delay(5);
       for (i=0;i<20;i++)
       {
          data(text1[i]);
       }
       command(0xC0);  //Second Line  [Set DDRAM address to Line 2 position 1]
       for (i=0;i<20;i++)
       {
          data(text2[i]);
       }
       command(0x94);  //Third Line  [Set DDRAM address to Line 3 position 1]
       for (i=0;i<20;i++)
       {
          data(text3[i]);
       }
       command(0xD4);  //Fourth Line  [Set DDRAM address to Line 4 position 1]
       for (i=0;i<20;i++)
       {
          data(text4[i]);
       }
    }

    void disp2()
    {
       int i;
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
       delay(5);
       for (i=0;i<6;i++)
       {
          data(text5[i]);
       }
       delay(250);
       for (i=0;i<14;i++)
       {
          command(0x1C);
          delay(40);
       }
       command(0x01);  //Display Clear
       delay(2);
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
       command(0xC0);  //Second Line  [Set DDRAM address to Line 2 position 1]
       for (i=0;i<6;i++)
       {
          data(text6[i]);
       }
       delay(250);
       for (i=0;i<14;i++)
       {
          command(0x1C);
          delay(40);
       }
       command(0x01);  //Display Clear
       delay(2);
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
       command(0x94);  //Third Line  [Set DDRAM address to Line 3 position 1]
       for (i=0;i<6;i++)
       {
          data(text7[i]);
       }
       delay(250);
       for (i=0;i<14;i++)
       {
          command(0x1C);
          delay(40);
       }
       command(0x01);  //Display Clear
       delay(2);
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
       command(0xD4);  //Fourth Line  [Set DDRAM address to Line 4 position 1]
       for (i=0;i<6;i++)
       {
          data(text8[i]);
       }
       delay(250);
       for (i=0;i<14;i++)
       {
          command(0x1C);
          delay(40);
       }
       command(0x01);  //Display Clear
       delay(2);
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
    }

    void setup()
    {
       DDRD = 0xFF;    //set PORTD as output
       PORTD = 0x00;   //initialize PORTD to 0x00
       pinMode(RS, OUTPUT);
       pinMode(RW, OUTPUT);
       pinMode(E, OUTPUT);
       digitalWrite(RW, LOW);
       digitalWrite(E, HIGH);
       command(0x38);  //Function Set  [8-bit mode, Font Table: English/Japanese (FT[1:0] = 00)]
       command(0x08);  //Display OFF
       command(0x01);  //Display Clear
       command(0x06);  //Entry Mode Set  [Auto increment address when a character is written]
       command(0x02);  //Home Command  [Set DDRAM address to Line 1 position 1]
       command(0x0C);  //Display ON
    }

    void loop()

      disp1();
      delay(3500);
      command(0x01);  //Display Clear
      disp2();
      delay(50);
    }
    0
  • stylonurus

    Michael,


    Thanks for posting the code for the parallel interface. This really helped me. My major problem was the toggling of E in the data write routine. I was setting it high before the write out to the PORT. If you study the diagram in the data sheet you would think that this would be correct.


    I also a different sequence with RS, E and RW prior to the initialization sequence although it working none the less. Although I still have not tested it with another display, this configuration appears to be more stable than my original yet somewhat slower. Not sure why but working on it. Thanks Again. I really appreciate it.

    0

Please sign in to leave a comment.