Hej! <code>Styra en HD44780-LCD
Är det någon därute som sitter på lite kod som gör så att man kan skriva ut lite text på en LCD? Det behöver inte vara några avancerade funktioner utan bara något som jag kan ha till en början så att jag i alla fall kan skriva ut lite text på båda raderna.
Det är en 2x20 teckendisplay med som styrs av HD44780.
Tack på förhand!Sv: Styra en HD44780-LCD
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
</code>