list p=16f84 errorlevel -302 ;unterdrückt Warnungen ;************************************************************** ;* Test definieren und Ausgabe eigener Zeichen ;* ;* PORTB: 0 Enable LCD ;* 1 ;* 2 RS 0=Steuerregister 1=Datenregister ;* 3 R/W 0=lesen 1=schreiben ;* 4-7 D4-D7 Datenbus zum LCD ;* ;************************************************************** ; ; Takt: 4 MHz ; ;************************************************************** include __config b'11111111110001' ;************************************************************** ; Variablen festlegen loops equ 0x0c loops1 equ 0x0d save equ 0x0e ;Sicherungsregister lcdstatus equ 0x0f ;STATUS LCD busy? lcddaten equ 0x10 ;Ausgabedaten für LCD HexZahl equ 0x11 ;Zählerinhalt für Umrechnung temp equ 0x16 ;diverse temp1 equ 0x17 tmpz equ 0x1a tmpz1 equ 0x1b org 0 goto initpic ;******************************************************** ; Initialisierung PIC initpic bcf status,rp0 clrf PORTA ;Initialisierung PortA bsf status,rp0 ;Bank1 movlw b'00000000' ;Ausgang movwf trisa bcf status,rp0 clrf portb bsf status,rp0 movlw 0x00 ;PortB Ausgänge movwf trisb bcf status,rp0 call initlcd ;LCD initialisieren ;************************************************************* ; eigenes Zeichen ins CGRAM schreiben, Adresse 0 (erstes Zeichen) movlw 0x40 ;Set GCRAM Adress call steuerout movlw 0x01 ;1.Byte vom eigenen Zeichen call datenout movlw 0x02 call datenout movlw 0x02 call datenout movlw 0x04 call datenout movlw 0x18 call datenout movlw 0x1f call datenout movlw 0x01 call datenout movlw 0x1f call datenout ;8.Byte, nun im LCD gespeichert ;**************************************************************** ; Hauptprogramm main movlw b'00000001' ;clear lcd call steuerout movlw 'H' ;zum Prüfen nur "Hallo " ausgeben call datenout movlw 'a' call datenout movlw 'l' call datenout movlw 'l' call datenout movlw 'o' call datenout movlw ' ' call datenout movlw '' call datenout sleep ;***************************************************************** ; Zeitverzögerung um loops * 1 ms ; 1 Befehl = 1µs. 1000 Befehle = 1ms wait wait1 movlw d'99' ;angepaßt, war 110 movwf loops1 wait2 nop nop nop nop nop nop nop decfsz loops1,f goto wait2 decfsz loops, F goto wait1 return ;***************************************************************** ; LCD Initialisieren ; initlcd movlw d'20' ;20ms warten movwf loops call wait movlw b'00110000' ;3?h ins Steuerregister call steuer8bit movlw d'5' ;5ms warten movwf loops call wait movlw b'00110000' ;3?h ins Steuerregister call steuer8bit movlw d'1' ;1ms warten movwf loops call wait movlw b'00110000' ;3?h ins Steuerregister call steuer8bit movlw d'5' ;5ms warten -> eigentlich statt dessen Busy abfragen movwf loops call wait movlw b'00100000' ;2?h ins Steuerregister call steuer8bit movlw d'1' ;1ms warten movwf loops call wait movlw b'00101000' ;SystemSet 4bit, 2zeilig, 5x7 call steuerout movlw b'00001000' ;LCD aus call steuerout movlw b'00000001' ;clear lcd call steuerout movlw b'00000010' ;Cursor home call steuerout movlw b'00000110' ;entry mode call steuerout movlw b'00001100' ;LCD an, Cursor - Unterstrich aus call steuerout return ;***************************************************************** ; Steuerbefehle zum Display übertragen steuer8bit movwf PORTB bsf PORTB,0 nop bcf PORTB,0 return ;**************************************************************** ; Steuerwort 4bittig übertragen steuerout call lcdbusy movwf lcddaten andlw h'f0' movwf PORTB bsf PORTB,0 nop bcf PORTB,0 swapf lcddaten,w andlw h'f0' movwf PORTB bsf PORTB,0 nop BCF PORTB,0 return ;**************************************************************** ; Datenwort 4bittig übertragen datenout call lcdbusy movwf lcddaten andlw h'f0' movwf PORTB bsf PORTB,2 bsf PORTB,0 nop bcf PORTB,0 swapf lcddaten,w andlw h'f0' movwf PORTB bsf PORTB,2 bsf PORTB,0 nop BCF PORTB,0 bcf PORTB,2 return ;**************************************************************** ; LCD Busy lcdbusy movwf save ;Akku sichern bsf STATUS,RP0 ;PortB7-4 Eingänge movlw h'f0' movwf TRISB bcf STATUS,RP0 bsf PORTB,3 ;LCD lesen busy1 bsf PORTB,0 ;LCD enable nop movf PORTB,w movwf lcdstatus bcf PORTB,0 nop ;Lesezyklus 2.te Hälfte vom Byte bsf PORTB,0 nop bcf PORTB,0 btfsc lcdstatus,7 goto busy1 bsf STATUS,RP0 ;PortB Ausgänge movlw h'00' movwf TRISB bcf STATUS,RP0 bcf PORTB,3 ;LCD schreiben movf save,w return end