NHD-0420DZW-AY5 and Arduino
Hi
I have spent several hours, even days, trying to communicate properly and robustly with the NHD-0420DZW-AY5 from an Arduino Nano but in vain. Neither the standard Arduino way, nor third-party examples, nor trying from scratch myself and nor using this: https://newhavendisplay.com/content/app_notes/4_bit_character.txt seems to work, when converted as below (16 vs 20 char can hardly be the issue):
#define lcdRS 3 // D/I is P3.0
#define lcdRW 13 // WR is P3.7 ***GND***
#define lcdEnable 4 // E is P3.4 active LOW
#define lcdData4 9
#define lcdData5 10
#define lcdData6 11
#define lcdData7 12
char msg0[] = "Newhaven Display";
char msg1[] = "4-bit interface ";
void nybble()
{
digitalWrite(lcdEnable, LOW); // Reset P3.4 'E
delay(1); // Waitms 1 'enable pulse width >= 300ns
digitalWrite(lcdEnable, HIGH); // Set P3.4 'E
}
void writeCom(byte val)
{
digitalWrite(lcdData4, (val >> 4) & 1); // P1 = Com 'move data to Port 1
digitalWrite(lcdData5, (val >> 5) & 1);
digitalWrite(lcdData6, (val >> 6) & 1);
digitalWrite(lcdData7, (val >> 7) & 1);
digitalWrite(lcdRS, LOW); // Reset P3.0 'RS = Instruction register
nybble(); // Call Nybble 'write high 4 bits
digitalWrite(lcdData4, val & 1); // Rotate Com , Left , 4 'rotate; P1 = Com 'move data to Port 1
digitalWrite(lcdData5, (val >> 1) & 1);
digitalWrite(lcdData6, (val >> 2) & 1);
digitalWrite(lcdData7, (val >> 3) & 1);
nybble(); // Call Nybble 'write low 4 bits
}
void writeData(byte val)
{
digitalWrite(lcdData4, (val >> 4) & 1); // P1 = A
digitalWrite(lcdData5, (val >> 5) & 1);
digitalWrite(lcdData6, (val >> 6) & 1);
digitalWrite(lcdData7, (val >> 7) & 1);
digitalWrite(lcdRS, HIGH); // Set P3.0 'RS = Data register
nybble(); // Call Nybble
digitalWrite(lcdData4, val & 1); // Rotate A , Left , 4, P1 = A
digitalWrite(lcdData5, (val >> 1) & 1);
digitalWrite(lcdData6, (val >> 2) & 1);
digitalWrite(lcdData7, (val >> 3) & 1);
nybble(); // Call Nybble
}
void setup()
{
// Pin setup
pinMode(lcdRS, OUTPUT);
pinMode(lcdRW, OUTPUT);
pinMode(lcdEnable, OUTPUT);
pinMode(lcdData4, OUTPUT);
pinMode(lcdData5, OUTPUT);
pinMode(lcdData6, OUTPUT);
pinMode(lcdData7, OUTPUT);
// Communicate with LCD
digitalWrite(lcdRS, HIGH); // Set P3
digitalWrite(lcdRW, LOW); // Somewhat a contradiction to set P3!!!!!!!!!!
digitalWrite(lcdEnable, HIGH);
digitalWrite(lcdRS, LOW); // Reset P3.0
delay(100); // Waitms 100
digitalWrite(lcdData4, HIGH); // A = &H30; P1 = A
digitalWrite(lcdData5, HIGH);
digitalWrite(lcdData6, LOW);
digitalWrite(lcdData7, LOW);
nybble(); // Call Nybble 'wake up
delay(100); // Waitms 100
nybble(); // Call Nybble 'wake up
delay(10); // Waitms 10
nybble(); // Call Nybble 'wake up
delay(10); // Waitms 10
digitalWrite(lcdData4, LOW); // A = &H20 ' 4-bit interface; P1 = A
digitalWrite(lcdData5, HIGH);
digitalWrite(lcdData6, LOW);
digitalWrite(lcdData7, LOW);
nybble();
writeCom(0x28); // Com = &H28 '4-bit 2 lines; P1 = A; Call WriteCom
writeCom(0x10); // Com = &H10 'cursor shift; Call WriteCom
writeCom(0x0F); // Com = &H0F 'display on; Call WriteCom
writeCom(0x06); // Com = &H06 'entry mode; Call WriteCom
writeCom(0x01); // Com = &H01 'home; Call WriteCom
for (byte i = 0; i < 16; i++) // Restore Dta1; For Count = 1 To 16; Next Count
{
writeData(msg0[i]); // Read A; Call Writedata
}
writeCom(0xC0); // Com = &HC0 '2nd line
for (byte i = 0; i < 16; i++) // Restore Dta1; For Count = 1 To 16; Next Count
{
writeData(msg1[i]); // Read A; Call Writedata
}
delay(5);
}
void loop()
{
}
One thing that puzzles me using the above code from NHD is that it does now seem to follow the 4 bit procedure found in the data sheet p. 21. Furthermore, is it my observation that if the display has been improper communicated with the initialization procedure does not seem to work at all.
So I am looking for a bullet proof way of operating the display - please.
So I am looking for a bullet proof way of operating the display - please.
« Last Edit: November 02, 2017, 12:59:30 PM by MikD »
0
-
Hi
This may help for anyone looking here in the future http://runawaybrainz.blogspot.com/2014/01/midas-2004-oled-character-display.html0
Please sign in to leave a comment.
Comments
1 comment