;LCD-Control Includefile ; LCDInit: Initialisiert das Display (Immer als Erstes aufrufen.) ; rcall LCDInit ; LCDClear: Löscht Anzeige ; rcall LCDClear ; LCDHome: Setzt Cursor auf Links oben. ; rcall LCDHome ; LCDLocate: Setzt die neue Schreibposition ; ldi R16, Zeile ;1-4 ; ldi R17, Spalte ; 0-40 ; rcall LCDLocate ; LCDByte: Wert wird zweistellig als Hexadezimalzahl dargestellt ; ldi R16, Wert ; rcall LCDByte ; LCDWrite: Schreibt ASCII-Zeichen an die aktuelle Position ; ldi R16, ASCIIWert ; rcall LCDWrite ; LCDString: Schreibt Nullterminierten String and die aktuelle Position ; LDI ZL,LOW(Text2) ; Registerpaar Z zeigt auf das ; LDI ZH,HIGH(Text2) ; erste Byte iim String. ; rcall LCDString ; Der String sollte so aussehen: ; Text: ;Label ; .db "Text",0x00 ;Nullterminated Text ; .equ Text2=Text*2 ; Umwandlung Word nach ByteAdresse ; Displayanschluss: ; P0 = D4; P1 = D5; P2 = D6; P3 = D7; P4 = E; P5 = RS; RW = GND .cseg .equ LCDSpeed=32 ; 8 = 1MHz; 16 = 2MHz; 32 = 4MHz; 64 = 8MHz; 128 = 16MHz; 160 = 20MHz .equ LCDPort = PORTB ; Verwendeten Port eintragen, ; Im Hauptprogramm Bit 0-5 dieses Ports als Ausgang setzen. ;---------------------------------------------- LCDInit: rcall LCDDelay100 rcall LCDDelay100 ldi R16, 0x03 ;Erstinit out LCDPort, R16 rcall LCDDelay sbi LCDPort, 4 nop nop nop cbi LCDPort, 4 rcall LCDDelay100 sbi LCDPort, 4 nop nop nop cbi LCDPort, 4 rcall LCDDelay sbi LCDPort, 4 nop nop nop cbi LCDPort, 4 rcall LCDDelay20 ldi R16, 0x02 ;Setze 4-Bit out LCDPort, R16 rcall LCDDelay sbi LCDPort, 4 nop nop nop cbi LCDPort, 4 rcall LCDDelay ldi R16, 0x28 ;Function Set, 0x20 für einzeilige Displays, 0x28 für mehrzeilige Displays. rcall LCDOut ldi R16,0x08 ;Display off rcall LCDOut ldi R16,0x0c ;Display on rcall LCDOut ldi R16,0x06 ;Set Entrymode rcall LCDOut ldi R16,0x14 ;Cursor/Display Shift rcall LCDOut ret ;---------------------------------------------- LCDWrite: push R16 swap R16 andi R16, 0x0f ori R16, 0x20 out LCDPort, R16 nop nop nop nop sbi LCDPort, 4 nop nop nop nop nop nop cbi LCDPort, 4 rcall LCDDelay pop R16 andi R16, 0x0f ori R16, 0x20 out LCDPort, R16 nop nop nop nop sbi LCDPort, 4 nop nop nop nop nop nop cbi LCDPort, 4 rcall LCDDelay ret ;---------------------------------------------- LCDHome: push R16 ldi R16,0x02 ;Cursor home rcall LCDOut rcall LCDDelay20 ldi R16, 0x80 rcall LCDOut pop R16 ret ;---------------------------------------------- LCDClear: push R16 ldi R16,0x01 ;LCD Clear rcall LCDOut rcall LCDDelay20 ldi R16, 0x80 rcall LCDOut pop R16 ret ;---------------------------------------------- LCDString: push R16 LCDString1: lpm R16, Z+ cpi R16, 0 breq LCDString_Ende rcall LCDWrite rjmp LCDString1 LCDString_Ende: pop R16 ret ;---------------------------------------------- LCDByte: push R17 push R16 andi R16, 0xf0 ;unteres nibble weg swap R16 ;oberes nibble nach unten cpi R16, 0x0a ;Grösser 9? brlo LCDByte1 ldi R17, 7 add R16, R17 LCDByte1: ldi R17, 0x30 add R16, R17 rcall LCDWrite pop R16 andi R16, 0x0f ;oberes nibble weg cpi R16, 0x0a ;Grösser 9? brlo LCDByte2 ldi R17, 7 add R16, R17 LCDByte2: ldi R17, 0x30 add R16, R17 rcall LCDWrite pop R17 ret ;---------------------------------------------- LCDLocate: cpi R16, 1 brne LCDLocate1 ldi R16, 0x80 rjmp LCDLocate_Done LCDLocate1: cpi R16, 2 brne LCDLocate2 ldi R16, 0xc0 rjmp LCDLocate_Done LCDLocate2: cpi R16, 3 brne LCDLocate3 ldi R16, 0x94 rjmp LCDLocate_Done LCDLocate3: ldi R16, 0xd4 LCDLocate_Done: add R16, R17 rcall LCDOut ret ;---------------------------------------------- LCDOut: push R16 andi R16, 0xf0 swap R16 out LCDPort, R16 nop nop nop nop sbi LCDPort, 4 nop nop nop nop nop nop cbi LCDPort, 4 rcall LCDDelay pop R16 andi R16, 0x0f out LCDPort, R16 nop nop nop nop sbi LCDPort, 4 nop nop nop nop nop nop cbi LCDPort, 4 rcall LCDDelay ret LCDDelay: push R16 ;Warteschleife ldi R16, LCDSpeed ;255 Durchläufe LCDDelay_Again: dec R16 ;Durchläufe -1 nop ;Bremse nop nop nop tst R16 brne LCDDelay_Again ;Abgelaufen? Dann raus pop R16 ret LCDDelay20: push R16 ldi R16, 32 LCDDelay20_A: rcall LCDDelay dec R16 cpi R16, 0 brne LCDDelay20_A pop R16 ret LCDDelay100: push R16 ldi R16, 160 LCDDelay100_A: rcall LCDDelay dec R16 cpi R16, 0 brne LCDDelay100_A pop R16 ret