PDA

View Full Version : Code that worked with WINDSTAR LCD doesn't work with Newhaven LCD?



jellis00
- 13th April 2010, 03:46
I just transitioned a new product design from a WINDSTAR 2x16 LCD to a NEWHAVEN 2x8 LCD to save a few bucks parts cost and some panel space on the product front panel, plus the NEWHAVEN operates without a backlight. I had the PBPro code working fine with the WINDSTAR while using it as a 4-bit interface display. I notice that the WINDSTAR LCD uses a ST7006U controller while the NEWHAVEN uses a SPLC780D, but the Command/Instruction tables are identical for both LCDs. I presumed that since the NEWHAVEN LCD is also a 4-bit interface display, has exactly the same electrical interface, and the Instruction Table is the same, that all I would have to do is change those lines of code that placed the characters on each line so that they fit inside of the 8 available characters per line. In fact, I can't get any characters to appear on the screen of the NEWHAVEN display. The Newhaven data sheet includes example initialization routines in C, but I don't understand C so can't replicate in PBPro. I am attaching my PBPro initialization routine for the WINDSTAR and the C code routines for the NEWHAVEN. Can anyone advise me how to change my PBPro code to match this C code??


InitializeDisplay: ' Subroutine to initialize 2X16 LCD display
'=================
'-----SETUP FOR USING 2x16 LCD THAT IS INSTALLED IN EASYPIC6--------
' Blink LED_GRN twice to indicate entered IntializeDisplay
For i = 0 to 1
HIGH LED_GRN
Pause 500
LOW LED_GRN
PAUSE 500
Next

' LCD DEFINES FOR USING 2x16 LCD with PortA in EASYPIC6
DEFINE LCD_DREG PORTA ' Use PORTA for LCD Data
DEFINE LCD_DBIT 0 ' Use lower(4) 4 bits of PORTA
' PORTA.0 thru PORTA.3 connect to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTA ' PORTA for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 4 ' PORTA.4 pin for LCD's RS line
DEFINE LCD_RWREG PORTC ' LCD read/write port
DEFINE LCD_RWBIT 2 ' LCD read/write bit
DEFINE LCD_EREG PORTA ' PORTA for Enable (E) bit
DEFINE LCD_EBIT 5 ' PORTA.5 pin for LCD's E line
DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 1500' Command Delay (uS)
DEFINE LCD_DATAUS 44 ' Data Delay (uS)

' DEFINE LCD Control Constants
Line1 CON 128 ' Point to beginning of line 1 ($80)
Line2 CON 192 ' Point to beginning of line 2 ($C0)

' Test the LCD during initialization
LCDOut $fe,1:FLAGS=0:Pause 250 ' Clear Display
LCDOut $fe,Line1+3," LCD TEST " ' Display on 1st line
Pause 500
LCDOut $fe,Line2+2,"..Power On..!!" ' Display on 2nd line
PAUSE 1000
Return


Here is the C code routines that came with the NEWHAVEN:



4-bit Initialization:
/************************************************** ********/
void command(char i)
{
P1 = i; //put data on output Port
D_I =0; //D/I=LOW : send instruction
R_W =0; //R/W=LOW : Write
Nybble(); //Send lower 4 bits
i = i<<4; //Shift over by 4 bits
P1 = i; //put data on output Port
Nybble(); //Send upper 4 bits
}
/************************************************** ********/
void write(char i)
{
P1 = i; //put data on output Port
D_I =1; //D/I=HIGH : send data
R_W =0; //R/W=LOW : Write
Nybble(); //Clock lower 4 bits
i = i<<4; //Shift over by 4 bits
P1 = i; //put data on output Port
Nybble(); //Clock upper 4 bits
}
/************************************************** ********/
void Nybble()
{
E = 1;
Delay(1); //enable pulse width >= 300ns
E = 0; //Clock enable: falling edge
}
/************************************************** ********/
void init()
{
P1 = 0;
P3 = 0;
Delay(100); //Wait >15 msec after power is applied
P1 = 0x30; //put 0x30 on the output port
Delay(30); //must wait 5ms, busy flag not available
Nybble(); //command 0x30 = Wake up
Delay(10); //must wait 160us, busy flag not available
Nybble(); //command 0x30 = Wake up #2
Delay(10); //must wait 160us, busy flag not available
Nybble(); //command 0x30 = Wake up #3
Delay(10); //can check busy flag now instead of delay
P1= 0x20; //put 0x20 on the output port
Nybble(); //Function set: 4-bit interface
command(0x28); //Function set: 4-bit/2-line
command(0x10); //Set cursor
command(0x0F); //Display ON; Blinking cursor
command(0x06); //Entry Mode set
}
/************************************************** ********/

