Im folgenden ein kleines Demoprogramm, das zeigt wie man ein LCD-Display mit KS070B Controller an einer PicAxe 14M2 betreibt. Das Display entspricht dem „LCD 162C“, das z.B. von der Firma Reichelt vertrieben wird. Das Programm ist weitgehend selbsterklärend und dürfte auch von Einsteigern verstanden werden.
'PicAxe LCD-DEMO
'***************************************
'PicAxe-Typ : 14M2
'LCD-Modul : LCD 162C (KS070B Controller)
'Beschreibung : Das LCD-Display wird im 4-Bit Modus betrieben.
' Nach der Initialisierung werden zwei Textzeilen
' auf dem Display ausgegeben
'Variablen
symbol bvLcdDatas = b1
symbol bvCursorPos = b2
symbol bvTextIndex = b3
symbol bvTextLen = b4
symbol bvTmp1 = b5
symbol bvTmp2 = b6
; I/O Pins:
; pinRS -> C.0 -> Pin 07 (RS von LCD)
; pinE -> C.1 -> Pin 06 (E von LCD)
; pinDB7 -> B.3 -> Pin 10 (Data von LCD)
; pinDB6 -> B.2 -> Pin 11 (Data von LCD)
; pinDB5 -> B.1 -> Pin 12 (Data von LCD)
; pinDB4 -> B.0 -> Pin 13 (Data von LCD)
symbol pinE = C.1
symbol pinRS = C.0
symbol pinTemp1 = B.4
symbol pinTemp2 = B.5
;Strings für Textausgabe
EEPROM 0, ("Text 1")
EEPROM 6, ("Text 2")
dirsB = %001111
; -----------------------------------------------------
; Start Hauptprogramm
; -----------------------------------------------------
Main:
call InitLCD
; Text "Text 1" in Zeile 1 ausgeben
bvCursorPos = 128
call SetCursorPos
bvTextIndex = 0
bvTextLen = 6
call WriteText2Lcd
; Text "Text 2" in Zeile 2 ausgeben
bvCursorPos = 192
call SetCursorPos
bvTextIndex = 8
bvTextLen = 8
call WriteText2Lcd
Ende:
goto Ende
; -----------------------------------------------------
; Unterprogramme
; -----------------------------------------------------
WriteText2Lcd:
bvTmp2 = bvTextIndex + bvTextLen - 1
for bvTmp1 = bvTextIndex to bvTmp2
read bvTmp1, bvLcdDatas
call WriteDatas2LCD
next bvTmp1
return
SetCursorPos:
'128 (0x80) = Z1S1, 129 (0x81) = Z1S2, .... 146 (0x92) = Z1S19, 147 (0x93) = Z1S20 (Rest = Buffer)
'192 (0xC0) = Z2S1, 193 (0xC1) = Z2S2, .... 210 (0xD2) = Z2S19, 211 (0xD3) = Z2S20 (Rest = Buffer)
bvLcdDatas = bvCursorPos
call WriteCmd2LCD
return
WriteDatas2LCD:
high pinRS
call WriteToLCD
return
WriteCmd2LCD:
low pinRS
call WriteToLCD
return
WriteToLCD:
;High-Nibble übertragen
pinsB = bvLcdDatas and 240 / 16
pulsout pinE, 1
;Low-Nibble übertragen
pinsB = bvLcdDatas and 15
pulsout pinE, 1
return
InitLCD:
low pinRS
pause 10 ; LCD braucht min. 10ms zum starten
pinsB = $03
pulsout pinE, 1 : pause 5
pulsout pinE, 1 : pauseus 100
pulsout pinE, 1
pinsB = $02 : pulsout pinE, 1
bvLcdDatas = $28 : call WriteCmd2LCD ; 4 Bit I/O, 2 Zeilen LCD, 5 x 7 dots
bvLcdDatas = $0C : call WriteCmd2LCD ; Display On
bvLcdDatas = $01 : call WriteCmd2LCD ; Clear Display
bvLcdDatas = $06 : call WriteCmd2LCD ; Entry Mode = Increment/No Display Shift
return