FlowCode interrupts for RB0

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Cimbian
Posts: 2
Joined: Thu Sep 04, 2008 6:05 pm
Contact:

FlowCode interrupts for RB0

Postby Cimbian » Thu Sep 11, 2008 12:37 pm

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.

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: FlowCode interrupts for RB0

Postby Benj » Thu Sep 11, 2008 1:12 pm

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.

Cimbian
Posts: 2
Joined: Thu Sep 04, 2008 6:05 pm
Contact:

Re: FlowCode interrupts for RB0

Postby Cimbian » Thu Sep 11, 2008 3:17 pm

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.

kirstom14
Posts: 40
Joined: Thu Nov 15, 2007 9:13 am
Contact:

Re: FlowCode interrupts for RB0

Postby kirstom14 » Thu Oct 13, 2011 3:59 pm

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
tomcat14

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: FlowCode interrupts for RB0

Postby Spanish_dude » Thu Oct 13, 2011 7:14 pm

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