Intterupt probelm in PIC16F877A??? help urgent

Status
Not open for further replies.

Gundam82

New Member
yo... i using PIC16F877A microcontroller.... then....when the interrupt pin is activated, it goes to interrupt routine.... but then... i just stay there forever.... it not go back to starting point... why????

list p=pic16f877a
#include "p16f877a.inc"
__CONFIG _WDT_OFF & _PWRTE_ON & _XT_OSC & _CP_OFF

D2 EQU 1DH
D1 EQU 1EH
;----------------------------------STARTING-LOCATION----------------------------------------
ORG 0X00
GOTO INITIAL
ORG 0X04
GOTO ISR
INITIAL: BSF STATUS,RP0
MOVLW 0XFF ;SET PORTB AS INPUT PORT
MOVWF PORTC
MOVLW 0X00 ;SET PORTC AS OUTPUT PORT
MOVWF PORTD
BCF STATUS,RP0
CLRF PORTA
CLRF PORTB
BSF INTCON,GIE
BSF INTCON,RBIE
BCF INTCON,INTF

..................
.............
..........
...............
ISR: CLRF PORTD ; THR PROGRAM JUST KEEP HERE
BSF PORTD,4 ; WAT I WAN IS IT WILL GO
GOTO DELAY ; BACK TO INITIAL POINT :cry:
BCF INTCON,INTF
RETFIE

DELAY: .............

END
 
For a start you have 'Goto Delay' jumping out of the ISR, so it never reaches the RETFIE!. You're also not saving any context, as an absolute minimum you should save the STATUS and W registers, check MicroChip application notes for details.
 
I TRY OLEDI`~~ I STILL THE SAME~ `IS THERE ANY PROBLEM WITH PROGRAM??? PLS PLS~~~~


list p=pic16f877a
#include "p16f877a.inc"
__CONFIG _WDT_OFF & _PWRTE_ON & _XT_OSC & _CP_OFF

D2 EQU 1DH
D1 EQU 1EH
W_TEMP EQU 1FH
STATUS_TEMP EQU 1CH

;----------------------------------STARTING-LOCATION-------------------------------
ORG 0X00
GOTO INITIAL
ORG 0X04
ISR:
MOVWF W_TEMP ; Copy W to TEMP register,
SWAPF STATUS, W ; Swap status to be saved into W
MOVWF STATUS_TEMP ; Save status to STATUS_TEMP register

CLRF STATUS ; Force page zero
CLRF PORTB
CLRF PORTC
CLRF PORTD
BSF PORTD,4
CALL DELAY
BCF PORTD,4
BCF INTCON,INTF ; CLEAR THE INTERRUPT FLAG BIT

;now restore context before exiting interrupt
SWAPF STATUS_TEMP, W ; Swap nibbles in STATUS_TEMP register and place result into W
MOVWF STATUS ; Move W into STATUS register (sets bank to original state)
SWAPF W_TEMP, F ; Swap nibbles in W_TEMP and place result in W_TEMP
SWAPF W_TEMP, W ; Swap nibbles in W_TEMP and place result into W
RETFIE ; RETURN FROM INTERRUPT

;---------------------------------------------------------------------------------------------------------
INITIAL: BSF STATUS,RP0
MOVLW 0X01
MOVWF TRISB
MOVLW 0XFF ;SET PORTB AS INPUT PORT
MOVWF TRISC
MOVLW 0X00 ;SET PORTC AS OUTPUT PORT
MOVWF TRISD
BCF STATUS,RP0
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF INTCON
BSF INTCON,GIE
BSF INTCON,INTE

START: ----
------
--------

DELAY: MOVLW B'11111111'
MOVWF D2
DELAY2: MOVLW B'10001000'
MOVWF D1
DELAY3: DECFSZ D1,F
GOTO DELAY3
DECFSZ D,F
GOTO DELAY2
RETURN
END
 
Ok

First, What are you trying to do?

Second, your variables are out of the RAM space, you must put them at address 20h, addresses 1C,1D,1E and 1F are below 20h.

I think inside the interrupt is not recommendable to start a delay.
and always work on bank 0

clear ports before assign set them as inputs or outputs.

If you are waiting for and event in RB0/INT, why not you just poll the pin up to an event occurs then if it happens start a delay.
 
sardineta is correct try this

Code:
D2 EQU 0x20 
D1 EQU 0x21 
W_TEMP EQU 0x22 
STATUS_TEMP EQU 0x23
 
 
thanks~~ every one~~~~ i solve the problem ~~ oledi`!!!! everyrthing fine now~~~ i just change my delay subroutine inside the ISR...... now it can go back waiting for my command~~~~ anyway`~~~
thanks~~ all!!!!!!


ORG 0X00
GOTO INITIAL
ORG 0X04
ISR:BSF PORTB,1 ; TURN ON BUZZER
BSF PORTB,2
BSF PORTD,4
CALL DELAY
CLRF PORTB
CLRF PORTD
CALL DELAY
BCF INTCON,INTF ; CLEAR THE INTERRUPT FLAG BIT
RETFIE ; RETURN FROM INTERRUPT
DELAY: MOVLW B'11111111'
MOVWF D3
DELAY1: MOVLW B'11111111'
MOVWF D2
DELAY2: MOVLW B'11111111'
MOVWF D1
DELAY3: DECFSZ D1,F
GOTO DELAY3
DECFSZ D2,F
GOTO DELAY2
DECFSZ D3,F
GOTO DELAY1
RETURN

................
..............
...........
................ :lol: :lol: :lol: :lol: :lol: [/i]
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…