Type Glcd( _
InitializedFlag As Boolean, _
ClockPin As Byte, _
DataPin As Byte, SelectPin As Byte, _
NumCols As Byte, _
NumRows As Byte, _
Row As Byte, _
Col As Byte, _
other per-instance variables _
)
Private LCD1 As Glcd
Private LCD2 As Glcd
Glcd_Initialize(LCD1, 1, 2, 3)
Glcd_Initialize(LCD2, 4, 5, 6)
'poor man's object.method of LCD1.ClearScreen
Glcd_ClearScreen(LCD1)
'poor man's object.method of LCD1.Print("String")
Glcd_Print(LCD1, "String")
'poor man's object.method of LCD1.PrintAt(1, 10, "World")
Glcd_PrintAt(LCD1, 1, 10, "World")
'and then implement class methods as subs, passing specific instance as first parameter, eg:
Sub Glcd_Print(LCD As Glcd, S As String)
For I = 0 To S.Length - 1
Glcd_PrintChar(LCD, S.CharAt(I))
Next I
End Sub
Sub Glcd_PrintChar(LCD As Glcd, C As Char)
Glcd_OutputByte(LCD, Asc(C))
LCD.Col = LCD.Col + 1
If LCD.Col > Lcd.NumCols then
LCD.Col = 1
If LCD.Row < LCD.NumRows Then
LCD.Row = LCD.Row + 1
End If
End If
End Sub
Sub Glcd_OutputByte(LCD as Glcd, B as Byte)
'you'd probably need to insert some delays in here,
'eg on a 160 MHz or whatever CPU, the signalling would likely be too fast for the LCD
SetPin(LCD.ClockPin, False)
SetPin(LCD.SelectPin, True)
Dim BitMask As Byte = 1
For BitNumber = 0 to 7
SetPin(LCD.DataPin, Bit.And(B, BitMask) <> 0)
SetPin(LCD.ClockPin, True)
SetPin(LCD.ClockPin, False)
BitMask = BitMask + BitMask
Next
SetPin(LCD.SelectPin, False)
End Sub
Sub Glcd_Clear(LCD As Glcd)
Glcd_OutputByte(LCD, 12) 'ASCII Form Feed = Clear Screen
LCD.Row = 1
LCD.Col = 1
End Sub