NHD‐0420DZW‐AB5 Lines

Comments

1 comment

  • Michael_L

    It seems like you may not be addressing the lines correctly?  Take a look at the code below:

    //---------------------------------------------------------
    /*
    NHD_0420DZW_mega.ino
    Program for writing to Newhaven Display 4 x 20 Character OLED (4-bit, 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 4 bit data bus is connected to PORTA[3..0] of the Arduino Mega2560

    int RS =  30;    // RS signal connected to digital pin 30 of Arduino Mega2560
    int RW =  31;    // R/W signal connected to digital pin 31 of Arduino Mega2560
    int  E =  32;    // E signal connected to digital pin 32 of Arduino Mega2560

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

    void toggle()
    {
       digitalWrite(E, HIGH);
       delay(1);
       digitalWrite(E, LOW);
    }

    void command(char c)

       
       PORTA = (c>>4);
       digitalWrite(RS, LOW);
       toggle();
       //delay(10);
       PORTA = c;
       toggle();
    }

    void data(char d)
    {
       
       PORTA = (d>>4);
       digitalWrite(RS, HIGH);
       toggle();
       //delay(10);
       PORTA = d;
       toggle();
    }



    void disp()
    {
       int i;
       delay(50);
       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 setup()
    {
       //delay(200);
       
       DDRA = 0xFF;    //set PORTA (dat bus) as output
       PORTA = 0x00;   //initialize PORTA to 0x00
       DDRC = 0xFF;    //set PORTC (control lines) as output
       PORTC = 0x00;   //initialize PORTC to 0x00
       delay(5);
       toggle();
       delay(5);
       //toggle();
       //delay(5);
       //toggle();
       //delay(5);
       
       
       PORTA = 0x2;
       toggle();
       command(0x28);
       //command(0x28);
       //toggle();
       //PORTA = 0x8;
       //toggle();
       /*PORTA = 0x2;
       toggle();
       toggle();
       PORTA = 0x8;
       toggle();*/
       /*PORTA = 0x2;
       toggle();
       toggle();
       PORTA = 0x8;
       toggle();*/
       PORTA = 0x0;
       toggle();
       PORTA = 0x8;
       toggle();
       PORTA = 0x0;
       toggle();
       PORTA = 0x1;
       toggle();
       delay(5);
       PORTA = 0x0;
       toggle();
       PORTA = 0x6;
       toggle();
       PORTA = 0x0;
       toggle();
       PORTA = 0x2;
       toggle();
       PORTA = 0x0;
       toggle();
       PORTA = 0xC;
       toggle();
       delay(10);
    }

    void loop()

      disp();
      delay(3000);
    }


    Take special note of the disp() function, as it addresses each line and writes to it successfully.

    0

Please sign in to leave a comment.