Darrel Taylor
- 13th April 2010, 04:43
Try bumping up the LCD_COMMANDUS value.

1500 is just Under the minimum for that display (according to the datasheet).

1600 should work, but try 2000.
<br>

Acetronics2
- 13th April 2010, 15:24
Hi,

I confirm ... LCD Commandus = 2000 !

I do not know why, but ALL the 2x8 LCDs I have used so far always look a bit " lazy " ...and they only work with Lcd_Commandus set to 2000 !!!


I just made the test with a 2x16 LCD, SPLC780D controller display ... no difference with either 1500 or 2000 ... so, where's the truth ???

Experiece told ... 2000 works @ each time !!!

Alain

jellis00
- 13th April 2010, 21:04
I confirm ... LCD Commandus = 2000 !


Darrel/Alain,
I tried 2000 and also 3000 and the LCD module still doesn't display any characters, but I still know it is alive by rotating the contrast potentiometer near 0 ohms and the block letters appear on line 1 of the display. But no characters when transmitted,no matter what contrast setting.

I noticed one very suttle difference in the Command table between the two devices for the "Clear Display" command that I am wondering if it makes a difference...and if so how I would modify my PBP code to make the change in the command. The two command tables are attached as images.

mark_s
- 13th April 2010, 22:15
Jellis,

I think the problem is your Line 1 and 2 start address. "$80 $C0"
Try $00 - Line 1 and $40 Line 2

Hope this helps

Darrel Taylor
- 13th April 2010, 23:00
' LCD DEFINES FOR USING 2x16 LCD with PortA in EASYPIC6
DEFINE LCD_DREG PORTA ' Use PORTA for LCD Data
DEFINE LCD_DBIT 0 ' Use lower(4) 4 bits of PORTA
' PORTA.0 thru PORTA.3 connect to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTA ' PORTA for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 4 ' PORTA.4 pin for LCD's RS line
DEFINE LCD_RWREG PORTC ' LCD read/write port
DEFINE LCD_RWBIT 2 ' LCD read/write bit
DEFINE LCD_EREG PORTA ' PORTA for Enable (E) bit
DEFINE LCD_EBIT 5 ' PORTA.5 pin for LCD's E line


Are you doing something different?

The EASYPIC6 schematic says the LCD is on PORTB.
<br>

jellis00
- 13th April 2010, 23:00
I think the problem is your Line 1 and 2 start address. "$80 $C0"
Try $00 - Line 1 and $40 Line 2


I tried that, Mark, and it didn't make any difference.
Where did you get the info of start of line 1 at $00 and start of line 2 at $40 for the NEWHAVEN LCD? I went through the data sheet for the NEWHAVEN display very throroughly and couldn't find anywhere that it specifies the 1st character address in Line 1 or Line 2. For that matter, I also went through the data sheet for the WINSTAR LCD and it doesn't show $80 or $C0 either.

jellis00
- 13th April 2010, 23:08
Are you doing something different?

The EASYPIC6 schematic says the LCD is on PORTB.
<br>

Yes, Darrel, I have the LCD hooked up to PortA in my development setup on the EasyPic6 via a Port expander with a ProtoBoard.
I also have the prototype PCB board laid out so that the LCD is connected to PortA in the same way as I have it working on the EasyPic. So my LCD DEFINES are correct (at least for the WINSTAR) and work on the EasyPic configuration with the WINSTAR LCD, but they don't on the prototype PCB with the NEWHAVEN display. Hope this makes it more clear.
NEWHAVEN tech support told me that as long as I saw the character dot matrix blocks on Line 1 of the display whenever it is powered up but with contrast to a minimum, it means the module is alive. That is my situation, but still can't get characters to display. I have sent this posting to NEWHAVEN to see if they can tell me why my PBP initialization isn't working, but doubt they will since their examples for their module are all in C.

