NHD-0420DZW-AG5 parallel interface
After some debugging I noticed a few things that I did not understand.
1. In the writeOledData routine I ended up commenting out the LCD_RW = 1 to stop the duplicates from occurring. Why would this make fix the problem?
And now any character over 0x7F completely overwites the display with some character above 0x7F. Often it is a 0xB9 but after it is written, its a lot of work to get it back to normal. Loading code or power cyccling don't help. It's stuck in this bad display state?
2. In order to display the character on the display I use the toggle_E() which just performs a LCD_E = ~LCD_E
If I try to use implicit calls LCD_E = 1 followed by LCD_E =0 around the P4=cmd statement (see below), (or vicaversa) something strange happens like the 2nd and 4th line never get displayed.
3. Lastly, Once I get all bad characters as I mentioned above in 1, I can load from a debugger (IDE) a previously working hex and it won't matter. It still remains bad even after I power off and back on.
It would help to look at working example that uses a parallel interface. All the examples I have seen use serial. Below is the code for my data write.
Thanks
void writeOledData(U8 cmd)
{
U8 checkBusy;
U8 eValue;
// write data
LCD_RS = 1;
LCD_RW = 0;
toggle_E();
P4 = cmd;
toggle_E();
spinLock(1, ONE_MS_RELOAD); // Spin 1ms or so
// check for busy
//LCD_RW = 1; // causes double characters
//LCD_RS = 0; // does nothing
// As long as I write a character that has a value 0x7F or less
// CheckBusy is always returns high bit not set
checkBusy = P4;
while (checkBusy & 0x80) {
spinLock(1, ONE_MS_RELOAD); // Spin 1ms or so
checkBusy = P4;
eValue++;
if ( eValue >= 10) {
toggle_E(); // This actually runs with characters higher than 0x7F and sometimes works
}
}
}
-
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 -
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.
Comments
2 comments