Ik heb volgende code ontwikkeld met een PIC16F628 en deze werkte maar nu wil ik ze integreren in een groter project en maar krijg ze niet meer aan het werk.
De code stuurt de inhoud van het register lichtsterkte naar een LCD display. Ik heb natuurlijk al enkele wijzigingen aangebracht tov het 16F628 project.

De instructielijnen zijn gekoppelt aan PORTA 0 tem 2
De datalijnen zijn gekoppelt aan PORTC
Werkt met 10MHz crystal.



; 
;	Title "LCD test."
;
	list P = 16F870
	include "P16f870.inc"

    __CONFIG _HS_OSC & _WDT_OFF & _PWRTE_OFF & _LVP_OFF & _CP_OFF & _CPD_OFF  	 

;
; --------------------
; USER RAM DEFINITIONS
; --------------------
;
	CBLOCK h'20'
;
MessPt
DisData
DelayL
DelayM
DelayH
t1
w2
Lichtsterkte
save_wREG
save_pclath
save_status
CyclesTMR1
LCD_REG			;bit0 = Display off
	ENDC

lcdRS	equ 	d'0'		; RB4 = LCD RS pin
lcdRW	equ 	d'1'		; RB2 = LCD RW pin
lcdE	equ 	d'2'		; RB5 = LCD E pin

;****************************************************************
;
;                         START
;
;****************************************************************
	org 	0x00
	GOTO	INIT

;****************************************************************
;
;                         INTERUPT
;
;****************************************************************	
 	org		0x04
	
	;bewaren wREG en PCLATCH
	MOVWF	save_wREG
	CLRW

	MOVF	STATUS,W		;w now has copy of status
	BCF		STATUS,IRP
	BCF		STATUS,RP1
	BCF		STATUS,RP0		;ensure we are in bank 0 now!
	MOVWF	save_status		;save status
	
	MOVF	PCLATH,W		;save pclath
	MOVWF	save_pclath	
	CLRF	PCLATH		
	
	;**************Controle van de interupt*************
	BTFSC	PIR1,TMR1IF		;TMR1_INT
	GOTO	TMR1_INT
	GOTO	INIT			;Reset (illegal interupt)
	
	;************* TMR1 INT ********************
TMR1_INT
	;Clear interupt flag
	BCF		PIR1,TMR1IF

	DECFSZ	CyclesTMR1
	GOTO	END_TMR1_INT
	
	;schakel display uit
	BSF		LCD_REG,0

	MOVLW	D'50'
	MOVWF	CyclesTMR1
END_TMR1_INT
	;herstellen wREG en PCLATCH
	MOVF	save_pclath,W
	MOVWF	PCLATH			;restore pclath. (Page=original)

	MOVF	save_status,W
	MOVWF	STATUS			;restore status! (bank=original)

	SWAPF	save_wREG,F		;restore w from *original* bank! 
	SWAPF	save_wREG,W

	RETFIE
;*******************************************************************
;
;                      INITIALISATIE
;
;*******************************************************************
INIT		
	MOVLW   0x20            ;Clear memory
    MOVWF   FSR
    MOVLW   D'13'             ;Clear a total of 13 RAM addresses
    MOVWF   0x60
CLRMEM          
	CLRF    INDF            ;Clear this address
    INCF    FSR,f           ;Increment pointer
    DECFSZ  0x60,f          ;Decrement counter
    GOTO    CLRMEM          ;Repeat until done

;hier werd vroeger 0x07 in CMCON geschreven
	;*** Port mode initializing
    bsf     STATUS,RP0      ;Change to Bank1
    movlw   b'00000110'     ;RA port to digital mode
    movwf   ADCON1          ;Set ADCON1 register
    movlw   b'00000000'     ;RA port to output mode
    movwf   TRISA           ;Set TRISA register
    movlw   b'00000111'     ;RB0-RB2:input
    movwf   TRISB           ;Set TRISB register
    movlw   b'00000000'     ;RC port to output mode
    movwf   TRISC           ;Set TRISC register


	;*** Port initializing
    clrf    PORTA           ;Clear PORTA
    clrf    PORTB           ;Clear PORTB
    clrf    PORTC           ;Clear PORTC

	
	;Enable timer1 int
	MOVLW	 b'00000001'
	MOVWF	 PIE1
	
	BCF		 STATUS,RP0
	
	;initialiseer timer1
	BSF		 T1CON,T1CKPS0
	BSF		 T1CON,T1CKPS1
	BSF		 T1CON,TMR1ON	
		
	CLRF	 TMR1H
	CLRF	 TMR1L
	
	MOVLW	 b'11000000'
	MOVWF	 INTCON		

		
;
; -----------------------------------------------------
; INIT LCD ROUTINES 
; -----------------------------------------------------
;
INIT_LCD
	;Zet display aan
	BSF		 PORTA,3

	MOVLW	 50h			; 25mS powerup delay @ 4MHz
	MOVWF	 DelayH		; data sheet says 15mS
	CLRF	 DelayL
PUPD	
	DECFSZ	 DelayL
	GOTO 	 PUPD
	DECFSZ 	 DelayH
	GOTO	 PUPD

    CALL	 Control        	; initialize display

	CLRF	 MessPt
	MOVLW	 0x80		; line 1
	CALL	 LCDins
Loop1
	CALL	 TheText
	XORLW	 0h
	BTFSC	 STATUS,Z
	GOTO	 DoLine2

	CALL	 LCDout
	INCF	 MessPt
	GOTO	 Loop1

