View Full Version : Need help with optrex LCD
mk432
- 9th September 2004, 20:14
I am having a horrible time trying to get an optrex LCD (DMC 16433) to spit out anything. I have a PIC 18F458 that works fine on a LAB-X1 LCD board, yet when I try to hook it up with a 4 line optrex, I get two solid bars on the first and third line. I think I have it set right, I just can't figure out what is wrong about it.
DEFINE LCD_LINES 4
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
DEFINE OSC 40 '40 MHz clock
ADCON1 = 7 ' Set PORTA and PORTE to digital
'Low PORTE.2 ' LCD R/W line low (W)
TRISD = 0 ' Set PORTD (LEDs) to all output
PORTD = 0 ' All LEDs off
INTCON2.7 = 0 ' Enable internal pullups on PORTB
TRISB=%11110000 ' =1 makes B port input and =0 makes B port output
PORTB = 0 ' PORTB lines low to read buttons
Pause 100 ' Wait for LCD to startup '
LCDOut $fe, 1 ' Clear screen
loop:
Pause 500
LCDOut $fe, $80, "Hello"
LCDOut $fe, $c0, "World"
Pause 500
LCDOut $fe, 1 ' Clear screen
GoTo loop ' Do it forever
End
If you have any thoughts I would love to hear them.
Melanie
- 9th September 2004, 22:15
I have two thoughts initially...
1. That initial Pause 100 is far too short.... increase it to Pause 2000 at first, you can then pare it back to Pause 1000 if it does the trick.
2. Don't tamper with the LCD Port pins manually, leave it to PICBasic. You've got the data pins on PortD, you then manually set the WHOLE of PortD to zero with...
PORTD = 0 ' All LEDs off
Don't do it. Set the non-LCD pins individually and don't play with the LCD pins unless you know what you're doing... ie...
PortD.0=0
PortD.1=0 etc etc.
Better still... define those pins at the start of your program... eg...
LEDA var PortD.0
LEDB var PortD.1 etc etc
then within your program you can just refer to the aliases...
Low LEDA
Low LEDB and so forth.
mk432
- 10th September 2004, 17:58
Thank you Melanie. I got it to work, check it out:
DEFINE LCD_LINES 4
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
DEFINE OSC 4 '10 MHz clock
Pause 5000
ADCON1 = 7 ' Set PORTA and PORTE to digital
' Low PORTE.2 ' LCD R/W line low (W)
TRISD = 0 ' Set PORTD (LEDs) to all output
' PORTD = 0 ' All LEDs off
INTCON2.7 = 0 ' Enable internal pullups on PORTB
TRISB=%11110000 ' =1 makes B port input and =0 makes B port output
PORTB = 0 ' PORTB lines low to read buttons
loop: LCDOut $fe, 1 ' Clear screen
Pause 1000 ' Wait .5 second
LCDOut $fe, $80, "Line 1" ' Display "Line 1"
Pause 1000
LCDOut $fe, $c0, "Line 2" ' Move to line 2 and display "Line 2"
Pause 1000
LCDOut $fe, $94, "Line 3" ' Move to line 3 and display "Line 3"
Pause 1000
LCDOut $fe, $D4, "Line 4" ' Move to line 4 and display "Line 4"
Pause 1000 ' Wait .5 second
LCDOut $fe, 1
GoTo loop ' Do it forever
End
I had to reduce the speed from 40Mhz to 4Mhz, add a 5 second boot pause, and then a 1 second pause after each LCDOUT statement. It's awful but it works, I guess the PIC18F is too fast for the HD44780 chip set.
Melanie
- 11th September 2004, 10:00
I've known Optrex were slow, but that's just plain ridicculous. Are you sure you told PICBasic you were working at 40MHz? I see that DEFINE OSC 40 statement, you sure you didn't miss-spell it?
What happens if you try this now...
loop:
LCDOut $FE, 1
Pause 1000
LCDOut "Line 1",$FE, $C0, "Line 2",$FE, $94, "Line 3",$FE, $D4, "Line 4"
Pause 1000
GoTo loop
You should get all the text displaying in one hit with a 1 second pause, and repeat. You need one puase somewhere to allow time to read what you've displayed before it gets erased again.
Amother point... have you otherwise accounted for grounding the R/W line? You've rem'd it out in your last posting, I trust you've not left it floating.
There's a couple of other defines for the LCD...
Define LCD_COMMANDUS 2000
Define LCD_DATAUS 50
You can try increasing those... (say double them as a starting point). You should be able to use your LCD with the PIC running at 40MHz without problems.
Melanie
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.