I am having trouble deciphering your code, but I have some Arduino code for this display in 4-bit mode and I have posted it 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 command(char c)
{
digitalWrite(RS, LOW);
PORTA = (c>>4);
digitalWrite(E, HIGH);
digitalWrite(E, LOW);
PORTA = c;
digitalWrite(E, HIGH);
digitalWrite(E, LOW);
}
void data(char d)
{
digitalWrite(RS, HIGH);
PORTA = (d>>4);
digitalWrite(E, HIGH);
digitalWrite(E, LOW);
PORTA = d;
digitalWrite(E, HIGH);
digitalWrite(E, LOW);
}
void toggle()
{
digitalWrite(E, HIGH);
digitalWrite(E, LOW);
}
void disp()
{
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 setup()
{
DDRA = 0xFF; //set PORTA as output
PORTA = 0x00; //initialize PORTA to 0x00
pinMode(RS, OUTPUT);
pinMode(RW, OUTPUT);
pinMode(E, OUTPUT);
digitalWrite(RS, LOW);
digitalWrite(RW, LOW);
digitalWrite(E, HIGH);
PORTA = 0x2; // initialize OLED
toggle(); //
toggle(); //
PORTA = 0x8; //
toggle(); //
PORTA = 0x0; //
toggle(); //
PORTA = 0x8; //
toggle(); //
PORTA = 0x0; //
toggle(); //
PORTA = 0x1; //
toggle(); //
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);
}
This code will display text on all 4 lines of the OLED. *the delay values are in milliseconds*