LCDInfo.com
http://forum.lcdinfo.com/

How to initialize an LCD (a VB6 program problem)
http://forum.lcdinfo.com/viewtopic.php?f=9&t=81
Page 1 of 1

Author:  Moondawq [ Sun Jan 12, 2003 4:31 ]
Post subject:  How to initialize an LCD (a VB6 program problem)

Hey all...

I have the wierdest problem. I've created a small program that displays my computers IP-address, netmask and gateway on my LCD screen (a winstar with a HD44780). Now, the program worked fine, the LCD initialized, the info was written, all procedures for clearing, cursor movement etc. worked.

Then I accidently tried to print out a document and suddenly my LCD "hang". Suddenly I was unable to initialize the LCD any more, nor clear it or write anything to it. I tried to reboot but it didnt help. Then I tried to remove the LCD from the parallel port and reboot and then attach the LCD again - still nothing. Now my program doesnt work anymore.

The wierd thing is that other programs like LCDInfo and LCDSmarte 5.1 still works fine with the LCD.

Evern wierder is the fact that this happened to me once before while I developed the program. I was using a freeware parallel port interface (an ocx) but suddenly my LCD couldnt display anything. I removed the parallel port interface and installed dlportio from DriverLinx instead. After changing the code to the new dll everything worked fine again. I thought it was that other freeware dll that was buggy and forgot about the problem - but now Im back.

Perhaps I'm initializing the LCD wrong so it only works after some other program has put some of the bits in the right place? (although it still doesnt work, even if I use another LCD program first)

My question is then: How do I initialize the LCD properly? I hate the fact that other LCD programs that use dlportio works fine, but mine doesnt.(especially when it used to work and nothing was changed in the code).

Currently I'm initializing the display with RS set low and 3 times 0x30 (decimal 48) sent to the LCD.


Any help would be extremely welcome.
Thanks,
Jesper

(p.s. of course the program and source will be publicly available once Im done :-) - With you credited... hehe )

------------------------Code begin--------------------
Public Const BASE = &H378 ' Parallel port address
Public Const CTRL = BASE + 2 ' Control address (always address of parallel port + 2
Public Const E = 1 ' Enable bit to be used as a toggle (on/off)
Public Const RS = 4 ' RS bit H/L Register select, H=data, L=instruction
Public Const InitSequence = 48 ' Init sequence to run 3 times
Public Const DL = 16 ' interface data length 0=4 bit interface 1=8 bit interface
Public Const N = 8 ' Number of display lines 0=1/8 1=1/16
Public Const F = 4 ' Character font 0=5x7 1=5x10
Public Const D = 4 ' Display bit 0=off 1=on
Public Const C = 2 ' Cursor on/off 0=off 1=on
Public Const B = 1 ' Cursor blink 0=blink off 1=blink on
Public Const SC = 8 ' 0 = move cursor 1=shit display
Public Const RL = 4 ' Shit direction 0=shift left 1=shift right
Public Const DisplayControl = 8 ' Display control bit (set when you want to control display)
Public Const DisplayShift = 16 ' Display shift bit (set when you want to control cursor move dir etc)
Public Const FunctionSet = 32 ' Function bit (set when you want to control display lines etc.)
Public Const clear = 1


Public Sub LCDInit() 'Initializes the LCD
SetRSLow 'Enter command mode
For I = 1 To 3
LCDDataWrite InitSequence 'Run init sequence 3 times
SetEnable 'Toggle E-bit
Next
'Set interface to 8 bit + display lines to 1/16 (two line display)
LCDDataWrite FunctionSet + DL + N
SetEnable 'Toggle E-bit
'Set Display on + cursor showing
LCDDataWrite DisplayControl + D + C
SetEnable 'Toggle E-bit
'clear display
LCDDataWrite clear
SetEnable 'Toggle E-bit
End Sub


Public Sub SetEnable() 'Toggles the E (enable) bit
LCDControlWrite E, True 'Toggles E bit on
Sleep (10) 'Delay processing
LCDControlWrite E, False 'Toggles E bit off again
Sleep (10) 'Delay processing
End Sub


Public Sub SetRSHigh() 'Toggles RS bit for data
LCDControlWrite RS, True 'Toggles RS bit high
End Sub


Public Sub SetRSLow() 'Toggles RS bit for instructions
LCDControlWrite RS, False 'Toggles RS bit low
End Sub


Public Sub LCDControlWrite(data As Byte, Operator As Boolean) 'Writes to control address
If Operator = True Then
DlPortWritePortUchar CTRL, DlPortReadPortUchar(CTRL) Or data 'Write chosen bit high (+ leaves other bits intact)
Else
DlPortWritePortUchar CTRL, DlPortReadPortUchar(CTRL) And (255 - data) 'Write chosen bit low (+ leaves other bits intact)
End If
End Sub


Public Sub LCDDataWrite(data As Byte) 'Writes to parallel port with data
DlPortWritePortUchar BASE, data 'Writes chosen byte to parallel port
End Sub


------------------Code end--------------------

Author:  Henri [ Sun Jan 12, 2003 15:04 ]
Post subject:  Re: How to initialize an LCD (a VB6 program problem)

Moondawq wrote:
The wierd thing is that other programs like LCDInfo and LCDSmarte 5.1 still works fine with the LCD.

Which LCDInfo are you referring in this ? As I don't think my LCDInfo should work with a HD44780 display ?

Unfortunately I don't know much about initializing HD44780 as I've never programmed any character module, only graphical ones.

Author:  Moondawq [ Tue Jan 14, 2003 13:59 ]
Post subject:  Re: LCDInfo

Hey,

Sorry my mistake. I was reffering to a program one of my collegues made for use with his own LCD screen (he named it LCDInfo too). However the program was both poorly programmed + he's no longer employeed at my company so I'm having a hard time tracking him down to get an answer from him.

Thanks for reading my post though.

Page 1 of 1 All times are UTC + 2 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/