7 Aralık 2012 Cuma

Interfacing Alphanumeric LCD to Parallel Port using Visual Basic 6.0

this page will let you learn a very easy tutorial for interfacing alphanumeric LCD 16x2 to parallel port of your computer using Visual Basic 6.0

Before staring with VB6 programming one should be clear with the concepts of the parallel port. Refer this link Parallel port tutorial.More information

Connection Diagram:

Caution:Make sure that 5V and GND lines are properly connected otherwise you may end up in damaging parallel port.

If you want backlight than connect pin 15 of LCD to 5V and pin 16 of LCD to GND. By adjusting 10k resistor make pin 3 of LCD at 0V. If connection are proper you will see this after power on.

Pin Information of LCD:


Algorithm to send data to LCD:

1.Make R/W low

2.Make RS=0 ;if data byte is command

RS=1 ;if data byte is data (ASCII value)

3.Place data byte on data register

4.Pulse E (HIGH to LOW)

5.Repeat the steps to send another data byte

LCD Initialization:

This is the pit fall for beginners.Proper working of LCD depend on the how the LCD is initialized. We have to send few command bytes to initialize the lcd. Simple steps to initialize the LCD

1.Specify function set:

Send 38H for 8-bit,double line and 5x7 dot character format.

2.Display On-Off control:

Send 0FH for display and blink cursor on.

3.Entry mode set:

Send 06H for cursor in increment position and shift is invisible.

4. Clear display:

Send 01H to clear display and return cursor to home position.

 

NOTE:One must refer the datasheet of LCD to get the proper time delay and required sequence.

Click here :  Interface LCD with 8051


Major hurdle in accessing parallel port in Windows Xp is the knowledge of using inpout32 files.Download these files Driver files

Now save inpout32.dll and port.dll in system32 folder in windows directory.We will use certain subroutine provided by these dll files in our VB6 code.Open new project in VB6 and create the form as shown below.

Set the Maxlength of two textboxes to 16.Create "Start" and "Clear" command button.Now double click on form and copy paste the code given below.

Visual Basic Code

Dim data As Variant
Private Sub Clear_Click()
LowRs
Out Val(&H378), Val(1)
 ' function to send data to parallel port
Enable
txtlcd1.Text = " " 
' line 1 for LCD
txtlcd2.Text = " "
 ' line 2 for LCD
End Sub
Private Sub Start_Click()
Out Val(&H37A), Val(Inp(&H37A) And &HDF)
lcd_int
LCDWriteString txtlcd1.Text
next_line 
' function to set cursor to second line
LCDWriteString txtlcd2.Text
End Sub
Sub LowRs()
Out Val(&H37A), Val(Inp(&H37A) Or &H8) 
' Rs Low
End Sub

Sub LowEn()
Out Val(&H37A), Val(Inp(&H37A) Or &H1) 
' En Low
End Sub
Sub HighRs()
Out Val(&H37A), Val(Inp(&H37A) And &HF7) 
' Rs High
End Sub
Sub HighEn()
Out Val(&H37A), Val(Inp(&H37A) And &HFE) 
' En High
End Sub
Sub lcd_write(data%)
HighRs
Out Val(&H378), Val(data)
Enable
End Sub
Sub next_line()
LowRs
Out Val(&H378), Val(&HC0)
Enable
End Sub

Sub lcd_int() 'subroutine to initialize LCD
LowRs
Out Val(&H378), Val(&H38)
Enable
LowRs
Out Val(&H378), Val(&HC)
Enable
LowRs
Out Val(&H378), Val(&H6)
Enable
LowRs
Out Val(&H378), Val(&H1)
Enable
End Sub

Sub Enable()
DELAYUS 20000
HighEn
DELAYUS 2000
LowEn
DELAYUS 2000
End Sub
' function to send ASCII character one by one to LCD
Public Sub LCDWriteString(ByVal OutStr As String)
Dim i As Integer 'write a string to LCD
For i = 1 To Len(OutStr)
lcd_write (Abs(Asc(Mid(OutStr, i, 1))))
Next i
End Sub

Now go to Project>Add Module .Select inpout4.bas and port.bas

Subroutine Out Val (&address), Val(data) and DELAYUS 2000 is found in inpout4.bas and port.bas respectively. ReferPC Interfaces Under Windows

Running the Program:

1.Press F5 to run the program

2.Write the text you want to display on the LCD in the text boxes

3.Click "Start" command button.

4.You will see that the same text appears on LCD as shown in the text boxes.

5.To send other text click "Clear" command button and repeat the same procedure.



Hiç yorum yok: