PDA

View Full Version : How to Read 6 Inputs anytime ?



iugmoh
- 19th February 2008, 08:39
Hi all,
I need your help in this subject , how to read 6 inputs as interrupt any time for PIC16F877A , beacuse our system entering in multiple sub routines so using polling way in main code not visible when our programm entering in another subroutine , so I can't know the change in these inputs.

How I can solve this problem ?

Archangel
- 19th February 2008, 09:26
http://www.picbasic.co.uk/forum/showthread.php?t=1367

search enable port change interrupts

sayzer
- 19th February 2008, 09:27
In order to understand the question properly,

1. Do you need to know which one of the inputs caused the interrupt? or it does not matter?
2. When you say "...I don't know the change in these inputs", do you need an interrupt when there is a "change" on at least one pin?

- PORTB7:4 gives you four pins but you need six.
-----------

iugmoh
- 19th February 2008, 09:43
oky I want to know which input is pressed so I decide what to do ?

sayzer
- 19th February 2008, 10:54
So, you do not need a "change" on the pins.

You have buttons and they can only be pressed, right?

"Change" means =>
If the button is pressed, there is a change. While the button is being pressed, there is no change.
If the button is released, there is also a change.


Are you sure you need interrupt to do this? any particular reason? Many people can solve their issues without using interrupt; simple pin readings can be more then good enough. This may be true in your case, may be.

You may want to check the status of a port for all six pins.

Archangel
- 19th February 2008, 17:23
Hi Sayzer,
Looks like he wants an assembly interrupt to jump out of any running process.


"beacuse our system entering in multiple sub routines so using polling way in main code not visible when our programm entering in another subroutine"
looks like a job for instant interrupts.

iugmoh
- 19th February 2008, 18:00
Thanks
I think sayzer understand what I mean, but I think without interrupt we can't know what button is presesd due to busy of my porgramm in other sub routines than main code

Charles Linquis
- 20th February 2008, 03:34
It sounds like you have more inputs than you have PORTB interrupt pins - or maybe your switches aren't connected to PORTB at all.

In that case, you could write an interrupt routine on a timer. The interrupt would read all ports connected to the buttons into variables, then return from the ISR.

Your main program can then (bitwise) AND the variables with a mask to pick out
which button was pushed.

Dave
- 20th February 2008, 12:00
iugmoh, Why not use 1 interrupt pin with a pullup resistor tied to as many diodes as you have switches. Then have 1 port change interrupt read the switch inputs and give the results? Why make it so complicated? Just a thought......

Dave Purola,
N8NTA

sayzer
- 20th February 2008, 12:37
iugmoh, Why not use 1 interrupt pin with a pullup resistor tied to as many diodes as you have switches. Then have 1 port change interrupt read the switch inputs and give the results? Why make it so complicated? Just a thought......

Dave Purola,
N8NTA

This is where I was going to go.