VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 1  'vbSimpleBound
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "LcdScreen"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Base 1
Public Enum lcdCustomCharSlot
    Custom1 = 0
    Custom2 = 1
    Custom3 = 2
    Custom4 = 3
    Custom5 = 4
    Custom6 = 5
    Custom7 = 6
    Custom8 = 7
End Enum
Public Enum lcdController
    lcdfirst = 1
    lcdsecond = 2
End Enum
Public Enum lcdFonts
    size5x8 = 0
    size5x10 = 1
End Enum
Public Enum lcdOnOff
    lcdon = 1
    lcdOff = 0
End Enum
Public Enum lcdDirection
    lcdIncrement = 1
    lcdDicrement = 0
End Enum
Public Enum lcdShiftMode
    lcdShift = 1
    lcdNoShift = 0
End Enum
Public Enum lcdMoveOrShift
    lcdMoveCursor = 0
    lcdShiftDisplay = 1
End Enum
Public Enum lcdMove
    lcdRight = 1
    lcdLeft = 0
End Enum
Public Enum lcdDataLength
    lcd4bit = 0
    lcd8bit = 1
End Enum
Public Enum lcdLines
    lcd1line = 0
    lcd2lines = 1
End Enum
    
Private CustomArray(2, 8, 8) As Integer
Private CustomArrayCount As Integer
Public FormWhereEmulatorIs As Form


Public Sub PrintAscii(ByVal AsciiCode As Integer, Row As Integer, Optional Column As Integer)
Dim StringToSend As Integer
Dim Control As lcdController
If Column <> Empty Then
Select Case Row
    Case 1
        SetDDRAMaddress 1, Column - 1
        Control = lcdfirst
    Case 2
        SetDDRAMaddress 1, Column - 1 + 40
        Control = lcdfirst
    Case 3
        SetDDRAMaddress 2, Column - 1
        Control = lcdsecond
    Case 4
        SetDDRAMaddress 2, Column - 1 + 40
        Control = lcdsecond
End Select

ElseIf Row <> Empty Then
    Select Case Row
        Case 1
            
            Control = lcdfirst
        Case 2
           
            Control = lcdfirst
        Case 3
            
            Control = lcdsecond
        Case 4
            
            Control = lcdsecond
    End Select
End If
    WriteData Control, AsciiCode

End Sub

Public Sub PrintCentered(ByVal Row As Integer, ByVal TextToPrint As String)
Dim Start As Integer
    If Len(TextToPrint) > 40 Then Exit Sub
    
    If Len(TextToPrint) Mod 2 = 0 Then
        Start = ((40 - Len(TextToPrint)) / 2)
    ElseIf Len(TextToPrint) Mod 2 <> 0 Then
        Start = ((40 - Len(TextToPrint) + 1) / 2)
    End If
        PrintText Row, Start + 1, TextToPrint
End Sub




Public Sub PrintText(ByVal Row As Integer, ByVal Column As Integer, ByVal TextToPrint As String)

Dim StringToSend As Integer
   
For j = 1 To Len(TextToPrint)
    StringToSend = Asc(Mid(TextToPrint, j, 1))
    PrintAscii StringToSend, Row, Column + (j - 1)
Next j
End Sub

Public Sub Home(controller As lcdController)
Instruct controller, 2
End Sub

Public Sub Clear(controller As lcdController)
Instruct controller, 1
End Sub


Private Sub WriteData(ByVal controller As lcdController, ByVal Data As Integer)
If Data = 92 Then Data = 47 '"/"
WaitLCD controller
If controller = lcdfirst Then
    'uncomment the following line if you use the LCD Emulator
    'FormWhereEmulatorIs.LcdEmulator.WriteData lcdfirst, Data
    
    'the 'out' function is part of the hwinterface.ocx (LPT Access control) included with the class
    Out 888, Data
    Out 890, 14
    Out 890, 11
ElseIf controller = lcdsecond Then
    'FormWhereEmulatorIs.LcdEmulator.WriteData lcdsecond, Data
    'uncomment the following line if you use the LCD Emulator
    Out 888, Data
    Out 890, 7
    Out 890, 11
