Microcontroller multiplexes DIP switches to I/O port
Gregory Willson, ACS Defense Inc, Warrenton, VA -- EDN, 2/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)
















