Controlling 1x16 character display NHD-0116GZ.
Too bad they are no longer available, I have to use this dreadful Newhaven 1x16.
The specific problem is: I cannot display 2nd line of 8 characters. No matter what I do.
It seems there is some flaw with the Sitronics LCD controller.
All the sample programs that they show do not work. Meaning, I can't make them work. None explain how to start 2nd line, address hexC0.
No matter how I change the initialization, the second 8 characters are always blank.
I guess the sample programs were written by people who did not have to make them work. None of them show how to get the second 8 characters started.
I use two types of microprocessors, 65C02 and Microchip PIC.
I program PIC in MicroEngineering Labs PicBasic. It works perfectly.
I guess they went through the agony of finding the way through Sitronics bugs.
They always put in the starting line address hex80 and hexC0.
When I send this instruction in 65C02 assembly language, it gets ignored.
If I could get to assembler language output of PicBasic, then I would be able to convert it to 65C02 assembly code. Unfortunately, that is not possible.
Any suggestion would be appreciated.
Please, no C code, I don't know that.
-
I'm sorry you are having troubles getting the second set of 8 characters working, however, the example programs provided on our website, and also in the datasheet do in fact work. I just confirmed this again with an Arduino Mega and have shared my code below (it is in C language). On our example program code webpage we have a link to essentially this same code in C, and also in BASIC. Below are some links to them:
C: https://newhavendisplay.com/content/app_notes/8_bit_character_C.txt
BASIC: https://newhavendisplay.com/content/app_notes/8_bit_character.txt
You will see from the code below that I am sending command 0x01 to clear the display and return the address pointer to home. To get to the second set of 8 characters, I send 0xC0 before I write the data to be displayed.// R/W signal is tied to ground (always write, never read)
// delay values are in milliseconds
int RS = 30; //RS signal connected to digital pin 30 of Arduino Mega2560
int E = 31; //E signal connected to digital pin 31 of Arduino Mega2560
const char text1[] = {"Newhaven Display"};
const char text2[] = {" Character LCD "};
void command(char c)
{
digitalWrite(RS, LOW);
PORTA = c;
digitalWrite(E, HIGH);
delay(1);
digitalWrite(E, LOW);
}
void data(char d)
{
digitalWrite(RS, HIGH);
PORTA = d;
digitalWrite(E, HIGH);
delay(1);
digitalWrite(E, LOW);
}
void Home()
{
command(0x01);
delay(5);
}
void nextline()
{
command(0xC0);
}
void disp_pic()
{
int i;
Home();
for (i=0;i<16;i++)
{
data(text1[i]);
}
nextline();
for (i=0;i<16;i++)
{
data(text2[i]);
}
}
void setup()
{
DDRA = 0xFF; //set PORTA as output
PORTA = 0x00; //initialize PORTA to 0x00
pinMode(RS, OUTPUT);
pinMode(E, OUTPUT);
digitalWrite(E, HIGH);
delay(40);
command(0x30);
delay(5);
command(0x30);
delay(5);
command(0x30);
delay(5);
command(0x38);
command(0x10);
command(0x0c);
command(0x06);
delay(5);
}
void loop()
{
disp_pic();
delay(5000);
}The code above is generic code that works for all of our character displays, regardless of how many lines/characters. For this 1x16 character display, the resulting text shown on the screen is: Newhaven Charact (cut off because the display is only 16 characters).
0 -
Hello Michael,
thank you for your prompt and encouraging reply.
I did see the samples you mention, printed them a while ago.
I have been programming all of this, except for one thing:
I have the R/W pin grounded, since I don't need to read anything from the LCD.
I just use adequate delays so don't need to check busy flag.
I only write to it, so R/W=0.
It is not clear to me why I would need to set R/W, here is the segment:
.................................
Sub Writecom
P1 = A
Reset P3.0 'instruction
Set P3.4 'E
Set P3.7 'RW <<<<<==================
Waitms 1
Reset P3.4 'E
Reset P3.7 'RW
End Sub
...................................
Is setting the R/W in the above subroutine really necessary? If it was that would actually be great as it would solve my problem.
By the way, Hitachi controller did not required it.
Regards,
Ike-1 -
In the code I provided in my previous post, the first comment actually shows that I have the R/W grounded and am not toggling it in my program. Therefore it is not necessary to do this. The reason why it is in the other example code is because many people do in fact read from the display. That would mean the R/W signal is connected to the MCU, which would in turn mean that it would be necessary to set/reset it based on if you were reading or writing to the display.
0 -
I still have to go the Basic example provided on this site.
Here is what the instruction write subroutine looks like:
.................................
Sub Writecom
P1 = A
Reset P3.0 'instruction
Set P3.4 'E
Set P3.7 'RW <<<<<==================
Waitms 1
Reset P3.4 'E
Reset P3.7 'RW
End Sub
...................................
First, the code resets D/I, indicating this will be Instruction sent to LCD controller.
Then, Enable is set.
Then Read/Write is set, indicating this is READ instruction? Should not this be WRITE to LCD controller?
Then, Enable is reset, at this time the instruction is sent to LCD controller, as a READ.
We are not really reading from LCD controller, we are writing the instruction to it.
I would appreciate clarification of this.0 -
My apologies Ike, there was an oversight on my behalf. You are correct, it seems that the BASIC example code does in fact have an error in the write routines. It should be resetting the RW pin first, then setting it, not the other way around. We will need to update this ASAP.
I know you did mention that you have the RW pin grounded, is this still the case? As I mentioned previously in my example code I too have the RW pin grounded, and this method is perfectly fine if only writing to the display.
Also, for this display, please make sure you are sending HEX 38 for the function set command as shown in the example.0
Please sign in to leave a comment.
Comments
5 comments