Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic 16f886 interrupt vector

Status
Not open for further replies.

W_Heisenberg

Full Member level 4
Joined
Feb 27, 2011
Messages
217
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Location
Boston
Activity points
2,575
the address should be h'04', right?

for my project, i can get the interrupt flag be active, but why the program can not enter the ISR(interrupt subrountine). anyone had this problem before? how to fix this?

thanks a lot, guys.
 

Have you enabled the interrupt you are trying to use and also the global interrupt enable?
The interrupt flags get set whether or not the interrupt is enabled.
 

i enbabled the GIE, and RBIE(the change on portb), anything else to do? the problem is by using pickit2, I entered the debugging mode, and I really see the flag is set, yet not entering my ISR, which is so wierd.
 

Show us the code you are using, if it's not too big.
 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;
;Date: Nov. 17, 2010 ;
;Version: 0.0.3 ;
;Title: EE395_PROJ ;
; ;
;Description: This program will ;
;combinethe bluetooth module and ;
;pic16f886 to form a transimitter ; ;
; ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
include "P16f886.inc"
;list p=16f886
;__config 0x02f5 ;remember that config can also set not in code


;*****************************************************pins layout**********************************************************
;RC1 = right turn request
;RC0 = left turn request
;RA1 = right turn led
;RA0 = left turn led
;
;RC7 = RX
;RC6 = TX


;*****************************************************Constant Declarations************************************************
DATA_OUT equ h'21' ;for recording the value of input PORTA
;DATA_IN equ h'22' ;for recording the value of
ERR equ h'23' ;for error checking in receiving data (UART module)
COUNT equ h'24';
N equ d'249'


#define BAUD d'9600' ;baud rate is 9600
#define XTAL d'4' ;4MHz clock as its default
#define X ((XTAL*d'1000000')/(d'64'*BAUD))-1 ;which is 5, baud rate now is 10416 and SPBRG=5


;*****************************************************initialization********************************************************
org h'00'
goto start
org h'04'
goto ISR
;***Set Up Ports***
start
BANKSEL ANSELH
CLRF ANSELH
BANKSEL TRISB ;
MOVLW B'00000011' ;set RC0, RC1 as input, other as outputs
MOVWF TRISB
BANKSEL PORTB ;
CLRF PORTB ;Init PORTC

BANKSEL ANSEL ;
CLRF ANSEL ;digital I/O
BANKSEL TRISA ;
MOVLW B'00000000';et RA0, RA1 as output
MOVWF TRISA
BANKSEL PORTA ;
CLRF PORTA ;Init PORTA

BANKSEL TRISC
MOVLW b'10000000' ;make PORTC RC7/RX(input), RC6/TX(output)
MOVWF TRISC
BANKSEL PORTC
CLRF PORTC

;***initialize the oscillator***
BANKSEL OSCCON
MOVLW b'01101000'
MOVWF OSCCON

;***initialize the uart***
BANKSEL SPBRG
MOVLW B'00000101'
MOVWF SPBRG

;BRGH default 0
;BRG16 default 0, 8 bit generator
;so baud rate is 10416 now

;SYNC default 0, asychrnous
BANKSEL RCSTA
BSF RCSTA, SPEN ;SPEN set, (configures RX/DT and TX/CK pins as serial port pins)
BSF RCSTA, CREN
;RX9 default 0, 8 bit transmittion

BANKSEL TXSTA
BSF TXSTA, TXEN ;transmit enabled




;***initialize interrupt***
BANKSEL PIE1
BSF PIE1, TXIE ;tx interrupt enable
BANKSEL INTCON ;enable external interrupt
BSF INTCON, PEIE
;BSF INTCON, RBIE
BSF INTCON, GIE ;enable global interrupt
;BANKSEL IOCB
;BSF IOCB, IOCB0
;BSF IOCB, IOCB1
;*****************************************************main program**********************************************************
;light up left or right led when left or right request comes
main
;***led control***
bcf STATUS ,RP1
bcf STATUS ,RP0
clrf PORTB
; bsf INTCON, RBIE
;bcf INTCON, RBIF
;loop

donothing
nop
loop
btfss PIR1, TXIF
goto loop
movf PORTB,w ;read the request from PORTA, 0 = w
movwf DATA_OUT
movwf TXREG
goto donothing ;here is tricky, the ISR failed, who knows why?


org 0x80
ISR

movf DATA_OUT, w
movwf PORTA
call DELAY_100ms
;bcf INTCON, RBIF
;bcf INTCON, INTF
bcf PIR1, TXIF
clrf PORTB
clrf PORTA
retfie

DELAY_100ms
movlw d'100'
movwf COUNT
DELAY_1ms
movlw N
D_LOOP
addlw -1
btfss STATUS, Z
goto D_LOOP
decfsz COUNT, f
goto DELAY_1ms
return

end


//the above are my codes, and I enabled TXIF this time, inoder to see whether a transmission is completed.
 

In the interrupt routine you have to save and restore at least the W reg and the status reg.
When I run it in Mplab sim, The TXIF flag is getting set, as you don't clear it, it keeps jumping to the interrupt routine.
Use Mplab sim and step through the code.

Code:
    org h'04'
    
    movwf   Wtemp      ;Save W
    movfw   STATUS
    movwf   Status     ;Save STATUS

    movf DATA_OUT, w
    movwf PORTA

    call DELAY_100ms

;bcf INTCON, RBIF
;bcf INTCON, INTF

    bcf PIR1, TXIF
    clrf PORTB
    clrf PORTA

    movfw   Status
    movwf   STATUS     ;Restore STATUS
    swapf   Wtemp,f
    swapf   Wtemp,w    ;Restore W
    retfie
 

so I have to restore status and W in order to entering into ISR?
is that what you mean? i would try this, thanks in advance
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top