;******************************************************************** ;* Initialisierungstest fuer LCD-Anzeige ;* mit KS0066U-(ST7066)-kompatiblem Controllerchip ;* 4-Bit-Modus ;* Daten-/Steuerbits auf PORTB, Bit B4 bis B7 ;* Enableimpuls auf PORTB, Bit B0 ;* RS auf PORTB, Bit B1 ;* 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" mit Verschiebung nach ;* rechts ;* Taste2 gedrueckt => Ausgabe ab Zeile 2 Position 1 "12345" ;* Taste3 kurz gedrueckt und dann Taste 1 ;* betaetigt=>Ausgabe"TXET>-" ;* spiegelverkehrt,bzw. bei Taste2 Liste in umgekehrter ;* Reihenfolge ;* Taste3 laenger gedrueckt => Ausgabe "<=123" von rechts nach ;* links ;* voriger Text wird von unten rechts ueberschrieben ;* Taste4 => Cursor Position 1 und Reset Shift-Einstellung ;* erst Resettaste gedrueckt, dann Taste3 => alternativer Text ;* wird ;* von unten rechts nach oben links in umgekehrter Folge ;* geschrieben ;* ;* CPU Takt 4 MHz (Rev.4-260708) ;******************************************************************** ; .nolist .include "8535def.inc" .list .def temp = r16 .def temp1 = r17 .def zeit = r18 .def zeit1 = r19 .def zeit2 = r20 .def zeichen1 = r21 .equ daten = portb .equ impuls = portb .equ taste = pina .org 0x000 ;Stapelzeigerregister-Initialisierung ldi temp, low(ramend) out SPL, temp ldi temp, high(ramend) out SPH, temp ;Port-Initialisierung: PortB und PortD durch Laden von HexFF ;in Datenrichtungsregister auf 8-Bit-Breite als Ausgang ;setzen und interne Pullup-Widerstaende aktivieren ;PortA durch Laden von Hex00 in Datenrichtungsregister auf ;8-Bit-Breite als Eingang definieren ldi temp1, 0xFF out ddrb, temp1 ldi temp1, 0xFF out ddrd, temp1 ldi temp1, 0x00 out ddra, temp1 ;Einschaltverzoegerung rcall Verzoegerung2 rcall Verzoegerung2 rcall Verzoegerung2 nop ; Reset (Test: alle Ausgaenge auf "low") ldi temp, 0x00 out impuls, temp ;RS auf "low" Pinout PORTD ldi temp, 0x00 out daten, temp rcall enable nop rcall Verzoegerung ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;als Uebersprechen-Test auf Leitungen ; ;darf nicht stoeren - sonst keine Funktion ; Acht-Bit-Initialisierung ldi temp, 0x00 ;RS wieder auf "low" Pinout PORTD out impuls, temp ldi temp, 0x30 out daten, temp rcall enable rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS wieder auf "low" Pinout PORTD out impuls, temp ldi temp, 0x30 out daten, temp rcall enable rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS wieder auf "low" Pinout PORTD out impuls, temp ldi temp, 0x30 out daten, temp rcall enable rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;Acht-zu-Vier-Bit-Modus-Wechsel ldi temp, 0x00 ;RS wieder auf "low" Pinout PORTD out impuls, temp ldi temp, 0x20 out daten, temp rcall enable rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;Vier-Bit-Modus; zwei Zeilen, ab hier mit Nibbletauschen ldi temp, 0x00 ;RS wieder auf "low" Pinout PORTD out impuls, temp ldi temp, 0x28 ;Vier-Bit-Modus, zwei Zeilen, ; ;Standardpixelung rcall Kommando rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;On Off Control; Display einschalten: ldi temp, 0x00 ;RS wieder auf "low" Pinout PORTD out impuls, temp ldi temp, 0x08 ;Anzeige ausschalten rcall Kommando rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;Anzeige loeschen: ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ldi temp, 0x01 rcall Kommando rcall Verzoegerung2 nop rcall Verzoegerung2 nop ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;Entry/Shift Mode Set: ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ldi temp, 0x06 rcall Kommando rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ;RS auf "low" Pinout PORTD ldi temp, 0x00 out impuls, temp ;ldi temp, 0x10 ;Cursor/Display shift, Cursor nach rechts ;rcall Kommando rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ldi temp, 0x0E ;Anzeige und Cursor wieder einschalten rcall Kommando rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ldi temp, 0x01 ;Anzeige loeschen rcall Kommando rcall Verzoegerung2 nop rcall Verzoegerung2 ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp rjmp Schleife_End Schleife_End: ;Tastenabfragen, Tasten 1 bis 4 sbis taste, 0x00 rcall Schleife_1 nop sbis taste, 0x01 rcall Schleife_2 nop sbis taste, 0x02 rcall Schleife_3 nop sbis taste, 0x03 rcall Schleife_4 rjmp Schleife_End Schleife_1: ;Text-1-Ausgabe - Taste 1 rcall Verzoegerung2 ldi temp, 'T' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, 'E' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, 'X' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, 'T' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, '*' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, ' ' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, '-' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, 62 rcall Datenuebernahme rcall Verzoegerung2 ldi temp, ' ' rcall Datenuebernahme rcall Verzoegerung2 ret ;Schleife_End Schleife_2: ;Zeichenliste (Zahlen) - Taste 2 rcall Zeichen nop ret ;rjmp Schleife_End Schleife_3: ;Text-2-Ausgabe - Taste 3 ldi temp, 0x04 ;Entry Mode Set "Linksschieben" rcall Kommando rcall Verzoegerung2 ldi temp, 0x18 rcall Kommando rcall Verzoegerung2 ldi temp, '=' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, 60 rcall Datenuebernahme rcall Verzoegerung2 ldi temp, ' ' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, '3' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, '2' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, '1' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, ' ' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, '=' rcall Datenuebernahme rcall Verzoegerung2 ldi temp, 60 rcall Datenuebernahme rcall Verzoegerung2 ldi temp, ' ' rcall Datenuebernahme rcall Verzoegerung2 nop ret ;rjmp Schleife_End Schleife_4: ;Cursor home - Entry Mode Reset- Taste 4 rcall Verzoegerung ldi temp, 0x06 rcall Kommando rcall Verzoegerung2 ldi temp, 0x10 rcall Kommando rcall Verzoegerung2 ldi temp, 0x01 rcall Kommando rcall Verzoegerung2 nop ret ;rjmp Schleife_End Zeichen: ;Zeichenliste (Ziffern) generieren (Taste 2) ldi temp, 0xC0 ;Position Anfang Zeile 2 rcall Kommando ldi zeichen1, 0x31 ;Ziffer 1 mov temp, zeichen1 rcall Datenuebernahme nop rjmp Zeichen_1 Zeichen_1: ;Schleife zaehlt hoch bis Ziffer 5 inc zeichen1 mov temp, zeichen1 rcall Datenuebernahme cpi zeichen1, 0x35 brne Zeichen_1 ret 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 ;Ausgabe oberes Nibble auf D4-D7 ldi temp, 0x02 ;RS auf "high" Pinout PORTD out impuls, temp ;Funktion wie "sbi impuls, 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 ;Ausgabe unteres Nibble auf D4-D7 rcall enable rcall Verzoegerung ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ret Kommando: mov temp1, temp ;Kopie des Wertes fuer weitere; ; ;Operation unten andi temp, 0b11110000 ;unteres Nibble ausblenden out daten, temp ;Ausgabe oberes Nibble auf D4-D7 ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ;Funktion wie "cbi impuls, 1" rcall enable nop nop swap temp1 ;Nibble-Vertauschen, Wert aus temp; ; ;kopiert, siehe oben andi temp1, 0b11110000 ;unteres Nibble ausblenden out daten, temp1 ;Ausgabe unteres Nibble auf D4-D7 rcall enable rcall Verzoegerung ldi temp, 0x02 ;RS kurz auf "high" Pinout PORTD out impuls, temp ldi temp, 0x00 ;RS auf "low" Pinout PORTD out impuls, temp ret Enable: nop sbi impuls, 0 ;Enable auf "high" setzen nop ;Impulsdauer mindestens nop ;0,5 Mikrosekunden laut Datenblatt nop ;lieber ein paar "nops" mehr nop ;spendieren nop nop nop cbi impuls, 0 ;Enable auf "low" zurücksetzen nop ret Verzoegerung: ;2+[4x(255-1)+3]x[5x(2-1)]+7=1,276 ms bei 4 MHz ldi zeit, 0xFF ldi zeit1, 0x05 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(255-1)]+7= ms bei 4 MHz ldi zeit, 0xFF ldi zeit1, 0xFF Verzoegerungs_Schleife2: dec zeit cpi zeit, 1 brlt Verzoegerungs_Schleife2 ldi zeit, 0xFF dec zeit1 cpi zeit1, 1 brlt Verzoegerungs_Schleife2 ret Verzoegerung3: 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