Use interupt on whole port on rising edge
Moderator: Benj
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Use interupt on whole port on rising edge
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?
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?
- Dan81
- Valued Contributor
- Posts: 268
- Joined: Sun Jan 15, 2006 4:07 pm
- Location: Albi France
- Been thanked: 60 times
- Contact:
Re: Use interupt on whole port on rising edge
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
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
- Attachments
-
- rising_edge.fcf
- not hard tested (only with Proteus)
- (14 KiB) Downloaded 353 times
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Use interupt on whole port on rising edge
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
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
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Use interupt on whole port on rising edge
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.
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.
Martin
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Use interupt on whole port on rising edge
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!
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!
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Use interupt on whole port on rising edge
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.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?
Last edited by medelec35 on Sun Sep 19, 2010 10:23 am, edited 1 time in total.
Martin
- Dan81
- Valued Contributor
- Posts: 268
- Joined: Sun Jan 15, 2006 4:07 pm
- Location: Albi France
- Been thanked: 60 times
- Contact:
Re: Use interupt on whole port on rising edge
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
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
- Attachments
-
- flip_flop_877.fcf
- (9.5 KiB) Downloaded 315 times
-
- Posts: 714
- Joined: Wed Jan 31, 2007 12:41 pm
- Has thanked: 1 time
- Been thanked: 26 times
- Contact:
Re: Use interupt on whole port on rising edge
hello
If i read the datasheet,i think , there is only port b0 use for int.
If i read the datasheet,i think , there is only port b0 use for int.
- Attachments
-
- int on ..877 .. 887.gif
- (83.59 KiB) Downloaded 3009 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Use interupt on whole port on rising edge
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: 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
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: 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
Martin
- Dan81
- Valued Contributor
- Posts: 268
- Joined: Sun Jan 15, 2006 4:07 pm
- Location: Albi France
- Been thanked: 60 times
- Contact:
Re: Use interupt on whole port on rising edge
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
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
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Use interupt on whole port on rising edge
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!
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!
- Attachments
-
- FlipFlopPoll.fcf
- (11.5 KiB) Downloaded 258 times
-
- Posts: 714
- Joined: Wed Jan 31, 2007 12:41 pm
- Has thanked: 1 time
- Been thanked: 26 times
- Contact:
Re: Use interupt on whole port on rising edge
Hello MJU
I think it works with int on b0 ok
Regards Wolfgang
I think it works with int on b0 ok
Regards Wolfgang
- Attachments
-
- FlipFlopPoll with int.fcf
- (10.5 KiB) Downloaded 233 times
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Use interupt on whole port on rising edge
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.
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.
- Dan81
- Valued Contributor
- Posts: 268
- Joined: Sun Jan 15, 2006 4:07 pm
- Location: Albi France
- Been thanked: 60 times
- Contact:
Re: Use interupt on whole port on rising edge
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
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
- Attachments
-
- flip_flop_877-v2.fcf
- without interrupt
- (11.5 KiB) Downloaded 234 times
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Use interupt on whole port on rising edge
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!
In that case not a single one will be counted.
I'm going to examine your solution.
Thanks!
- Dan81
- Valued Contributor
- Posts: 268
- Joined: Sun Jan 15, 2006 4:07 pm
- Location: Albi France
- Been thanked: 60 times
- Contact:
Re: Use interupt on whole port on rising edge
Hello Marcel
You can replace the "Switch" icon by 8 conditions.
Daniel
You can replace the "Switch" icon by 8 conditions.
Daniel
- Attachments
-
- flip_flop_877-v3.fcf
- (12.5 KiB) Downloaded 251 times
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Use interupt on whole port on rising edge
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!
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!
- Dan81
- Valued Contributor
- Posts: 268
- Joined: Sun Jan 15, 2006 4:07 pm
- Location: Albi France
- Been thanked: 60 times
- Contact:
Re: Use interupt on whole port on rising edge
Hello Marcel
It's the same think but I prefer the "goto".
And it is the only moment when I use this icon
Daniel
It's the same think but I prefer the "goto".
And it is the only moment when I use this icon
Daniel