INTERRUPT ON CHANGE- PIC16F877

Status
Not open for further replies.

samuel23

Newbie level 1
Joined
May 6, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
ISRAEL
Activity points
1,290
I need help with write a program in assembly that increment the PORTD (LED) when there is pressing on keyboard.
i try to write somting but it's not work.

my program is:

LIST P=PIC16F877
include <P16f877.inc>

org 0x00
reset: nop
goto start
goto INTERRUPT
org 0x020

start:
bcf STATUS, RP0
bcf STATUS, RP1
clrf PORTD
clrf PORTE
clrf INTCON
bcf INTCON,GIE ; global interrupt enable
bcf INTCON,RBIE ; enabling change interrupt
bsf INTCON,RBIF
bsf STATUS, RP0
movlw 0XF0
movwf TRISB
clrf TRISE ;PORTE= output
clrf TRISD
clrf OPTION_REG
bsf OPTION_REG,7
movlw 0x06
movwf ADCON1
bcf STATUS, RP0



INTERRUPT:

movf PORTB,w
bcf INTCON,RBIF
btfss PORTB,4
goto minut_inc

retfie

minut_inc:

incf PORTD

END
 

Hi,

Nice try, but way off I'm afraid - the ISR is one of the hardest things to find out about - its not well documented for the beginner.

Below as a proven ISR example you can follow.

However you need to do a few other things to get it your codeworking.

You need to set up the ISR Variable _temp files and you need to set up your ports before you can use them properly.

Never rely on the defaults, always set them all up with the TRIS instructions and Clear the Port / Lat if its an output.


Code:
; ***************************************************************************
; INTERUPT POINTS

	org	0x000			
	goto	start
	
	
	org	0x004					; memory location h004
; ***************************************************************************
; Interupt Service Routine    MUST RUN FROM HERE ONLY !
;
; First run the Context Save Registers   - you need to create the _temp files

isr_CS
	movwf	W_ISR_TEMP			; copy W to temp 
	swapf	STATUS,W			; swap status to be saved into W
	clrf	STATUS				; bank 0
	movwf	STATUS_ISR_TEMP		; save status in bank O
	movf	PCLATH,W			; save pclath
	movwf	PCLATH_ISR_TEMP
	clrf	PCLATH				; clear to page 0 for ISR
	movf	FSR,W				; save FSR
	movwf	FSR_ISR_TEMP



; User Code   - MUST STAY WITHING ISR BOUNDARIES  - DO NOT USE GOTOs OUT OF THE ISR - USE NO CALLS

isr_UC	bcf	STATUS,RP0			;  set bank0 - 			- EXAMPLE CODE
	btfsc	PIR1,TMR1IF			; timer1 overflow int
	goto	tm1over		        ; timer1 has overflowed
	goto 	isr_END				; not tmr1 overflow - error - go back

tm1over bcf	PIR1,TMR1IF			; reset timer1
	movlw	0x80				; preload with 80
	movwf	TMR1H

	ETC
	ETC
	
	

; CONTEXT RESTORE REGISTERS

isr_END
	 movf	FSR_ISR_TEMP,W
	movwf	FSR
	movf	PCLATH_ISR_TEMP,W
	movwf	PCLATH
	swapf	STATUS_ISR_TEMP,W	; swap status temp to w to set org bank
	movwf	STATUS				; movW to status
	swapf	W_ISR_TEMP,F		; restore W
	swapf	W_ISR_TEMP,W
	retfie						; return from isr

; End of ISR  
;****************************************************************************
 
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…