mark_s
- 13th April 2010, 23:12
I found the line address in the Newheaven data sheet. The bottom of
page 6. But it could be something else?

Darrel Taylor
- 13th April 2010, 23:30
Yes, Darrel, I have the LCD hooked up to PortA in my development setup on the EasyPic6 via a Port expander with a ProtoBoard.
Another silly question ...

Do you have a pull-up resistor on RA4?
<br>

jellis00
- 13th April 2010, 23:41
Another silly question ...

Do you have a pull-up resistor on RA4?
<br>
RA4 is connected in both my EasyPic6 development configuration and in my PCB prototype to the RS pin of the LCD. No Pull-up resistor is used in either case, and why do you ask?....from LCD data sheet the Register-Select is either 0 for command or 1 for data and therefore I didn't think it should have a pull-up resistor but should float free....am I wrong?

Darrel Taylor
- 13th April 2010, 23:51
On many chips, RA4 is Open-Collector and won't drive the pin high on it's own.

I'm assuming you're still using an 18F4550.

The datasheet doesn't specify, but in ISIS with an 18F4550, the LCD won't initialize without a pull-up.

It could just be a simulator thing.

Try it.
Stick a pull-up in there.
<br>

jellis00
- 14th April 2010, 18:16
On many chips, RA4 is Open-Collector and won't drive the pin high on it's own.

I'm assuming you're still using an 18F4550.

The datasheet doesn't specify, but in ISIS with an 18F4550, the LCD won't initialize without a pull-up.

It could just be a simulator thing.

Try it.
Stick a pull-up in there.
<br>
Tried a 10K pull-iup on RA4 and still no characters appearing on LCD. Going to hook up oscilloscope next to the various LCD interfaces to see if I can figure out what is going on.

I don't know what ISIS is or what you mean by it could be just a simulator thing. Is ISIS a simulator?

For your info I asked Microchip tech support about whether RA4 on 18F2550/4550 is open-collector or not and whether there should be any problem of it driving RA4 high with an LCD interface and here is their response:
----
Hi,
Thank you for contacting Microchip Technical Support.
RA4 can drive the pin High, please configure all the Port pin of PortA to digital by setting the bit in PCFG0-PCFG3 in ADCON1 Register.
For further assistance, do write to us with the following details.
1) Please attach your code along with MPLAB IDE workspace.(MCP and MCW files)
2) C18 -Version?
3) MPLAB version?
4) Screen shot of the disassembly listing in the view tab.
Awaiting for your reply
Thanks & Regards,
Microchip Technical Support

falingtrea
- 14th April 2010, 19:28
Also could be as simple as a contrast voltage issue (Vo). Do you have a pot on the Vo pin?

Also noticed pin 15 and 16 of the New Haven display are listed as NC in the data sheet, but the example schematic shows them as A+ and K- and shows then both grounded. So maybe you need some clarification from New Haven on how to connect up the display.

jellis00
- 14th April 2010, 21:41
Also could be as simple as a contrast voltage issue (Vo). Do you have a pot on the Vo pin?

Also noticed pin 15 and 16 of the New Haven display are listed as NC in the data sheet, but the example schematic shows them as A+ and K- and shows then both grounded. So maybe you need some clarification from New Haven on how to connect up the display.

Yes, I have a 20K ohm potentiometer connected as a Vo source for controlling contrast. I see the black matrix dots on the 1st line of the display when I power up with the pot set near 0 ohms....that is how Newhaven said I could tell if the LCD is alive and well and hasn't been zapped.

You are right, that on the prototype PCB pins 15 and 16 are connected to ground...did that because that is wn on scheamtic on Page 4 of the LCD data sheet.....but we checked with Newhaven tech support and they said it doesn't make any difference whether pins 15 and 16 are grounded or left un connected for this particular module that doesn't have a backlight.

Thanks for the comments, anyway...they help me keep thinking.

