Monitor 15 contacts with one PIC input

Microchip PIC12F683

Benabadji Noureddine

EDN

Several previously published Design Ideas and appnotes [1-4] show how to use many pushbuttons with a minimum number of inputs. They require an RC circuit where the timing can be measured to identify which pushbutton has been pressed, or an ADC input, with resistors forming a divider for each pushbutton pressed.

The following Design Idea shows another simple way to use up to 15 pushbuttons with only one I/O. The microcontroller chosen must contain an internal comparator with selectable values for the internal voltage reference VREF. The majority of Microchip 8-bit PIC microcontrollers in the mid-range family feature one or two internal comparators with just this.

As a simple and practical example, the circuit in Figure 1 uses an 8-bit PIC12F683 controlling a 4-bit LED display to show which button has been pressed. A comparator interrupt routine reacts immediately to any pushbutton pressed. The routine cycles through VREF values until the comparator output COUT returns high, which will indicate the pushbutton pressed.

Monitor 15 contacts with one PIC input
Figure 1. Sense 15 buttons with one input.

The algorithm, in brief:

  1. Idle state, Vref = (1/24). Vdd, Vcin- = 0 < Vref => Cout = 1
  2. Any pushbutton pressed => Vcin- > Vref => Cout = 0 => Call interrupt
  3. Inside interrupt, increase Vref = (i/24). Vdd, where i = 2 to 15, until Vref > Vcin- => Cout = 1 again => Btn(i-1) has been pressed. (if Vref remains < Vcin-, then i = 16 => Btn15 has been pressed)
  4. The four LEDs show the binary number of the button pressed.

The fully commented assembler source code takes less than 100 words. It is not overly optimized, so as to simplify understanding and make translation to other controllers easy.

References

  1. Bernhard Linke: Sense multiple pushbuttons using only two wires
  2. Read 10 or more switches using only two I/O pins of a microcontroller
  3. Petre Petrov: Measure two resistive sensors or multiple switches with a single Schmitt
  4. AN234: Hardware techniques for PICmicro microcontrollers (MICROCHIP | 2003) - download

EDN

EMS supplier