Searching \ for 'How to read 2 inputs connected together?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/ios.htm?key=input
Search entire site for: 'How to read 2 inputs connected together?'.

Truncated match.
PICList Thread
'How to read 2 inputs connected together?'
2000\02\03@044510 by Darren King

flavicon
face
part 0 16 bytes
</x-html>

2000\02\03@053711 by Joseph Rutsky

picon face
You would set one pin high/low and see which pin in the matrix is pressd
ny seeing which reads the same.  Reading in succession and keeping track
of which pin you are reading will tell you which key is pressed.

Joe

2000\02\03@055812 by Quentin

flavicon
face
Darren
If I understand you correctly, you are using a keypad with 6 connector
pins correct?
Then your keypad then either has 9 keys (3x3) or 8 keys (2x4)correct?
If so, read on, if not, please explain better.

The way I derived that you either has 8 or 9 keys is from what we know
as a matrix (no, not the movie) layout. Let's work on the 9 keys, then
your pins are something like this:
Pin
1---(7)-(8)-(9)
    |   |   |
2---(4)-(5)-(6)
    |   |   |
3---(1)-(2)-(3)
    |   |   |
    |   |   |
    |   |   |
    4   5   6

(keypad keys are in () )

pins 1, 2 , 3 we call scan lines and 4, 5, 6 we call datalines. What you
do now is to make the scan lines high in sequence and everytime the pin
is high, you read the data lines.
IE:
You make pin 1 high, then read 4, then 5, then 6 to see which one is
high, then you make pin 1 low and 2 high and read 4, 5, 6 again, etc.

Say pin 3 is high and after you read 4, 5 and 6, you see 6 is high, then
you you would know key 3 was pressed because the high of 3 gets switched
to 6 because key (3) was pressed.

The sequence of the scan lines and data lines you will have to get from
a data sheet.
For PIC examples see AN529.

Hope this helps
Quentin

2000\02\03@070630 by paulb

flavicon
face
Quentin wrote:

> 1---(7)-(8)-(9)
>      |   |   |
> 2---(4)-(5)-(6)
>      |   |   |
> 3---(1)-(2)-(3)
>      |   |   |
>      |   |   |
>      4   5   6

> You make pin 1 high, then read 4, then 5, then 6 to see which one is
> high, then you make pin 1 low and 2 high and read 4, 5, 6 again, etc.

 That's not *quite* correct.

 Firstly, pins you are using as an input must be given a known state.
The PIC has built-in pull-ups on port B which you may care to use or you
can use external pull-up resistors for all keyboard lines.

 Note that for protection against shorts to ground, which are rather
more likely than shorts to supply, it is usual to use pull-ups rather
than pull-downs as in a short to ground (being in effect the same as a
switch closure to ground) the current will be safely limited by the
pull-up.

 Secondly, you "strobe" each row (or if you wish, column) in turn by
making it an output and pulling it *low*, but the rows you are *not*
strobing, you do *not* pull high, but rather open-circuit them by making
them inputs.

 If both rows and columns are part of port B and you elected to use the
internal pull-ups, then the non-selected rows will be pulled up by the
pull-ups as well as the columns but this does not matter (in fact, you
don't really want any inputs to float).  The point is that by this means
multiple switch closures in any given row will *not* cause high and low
outputs to conflict.

 When one row, say pin 1, is low, then any column may be pulled down by
a corresponding closed switch on that row, while all other columns are
pulled up by their pull-ups.  By pulling each row low in turn, and
reading (generally in one I/O operation, using a shift operation to
test each in turn) all columns, all the switches can be read.

 You may note a couple of cunning tricks which may or may not be
useful.  One is to hold *all* rows low whilst reading the columns,
waiting for *any* closure before strobing them individually.  This makes
it very simple to perform a status check on the keyboard as a whole, it
can even be done in SLEEP using the Port B interrupt-on-change.

 Also, a quite fast way of finding a single key closure (i.e., does not
work if more than one key is pressed), is to pull all rows low and read
the columns, then pull all columns low and read the rows.  As long as
you only see one column and one row pulled down as a result, this
uniquely indicates the closure.

 Note that the PORT register is kept clear to do this, (do not use
read-modify-write instructions on it) and only the TRIS register is
changed (use the TRIS instruction!) but the PORT is read each time.
--
 Cheers,
       Paul B.

2000\02\03@092748 by Ken Webster
flavicon
face
Paul B. Webster wrote:
{Quote hidden}

Good advice!

I just happened to have an example sitting around.  It is for a 4x4 keypad
connected to a 17C756 on PORTB.  It doesn't do the fast scan ... just a
plain old one-row-at-a-time scan.  I had PORTB (output latch) set to 0.
Weak pullups were enabled.

Pinout is kinda funky (to make PCB layout easier):


6---(1)-(2)-(3)-(A)
    |   |   |   |
7---(4)-(5)-(6)-(B)
    |   |   |   |
5---(7)-(8)-(9)-(C)
    |   |   |   |
2---(*)-(0)-(#)-(D)
    |   |   |   |
    3   4   0   1



;------------------------------------------------------------
;Called by interrupt handler to scan the keypad
;Returns with W=ASCII if a key is pressed, W=0 otherwise
;Interrupt handler performs debounce
SCAN1   MOVLW   ~0X40         ;Enable ROW0 output
       MOVWF   DDRB
       NOP
       NOP
       BTFSS   PORTB,3
       RETLW   '1'
       BTFSS   PORTB,4
       RETLW   '2'
       BTFSS   PORTB,0
       RETLW   '3'
       BTFSS   PORTB,1
       RETLW   'A'
       MOVLW   ~0X80         ;ROW1
       MOVWF   DDRB
       NOP
       NOP
       BTFSS   PORTB,3
       RETLW   '4'
       BTFSS   PORTB,4
       RETLW   '5'
       BTFSS   PORTB,0
       RETLW   '6'
       BTFSS   PORTB,1
       RETLW   'B'
       MOVLW   ~0X20         ;ROW2
       MOVWF   DDRB
       NOP
       NOP
       BTFSS   PORTB,3
       RETLW   '7'
       BTFSS   PORTB,4
       RETLW   '8'
       BTFSS   PORTB,0
       RETLW   '9'
       BTFSS   PORTB,1
       RETLW   'C'
       MOVLW   ~0X04         ;ROW3
       MOVWF   DDRB
       NOP
       NOP
       BTFSS   PORTB,3
       RETLW   '*'
       BTFSS   PORTB,4
       RETLW   '0'
       BTFSS   PORTB,0
       RETLW   '#'
       BTFSS   PORTB,1
       RETLW   'D'
       RETLW   0


Cheers,

Ken

2000\02\03@153415 by paulb

flavicon
face
Ken Webster wrote:

> I just happened to have an example sitting around.  It is for a 4x4
> keypad connected to a 17C756 on PORTB.  It doesn't do the fast scan
> ... just a plain old one-row-at-a-time scan.

 Whoa-hoah, that *is* hard-wired!  And that's the series without the
rotten "bank select" muck-up.  Interesting.
--
 Cheers,
       Paul B.

2000\02\03@165510 by Andre Abelian

picon face
part 0 16 bytes
</x-html>

2000\02\03@183733 by John Mullan

picon face
part 0 16 bytes
</x-html>

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...