End If

End Sub
Public Sub EntryModeSet(controller As lcdController, Direction As lcdDirection, ShiftDisplay As lcdShiftMode)
Dim I_D, S As Integer
Dim DataToSend As Integer
I_D = 0
S = 0


If Direction = lcdIncrement Then I_D = 1
If ShiftDisplay = lcdShift Then S = 1


DataToSend = 4 + ((I_D * 2 ^ 1) + (S * 2 ^ 0))


Instruct controller, DataToSend

End Sub
Public Sub Instruct(ByVal controller As lcdController, ByVal Instruction As Integer)

WaitLCD controller

If controller = lcdfirst Then
    'uncomment the following line if you use the LCD Emulator
    'FormWhereEmulatorIs.LcdEmulator.Instruct lcdfirst, Instruction

    'the 'out' function is part of the hwinterface.ocx included with the class
    Out 888, Instruction
    Out 890, 10
    Out 890, 11
ElseIf controller = lcdsecond Then
    'uncomment the following line if you use the LCD Emulator
    'FormWhereEmulatorIs.LcdEmulator.Instruct lcdsecond, Instruction

    Out 888, Instruction
    Out 890, 3
    Out 890, 11
End If

End Sub
Public Sub SetDDRAMaddress(ByVal controller As lcdController, ByVal Address As Integer)

If Address <= 39 Then
Instruct controller, 128 + Address
ElseIf Address > 39 Then
Instruct controller, 128 + Address + 24
End If

End Sub
Public Sub SetCGRAMaddress(ByVal controller As lcdController, ByVal Address As Integer)
If Address <= 7 Then
Instruct controller, 64 + Address
End If

End Sub
Public Sub WaitLCD(controller As lcdController)
'add some code here to delay the computer so the hd4478 can proccess the commands
'i could use the busy flag of the controller so i just add a loop to delay.(not the best thing to
'do since the speed of conputer vary
For i = 1 To 3000
Next i
End Sub
Public Sub GotoXY(ByVal Row As Integer, ByVal Column As Integer)
    Select Case Row
    Case 1
        SetDDRAMaddress 1, Column - 1
        
    Case 2
        SetDDRAMaddress 1, Column - 1 + 40
        
    Case 3
        SetDDRAMaddress 2, Column - 1
        
    Case 4
        SetDDRAMaddress 2, Column - 1 + 40
End Select
End Sub
Public Sub MoveCursor(controller As lcdController, CursorOrShift As lcdMoveOrShift, RightOrLeft As lcdMove)
Dim C_S, R_L As Integer
Dim DataToSend As Integer
C_S = 0
R_L = 0


If CursorOrShift = lcdShiftDisplay Then C_S = 1
If RightOrLeft = lcdRight Then R_L = 1


DataToSend = 16 + ((C_S * 2 ^ 3) + (R_L * 2 ^ 2))



Instruct controller, DataToSend

End Sub
Public Sub DisplaySet(controller As lcdController, Display As lcdOnOff, Cursor As lcdOnOff, Blink As lcdOnOff)


Dim D, c, B As Integer
D = 0
c = 0
B = 0

If Display = lcdon Then D = 1
If Cursor = lcdon Then c = 1
If Blink = lcdon Then B = 1

DataToSend = 8 + ((D * 2 ^ 2) + (c * 2 ^ 1) + (B * 2 ^ 0))

Instruct controller, DataToSend
    
End Sub
Public Sub FunctionSet(controller As lcdController, DataLength As lcdDataLength, Lines As lcdLines, Font As lcdFonts)

f = 0
DL = 0
N = 0
If DataLength = lcd8bit Then DL = 1
If Lines = lcd2lines Then N = 1
If Font = size5x10 Then f = 1

DataToSend = 32 + ((DL * 2 ^ 4) + (N * 2 ^ 3) + (f * 2 ^ 2))


    Instruct controller, DataToSend


End Sub

