PDA

View Full Version : 4-line LCD Help - using PortA instead of B



Tom Gonser
- 22nd March 2005, 22:07
I have a 4-line LCD with 16 pins, the pin-outs seem to match use of the LCDOUT command.

I am using PortB, tho, and have to use PortA.. (0-3 for data lines, and 4,5 for the other two).. I have it setup as follows:

Define LCD_DREG PORTA
DEFINE LCD_DBIT 0
Define LCD_RSREG PORTA
Define LCD_RSBIT 4
Define LCD_EREG PORTA
Define LCD_EBIT 5
Define LCD_BITS 4
Define LCD_lines 4
Define LCD_Commandus 2000
Define LCD_Dataus 50

However, when I write out using $fe, LCDOUT, - I get nothing.... Any thoughts?

Thanks,
Tom

NavMicroSystems
- 23rd March 2005, 00:51
Tom,

see: here (http://www.picbasic.co.uk/forum/showthread.php?t=1254)

Let us know what brand and model of display you are using.

If it is more than 20 chars per line it is a dual controller display.

It could also be one of the "extended temperature range" models that require a negative voltage on Vee.

What does your hardware setup look like in detail?

You don't want us to guess, do you?

Tom Gonser
- 23rd March 2005, 01:54
Sorry!! ;-o

The details - of course!

Crystalfontz 20x4 display - CFAH2004L-YYB-JP. 16 pins LED backlight

1 VSS 0V Ground - Vss
2 VDD 5.0V Supply Voltage for logic -> 5v
3 VO (Variable) Operating voltage for LCD -> I have this pinned to 5V
4 RS H/L H: DATA, L: Instruction code -> to RA4
5 R/W H/L H: Read(MPU→Module) L: Write(MPU→Module) -> to Vss
6 E H,H→L Chip enable signal -> to RA5
7 DB0 H/L Data bit 0 - NA
8 DB1 H/L Data bit 1 - NA
9 DB2 H/L Data bit 2 - NA
10 DB3 H/L Data bit 3 - NA
11 DB4 H/L Data bit 4 -> RA0
12 DB5 H/L Data bit 5 -> RA1
13 DB6 H/L Data bit 6 -> RA2
14 DB7 H/L Data bit 7 -> RA3
15 A - LED +
16 K - LED -
17 Vee
18 NC

I have this hooked to PORTA instead of PORTB because I am using some on PortB, but per earlier post, it seems everything is in place. I just get no data appearing on the screen.

Maybe I have to turn off some register of PortA on the 16F876/A that I don't know about..

--------------------------------------------------------------------------
' 16F876/A

Include "modedefs.bas" ' Include serial modes

ADCON1 = 7

define LCD_DREG PORTA ' Set data pin of LCD to
define LCD_DBIT 0 ' PORTB.0-PORTB.3

define LCD_RSREG PORTA ' Set RS bit of LCD to
define LCD_RSBIT 4 ' PORTA.4

define LCD_EREG PORTA ' Set E bit of LCD to
define LCD_EBIT 5 ' PORTA.5

DEFINE LCD_LINES 4 ' 4 Lines LCD
define LCD_COMMANDUS 2000 ' Command delay time in uSec
DEFINE LCD_DATAUS 100 ' Data delay time in uSec


lcdout $fe, 1
lcdout $fe, 2
LCDOUT "Hellow World"
pause 2000

I have seen others with this unit get success with PBP.. just not me yet..

TG

anj
- 23rd March 2005, 02:46
You didnt mention it soooo, Do you have a pullup resistor on RA4?
Read PICmicro MCU specific Issues in the manual ( sect 2.5.1 )

Andrew

Tom Gonser
- 23rd March 2005, 02:58
Yes, 4.7k ohm on R4..

mister_e
- 23rd March 2005, 04:03
i didn't have any of those LCDs in stock but, can you place a trim pot on Vo pin. or just tie it to ground to see if you get at least some black square on???

Some LCD may need to place unused data pin to ground. Refer to your datasheet for that.

try removing thos DATAUS COMMANDUS defines
try a 2 secondes startup delay

NavMicroSystems
- 23rd March 2005, 10:31
PAUSE 2000
LCDOUT "Hello World"

Ceug2005
- 23rd March 2005, 11:33
TOM
"3. VO (Variable) Operating voltage for LCD -> I have this pinned to 5V "
Try VO = GND

Tom Gonser
- 23rd March 2005, 14:14
Here is the startup sequence for 4-bits for this LCD display..

I am going to try the POT on the VO line to see if that helps, but it has been at Vss and Vdd and nothing shows there.

I am not sure how to comply with the attached startup sequence however... Where do I send the bit? When?

Tom Gonser
- 23rd March 2005, 19:36
... Hmmm Now, I've got a POT on the VO which allows me to vary the cells from white to black. Still no data.

Same goes for both of the LDCs I have here, so it must be something with the PIC's treatment of the PortA?

I moved to an 18F2525..

Tom Gonser
- 24th March 2005, 17:26
OK, I have been going crazy on the 4-line LCD.. the book makes it look so easy.. I am trying to send it an initialization routine (which apparently I need to do?) This is a Crystalfontz unit which should be really nice... I attached the spec sheet in case an expert out there might be able to take a look. I am sure others will want to use these displays also.

http://www.crystalfontz.com/products/2004l/CFAH2004LYYBJP.pdf

In any event, I've taken all the advice here, and from the Mfg says I am seeing just what I should before it is initialized.. However I still get nothing on any LCD.. I *MUST* be doing something really stupid.

Here is the initialization routine I sent (which did nothing) - from page 17 of the LDC data sheet...


define LCD_DREG PORTA ' Set data pin of LCD to
define LCD_DBIT 0 ' PORTA.0-PORTA.3

define LCD_RSREG PORTA ' Set RS bit of LCD to
define LCD_RSBIT 5 ' PORTA.5

define LCD_EREG PORTA ' Set E bit of LCD to
define LCD_EBIT 4 ' PORTA.4

DEFINE LCD_LINES 4 ' 4 Lines LCD
define LCD_COMMANDUS 2000 ' Command delay time in uSec
DEFINE LCD_DATAUS 100 ' Data delay time in uSec

pause 20

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
High PortA.1 ' db5
high PortA.0 ' db4

pause 20

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
High PortA.1 ' db5
Low PortA.0 ' db4

pause 10

low PortA.5 ' RS
' RW is held low on board
high PortA.3 ' db7 - says "N" ??
high PortA.2 ' db6 - says "F"??
Low PortA.1 ' db5 - says "*" ??
Low PortA.0 ' db4 - says "*" ??

pause 2

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
Low PortA.1 ' db5
Low PortA.0 ' db4

pause 1

low PortA.5 ' RS
' RW is held low on board
High PortA.3 ' db7
low PortA.2 ' db6
low PortA.1 ' db5
Low PortA.0 ' db4

pause 1

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
low PortA.1 ' db5
Low PortA.0 ' db4
pause 1

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
Low PortA.1 ' db5
High PortA.0 ' db4

pause 1

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
High PortA.1 ' db5 - says "I/D" ??
High PortA.0 ' db4 - says "S" ??

pause 1

low PortA.5 ' RS
' RW is held low on board
low PortA.3 ' db7
low PortA.2 ' db6
low PortA.1 ' db5
Low PortA.0 ' db4

pause 1

for x = 1 to 100
lcdout $fe, 1
lcdout $fe, 2
LCDOUT "Hellow World"
pause 2000
next x

NavMicroSystems
- 24th March 2005, 18:19
Tom,

according to the datasheet the LCD has en embedded HD44780 (or compatible) controller.

with this controller you don't need to "manually" initialize the LCD.

The first LCDOUT command issued does all the initialisation for you.

assuming you have a 4k7 pull-up on RA4
the following should work on an 16F876(A)




DEFINE OSC 20 ' <-- set your clock speed here !

ADCON1=7 ' All Digital

DEFINE LCD_DREG PORTA ' Set data pin of LCD to
DEFINE LCD_DBIT 0 ' PORTA.0-PORTA.3

DEFINE LCD_RSREG PORTA ' Set RS bit of LCD to
DEFINE LCD_RSBIT 5 ' PORTA.5

DEFINE LCD_EREG PORTA ' Set E bit of LCD to
DEFINE LCD_EBIT 4 ' PORTA.4

DEFINE LCD_LINES 4 ' 4 Lines LCD

PAUSE 1000 ' wait for LCD controller to start up

Loop:

LCDOUT $FE,1 ' clear display and move cursor home

PAUSE 500 ' wait for "CLEAR" command to complete

LCDOUT "HELLO WORLD" ' print "HELLO WORLD" at current cursor position

PAUSE 1000

GOTO LOOP

END



If there is still no success there is most likely something wrong with your LCD and/or your PIC.

Tom Gonser
- 24th March 2005, 18:37
Thanks very much!

I am going to assume the LCDs from Crystalfontz don't work then. I ran the program and got nothing. Everything else on the PIC works fine. I have tried both of the LCDs I got from them, and the most I can see is line 1 and line 3 lit up with squares if I vary Vo.

Does anyone have any good sources of 4x20 LCD displays?

Thanks,
Tom

NavMicroSystems
- 24th March 2005, 23:35
Does anyone have any good sources of 4x20 LCD displays?

Tom,
it depends on where you are based.

Over here a good 4x20 Backlit LCD will be EUR 20 - EUR 30.
I have a source for 4x27 LCDs (non backlit) at EUR 5

contact me via PM
and see this (http://www.picbasic.co.uk/forum/showthread.php?t=1287)

bbarney
- 25th March 2005, 14:33
before writing off 2 lcd's why don't you try hooking them up to your printer port like this
http://www.myrolypoly.com/lcd_project/lcd_project.html
it's an easy to follow article,if they work that way you'll know for sure whether it's a code or pic problem or there both bad.digikey or mouser are good sources of lcd's.
good luck

Tom Gonser
- 25th March 2005, 15:38
Interestingly, I see that the Crystalfontz displays require a pretty substantial intitialization routine. I can't tell if that is the same as what PBP send as standard or not.

I downloaded a demo app, and it sets the bits E,RS,etc. high and low for about 10 seconds in a pattern that looks like it must be matching the tech notes for their displays. It takes the PC parallell port driver about 10 seconds to send all the bit settings, so I'd guess it is much more than 'standard'..

The Crystlfontz guys don't seem to be able to provide details about exactly WHAT bits need to be sent and in what order to initialize the LCD.

I think my time is better spent switching to an LCD that we KNOW works with PBP, which is too bad because CrystalFontz LCDs really look nice.

Thanks as ususal for all the help folks!

TG

mister_e
- 25th March 2005, 15:47
can you try something for me and post your results?




' place your LCD define here and all the others

pause 2000
FLAGS=0
pause 500
LCDOUT $fe,1
pause 500

start:
LCDOUT $FE,1,"Hello"
Here: goto Here

Tom Gonser
- 25th March 2005, 18:46
Thanks - I ran the following:

' VERY SIMPLE LCD TEST

OSCCON=%01111000
DEFINE OSC 8

Include "modedefs.bas" ' Include serial modes
@ __CONFIG _CONFIG1H, _OSC_INTIO67_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & 0bfh ;_XINST_OFF_4L

ADCON1 = 7

TrisA = %00000000
PortA = %00000000

DEFINE LCD_DREG PORTA ' Set data pin of LCD to
DEFINE LCD_DBIT 0 ' PORTA.0-PORTA.3

DEFINE LCD_RSREG PORTA ' Set RS bit of LCD to
DEFINE LCD_RSBIT 5 ' PORTA.5

DEFINE LCD_EREG PORTA ' Set E bit of LCD to
DEFINE LCD_EBIT 4 ' PORTA.4

DEFINE LCD_LINES 4 ' 4 Lines LCD


pause 2000
FLAGS=0
pause 500
LCDOUT $fe,1
pause 500

start:
LCDOUT $FE,1,"Hello"
Here: goto Here

END

-- No response from the LCD. I did use an LED to see if the lines were getting data - testing E, RS, and the 4 data lines, there is activity going on, so the PIC is sending data. I have to assume that the Crystalfontz LCD needs some sort of more advanced setup routine be sent to it.

TG

NavMicroSystems
- 25th March 2005, 20:00
Tom,

I guess you have double and triple checked you wiring.

if so
there must be something special with CrystalFontz.
I use a lot of LCDs and have tried a lot of brands (except CrystalFontz), without any problems at all.

Has anyone on the forum ever used a CrystalFontz - CFAH2004L-YYB-JP with a PIC ?

Archilochus
- 25th March 2005, 21:01
I just took a peek at the Hitachi 44780 LCD controller data sheet.
The initialization routine shown in the Crystalfontz part is the same - taken word-for-word from the Hitachi 44780 specs. So PBP should be initializing it properly.

Arch

NavMicroSystems
- 25th March 2005, 21:08
Arch,

that's what I thought, as it has an embedded 44780.

Assuming Tom has got his hardware wired up properly I don't know how to slove his problem.

Tom Gonser
- 25th March 2005, 23:31
The Mfg sent along this note:


--------------------------------------------------------------------------------
quote: "All I see are row 1 and 3 with shading, rows 2 and 4 blank, and no text."
--------------------------------------------------------------------------------

This is a sign that the lcd controller is not initialized. A typical init sequence is:

0x38 [wait 4mS] 0x38 [wait 100uS] 0x38 0x38 0x08 0x01 0x06 0x0C

just like the data sheet shows. Apparently LCDOUT is not performing the init. I think it has an internal flag to keep track of the init, and it probably thinks it doesn't need to do it again. I'm not really familiar with that code.
__________________

Does anyone know how to 'manually send' those commands? What is 0x38, etc?

Tom

NavMicroSystems
- 26th March 2005, 00:22
Tom,

You definitely don't have to worry about "initialisation" with PBP and a 44780 (or compatible),
PBP does it for you.

you have either got a bug in your wiring or your LCD is "dead" (or even both)

bbarney
- 26th March 2005, 02:54
I have to agree with Ralph,you have a short somewhere or bad connection.

Tom Gonser
- 26th March 2005, 13:20
OK, folks. Thanks for the help. I am going to rewire this to another LCD and see what happens. I agree something must have gotten messed up or fried, it just is not that complicated.

Tom

nomada
- 26th March 2005, 15:30
Hi to you all

I remembered that when I implemented Melanie's OLIMPIC TIMER with a Crystal Clear Technology LCD (with Hitachi controller) I couldn't have any character on dispaly until I set pull-ups on the four datas lines to LCD. I don't know if it could solve you problem, but I suppose it won't make things worst. maybe it deserves a try.

Sometimes components...

Have a nice weekend

ps. - lcd from CCT can be bought throw ARROW, they are cheap (!?), we use it in our vending machines and so far so good...

Bruce
- 26th March 2005, 16:48
If you're still using the 18F2525, then you need to change ADCON1 = 7 to ADCON1 = 15 or PortA is setup for A/D inputs, and you'll never get a response from your LCD.

Tom Gonser
- 26th March 2005, 23:10
Thanks, Bruce. I'll try that!

Tom

Tom Gonser
- 31st March 2005, 03:14
Made the change, and adjusted brightness -- WORKS!!

THANKS FOLKS.. It was the complexity of the 2525 and brightness adjustment that was holding me back.. Crystalfontz works fine. The support there is really good too!

Tom