Page 1 of 1

Use interupt on whole port on rising edge

Posted: Sat Sep 18, 2010 8:52 am
by MJU
Is it possible to use the whole B-port as an interrupt detection, and what more, only on the rising edge?
I see the option interrupt on INT (that means the whole B-port?), but sadly I can't find a way to only make it work on the rising edge.

I use the 16F877A and want to make pushbuttons on the B port like a flip flip.
This should only work on the rising edge, when a button is pushed (no matter how long), the output is set to 1.
If the button was released and again the button was pressed, the output becomes 0.

In my opinion it's best to use interrupts on rising edge to make this work, otherwise I have to make, for every switch, a software flip flop.
Can this be done with the custom code in the interrupt settings?

Re: Use interupt on whole port on rising edge

Posted: Sat Sep 18, 2010 10:13 am
by Dan81
Hello MJU

Try this file.
It is for a 16F887 (better and cheaper than 16F877).
For the 16F887 the 8 bits of the port B can have interrupt.

Daniel

Re: Use interupt on whole port on rising edge

Posted: Sat Sep 18, 2010 4:00 pm
by MJU
Thank you Dan81,

But I'm going to use the 16F877A, the 16F877 is an older version and the whole project is built around this PIC.
I thought that it would be possible with the custom code in the interupt options.
Maybe it's better to make a polling macro where I program the flip flops..

Thanks again

Re: Use interupt on whole port on rising edge

Posted: Sat Sep 18, 2010 5:26 pm
by medelec35
Hello MJU
You can use the port B interrupt, which will fire on rising and falling edge. You can then use a piece of code within the interrupt so set a flag only if port is high.
Take a look here:
http://www.matrixmultimedia.com/mmforum ... 75&p=19764
If you are struggling then post your Flowcode and I can implement it for you.

Re: Use interupt on whole port on rising edge

Posted: Sat Sep 18, 2010 8:26 pm
by MJU
Thank you Medelec35...

But my problem is that the PIC doesn't react to the change on any of the pins on port-B.
I would think that in the interrupt settings, the setting "interrupt on: PORT" would make the PIC look for any change on port B, or am I wrong?

The INT pin on the 16F877A is B0, but isn't there a way to expand this interrupt to the whole portB?
There are custom settings that can be applied, is there a way to make the PIC react on any change on PortB?
I preffer an interrupt on a rising edge of any pin on portB.

If this is not possible I must use polling to find the change, but I would be faster to have an interrupt.

Anyway, thanks for your help!

Re: Use interupt on whole port on rising edge

Posted: Sat Sep 18, 2010 9:45 pm
by medelec35
MJU wrote:But my problem is that the PIC doesn't react to the change on any of the pins on port-B.
I would think that in the interrupt settings, the setting "interrupt on: PORT" would make the PIC look for any change on port B, or am I wrong?
Your pic should react to port B interrupt on change. You are correct! If there is a change in the port b i/p's then the interrupt will be fired. All you need a a routine which ignores high to low changes.

Re: Use interupt on whole port on rising edge

Posted: Sun Sep 19, 2010 8:44 am
by Dan81
Hello MJU

Sorry I didn't see "If the button was released and again the button was pressed, the output becomes 0."

Now the filemust do what you hope.

In my previous reply I wrote : 16F887 and not 16F877, all your code must work on the 887

With 877 you have the interrup on RB4/5/6/7only but the whole port with the 887

Good luck


Daniel

Re: Use interupt on whole port on rising edge

Posted: Sun Sep 19, 2010 11:13 am
by saschech@gmx.de
hello

If i read the datasheet,i think , there is only port b0 use for int.

Re: Use interupt on whole port on rising edge

Posted: Sun Sep 19, 2010 1:52 pm
by medelec35
Hello saschech@gmx.de.

Unfortunately some data sheets are not laid out that well. 16F877 and 16F877A with regards to interrupts look like they fall into that category.
If you look at the index regarding portb you should see the following:
portb ioc.jpg
portb ioc.jpg (86.26 KiB) Viewed 11834 times
As far as I am aware most microcontrollers have either portB ioc of in some smaller devices porta IOC when portb is not available.
@ Dan81
That is a really good use of ioc on rising pulse only for RB4:RB7. Since I also misread post like you did, I removed my Flowchart as yours worked with RB4:RB7, and I only included RB7

Re: Use interupt on whole port on rising edge

Posted: Sun Sep 19, 2010 2:41 pm
by Dan81
Hello

About interrupt on portB : There are 2 kinds of interrupt.

- RB0/INT : where you can choose the edge rising or falling (but not both).

- RB Int on change : where an interrupt is lauched as soon as a change occurs on RB4..RB7 (and RB0..RB7 for"new" pic as 16F887).
But you have to make some jobs (reading inputs and some logical calculations) to find which RB has changed.
This interrupt is useful when you use keyboard (that's why RB port has got optional internal pull up).

If that can help

Daniel

Re: Use interupt on whole port on rising edge

Posted: Mon Sep 20, 2010 11:25 am
by MJU
Thanks all of you!

I appreciate all of your input.
But I have decided to step back from the interrupt idea for the switches, and use polling of the switches.
I know this is different from my first post, but my only goal was to seek for an option to make the whole port an interrupt.

Attached the way I will use the switches in my project.
If B0 is pressed, a variable is raised with 15 (and shown on the display).
No mather how long B0 is pressed, the button must first be released before another increment of the variable is allowed.
By pressing B1, the variable is set back to 0.

Maybe this way of making sure the variable isn't raised the whole time the button is pushed is too complicated, but I didn't see another way of making this work on all buttons.

If anyone has a better idea of how I can implement this (in a way it can be used with all switches), they are still welcome!

Re: Use interupt on whole port on rising edge

Posted: Mon Sep 20, 2010 3:58 pm
by saschech@gmx.de
Hello MJU

I think it works with int on b0 ok

Regards Wolfgang

Re: Use interupt on whole port on rising edge

Posted: Mon Sep 20, 2010 4:02 pm
by MJU
Thank you Wolfgang,

But I'm leaving the interrupt option.
If the interrupt works on the whole port or I can't use it for my purpose.

I've posted my flow because it could bring other people to ideas if the ever need such a thing.

Re: Use interupt on whole port on rising edge

Posted: Mon Sep 20, 2010 5:47 pm
by Dan81
Hello Marcel

My file (without interrupt ) with count up or down.

Daniel

PS : in your file LCD is connected on port A, A3 is not a general I/O , it needs pull up.


Daniel

Re: Use interupt on whole port on rising edge

Posted: Mon Sep 20, 2010 7:51 pm
by MJU
Hey Dan81, this is a great way of flip-flop the switches, but what if by accident multiple buttons are pressed?
In that case not a single one will be counted.

I'm going to examine your solution.
Thanks!

Re: Use interupt on whole port on rising edge

Posted: Tue Sep 21, 2010 4:56 am
by Dan81
Hello Marcel

You can replace the "Switch" icon by 8 conditions.

Daniel

Re: Use interupt on whole port on rising edge

Posted: Tue Sep 21, 2010 10:02 pm
by MJU
Thank you Dan81!

Strange question maybe, but why do you use a connection point (from A to A)?
Why no loop?

I'm going to use some things from this Flow!

Re: Use interupt on whole port on rising edge

Posted: Wed Sep 22, 2010 4:49 am
by Dan81
Hello Marcel

It's the same think but I prefer the "goto".
And it is the only moment when I use this icon

Daniel