View Full Version : what's wrong with this interrupt
micro
- 1st February 2006, 22:57
the prog. below is a simple interrupt enables RB7 to RB4 ports to work as external interrupt, i used one of them to view numbers countes from 0 to 5 and display it on serial LCD and return to a main prog. to view a message, but the problem when i enter intterupt i can not get out from it, i did the same prgo to RB0 and gave me good result, but with RB7-RB4 is not
trisa=%00000
trisb=%11111111
option_reg=%10000000
intcon = %10001000
I var byte
on interrupt goto int
main:
serout porta.0,2,[254,1]
pause 10
serout porta.0,2,["Hello"]
pause 100
goto main
disable interrupt
int:
for i=0 to 5
serout porta.0,2,[254,1]
pause 10
serout porta.0,2,[#i]
pause 1000
next i
INTCON.0=0
resume
enable interrupt
end
mister_e
- 2nd February 2006, 03:35
pic model ?
micro
- 2nd February 2006, 11:40
pic16f84
sorry i forgot that
Bruce
- 2nd February 2006, 16:33
Read portB on entry into the interrupt routine to end the mismatch condition.
SomeVar = PORTB ' read portB
Then clear the interrupt flag before exiting your interrupt routine.
INTCON.0 = 0 ' RB port change int flag is cleared.
Now whenever portB is different from the last value read, INTCON.0 will be set, and you'll vector back to your interrupt routine.
Read this app note for more details:
http://ww1.microchip.com/downloads/en/AppNotes/00566b.pdf
micro
- 2nd February 2006, 21:51
i solved the problem with another method as below
trisa=%00000
trisb=%11111111
option_reg=%10000000
intcon = %10001000
I var byte
on interrupt goto int
main:
back: if portb<>0 then intcon=%10001000 ; test bit 3
serout porta.0,2,[254,1]
pause 10
serout porta.0,2,["Hello"]
pause 100
goto main
disable interrupt
int:
for i=0 to 5
serout porta.0,2,[254,1]
pause 10
serout porta.0,2,[#i]
pause 1000
next i
INTCON=%10000000 ; cleared bit 3 bit
goto back ; back to test
resume
enable interrupt
end
i will read document, thank u for that, and waiting a reply from Mister_e
mister_e
- 3rd February 2006, 03:50
Micro,
Maybe your solution is working but will Behave weird one day or another.
I've nothing else to add from the Bruce's explanation. Everything is covered in his document.
AND it's also covered in the PORTB TRISB section 3.2 of your datasheet too.
BTW, why using interrupt on PORTB<7:4> if you never test wich pin gives you the interupt?
Acetronics2
- 3rd February 2006, 09:37
i solved the problem with another method as below
if portb<>0 then intcon=%10001000
Just a longer way to read PORTB ... no other method here !!!
Elegant solution would have been to display the port where the interrupt came from, in the "serout"
Alain
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.