Gast
#1388132
Hallo, ich möchte ein 1x16 Display (2x8) zweizeilig beschreiben. Das Display ist von reichelt (http://www.reichelt.de/?;ACTION=3;LA=2;GROUP=A5211;GROUPID=3005;ARTICLE=10945;START=0;SORT=artnr;OFFSET=16;SID=285LwJH6wQARwAAAQoaygd6117d70754e93fcbe1250a8de99b8ad). Ich weiss nur nicht wo ich den Befehl zur Ansteuerung genau einbinden soll. Auf jeden Fall muss die Adresse 0x40 angesprochen werden um den Zeilenwechsel zu ermöglichen. Das Display wurde bei der Initialisierung 2 zeilig initialisiert. Kann mir jemand helfen? Gruß Kay Hier das Programm: ;*********************************************************************** ;Ansteuerung eines LCD Displays ;PIC 16F628 ;Takt 4MHz ;Kay ;06.08.09 ;*********************************************************************** ;Pinbelegung des PIC**************************************************** ;*********************************************************************** ; PortB,0 -> Enable ; PortB,1 -> not connected ; PortB,2 -> RS (Register Select) ; PortB,3 -> RW (Read / Write) ; PortB,4 -> D4 (Datenbus 4 bittig) ; PortB,5 -> D5 (Datenbus 4 bittig) ; PortB,6 -> D6 (Datenbus 4 bittig) ; PortB,7 -> D7 (Datenbus 4 bittig) ; ; RS = 1 -> Daten des Datenbusses werden als Zeichen in den Textpuffer übertragen ; RS = 0 -> Daten des Datenbusses werden als Befehl in der Steuerregister geschrieben ; ; RW = 1 -> Lesefunktion ; RW = 0 -> Schreibfunktion ;*********************************************************************** ;Varablen vereinbaren*************************************************** ;*********************************************************************** loops equ 0x20 ; timer für wait loops2 equ 0x21 ; timer für wait loops3 equ 0x22 loops4 equ 0x23 loops5 equ 0x24 LcdStatus equ 0x25 ; LcdDaten equ 0x26 ; ;LcdE equ PortB,0 ; enable Lcd ;LcdRw equ PORTB,3 ; read/write Lcd ;LcdRs equ PORTB,2 ; Daten Lcd (nicht control) ;*********************************************************************** ;Programm starten******************************************************* ;*********************************************************************** org 0x00 goto Init ;*********************************************************************** ;Initialisierung des PIC************************************************ ;*********************************************************************** Init bsf status,rp0 ; select Bank1 movlw B'00000010' ; Pull up resistors activ movwf option_reg movlw B'11111111' ; PortA all input movwf trisa movlw B'00000000' ; PortB all output movwf trisb bcf status,rp0 ; select Bank0 movlw B'00000000' ; Interrupt disable movwf Intcon ;*********************************************************************** ;Hauptprogramm********************************************************** ;*********************************************************************** Main call InitLcd Out movlw 'G' movwf LcdDaten call OutLcdDaten movlw 'u' movwf LcdDaten call OutLcdDaten movlw 't' movwf LcdDaten call OutLcdDaten movlw 'e' movwf LcdDaten call OutLcdDaten movlw 'n' movwf LcdDaten call OutLcdDaten movlw ' ' movwf LcdDaten call OutLcdDaten movlw 'T' movwf LcdDaten call OutLcdDaten movlw 'a' movwf LcdDaten call OutLcdDaten ; 8 Zeichen fertig ; ACHTUNG ; Einfuegen eines Zeilenwechsels beim 2x8-Display call OutLcdControl movlw 'g' movwf LcdDaten call OutLcdDaten ;*********************************************************************** ;LCD initialisieren***************************************************** ;*********************************************************************** InitLcd movlw D'150' ; Delay after Vdd rises to 4,5V movwf loops call Wait bcf PortB,0 ; defined status for enable bit bcf PortB,2 ; RS = 0 -> instruction signal bcf PortB,3 ; RW = 0 -> write mode movlw B'00110000' ; InitLcd step 1: 8 bit interface call Transmit ; transfer 8 bit instruction signal movlw B'00110000' ; InitLcd step 2: 8 bit interface call Transmit ; transfer 8 bit instruction signal movlw B'00110000' ; InitLcd step 3: 8 bit interface call Transmit ; transfer 8 bit instruction signal movlw B'00100000' ; InitLcd step 4: 4 bit interface call Transmit ; transfer 8 bit instruction signal call LcdBusy ; Lcd busy? If Lcd busy, busy flag is high (PortB,7) movlw B'00000001' ; clear und cusor home call OutLcdControl movlw B'00101000' ; function set, 4-bit 2-zeilig, 5x7 call OutLcdControl movlw B'00001000' ; display off call OutLcdControl movlw B'00000110' ; entry mode, increment, disable display-shift call OutLcdControl ;movlw B'00000011' ; cursor home, cursor home ;call OutLcdControl movlw B'00001100' ; display on, cursor off, cursor flash off call OutLcdControl ;*********************************************************************** ;Transfer 8 bit intruction signal*************************************** ;*********************************************************************** Transmit movwf PortB ; Data to Databus bsf PortB,0 ; enable Chip signal nop ; wait bcf PortB,0 ; disable Chip signal movlw D'50' ; Delay of 50ms movwf loops call Wait return ;*********************************************************************** ;LCD busy at the moment?************************************************ ;*********************************************************************** LcdBusy bsf STATUS, RP0 ; make Port B4..7 input movlw B'11110000' iorwf TRISB, f bcf STATUS, RP0 BusyLoop bcf PortB,2 bsf PortB,3 ; Lesen bsf PortB,0 nop movf PortB, w movwf LcdStatus bcf PortB,0 nop bsf PortB,0 ; Enable nop bcf PortB,0 btfsc LcdStatus, 7 ; teste bit 7 goto BusyLoop bcf PortB,3 bsf STATUS, RP0 ; make Port B4..7 output movlw B'00001111' andwf TRISB, f bcf STATUS, RP0 return ;******************************************************************** ;aus W ein Byte mit Steuerdaten zum Display übertragen*************** ;******************************************************************** OutLcdControl movwf PortB call LcdBusy movf LcdDaten, w andlw H'F0' movwf PortB ; Hi-teil Daten schreiben bsf PortB,0 nop bcf PortB,0 ; Disable LcdBus swapf LcdDaten, w andlw H'F0' movwf PortB ; Lo-teil Daten schreiben bsf PortB,0 nop bcf PortB,0 ; Disable LcdBus return ;******************************************************************* ;aus W ein Datenbyte zum Display übertragen************************* ;******************************************************************* OutLcdDaten movwf LcdDaten call LcdBusy movf LcdDaten, w andlw H'F0' movwf PortB ; Hi-teil Daten schreiben bsf PortB,2 ; Daten bsf PortB,0 ; Enable LcdBus nop bcf PortB,0 ; Disable LcdBus swapf LcdDaten, w andlw H'F0' movwf PortB ; Lo-teil Daten schreiben bsf PortB,2 ; Daten bsf PortB,0 nop bcf PortB,0 ; Disable LcdBus bcf PortB,2 ; return ;******************************************************************* ;Subroutines******************************************************** ;******************************************************************* ;Zeitverzögerung um loops * 1 ms ; 4 MHz externer Takt bedeutet 1 MHz interner Takt ; also dauert 1 ms genau 1000 Befehle ; 100 Schleifen a 10 Befehle sind 1000 Befehle = 1 ms WAIT top movlw D'100' ; timing adjustment variable (1ms) movwf loops2 top2 nop ; sit and wait nop nop nop nop nop nop decfsz loops2, F ; inner loops complete? goto top2 ; no, go again decfsz loops, F ; outer loops complete? goto top ; no, go again retlw 0 ; yes, return from WAIT