Microcontroller multiplexes DIP switches to I/O port
Gregory Willson, ACS Defense Inc, Warrenton, VA -- EDN, February 17, 2000
At times, a µC must read a large number of DIP switches, such as for system identification, bus-address setup, manual configuration, or other purposes. However, the available number of I/O lines is sometimes not enough to assign a switch to each one. You can use multiplexer ICs to share one I/O port with multiple switches, but they complicate the circuit, dissipate additional power, and consume precious board real estate. Figure 1 shows a method of multiplexing 32 DIP switches using only 12 I/O pins and eight pullup resistors. Four 8-bit DIP switches connect in parallel to a single 8-bit I/O port. A pullup resistor on each port pin defaults the input to a high state; a switch closure pulls the input to a low state. The key to multiplexing the DIP switches is to ground each set of eight switches in turn using output pins from a second I/O port.
o deselect a set of switches, the controlling-port pin acts as an input, rendering it a high-impedance port. In this way, 12 I/O pins can read 32 switches, and 16 I/O pins can read 64 switches. Select the values of the pullup resistors to limit the total current into the controlling-port pin to less than the maximum sink current. Some µCs, such as the Microchip PIC16C6x family, provide the ability to enable weak internal pullups on I/O port pins. By using this feature, you can eliminate the eight external pullp resistors. The code fragment in Listing 1 illustrates reading the four 8-bit DIP switches and storing the results, using a Microchip PIC16C63 µC. (DI #2483)
-
Hi,
This wont work. Long story short the any closed switches in the 'idle' banks will short circuit other ports in the active bank. Sketch it out for 2x2 dips on 2 ports.
Simon - 2010-2-3 20:30:00 PST -
This idea wont work for specific conditions.
e.g. Switch 0's 0th bit is ON (Data = 1), Switch 1's 0th and 1st bit is ON (Data =3). Rest all are off, then still with this we ll get 0th switch read as 3 not as 1. Kindly comment on this.
We need diodes to isolate the switch inputs.
Suryakant Mulik - 2010-9-2 03:23:00 PST -
THis would oly work if only 1 dip switch on each bank was turned on at a time. any more would cause conflicts
Tom Lee - 2009-2-12 08:49:00 PST -
It´s a good article, however, from my point of vue, it seem that only one switch can be closed at a time. If several switches are closed at once, some RA port pins can be short-circuited...
Emmanuel Lomba - 2009-20-11 07:00:00 PST -
This design would not work without diodes top siolate the switches, or tristate buffers after the dips as well.
As it is shown, one gets short circuits via the onselected dip switches.
One problem with diodes is that it results in very close to theshold voltage level when the output is low ('0'). This is especially the case when using
Robert Salasidis - 2009-16-11 12:57:00 PST


