Public Sub Cls()
Clear lcdfirst
Clear lcdsecond
Sleep 2
End Sub
Public Sub PrintMessage(ByVal Message As String, Optional Pause As Single = 0)
Cls
PrintCentered 2, Message
If Pause <> 0 Then
    Sleep Pause
End If

End Sub
Public Sub PrintOnTitle(ByVal Text As String, Optional Pause As Single = 0)
PrintText 1, 1, Spaces(40)
PrintText 1, 1, Text
If Pause <> 0 Then
    Sleep Pause
End If

End Sub
Public Sub EditCustomChar(ByVal controller As lcdController, ByVal Index As Integer, Row1, Row2, Row3, Row4, Row5, Row6, Row7, Row8)
Dim i1, i2, i3, i4, i5 As Integer
    
    
    
    
  
 
        i1 = Val(Mid(Row1, 1, 1))
        i2 = Val(Mid(Row1, 2, 1))
        i3 = Val(Mid(Row1, 3, 1))
        i4 = Val(Mid(Row1, 4, 1))
        i5 = Val(Mid(Row1, 5, 1))
     CustomArray(controller, 1, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row2, 1, 1))
        i2 = Val(Mid(Row2, 2, 1))
        i3 = Val(Mid(Row2, 3, 1))
        i4 = Val(Mid(Row2, 4, 1))
        i5 = Val(Mid(Row2, 5, 1))
     CustomArray(controller, 2, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row3, 1, 1))
        i2 = Val(Mid(Row3, 2, 1))
        i3 = Val(Mid(Row3, 3, 1))
        i4 = Val(Mid(Row3, 4, 1))
        i5 = Val(Mid(Row3, 5, 1))
     CustomArray(controller, 3, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row4, 1, 1))
        i2 = Val(Mid(Row4, 2, 1))
        i3 = Val(Mid(Row4, 3, 1))
        i4 = Val(Mid(Row4, 4, 1))
        i5 = Val(Mid(Row4, 5, 1))
     CustomArray(controller, 4, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row5, 1, 1))
        i2 = Val(Mid(Row5, 2, 1))
        i3 = Val(Mid(Row5, 3, 1))
        i4 = Val(Mid(Row5, 4, 1))
        i5 = Val(Mid(Row5, 5, 1))
     CustomArray(controller, 5, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row6, 1, 1))
        i2 = Val(Mid(Row6, 2, 1))
        i3 = Val(Mid(Row6, 3, 1))
        i4 = Val(Mid(Row6, 4, 1))
        i5 = Val(Mid(Row6, 5, 1))
     CustomArray(controller, 6, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row7, 1, 1))
        i2 = Val(Mid(Row7, 2, 1))
        i3 = Val(Mid(Row7, 3, 1))
        i4 = Val(Mid(Row7, 4, 1))
        i5 = Val(Mid(Row7, 5, 1))
     CustomArray(controller, 7, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
        i1 = Val(Mid(Row8, 1, 1))
        i2 = Val(Mid(Row8, 2, 1))
        i3 = Val(Mid(Row8, 3, 1))
        i4 = Val(Mid(Row8, 4, 1))
        i5 = Val(Mid(Row8, 5, 1))
     CustomArray(controller, 8, Index) = (i1 * 2 ^ 4 + i2 * 2 ^ 3 + i3 * 2 ^ 2 + i4 * 2 ^ 1 + i5 * 2 ^ 0)
     
     LoadCharToLCD controller

End Sub
Private Sub LoadCharToLCD(controller As lcdController)
    SetCGRAMaddress controller, 0
    For i = 1 To 8
     For j = 1 To 8
    
        WriteData controller, CustomArray(controller, j, i)
     Next j
    Next i
   SetDDRAMaddress controller, 0
    
End Sub
Public Sub PrintCustomChar(ByVal Row As Integer, ByVal Column As Integer, ByVal CharFromCGRAM As lcdCustomCharSlot)
    PrintAscii CharFromCGRAM, Row, Column
    
End Sub
Public Sub JustPrint(controller As lcdController, AsciiCode As Integer)
    WriteData controller, AsciiCode
End Sub

