Probleme mit der Lcd-ansteuerung
Hallo
ich hab ein Problem mit dem Display DISPLAYTECH 162B (2x16 Zeichen). Ich verwende einen PIC16F627A mit 4Mhz taktfrequenz. Den Code hab ich von einem sprutbeispiel abgeändert. Bei dem "PIC Simulator IDE" hab ich das ausprobiert, hat super geklappt. Nachdem ich die Firmware auf den Mikrocontroller übertragen hatte, hat er nur auf den 2-Zeilenmodus umgeschaltet, dann war schluss. Am Kontrast liegt es glaub ich nicht, aber wenn man den Kontrast voll aufdreht (Vo = Gnd), ist dann die Anzeige immer so schwach im 2-Zeilenmodus.
Hier ist der Code:
Code:
list p=16f627
;**************************************************************
;* Pinbelegung
;* ----------------------------------
;* PORTA: 0 -
;* 1 -
;* 2 -
;* 3 -
;* 4 -
;* PORTB: 0 LCD Display E
;* 1
;* 2 LCD Display RS
;* 3 LCD Display R/W
;* 4-7 LCD Display D4 .. D7
;**************************************************************
#include <P16f627.INC>
; Configuration festlegen
; bis 4 MHz: Power on Timer, kein Watchdog, XT-Oscillator
__CONFIG _PWRTE_ON & _WDT_OFF & _XT_OSC
;**************************************************************
; Variablen festlegen
w_copy Equ 0x20
s_copy Equ 0x21
LcdDaten Equ 0x22
LcdStatus Equ 0x23
loops EQU 0x24
loops2 EQU 0x25
; Constanten festlegen
PORTC equ PORTB ; LCD-Control-Port
PORTD equ PORTB ; LCD-Daten-Port
LcdE equ 0 ; enable Lcd
LcdRw equ 3 ; read Lcd
LcdRs equ 2 ; Daten Lcd (nicht control)
Ini_con Equ B'00000000' ; TMR0 -> Intetupt disable
Ini_opt Equ B'00000010' ; pull-up
;********************************************************
; Das Programm beginnt mit der Initialisierung
Init bsf STATUS, RP0 ; Bank 1
movlw Ini_opt ; pull-up on
movwf OPTION_REG
movlw B'00000000' ; RA0 .. RA2 outputs, RA3, RA4 input
movwf TRISA ;
movlw B'00000000' ; PortB alle outputs
movwf TRISB
bcf STATUS, RP0 ; Bank 0
clrf PORTA
clrf PORTB
bsf CMCON, CM0
bsf CMCON, CM1
bsf CMCON, CM2
movlw Ini_con ; Interupt disable
movwf INTCON
call InitLCD ; Display initialisieren
; am LCD "Hallo" ausgeben
movlw 'H'
movwf LcdDaten
call OutLcdDaten
movlw 'a'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'o'
movwf LcdDaten
call OutLcdDaten
movlw ','
movwf LcdDaten
call OutLcdDaten
movlw 'W'
movwf LcdDaten
call OutLcdDaten
movlw 'i'
movwf LcdDaten
call OutLcdDaten
movlw 'e'
movwf LcdDaten
call OutLcdDaten
movlw ' '
movwf LcdDaten
call OutLcdDaten
movlw 'g'
movwf LcdDaten
call OutLcdDaten
movlw 'e'
movwf LcdDaten
call OutLcdDaten
movlw 'h'
movwf LcdDaten
call OutLcdDaten
movlw 't'
movwf LcdDaten
call OutLcdDaten
movlw 's'
movwf LcdDaten
call OutLcdDaten
movlw '?'
movwf LcdDaten
call OutLcdDaten
movlw B'11000000'
call OutLcdControl
movlw 'g'
movwf LcdDaten
call OutLcdDaten
movlw 'u'
movwf LcdDaten
call OutLcdDaten
movlw 't'
movwf LcdDaten
call OutLcdDaten
movlw ' '
movwf LcdDaten
call OutLcdDaten
movlw 'o'
movwf LcdDaten
call OutLcdDaten
movlw 'd'
movwf LcdDaten
call OutLcdDaten
movlw 'e'
movwf LcdDaten
call OutLcdDaten
movlw 'r'
movwf LcdDaten
call OutLcdDaten
movlw ' '
movwf LcdDaten
call OutLcdDaten
movlw 's'
movwf LcdDaten
call OutLcdDaten
movlw 'c'
movwf LcdDaten
call OutLcdDaten
movlw 'h'
movwf LcdDaten
call OutLcdDaten
movlw 'l'
movwf LcdDaten
call OutLcdDaten
movlw 'e'
movwf LcdDaten
call OutLcdDaten
movlw 'c'
movwf LcdDaten
call OutLcdDaten
movlw 'h'
movwf LcdDaten
call OutLcdDaten
movlw 't'
movwf LcdDaten
call OutLcdDaten
sleep
Main
goto Main
;*****************************************************************
;Zeitverzögerung um loops * 1 ms
; 4MHz externer Takt bedeutet 1MHz interner Takt
; also dauert 1 ms genau 1000 Befehle
; 110 Schleifen a 9 Befehle sind 990 Befehle = 0.99 ms
; die restlichen 10 Befehle für Einsprung und Rücksprung
WAIT
top movlw .110 ; timing adjustment variable (1ms)
movwf loops2
top2 nop ; sit and wait
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 subWAIT
;**********************************************************
; Initialisierung des LCD-Displays
InitLCD
movlw D'255' ; 250 ms Pause nach dem Einschalten
movwf loops
call WAIT
movlw B'00110000' ; 1
movwf PORTB
bsf PORTB, LcdE
nop
bcf PORTB, LcdE
movlw D'50' ; 50 ms Pause
movwf loops
call WAIT
movlw B'00110000' ; 2
call Control8Bit
movlw B'00110000' ; 3
call Control8Bit
movlw B'00100000' ; 4
call Control8Bit
movlw B'00101000' ; 5 function set, 4-bit 2-zeilig, 5x7
call OutLcdControl
movlw B'00001111' ; 6 display off/on
call OutLcdControl
movlw B'00000001' ; Display clear
call OutLcdControl
movlw B'00000110' ; 7 entry mode, increment, disable display-shift
call OutLcdControl
return
; ein Steuerbyte 8-bittig übertragen
Control8Bit
movwf PORTB
bsf PORTB, LcdE
nop
bcf PORTB, LcdE
movlw D'10'
movwf loops
call WAIT
return
; darauf warten, daß das Display bereit zur Datenannahme ist
LcdBusy
bsf STATUS, RP0 ; make Port B4..7 input
movlw B'11110000'
movwf TRISB
bcf STATUS, RP0
BusyLoop
bcf PORTC, LcdRs
bsf PORTC, LcdRw ; Lesen
bsf PORTC, LcdE
nop
movf PORTD, 0
movwf LcdStatus
bcf PORTC, LcdE
nop
bsf PORTC, LcdE ; Enable
nop
bcf PORTC, LcdE
btfsc LcdStatus, 7 ; teste bit 7
goto BusyLoop
bcf PORTC, LcdRw
bsf STATUS, RP0 ; make Port B4..7 output
movlw B'00000000'
movwf TRISB
bcf STATUS, RP0
return
; ein Byte mit Steuerdaten von LcdDaten zum Display übertragen
OutLcdControl
movwf LcdDaten
call LcdBusy
movf LcdDaten, w
andlw H'F0'
movwf PORTD ; Hi-teil Daten schreiben
bsf PORTC, LcdE
nop
bcf PORTC, LcdE ; Disable LcdBus
swapf LcdDaten, w
andlw H'F0'
movwf PORTD ; Lo-teil Daten schreiben
bsf PORTC, LcdE
nop
bcf PORTC, LcdE ; Disable LcdBus
return
; ein Datenbyte von LCDDaten zum Display übertragen
OutLcdDaten
bsf PORTA, 2 ; Test LED 2 on
movwf LcdDaten
call LcdBusy
movf LcdDaten, w
andlw H'F0'
movwf PORTD ; Hi-teil Daten schreiben
bsf PORTC, LcdRs ; Daten
bsf PORTC, LcdE ; Enable LcdBus
nop
bcf PORTC, LcdE ; Disable LcdBus
swapf LcdDaten, w
andlw H'F0'
movwf PORTD ; Lo-teil Daten schreiben
bsf PORTC, LcdRs ; Daten
bsf PORTC, LcdE
nop
bcf PORTC, LcdE ; Disable LcdBus
bcf PORTC, LcdRs ;
bcf PORTA, 2 ; Test LED 2 on
return
end
Danke schon mal im voraus.
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
ich habe mal gekramt und ein nicht allzugroßes Programm mit dem 16F628 und zweizeiligem Display gefunden. Es liest den code einer Universalfernbedienung ein (RC5-Code) und stellt ihn im Display sowohl binär als auch hexadezimal dar. Durch die Zeitangaben im Programm nicht verwirren lassen, die beziehen sich auf 20MHz, der Controller läuft aber nur mit 4MHz, langsamer geht immer. Die Verzögerung ist auf grund meiner Stromversorgung nötig, grundsätzlich aber günstig.
Gruß,
Micheal
Liste der Anhänge anzeigen (Anzahl: 2)
Hallo,
ich hab den Pin auf Ausgang bei der Servosteuerung. Ich benutze übrigens nur den PIC16F627A. Hier sind die Codes für das Display und für das Servo.
Gruß,
Johann
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo,
ich habe mir mal das Programm für das Servo angesehen. Deine erste Warteschleife dauert nicht 1ms sondern 3,85ms, die zweite nicht 12ms sondern 61,5ms (bei 4MHz). Ein Servo braucht 1 bis 2ms (1,5ms für Mitte) und eine Periodendauer von ca. 20ms. Ich habe die Schleifen jetzt mal auf 1,2ms bzw. 18,5ms geändert. Brauchst du wirklich "Low Voltage Programm Enable"? Wenn dein Programmiergerät mit 13V arbeitet (am MCLR-Pin) ist das nicht nötig, ich habe es im config ausgeschalten. Das neue config lautet: XT-Oszillator, ohne Watchdog-Timer, Power-Up-Timer on, Low-Voltage-Programm off, MCLR on, Code-Protect off. Um das Ganze zum Laufen zu bringen brauchst du einen Wiederstand von Pin RA4 nach +5V (ca. 1kOhm sollte gehen). Außerdem muss der MCLR-Pin auf +5V gelegt werden. Falls du auf den Quarz verzichten möchtest und den internen 4MHz-Takt nutzen willst musst du bei config 3f32h (statt 3f21h) eintragen.
Gruß,
Michael