Hallo. Hab Probleme mein LCD anzusteuern. Habe diesen code vom Herrn Sprut und habe ihn soweit auf mein Board umgeschrieben. Bin ihn paar mal durchgegangen und finde keinen Fehler. MPLAB akzeptiert ihn jedenfalls, aber mein Board nicht. Wäre sehr dankbar wenn jemand mal einen Blick darauf werfen würde. Vielen dank im vorraus.
Code:list p=18f8520 ;der Prozessortyp wird festgelegt include "p18f8520.inc" ;PIN-Belegung ;************************************************************************************* ; ; PORTJ: RJ2 - Register select (RS) ; RJ3 - Read and Write (R/W not) ; RJ4 - Enable (E) ; ; PORTH: RH0 - D0 ; RH1 - D1 ; . ; . ; RH7 - D7 ;************************************************************************************* ;Configuration bits CONFIG OSC = HS ; HS 20 MHz CONFIG PWRT = ON ; power up timer on CONFIG BOR = OFF ; brown out detect off CONFIG WDT = Off ; watchdog off CONFIG LVP = OFF ; lvp off ;************************************************************************************* ; Variablen festlegen LcdDaten EQU 0x20 LcdStatus EQU 0x23 loops EQU 0x24 loops2 EQU 0x25 ; PIC wird initialisiert org 0x0002C goto Init Init clrf TRISA ; alle PINs als output gesetzt clrf PORTA ; alle PINs auf low ziehen clrf TRISH ; alle PINs als output gesetzt clrf PORTH ; alle PINs auf low ziehen clrf TRISJ ; alle PINs als output gesetzt clrf PORTJ ; alle PINs auf low ziehen call InitLCD ; springe zur LCD Initialisierung ; am LCD "Hallo" ausgeben movlw B'01001000' ; 'H' in Bitweise 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 sleep ;***************************************************************** ;Zeitverzögerung um loops * 1 ms ; 10MHz externer Takt bedeutet 2,5MHz interner Takt ; also dauert 1 ms genau 2500 Befehle ; 249 Schleifen a 10 Befehle sind 996 Befehle = 0.996 ms ; die restlichen 25 Befehle für Einsprung und Rücksprung WAIT top movlw .249 ; 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 bcf PORTJ, 2 bcf PORTJ, 3 bsf PORTJ, 4 ; Enable low -> high nop bcf PORTJ, 4 ; Enable high -> low movlw D'50' ; 50 ms Pause movwf loops call WAIT movlw B'00110000' ; 1 call Control8Bit movlw B'00110000' ; 2 call Control8Bit movlw B'00110000' ; 3 call Control8Bit movlw B'00000001' ; 4 löschen und cusor home call OutLcdControl movlw B'00111000' ; 5 function set, 8-bit 2-zeilig, 5x8 call OutLcdControl movlw B'00001000' ; 6 display off call OutLcdControl movlw B'00000110' ; 7 entry mode, increment, disabldisplay-shift call OutLcdControl movlw B'00000011' ; 8 cursor home call OutLcdControl movlw B'00001011' ; 9 display on call OutLcdControl return Control8Bit movwf PORTH bsf PORTJ, 4 nop bcf PORTJ, 4 movlw D'10' movwf loops call WAIT return ; darauf warten, daß das Display bereit zur Datenannahme ist LcdBusy bsf PORTA, 1 ; Test LED 1 on movlw B'11111111' ; alle PINs inputs movwf TRISH BusyLoop bcf PORTJ, 2 ; Steuerregister bsf PORTJ, 3 ; lesen bsf PORTJ, 4 ; Enable nop movf PORTH, w movwf LcdStatus bcf PORTJ, 4 ; Disable btfsc LcdStatus, 7 ; teste bit 7 goto BusyLoop bcf PORTJ, 3 clrf TRISH bcf PORTA, 1 ; Test LED 1 off return ; ein Byte mit Steuerdaten von LcdDaten zum Display übertragen OutLcdControl movwf LcdDaten call LcdBusy movf LcdDaten, w movwf PORTH bsf PORTJ, 4 ;Enable nop bcf PORTJ, 4 ; Disable LcdBus return ; ein Datenbyte von LCDDaten zum Display übertragen OutLcdDaten bsf PORTA, 2 ; Test LED 2 on call LcdBusy movf LcdDaten, w movwf PORTH bsf PORTJ, 2 ; Daten bsf PORTJ, 4 ; Enable LcdBus nop bcf PORTJ, 4 ;Disable bcf PORTJ, 2 bcf PORTA, 2 ; Test LED 2 on return end







Zitieren

Lesezeichen