Lcd4-Klasse
Die Lcd4-Klasse ist ein voll funktionstüchtiges Beispiel zur Anwendung von Klassen in Luna. Sie dient der Ansteuerung von 2x16 Lcd-Displays mit HD44780/KS0070-kompatiblem Controller im 4Bit-Modus.
Funktionsumfang
Möglich sind mit dieser Klasse:
- Lcd Power on/off
- Text und Zeichen an beliebige Position schreiben
- Cursor sichtbar/unsichtbar
- Darstellung selbst erstellter Zeichen
Folgende Funktionen sind implementiert:
- PowerOn()
- PowerOff()
- Cls()
- CursorOn()
- CursorOff()
- CursorBlinkOn()
- CursorBlinkOff()
- CursorHome()
- CursorPos(row,column)
- CursorRight()
- CursorLeft()
- ShiftRight()
- ShiftLeft()
- Char(value)
- Text(txt, row, column)
- SetChar(char,charNum)
Source
- Die Lcd4-Klasse ist im Grunde obsolet, da ein Lcd4-Interface bereits als Library verfügbar ist. Sie dient der Veranschaulichung der Ansteuerung bzw. zur alternativen Ansteuerung. Die neueste Version ist immer in den Examples des LunaAVR-Archivs zu finden.
Anwendung
Zur Implementation in den eigenen SourceCode wird die Klasse einfach mittels Include am Ende des eigenen Programms eingebunden. Anschließend sind nur noch die entsprechenden Port-Pins zu definieren, an die man das Display angeschlossen hat und die Init()-Funktion der Klasse aufzurufen.
Beispiel
avr.device = atmega168 avr.clock = 20000000 avr.stack = 96 '----------------------------------------------------------- ' connect a HD44780 / KS0070 compatible 2x16 display ' and setup the pins you want to use '----------------------------------------------------------- #define Lcd4PinRS as portd.2 #define Lcd4PinRW as portd.3 #define Lcd4PinE as portd.4 ' do not connect the D0-D3 pins of Lcd #define Lcd4PinD4 as portc.0 #define Lcd4PinD5 as portc.1 #define Lcd4PinD6 as portc.2 #define Lcd4PinD7 as portc.3 '----------------------------------------------------------- ' this pin is to switch the power supply of your lcd on/off ' comment it out (also in the class init routine) if not used ' see lcd4.Init()-Routine in lcd4class.luna for further details #define Lcd4PinPower as portb.0 '----------------------------------------------------------- ' ********************************************************** ' the demo using this class ' ********************************************************** dim i,pos,a as byte dim s as string s="Lcd4 class demo!" Lcd4.Init() ' set own designed character (replaces ascii 0) Lcd4.SetChar(mychar.Addr,0) for pos=1 to len(s) for i=16 downto pos Lcd4.CursorPos(1,i) Lcd4.Char(s.ByteValue(pos)) waitms 20 next next wait 1 ' shifts the display complete out (right side) of visible screen for i=1 to 16 Lcd4.ShiftRight() waitms 35 next ' write to the non-visible screen Lcd4.Text(" Hallo Welt ",1,1) Lcd4.Text(chr(0)+"Tolle Sache!"+chr(0),2,2) ' shift display screen back for i=1 to 16 Lcd4.ShiftLeft() waitms 35 next ' enables the blinking cursor Lcd4.CursorBlinkOn() Do Loop #include "class\lcd4.luna" ' created with the Lcd char editor in LunaAVR (IDE) data myChar .db &b00000 .db &b01010 .db &b00000 .db &b00100 .db &b10001 .db &b01110 .db &b00000 .db &b00000 enddata