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.

This PIC16F676 INT code is not working? or my pic16f676 damage?

Status
Not open for further replies.

d@nny

Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
org 0x00
goto main
org 0x04
goto INTR

main:

banksel ANSEL
movlw B'00000000'
movwf ANSEL

banksel PORTA
clrf PORTA
banksel TRISA
movlw b'00000100'
movwf TRISA

banksel PORTC
clrf PORTC
banksel TRISC
clrf TRISC

banksel INTCON
bsf INTCON , 7
bsf INTCON , 4
bcf INTCON , 1

banksel OPTION_REG
bcf OPTION_REG , 6
FIN:

goto FIN


INTR:

movlw 0xff
movwf PORTC
banksel INTCON
bcf INTCON , 1
return

end
 

Did you supply this device with 12v, as you did with the other PIC? :shock:
:-D NO
actually i have now selected int on falling edge. the int0 is up with 4.7K and attach to ground with a micro button but it accept int when i release the button but not on push the button
mean on rising edge
 

I've fixed the code. This is it:
Code:
processor p16f676
include "p16f676.inc"
__config _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT

org 0x00
goto main
org 0x04
goto INTR

main:

banksel ANSEL
movlw B'00000000'
movwf ANSEL

banksel PORTA
clrf PORTA
banksel TRISA
movlw b'00000100'
movwf TRISA
movlw .7
movwf CMCON

banksel PORTC
clrf PORTC
banksel TRISC
clrf TRISC

banksel INTCON
bsf INTCON , GIE
bsf INTCON , INTE
bcf INTCON , INTF

banksel OPTION_REG
bcf OPTION_REG , INTEDG

FIN:
goto FIN

INTR:
banksel PORTC
movlw 0xff
movwf PORTC
banksel INTCON
bcf INTCON , INTF
retfie


end


The main problem is that, before entering the loop, you had switched to bank 1 where OPTION_REG is. However, as the interrupt occurs, in the ISR, you try to access bank 0 where PORTC is. So, before you do that, switch to bank 0 to send the output to PORTC, then back to bank 1 to clear the flag.

Also, when returning from the ISR, use
Code:
retfie

I've changed the bit numbers to names to make it easier to read.
You can configure the configuration bit settings as you require.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top