mark_s
- 14th April 2010, 22:14
Did you see the data sheet for line addresses? Look for "DDRAM" bottom page 6 in the LCD data sheet.

Also have you set ADCON1 to %00001111 for all digital on porta?

Byte_Butcher
- 14th April 2010, 22:30
Are you SURE you have the pinout correct on the New Haven display? It MAY not be the same as the windstar...

I know nothing of Windstar, but I use quite a few Lumex displays, and have recently started using some New Haven displays, and the pinout on the NewHaven that I'm using is NOT the same as the Lumex.

Lumex :

Pin1 = Ground
Pin2 = Vdd
Pin3 = Contrast adjust

New Haven:

Pin1 = Ground
Pin2 = Contrast adjust
Pin3 = Vdd

All other pins are the same except for 2 & 3 being swapped between NewHaven and Lumex.
Can't vouch for the Windstar, but you might want to have a look at the data sheets again?


Steve

Darrel Taylor
- 14th April 2010, 23:10
... and the pinout on the NewHaven that I'm using is NOT the same ...
Awesome!
Didn't see that coming, and I was looking at the datasheet, which agrees with you.

Easy enough to test.
Jellis, If you turn the contrast pot the other way, does it start smoking? :eek:
OK, probably not the best way to test it. :o

Add: Probably wouldn't anyway's, rats.
<br>

malc-c
- 14th April 2010, 23:23
I had a similar issue with a 16 x 2 LCD, which turned out required a voltage range between -5v and +5, and seemed to offer the ideal contrast when the voltage was around -3.5v

