Dim LCDAddr As Object = 0x27
Dim LCD_Backlight As Byte = 0x08
Dim BLEN As Int = 0
Dim fd As JavaObject
Dim fd1 As Int
Private Sub write_word(data As Int)
Dim temp As Int = data
If BLEN = 1 Then
' temp = Bit.And(data,0x08)
ADCDEVICE.wiringPiI2CWrite(fd, Bit.And(data,0x08))
Else
' temp = Bit.Or(data,0xF7)
ADCDEVICE.wiringPiI2CWrite(fd, Bit.Or(data,0xF7))
End If
'ADCDEVICE.wiringPiI2CWrite(fd, temp)
End Sub
'send control command to lcd
Private Sub send_command(comm As Int)
Dim buf As Int
' Send bit7-4 firstly
write_word(Bit.And(Bit.Or(comm, 0xF0), 0x04))
' buf = Bit.And(comm,0xF0)
' buf =Bit.Or(comm, 0x04)
' write_word(buf)
' Sleep(2)
buf = Bit.And(comm,0xFB)' Make EN = 0
write_word(buf)
' Send bit3-0 secondly
write_word(Bit.And(Bit.Or(comm, 0x0F), 0x04))
' buf = Bit.And(comm,0x0F)
' buf = Bit.Or(comm,0x04)
' write_word(buf)
' Sleep(2)
buf = Bit.And (comm,0xFB) ' Make EN = 0
write_word(buf)
' Sleep(2)
End Sub
Private Sub send_data(data As Int)
Dim buf As Int
' Send bit7-4 firstly
write_word(Bit.And(Bit.Or(data, 0xF0), 0x05))
' buf = Bit.And(data,0xF0)
' buf = Bit.Or(data,0x05) ' RS = 1, RW = 0, EN = 1
' write_word(buf)
' Sleep(2)
buf = Bit.And(data,0xFB) ' Make EN = 0
write_word(buf)
'Send bit3-0 secondly
'(data And &HF) buf = (data And &HF) buf Or &H5 ' RS = 1, RW = 0, EN = 1
write_word(Bit.And(Bit.Or(data, 0x0f), 0x05))
' buf = Bit.And(data,0x0f)
' buf = Bit.Or(data,0x05)
' write_word(buf)
' Sleep(2)
buf = Bit.And(data,0xFB) ' Make EN = 0
write_word(buf)
' Sleep(2)
End Sub
Private Sub Clear
send_command(0x01)
End Sub
'inizia lcd
Private Sub init()
send_command(0x33) ' Must initialize to 8-line mode at first
' Sleep(5)
send_command(0x32) ' Then initialize to 4-line mode
' Sleep(5)
send_command(0x28) ' 2 Lines & 5*7 dots
' Sleep(5)
send_command(0x0C) ' Enable display without cursor
' Sleep(5)
send_command(0X01) ' Clear Screen
ADCDEVICE.wiringPiI2CWrite(fd, LCD_Backlight)
Sleep(5)
End Sub
'Print the message on the lcd
Private Sub write( x As Int, y As Int, data As String)
Dim addr As Int
Dim i As Int
Dim tmp As Int
If x < 0 Then
x = 0
End If
If x > 15 Then
x = 15
End If
If y < 0 Then
y = 0
End If
If y > 1 Then
y = 1
End If
' Move cursor
addr = 0x80 + 0x40 * y + x
send_command(addr)
tmp = data.Length
For i = 0 To tmp - 1
send_data(i)
Next
End Sub
Public Sub lcdinizia
fd = Me
fd = ADCDEVICE.wiringPiI2CSetup(0x27)
If CInt(fd) <0 Then
Log(" ==>> GPIO SETUP FAILED")
Else
Log("Fatto")
End If
init
write(0, 0, "Hi man.Welcome ")
write(0, 1, "to osoyoo.com")
Sleep(3000)
Clear
Do While True
write(0,0,"This is Lesson13")
write(0,1,"IIC LCD Test")
Sleep(1000)
Loop
End Sub
Sub CInt(o As Object) As Int
Return Floor(o)
End Sub