Hallo, wo muss ich bei einem 16x1 LCD Display den Befehl movlw H'40' zum
Zeilenwechsel einbinden?
Hier das Programm:
;***********************************************************************
;Ansteuerung eines LCD Displays
;PIC 16F628
;Takt 4MHz
;
;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
; die folgenden 2 Zeilen nur bei einem 1-Zeiligen Display 1x16 (intern
2x8 organisiert)
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
;Zeitverzögerung
;100 Schleifen a 10 Befehle sind 1000 Befehle = 1 ms
;1 ms x 100 Schleifen = 100 ms
;100ms x 10 = 2000 ms = 1 sek
Delay
;*******
top3 movlw D'10'
movwf loops3
;*******
top4 movlw D'100'
movwf loops4
;*******
top5 movlw D'100'
movwf loops5
;*******
top6 nop
nop
nop
nop ; die Schleife top6 wird mit 10 Befehlen 100x durchlaufen
-> 1 ms
nop
nop
nop
decfsz loops5,f
goto top6
;*******
decfsz loops4,f ; wurde die Schleife top6 100x durchlaufen, gehe
zu top5 -> 100 x 1 ms
goto top5
;*******
decfsz loops3,f ; wurde die schleife 10 x für 100 ms
durchlaufen?
goto top4 ; nein
retlw 0 ; ja
;********************************************************************