PDA

View Full Version : Need help with interrupt



mbox
- 22nd August 2010, 01:34
I'm trying to learn DT's Interrupt, from the original I modify a little. I added 2 buttons to trigger the external interrupt.. but don't know how, it works only on Button 1.

INCLUDE "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

TrisB = %00000111
PortB = %00000000
LED1 VAR PORTB.6
x var byte
x=0

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts

Main:

PAUSE 1
High PortB.7
pause 20
low PortB.7
Pause 20
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
serout 5,2400, [$FE, 1]
serout 5,2400,[254,192]
SEROUT 5,2400,[" Val ",#x] ' Send x value to LCD
TOGGLE LED1
x=x+1
@ INT_RETURNCan any one tell me what I'm missing?

thanks in advance

gadelhas
- 22nd August 2010, 02:12
I'm trying to learn DT's Interrupt, from the original I modify a little. I added 2 buttons to trigger the external interrupt.. but don't know how, it works only on Button 1.

INCLUDE "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

TrisB = %00000111
PortB = %00000000
LED1 VAR PORTB.6
x var byte
x=0

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts

Main:

PAUSE 1
High PortB.7
pause 20
low PortB.7
Pause 20
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
serout 5,2400, [$FE, 1]
serout 5,2400,[254,192]
SEROUT 5,2400,[" Val ",#x] ' Send x value to LCD
TOGGLE LED1
x=x+1
@ INT_RETURNCan any one tell me what I'm missing?

thanks in advance

Hi,

I only can see one button connected to External Interrupt RB0. PIC16F628, only haves 1 External Interrupt, that is the RB0 Pin. The other butons that you add to the circuit, will not work as interruopt.

mbox
- 22nd August 2010, 02:31
Hi,

I only can see one button connected to External Interrupt RB0. PIC16F628, only haves 1 External Interrupt, that is the RB0 Pin. The other butons that you add to the circuit, will not work as interruopt.
Hi gadelhas, thanks for the quick reply.

Acetronics2
- 22nd August 2010, 09:47
Hi,

I only can see one button connected to External Interrupt RB0. PIC16F628, only haves 1 External Interrupt, that is the RB0 Pin. The other butons that you add to the circuit, will not work as interruopt.

Hi, Folks

I think something has to be cleared ...

You also can get " interrupt on change " interrupt with Port B.4 to B.7 ... or ' comparator interrupts" from the Comparator inputs ...

so, the 3 buttons can generate their own interrupt ...

Obviously the scheme has to be modified to place the buttons on the right pins ....

Alain

gadelhas
- 22nd August 2010, 15:09
Hi, Folks

I think something has to be cleared ...

You also can get " interrupt on change " interrupt with Port B.4 to B.7 ... or ' comparator interrupts" from the Comparator inputs ...

so, the 3 buttons can generate their own interrupt ...

Obviously the scheme has to be modified to place the buttons on the right pins ....

Alain

Not only the sheme but also the interrupt source on PBP code. Instead of INT_INT, must put RBC_INT, to make it Interrupt on PortB Change.

HankMcSpank
- 22nd August 2010, 17:53
so you need two buttons to generate an interrupt?

I've just been through all this pain & rx'ed a lot of help on my recent thread...

http://www.picbasic.co.uk/forum/showthread.php?t=13558

To summarise....you can have two switches connected to just the one PIC 'INT' pin - but you'll need to connect some diodes if going that way (I posted a schematic on the above thread).
Else, as Bruce kindly informed me on that very thread, you can use Interrupt on Change...which was a little more involved (but not a whole lot more)...& which doesn't need diodes & gives you a whole lot more options wrt which PIC pins you can connect your switches to.

mbox
- 24th August 2010, 16:48
so you need two buttons to generate an interrupt?

I've just been through all this pain & rx'ed a lot of help on my recent thread...

http://www.picbasic.co.uk/forum/showthread.php?t=13558

To summarise....you can have two switches connected to just the one PIC 'INT' pin - but you'll need to connect some diodes if going that way (I posted a schematic on the above thread).
Else, as Bruce kindly informed me on that very thread, you can use Interrupt on Change...which was a little more involved (but not a whole lot more)...& which doesn't need diodes & gives you a whole lot more options wrt which PIC pins you can connect your switches to.

Thanks guys for the support, I will explore more on this when I get home...