Author Topic: Controlling 1x16 character display NHD-0116GZ.  (Read 4618 times)

icagan

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Controlling 1x16 character display NHD-0116GZ.
« on: May 13, 2014, 09:24:34 PM »
I had been programming and using 1x20 character LCD displays for some 30 years, never had ANY single problem. These were Optrex, Samsung and others, all based on Hitachi LCD controller.
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.

Michael_L

  • Administrator
  • Hero Member
  • *****
  • Posts: 356
  • Karma: 33
    • View Profile
Re: Controlling 1x16 character display NHD-0116GZ.
« Reply #1 on: May 14, 2014, 09:16:46 AM »
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: http://www.newhavendisplay.com/app_notes/8_bit_character_C.txt
BASIC: http://www.newhavendisplay.com/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.

Code: [Select]
// 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).

icagan

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: Controlling 1x16 character display NHD-0116GZ.
« Reply #2 on: May 14, 2014, 01:38:20 PM »
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

Michael_L

  • Administrator
  • Hero Member
  • *****
  • Posts: 356
  • Karma: 33
    • View Profile
Re: Controlling 1x16 character display NHD-0116GZ.
« Reply #3 on: May 14, 2014, 04:05:41 PM »
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.

icagan

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: Controlling 1x16 character display NHD-0116GZ.
« Reply #4 on: May 21, 2014, 11:03:55 AM »
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.

Michael_L

  • Administrator
  • Hero Member
  • *****
  • Posts: 356
  • Karma: 33
    • View Profile
Re: Controlling 1x16 character display NHD-0116GZ.
« Reply #5 on: May 21, 2014, 03:31:37 PM »
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.

 

Blank Display on NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM

Started by SteveCBoard Character LCDs

Replies: 3
Views: 4550
Last post May 13, 2014, 12:04:36 AM
by SteveC
NHD‐C12864A1Z‐FSW‐FBW‐HTT display clears after draw

Started by EdAverillBoard Graphic LCDs

Replies: 6
Views: 5684
Last post November 07, 2014, 08:25:20 AM
by Michael_L
NHD‐4.3‐480272EF‐ATXL#‐CTP | FAN5333 | BBB | Nothing on the Display

Started by Alias_AliasBoard TFTs

Replies: 1
Views: 3388
Last post September 25, 2015, 03:09:24 PM
by Paul_B
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 8785
Last post July 10, 2014, 08:46:06 AM
by Michael_L
NHD-0420DZW-AG5 - Display "sometimes" shows only 2 lines

Started by stylonurusBoard OLEDs

Replies: 5
Views: 5564
Last post June 18, 2014, 10:09:49 AM
by Michael_L