Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/26/06 04:44
Read: times


 
Msg Score: +2
 +1 Good Answer/Helpful
 +1 Good Question
#121052 - it's quite simple ... therein lies the beauty.
Responding to: ???'s previous message
You have 16 switches in the cited example, organized as four rows and four columns. no current can flow between the rows or columns unless a switch is closed. So long as only one switch is closed, it is very simple to tell which one it is. This is done by first initializing the MCU and allowing it to arrive at a stabile state, then writing all '1's (0FF in hexadecimal) to, in this case, P1. You then initialize a timer to time out nominally 25 milliseconds or so, the time isn't very critical, though it must be long enough to mask the "bounce" time of the switches you're using.

When you write a '0' to one, and only one, of the rows, which you should do in sequence, e.g. 0EFh, followed by 0DFh, followed by 0BFh, followed by 07Fh, and then repeating the sequence each time the interval timer overflows, then read the value on P1 after the next timeout, you'll only see the value you've written, unless a switch is closed, in which case, since you know which code you've written, you can XOR that value with what you read, and it will yield a '1' in the column in which the switch is closed. You must "see" the closed switch on two successive timeouts, in order to allow for the bounce. You can use any number of interpretation methods, e.g. table lookup, to interpret what you've read if two identical nonzero values turn up after you've xor'd the port value twice, with a nonzero return value.

Perhaps this clears things up for you.

Remember, if you write a zero to a row, it will appear in a column only if a switch is closed. If it appears in more than one row, then you've probably struck more than one key. I recommend you guard against that, as it will produce confusing "sneak paths" which give false readings.

RE


List of 41 messages in thread
TopicAuthorDate
connecting a keypad . HOW?            01/01/70 00:00      
   Because...            01/01/70 00:00      
      How many times will this come up?            01/01/70 00:00      
         To be fair            01/01/70 00:00      
         Help him!            01/01/70 00:00      
            OK ... but just this once!            01/01/70 00:00      
   it's quite simple ... therein lies the beauty.            01/01/70 00:00      
      In minute detail            01/01/70 00:00      
         Credit goes to original author Michael Karas            01/01/70 00:00      
            Yes - Credit to Michael Karas            01/01/70 00:00      
      Diodes prevent \"ghosting\"            01/01/70 00:00      
         indeed, but rarely needed            01/01/70 00:00      
            Think of a piano, where each key counts...            01/01/70 00:00      
               How often do you intend to use multiple keys?            01/01/70 00:00      
                  There is the case of...            01/01/70 00:00      
                     True, but how often?            01/01/70 00:00      
                        Agreed            01/01/70 00:00      
                        general input            01/01/70 00:00      
                  I agree, but...            01/01/70 00:00      
      a small catch            01/01/70 00:00      
         In this case, the pullups were external            01/01/70 00:00      
            HUH????            01/01/70 00:00      
               Sorry, I should have said you must not ...            01/01/70 00:00      
                  just visualize            01/01/70 00:00      
                     It happens all the time ...            01/01/70 00:00      
                        current limits            01/01/70 00:00      
                           transistors open won't conduct            01/01/70 00:00      
                              Totally unsuited with push/pulls, unless...            01/01/70 00:00      
                                 This is true, which is why one should READ first            01/01/70 00:00      
                                    there is no reason, but 'linear thinking' (outputs            01/01/70 00:00      
                                       Some encoders "see" pretty high impedances            01/01/70 00:00      
                                          cruel and unusual            01/01/70 00:00      
                                       No!            01/01/70 00:00      
                                          OK, rephrase            01/01/70 00:00      
                                             Ah, sorry!            01/01/70 00:00      
                                    Benefit of additional pull-ups            01/01/70 00:00      
   Disappearing Original Post!            01/01/70 00:00      
      that is not all that is missing!            01/01/70 00:00      
         Bug            01/01/70 00:00      
            Bugs            01/01/70 00:00      
               OOps            01/01/70 00:00      

Back to Subject List