Page 1 of 1

FlowCode interrupts for RB0

Posted: Thu Sep 11, 2008 12:37 pm
by Cimbian
I know this will be simple for many but is there a basic example for using interrupts from PortB of a PIC?

Basically, a number of buttons on PortB, two of which need to break a function (reset and A.N.other)
Enable an interrupt
Run code as normal
If a key is pressed break from the run-mode and do 'something else'.

Sounds simple and probably is but I can't get my head around it in FlowCode.

Re: FlowCode interrupts for RB0

Posted: Thu Sep 11, 2008 1:12 pm
by Benj
Hello

An RB0 interrupt in Flowcode occurs when you switch the logic level from pin RB0 from low to high or visa versa depending on your interrupt enable properties.

To switch the RB0 input from high to low you are going to need an external pull up or pull down resistor.

Eg here is a typical circuit using a single push to make switch and a 4.7K resistor.

5V----Switch----RB0----4.7K Resistor-----GND

When the interrupt is triggered the macro you selected via Flowcode will be run once.

Hope this helps.

Re: FlowCode interrupts for RB0

Posted: Thu Sep 11, 2008 3:17 pm
by Cimbian
Ben,
I'm okay with that level. I guess the question was for a simple sample of using a port interrupt within Flowcode.
Doh! :oops: sorted now.

Re: FlowCode interrupts for RB0

Posted: Thu Oct 13, 2011 3:59 pm
by kirstom14
Hi,

I am trying to do an emergency stop using the RB0 interrupt. The problem is that when the interrupt is triggered,
the macro chosen is only done once,
When the interrupt is triggered the macro you selected via Flowcode
will be run once
, and I need it to continue to run until the emergency stop is released.

What can I do to loop until the button is released? I did a loop in the macro but still it run only once :S

Thanks for your help

Re: FlowCode interrupts for RB0

Posted: Thu Oct 13, 2011 7:14 pm
by Spanish_dude
Hi kirmstom14,

This is how I would do it :

Code: Select all

//main program
char stop = 0; // variable for stopbutton used as a "flag"
while(1) // main loop
{
    if (stop == 1)
    {
        // do stuff

        // when stuff done
        stop = 0;
    }
    else
    {
        // do some other stuff
    }
}

Code: Select all

// interrupt
stop = 1; // stop button pressed
This only works well when there is no delay in the "else" part of the program.

Nicolas