;******************************************************************** ;* Initialisierungstest fuer LCD-Anzeige * ;* mit KS0066U-kompatiblem Controllerchip * ;* 4-Bit-Mode * ;* Daten-/Steuerbits auf PORTB, Bit D4 bis D7 * ;* Enableimpuls auf PORTD, Bit D0; (bzw. PORTB, hier ausgeremt) * ;* RS auf PORTD, Bit D1; (bzw. PORTB, hier ausgeremt) * ;* R/WQuer auf Masse fest verdrahtet * ;* nach Power-On => blinkender Cursor obere Zeile links * ;* nach Druecken auf Resettaste =>blinkender Cusor obere Zeile links* ;* Tasten auf PORTA: * ;* Taste1 gedrueckt => Ausgabe "TEXT*" * ;* Taste2 kurz gedrueckt und dann Taste 1 betaetigt=>Ausgabe "*TXET"* ;* spiegelverkehrt * ;* Taste2 laenger gedrueckt => Ausgabe "o&s" von rechts nach links * ;* voriger Text wird von unten rechts ueberschrieben * ;* Taste3 => Cursor Position 1 und Reset Shift-Einstellung * ;* erst Resettaste gedrueckt, dann Taste2 => alternativer Text wird * ;* von unten rechts nach oben links geschrieben * ;* * ;* CPU Takt 4 MHz (Rev.4-120708)* ;******************************************************************** ; .nolist .include "8515def.inc" .list .def temp = r16 .def temp1 = r17 .def zeit = r18 .def zeit1 = r19 .def zeit2 = r20 .equ daten = portb .equ impuls = portd ;.equ impuls1 = portb ;fuer RS und Enable Pinout PORTB .equ taste = pina .org 0x000 ;Stapelzeigerregister fuer Spruenge einrichten: ldi temp, low(ramend) out SPL, temp ldi temp, high(ramend) out SPH, temp ;Initialisierung; Datenrichtungsregister auf 8-Bit-Breite ;setzen und interne Pullup-Widerstaende aktivieren ldi temp1, 0xFF out ddrb, temp1 ldi temp1, 0xFF out ddrd, temp1 ldi temp1, 0x00 out ddra, temp1 ;PORTA als Eingaenge fuer Tastenabfrage rcall Verzoegerung3 ; Reset ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x00 out daten, temp rcall enable rcall Verzoegerung2 ; Acht-Bit Init ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x30 out daten, temp rcall enable rcall Verzoegerung2 ; Acht-zu-Vier-Bit-Modus Change ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x20 out daten, temp rcall enable rcall Verzoegerung ;Vier-Bit-Modus; zweizeilig: ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x2C rcall Kommando rcall Verzoegerung2 ; On Off Control; Display einschalten: ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x0F rcall Kommando rcall Verzoegerung2 ;Anzeige loeschen: ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x01 rcall Kommando rcall Verzoegerung2 ;Entry Mode Set: ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x06 rcall Kommando rcall Verzoegerung3 ; nochmals zweizeilig ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x2C rcall Kommando rcall Verzoegerung2 ;nochmals Entry Mode Set: ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ;out impuls1, temp ;RS auf "low" Pinout PORTB ldi temp, 0x06 ;"Rechtsschieben" rcall Kommando rcall Verzoegerung3 rjmp Schleife_End Schleife_End: ;Tastenabfragen sbis taste, 0x00 rjmp Schleife_1 sbis taste, 0x01 rjmp Schleife_2 sbis taste, 0x02 rjmp Schleife_3 rjmp Schleife_End Schleife_1: ;Text-1-Ausgabe - Taste 1 ldi temp, 'T' rcall Datenuebernahme rcall Verzoegerung ldi temp, 'E' rcall Datenuebernahme rcall Verzoegerung ldi temp, 'X' rcall Datenuebernahme rcall Verzoegerung ldi temp, 'T' rcall Datenuebernahme rcall Verzoegerung ldi temp, '*' rcall Datenuebernahme rcall Verzoegerung rjmp Schleife_End Schleife_2: ;Text-2-Ausgabe - Taste 2 rcall Verzoegerung ldi temp, 0x04 ;Entry Mode Set "Linksschieben" rcall Kommando rcall Verzoegerung3 ldi temp, 's' rcall Datenuebernahme rcall Verzoegerung3 ldi temp, '&' rcall Datenuebernahme rcall Verzoegerung3 ldi temp, 'o' rcall Datenuebernahme rcall Verzoegerung3 rjmp Schleife_End Schleife_3: ;Cursor home - Entry Mode Reset- Taste3 rcall Verzoegerung ldi temp, 0x06 rcall Kommando rcall Verzoegerung3 ldi temp, 0x01 rcall Kommando rcall Verzoegerung3 rjmp Schleife_End Datenuebernahme: mov temp1, temp ;Kopie des Wertes fuer weitere; ; ;Operation unten andi temp, 0b11110000 ;unteres Nibble ausblenden ori temp, 0b00000010 ;RS auf "high" maskieren(Pinout PORTB) out daten, temp ;oberes Nibble, Bit4 bis 7 ausgeben ldi temp, 0x02 ;RS auf "high" Pinout PORTD out impuls, temp ;Funktion wie "sbi impuls, 1" ;out impuls1, temp ;RS auf "high" Pinout PORTB ; ;Funktion wie "sbi impuls1, 1" rcall enable nop nop swap temp1 ;Nibble-Vertauschen, Wert aus temp; ; ;kopiert, s.o. andi temp1, 0b11110000 ;unteres Nibble ausblenden ori temp1, 0b00000010 ;RS auf "high" maskieren(Pinout PORTB) out daten, temp1 ;unteres, jetzt verschobenes Nibble; ; ;aus temp1, Bit4 bis Bit7 ausgeben rcall enable clr temp clr temp1 rcall Verzoegerung ret Kommando: mov temp1, temp ;Kopie des Wertes fuer weitere; ; ;Operation unten andi temp, 0b11110000 ;unteres Nibble ausblenden out daten, temp ;oberes Nibble, Bit4 bis 7 ausgeben ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ;Funktion wie "cbi impuls, 1" ;out impuls1, temp ;RS auf "low" Pinout PORTB ; ;Funktion wie "cbi impuls1, 1" rcall enable nop nop swap temp1 ;Nibble-Vertauschen, Wert aus temp; ; ;kopiert, siehe oben andi temp1, 0b11110000 ;unteres Nibble ausblenden out daten, temp1 ;unteres, jetzt verschobenes Nibble; ; ;aus temp1, Bit4 bis Bit7 ausgeben rcall enable clr temp clr temp1 rcall Verzoegerung ret Enable: nop sbi impuls, 0 ;Enable auf "high" setzen ;sbi impuls1, 0 ;bei Pinout PORTB nop ;Zeitverzoegerung mindestens nop ;1000 Nanosekunden laut Datenblatt nop ;lieber ein paar "nops" mehr nop ;spendieren nop nop nop cbi impuls, 0 ;Enable auf "low" zurücksetzen ;cbi impuls1, 0 ;bei Pinout PORTB nop ret Verzoegerung: ;2+[4x(255-1)+3]x[5x(2-1)]+7=1,276 ms bei 4 MHz ldi zeit, 0xFF ldi zeit1, 0x02 Verzoegerungs_Schleife: dec zeit cpi zeit, 1 brlt Verzoegerungs_Schleife ldi zeit, 0xFF dec zeit1 cpi zeit1, 1 brlt Verzoegerungs_Schleife ret Verzoegerung2: ;2+[4x(255-1)+3]x[5x(32-1)]+7= 39,49 ms bei 4 MHz ldi zeit, 0xFF ldi zeit1, 0x20 Verzoegerungs_Schleife2: dec zeit cpi zeit, 1 brlt Verzoegerungs_Schleife2 ldi zeit, 0xFF dec zeit1 cpi zeit1, 1 brlt Verzoegerungs_Schleife2 ret Verzoegerung3: ; aehhm... muss noch genauer ausrechnen ldi zeit, 0xFF ldi zeit1, 0xFF ldi zeit2, 0xA0 Verzoegerungs_Schleife3: dec zeit cpi zeit, 1 brlt Verzoegerungs_Schleife3 ldi zeit, 0xFF dec zeit1 cpi zeit1, 1 brlt Verzoegerungs_Schleife3 dec zeit2 cpi zeit2, 1 brlt Verzoegerungs_Schleife3 ret