Not saying this is the cause (haven't looked at the datasheet for your display), but it did catch me out.

Byte_Butcher
- 15th April 2010, 00:23
When I bought my Newhaven displays, the pinout difference stood out immediately to me in the data sheet.
On the Lumex, and all other displays I've used, the Vss, Contrast, and Vdd pins are laid out in a row with the contrast in the middle like the pins on a pot usually are, with a voltage across the "outer" legs and the wiper in the middle.

The out of sequence power / contrast / ground sequence caught my eye right off.

Sorry I didn't mention it sooner. I didn't think about it until the word "Newhaven" came up again in one of the later posts and sparked a brain cell....

I hope that's the problem for Jellis00 !


Steve

jellis00
- 15th April 2010, 01:59
The out of sequence power / contrast / ground sequence caught my eye right off.

Sorry I didn't mention it sooner. I didn't think about it until the word "Newhaven" came up again in one of the later posts and sparked a brain cell....

I hope that's the problem for Jellis00 !

Unfortunately not, Steve.
Here is data right out of the data sheet for my display and Contrast Vo is in the right plac:.
Pin No. Symbol Function Description
1 Vss Power Supply Ground
2 VDD Power Supply Supply voltage for logic (+3.3V)
3 V0 Power Supply Power supply for contrast (approx. 0.3V)

My MCU interface to the Newhave LCD is correct with their data sheet and is shown in attached image. Still looking for the problem.

Byte_Butcher
- 15th April 2010, 03:10
Well that's a tough nut to crack...

Did I miss it or is there link to the Data Sheet for your newhaven display somewhere?


steve

jellis00
- 15th April 2010, 05:08
Well that's a tough nut to crack...

Did I miss it or is there link to the Data Sheet for your newhaven display somewhere?


You can get the spec on this display I am using at this URL:

http://www.newhavendisplay.com/index.php?main_page=product_info&cPath=2_80&products_id=258

mackrackit
- 15th April 2010, 06:56
I know you tried COMMANDUS 3000, have you also tried bump up DATAUS? I have some displays(brand???) that need COMMANDUS 3000 and DATAUS 150.

Silly question...
Is the ADC stuff off..?

jellis00
- 24th April 2010, 00:50
I am totally embarrassed to tell everyone I found the problem....and it was one of my own making. I had an intermittent trace on the PCB between the MCU pin and the LCD's R/W pin. I wouldn't have found this if Darrel Taylor hadn't sent me a manual initialization routine that (as he said) if the LCD didn't work with it, it never would. When it didn't work it forced me to go back aqnd re-verify the PCB interfaces to the LCD. I had done this before but somehow missed the bad R/W interconnect....I suppose it was intermittenly working at the time.

At any rate, I totally appreciate all the good advice I received on this thread. The people that support this forum are the best.

As a small token of "give back" I am posting my final code for the routine that now works with the NEWHAVEN displays. I highly recommend them...they are low cost ($8.25 ea) and even though they don't require a backlight their reflectance performance gives a very readable display in even low light conditions....plus their tech support is outstanding.
Here is code for initializing their 2x8 LCD modules...they have one for 5vdc operation and one for 3vdc operation that has exactly the same physical and electrical interfaces...and both at $8.25.

InitializeDisplay: ' Subroutine to initialize NEWHAVEN NHD-0208AZ-RN-YBW
'================= ' 2x8 LCD2X8 LCD display

' Blink LED_GRN twice to indicate entered IntializeDisplay
For i = 0 to 1
HIGH LED_GRN
Pause 500
LOW LED_GRN
PAUSE 500
Next

' LCD DEFINES FOR USING 2x8 LCD with PortA
DEFINE LCD_DREG PORTA ' Use PORTA for LCD Data
DEFINE LCD_DBIT 0 ' Use lower(4) 4 bits of PORTA
' PORTA.0 thru PORTA.3 connect to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTA ' PORTA for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 4 ' PORTA.4 pin for LCD's RS line
DEFINE LCD_RWREG PORTC ' LCD read/write port
DEFINE LCD_RWBIT 2 ' LCD read/write bit
DEFINE LCD_EREG PORTA ' PORTA for Enable (E) bit
DEFINE LCD_EBIT 5 ' PORTA.5 pin for LCD's E line
DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 10000' Command Delay (uS)
DEFINE LCD_DATAUS 100 ' Data Delay (uS)

' DEFINE LCD Control Constants
Line1 CON 128 ' Point to beginning of line 1 ($80)
Line2 CON 192 ' Point to beginning of line 2 ($C0)

' Test the LCD during initialization
LCDOut $fe,1:FLAGS=0:Pause 250 ' Clear Display
LCDOut $fe,Line1,"LCD TEST" ' Display on 1st line
Pause 500
LCDOut $fe,Line2,"Power On!" ' Display on 2nd line
PAUSE 1000
Return

jmgelba
- 9th March 2011, 14:42
Bumping this old thread as I'm about to use a Newhaven display for the first time. I have a NHD-0216K1Z-NSRGB-FBW 16x2 5.0V display. http://www.newhavendisplay.com/specs/NHD-0216K1Z-NSRGB-FBW.pdf I'll be using a 18F2550 for the first time. The LCD will be on portB and in 4 bit mode.

Looking at the above working code, is that really a 10000us delay? What does the FLAGS=0 mean?

jellis00
- 9th March 2011, 19:25
Looking at the above working code, is that really a 10000us delay?

Yes, it was, but this code was a very early version of my attempts to make it work. I just looked up in my latest code and I am now using the following statements that work with the display I am using, the NHD-0208AZ-RN-YBW:
DEFINE LCD_COMMANDUS 1500 ' Command Delay (uS)
DEFINE LCD_DATAUS 44 ' Data Delay (uS)
You may have to play with these values for your particular display module. Also don't be afraid to call Newhaven tech support...they are outstanding and helped me a great deal.


What does the FLAGS=0 mean?
Go to the page in the PicBasic Pro Compiler manual (it is also online if you can't find your manual) and look up the page that describes the use of the command LCDOUT. It explains what FLAGS=0 is used for. It is used to reset an internal flag to tell the program to initialize it the next time it uses LCDOUT after having been powered down and then powered back up. Very important if you are shutting off power to the LCD during the program when it is not being used to save battery power. That is why I used it.

I hope all of this helps.

BTW, one of the ongoing problems many people have had who use the NEWHAVEN LCD display modules is how to get a clean looking mounting, which normally requires a bezel. Bezels are hard to come by for these displays. I found a company that has a good set, one which worked with mine. Go to http://www.rmfproducts.com to see what they offer. Prices are also reasonable....their Model 140-1 for my LCD display size only costs $2.15 each in quantities of 1-99, and $2.00 each for 100 or more.

I hope all this helps you.
/s/ John Ellis

jmgelba
- 9th March 2011, 19:40
Thank you for that wealth of information.

This display will be mounted in a custom cast aluminum enclosure with a graphical overlay over the top. This will also contain the push buttons, the bezel info is good to know. The project is a control and monitor for a 400W LED driver.

Which PIC did you end up using?

jellis00
- 9th March 2011, 19:51
Which PIC did you end up using?

Because most of my applications have a USB interface, I have favored using either the 18F2550 or 18F4550. If you don't need a USB interface these are probably over kill, but they are so low in price and have so many IO pins, they are a good choice even if you don't need the USB. I use the 18F2550 whenever I can because it is a 20 pin IC and a lot smaller than the 4550 for board layout. I published an article in the recent Forum Competition that you can see by going to that location on the Home page. Mine is the Ultrasonic Ranger application and all of my code is posted there, including the routines that intialize and use the NEWHAVEN display.

jmgelba
- 9th March 2011, 20:19
Nice. I'm also using a 18F2550 - for the first time. I've started browsing through the datasheet and am currently finishing up the schematic and about to start on the layout.

This project calls for several analog in's, the LCD, the USB, 4 switch inputs, and control of a digital pot. Oh and a couple of indicator LED's.

Nothing like jumping in with both feet!

jellis00
- 9th March 2011, 20:38
So it soounds like you are still building schematic/layout and haven't started coding yet??
When you get into the coding of the USB interface you will probably run into problems. I did, and got a lot of help from Darrell Taylor and the Forum. When you get to that stage and need help, let me know and I may be able to refer you to some well hidden postings that will help you with the USB.

jmgelba
- 9th March 2011, 22:09
Correct.

I've done a little searching and found the keep alive requirements and DT's keep alive program. Other than that, and the requirement for a 0.47uF cap on the USB supply pin, I havent gotten too far in to it. I'm concentrating on hardware as the first rev pcb has to work first time. I need to send out a somewhat functioning proto next week.

:eek::eek:

jmgelba
- 11th March 2011, 16:29
Are you using your display in 4 bit or 8 bit and if its 4 bit, have you tied the unused data pins to ground?

jellis00
- 13th March 2011, 07:19
Are you using your display in 4 bit or 8 bit and if its 4 bit, have you tied the unused data pins to ground?
I am using it in 4-bit and yes the unused data pins have to be grounded.

jmgelba
- 14th March 2011, 17:25
Thanks. Incidentally, the datasheet from Digikey for the part number I'm using is incorrect. It didnt show how to connect the RGB backilighting correctly. Good job I double checked by calling New Haven tech support. The pin out was wrong - missing 2 pins and swapping the backlight A and K. Yikes Digikey!!

jellis00
- 14th March 2011, 18:00
Thanks. Incidentally, the datasheet from Digikey for the part number I'm using is incorrect. It didnt show how to connect the RGB backilighting correctly. Good job I double checked by calling New Haven tech support. The pin out was wrong - missing 2 pins and swapping the backlight A and K. Yikes Digikey!!
Which LCD model of theirs are you using?
Did Newhaven warn you about incorrect data sheets on any other LCDs of theirs that are sold at DigiKey?
JE

jmgelba
- 14th March 2011, 18:38
NHD-0216K1Z-NSRGB-FBW

New Haven did not warn me of any other issues with data sheets. It looks like Digikey has an early version of the correct datasheet that contains errors, as the part number of the device and the datasheet do match. However the data sheet downloaded directly from New Haven is definitely different.

Take a look at page 3 of this link: http://www.newhavendisplay.com/specs/NHD-0216K1Z-NS_RGB_FBW-REV1.pdf

And take a look at pages 3 and 4 of this link: http://www.newhavendisplay.com/specs/NHD-0216K1Z-NSRGB-FBW.pdf

The second link is from Digikey and pages 3 and 4 clearly show 16 pins, not 18 per the actual device. The correct pinout is pins 16, 17 and 18 are the anodes for red, green and blue respectively. Pin 15 is the cathode pin.

The digikey link shows pin 15 as anode and pin 16 as cathode.