On Sat, 22 Jul 1995, jory bell wrote: > I came across a reference to a "2 of N" keyboard scanning method, which > uses less io thant the typical xy system. > Maybe I am in the dark ages here, but can anyone tell me the > hardware/software basis for this? Let preface this by saying that I'm guessing. Connect a switch between each pair of I/O pins. With N pins, you can pair up the pins .5 * N * (N-1) different ways. With 6 pins, that is 15 switchs. An XY system would only allow 9 switches. Scanning is somewhat more complex, but it's only software. For each pin Set all other pins as input Set selected pin as output Output 0 (assuming pull up resistors) For each input pin If 0; Key pressed, do something usefull Next input pin Next pin If you add a diode with a large voltage drop, ie. a green LED, to each switch, you can do N key rollover. The diode's voltage drop has to be big enough so that two diodes in series have a combined voltage drop too large to pull an input pin down to a logic zero. For slightly more switches: connect the pullup resistors to an output pin, such that they can be pull up or pull down. Now you connect 2 switches (with 2 diodes) between each pair of outputs, except the resistor driver. This is good for (N-1) * (N-2) switches. 6 pins can handle 20 switches. With this mechanism, you can also read the state of any switch independently of the state of any other switch. The PIC inputs draw too little current to make the LEDs glow visibly. ++++++++++++++++ I was thinking of using a similar circuit to control many devices from a PIC. Alas the devices used too much current. But, if you want to drive green LEDs one at a time, you can control 30 with 6 pins, 42 with 7 pins, or 56 with 8 pins. You'll also need a current limiting resistor for each LED. +++++++++++++++ I assume the reason that few people bother with this sort of scheme is that parts is parts. Once you've gone to the trouble of installing 30 switches, the cost of a PIC with more I/O or one more chip is insignificant. -- Paul Haas paulh@hamjudo.com http://www.hamjudo.com