PDA

View Full Version : Four Line LCD - LCD_EBIT



cc1984
- 16th July 2011, 13:02
Anybody got ideas on how to define/control two LCD_EBIT lines and still use the LCDOUT function? I have a Newhaven display that has an enable pin for the top half (first 2 lines) and also another one for the bottom half (last 2 lines). I tried to make a subroutine to redefine LCD_EBIT, but redefinition during runtime is not allowed. I can use LCDOUT to write to the top or the bottom half, but I need to write to both.... Any ideas would be appreciated.

DaveC3
- 16th July 2011, 13:45
Here is how I made a 4x40 work
5763



'************************************************* ***************
'* Name : USBladem4X40LCD *
'* Author : Dave Cutliff *
'* Notice : Copyright (c) 2005 Patent pending *
'* : All Rights Reserved *
'* Date : 7/22/05 *
'* Version : 1.0 *
'* Notes : PIC18F2455 *
'* : LCD 4X40 Dual driver *
'************************************************* ***************



Define OSC 48
'**** LCD ************************************************** *****
'Set LCD Data port
DEFINE LCD_DREG PORTB
'Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
'Set LCD Register Select port
DEFINE LCD_RSREG PORTB
'Set LCD Register Select bit
DEFINE LCD_RSBIT 0
'Set LCD Enable port
DEFINE LCD_EREG PORTB
'Set LCD Enable bit
DEFINE LCD_EBIT 3
'LCD RW Register PORT
'DEFINE LCD_RWREG PORTB
'LCD read/write pin bit
'DEFINE LCD_RWBIT 5
'Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
'Set number of lines on LCD
DEFINE LCD_LINES 4
'Set command delay time in us
DEFINE LCD_COMMANDUS 2000
'Set data delay time in us
DEFINE LCD_DATAUS 50

LCD1_Disable var portb.2
LCD2_Disable var portb.1
'*** Program variables *****************************************
buffer1 Var Byte[8]
buffer2 Var Byte[8]
cnt Var Byte


lcdcnt var byte
'lcdchr var byte
lcdlen var byte
lcdline var byte
lcd var byte
lcdfunction var byte

'x var byte
'y var byte
'j var byte
k var byte
'ln var byte
'tmp1 var byte
'************************************************* **************
USBInit
pause 500
' Initialize LCD
input LCD1_Disable
input LCD2_Disable
LCDOut $fe,1 'clear lcd
pause 100
LCDOut $fe,2 'home
LCDOut $fe,$0c 'Curser off
LCDOut " USB 4X40 LCD "
LCDOut $FE,$C0
LCDOut " DAVE CUTLIFF "
low LCD1_Disable
input LCD2_Disable
LCDOut $fe,1 'clear lcd
LCDOut $fe,2 'home
LCDOut $fe,$0c 'Curser off
LCDOut " Highspeed USB Project "
LCDOut $FE,$C0
LCDOut " August 2005 "
pause 100
goto idleloop
'*********************subrouteens***************** ********
READ_SETUP:
USBService
lcdlen = buffer1[3]
lcdline = buffer1[1]
lcdfunction = buffer1[2]
lcd = buffer1[0]
if lcd= 0 then
input LCD1_Disable
LOW LCD2_Disable
else
LOW LCD1_Disable
input LCD2_Disable
endif
if lcdfunction = 1 then lcdout $FE,1
lcdout $FE,lcdline

RETURN

Write_LCD:
USBService
lcdcnt = 1
While lcdcnt < lcdlen
for k = 1 to 7
lcdcnt = lcdcnt + 1
LCDOUT buffer2[k]
if lcdcnt = lcdlen then goto outloop
usbin 2, buffer2, cnt, idleloop
next k

wend
Return


outloop:
USBService ' Must service USB regularly
USBOut 1, buffer1, cnt, outloop ' Send the bytes back
return
'************************************************* ***************
' Wait for USB input of 8 numbers.
idleloop:
USBService ' Must service USB regularly
cnt = 8 ' Specify input buffer size
USBIn 1, buffer1, cnt, idleloop
gosub READ_SETUP
gosub outloop
usbin 2, buffer2, cnt, idleloop
GOSUB Write_LCD
gosub outloop


goto idleloop





Hope this helps

Dave

sayzer
- 16th July 2011, 13:48
You may want to use a 7408;
This way, you can have one enable pin from PIC (coming from LCDOUT command), and two other Pins for each half.
When you want to write to first half, HIGH first and LOW second; and the other way around for second half.

cc1984
- 16th July 2011, 14:32
Great Ideas. Thanks!

mister_e
- 18th July 2011, 04:58
It's really up to you to decide which one to use, 7408 or not. Cost effective wise, I think Dave's approach is the one. Back in time
http://www.picbasic.co.uk/forum/showthread.php?t=626&

cc1984
- 19th July 2011, 00:17
So far what I have ended up with was 2 transistors, NPN and PNP (3904 & 3906). I tied one line from the pic to control the transistors, two 2.2K resistor going from the control line to the base of each transistor. I connected the LCDOUT control line to the collector of the NPN and the emitter of the PNP. I use the control line to turn on or off the control line to pass the enable signal to either the enable1 or enable2 on the lcd. I only had to add one IO line from the PIC and 2 transistors. I have 4 of these displays on the panel so I was not excited about adding more chips to the design. Not sure how to upload a schematic, but would like everyone/anyone to see if they see a problem with the design. However, it works great!
Thanks.