DoLine2		
	MOVLW	 0xC6		; line 2
	CALL 	 LCDins
		
	;verstuur percentage
	MOVLW	 0x43
	MOVWF	 Lichtsterkte
	;honderdtallen
	MOVFW	 Lichtsterkte
	CALL	 GETHNDS
	ADDLW	 0x30			
	CALL	 LCDout
		
	;Tientallen
	MOVFW	 Lichtsterkte
	CALL	 GETTENS
	ADDLW	 0x30		
	CALL	 LCDout	

	;Eenheden
	MOVFW	 Lichtsterkte
	CALL	 GETONES
	ADDLW	 0x30		
	CALL	 LCDout
	
	;percent teken
	MOVLW	 0x25		
	CALL	 LCDout
		
;***************************************************************
;
;						MAINLOOP
;
;***************************************************************
MnLoop
	;Controleer of display moet branden
	BTFSS	LCD_REG,0
	GOTO	NO_DOOF_DISPLAY
	
	;Zet display uit
	MOVLW 	.8             ; turn display off
	CALL 	LCDins         ; output to display	
	BCF		PORTA,3
	
	BCF		LCD_REG,0		
	;Disable timer1 int
	BSF		STATUS,RP0
	MOVLW	 b'00000000'
	MOVWF	 PIE1
	BCF		 STATUS,RP0
NO_DOOF_DISPLAY

	;Controleer of er geen nieuwe waarde voor de display is
	BTFSS	LCD_REG,1
	GOTO	NO_NEW_VALUE

	;Zet display aan
	GOTO	INIT_LCD
	
	BCF		LCD_REG,1
	;Enable timer1 int
	BSF		STATUS,RP0
	MOVLW	 b'00000001'
	MOVWF	 PIE1
	BCF		 STATUS,RP0
NO_NEW_VALUE

	GOTO 	MnLoop


; -----------------
; SEND CONTROL DATA
; LCD INITIALIZATION CODES
; -----------------
; According to the data sheet, a delay of 4mS minimum must occur 
; between each control data byte being sent.
;
Control   
	movlw 	38h           ; (128) display initialisation
	call 	LCDins         ; output to display
    movlw 	38h			; page 45 of the data sheet
	call 	LCDins         ; output to display
    movlw 	38h           ; two line
	call 	LCDins         ; output to display

    movlw 	.6            ; increment display
	call 	LCDins         ; output to display
    movlw 	0ch           ; display = on, cursor = off
	call 	LCDins         ; output to display
    movlw 	.1            ; clear display
    call 	LCDins         ; output to display
	return

;Text lijn 1
TheText	
	movlw 	High($)
	movwf 	PCLATH
	movf 	MessPt,W
	addwf 	PCL
	DT "  LICHTSTERKTE", 0h
		

; -----------------------------
; OUTPUT 1 DATA BYTE TO DISPLAY
; -----------------------------
;
LCDout    
	;movf DisData,w
    movwf	PORTC
    bsf 	PORTA,lcdRS     ; (4) Write data to display
    call 	Clock
    bsf 	PORTA,lcdE      ; (5) enable
    call 	Clock
    bcf 	PORTA,lcdE      ; (5)
    call 	Clock
    bcf 	PORTA,lcdRS     ; (5)
    bcf 	STATUS,RP0      ; ram page 0
    return
;
; ------------------------------------
; OUTPUT 1 INSTRUCTION BYTE TO DISPLAY
; ------------------------------------
;
LCDins    
	movwf	PORTC
    bcf 	PORTA,lcdRS     ; (4) Write instruction to display
    call 	Clock
    bsf 	PORTA,lcdE      ; (5) enable
    call 	Clock
    bcf 	PORTA,lcdE      ; (5)
    call 	Clock

	clrf 	DelayL
	movlw 	8h		; about 6mS delay @ 4MHz
	movwf 	DelayH
ctlp1     
	decfsz 	DelayL
    goto 	ctlp1
	decfsz 	DelayH
	goto 	ctlp1

    return
;

;
; -----------------------------
; CLOCKING DELAY - 200uS @ 4MHz
; -----------------------------
;
Clock	
		CLRF  	DelayL	;40h bij 4MHZ

		MOVLW	D'2'			
		MOVWF	DelayM
kdloop    
		DECFSZ	DelayL
        GOTO 	kdloop
        DECFSZ	DelayM
		GOTO	kdloop

		RETURN

;******************************************************************
;
;					OMZETTEN HEX NAAR BCD
;
;*****************************************************************
;This routine will return the number of decimal 
;hundreds from an 8-bit binary
;Input: w
;Output: w
;RAM:2
;Cycles: 12-24

GETHNDS		
	movwf	t1
    clrf    w2
gethnds_loop	
	movlw	.100
	incf	w2,f
	subwf	t1,f
	btfsc	STATUS,C
	goto 	gethnds_loop
	decf	w2,w
	return		
;---
;This routine will return the number of decimal 
;tens from an 8-bit binary
;Loop based, so it might take some time...
;It needs getones too
GETTENS		
	movwf	t1
    clrf    w2
gettens_loop	
	movlw	.10
	incf	w2,f
	subwf	t1,f
	btfsc	STATUS,C
	goto 	gettens_loop
	decf	w2,w
	return
	
;---
;This routine will return the number of decimal 
;ones from an 8-bit binary	
GETONES		
	movwf	w2
	movlw	.10
deltens_loop	
	subwf	w2,f
	btfsc	STATUS,C
	goto 	deltens_loop
	addwf	w2,w	
	return

; -----------------------
; BOOT CODE START ADDRESS
; -----------------------
; DO NOT PLACE ANY CODE PAST THIS POINT
;
	org 0x0F00
;
;
	end

Ik heb het zelf al gevonden, zat niet in de goede bank voor het clearen van de PORTS.