list p=16c84 ;************************************************************** ;* Wort auf LCD ausgeben ;* ;* ;* PORTB: 0 Enable LCD ;* 1 ;* 2 RS ;0=Steuerregister 1=Datenregister ;* 3 R/W ;0=lesen 1=schreiben ;* 4-7 D4-D7 ;* ;************************************************************** ; ; Takt: 4 MHz ; ;************************************************************** #include __CONFIG _PWRTE_ON & _WDT_OFF & _XT_OSC ;************************************************************** ; Variablen festlegen loops Equ 0x20 loops1 equ 0x21 save equ 0x23 lcdstatus equ 0x24 lcddaten equ 0x25 ;******************************************************** ; Initialisierung PIC initpic BSF STATUS,RP0 ;Umschalten Bank 1 movlw b'00000000' MOVWF TRISB ;Port B Ausgänge BCF STATUS,RP0 ;Bank 0 clrf PORTB movlw b'00000000' ;disable Interrupt movwf INTCON call initlcd main movlw 'D' call datenout movlw 'a' call datenout movlw 's' call datenout movlw ' ' call datenout movlw 'i' call datenout movlw 's' call datenout movlw 't' call datenout movlw h'040' ;2te Zeile call steuerout movlw 'e' call datenout movlw 'i' call datenout movlw 'n' call datenout movlw ' ' call datenout movlw 'T' call datenout movlw 'e' call datenout movlw 's' call datenout movlw 't' call datenout sleep ;***************************************************************** ;* 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'1' ;1ms 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'00001111' ;LCD an, Cursor blint, Unterstrich ein call steuerout return ;***************************************************************** steuer8bit movwf PORTB bsf PORTB,0 nop bcf PORTB,0 return ;***************************************************************** ; Zeitverzögerung um loops * 1 ms ; 1 Befehl = 1µs. 1000 Befehle = 1ms wait wait1 movlw d'110' movwf loops1 wait2 nop nop nop nop nop nop nop decfsz loops1,f goto wait2 decfsz loops, F goto wait1 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 ;neu hinzugekommen der bsf PORTB,0 ;2te Lesezyklus 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