AN-203 I/O Expansion Techniques
interrupt, locking the task is not sufficient to avoid this problem because an external interrupt will cause the current
task to be suspended even if it is locked.
Private Const dataPin as Byte = 17
Private Const selMask as Byte = &H07
Dim b as Byte
' initialize the I/O pins so that pins 18-20 are outputs
Register.DDRA = Register.DDRA Or selMask
' read data from input channel 3
b = GetInput(3)
Function GetInput(ByVal channelNum as Byte) As Byte
' output the channel select code to the multiplexer
channelNum = channelNum And selMask
Register.PortA = (Register.PortA And Not selMask) Or channelNum
' read the selected input
GetInput = GetPin(dataPin)
This technique can be extended even further by using stages of multiplexers. For example, the outputs of two
74HC151 devices could be multiplexed through a 74HC157. This would provide 16 inputs while using only 5 I/O
pins. Note that the S2 to S0 inputs of both ‘151 multiplexers can be driven by the same output pins. Only one
additional output pin would be required to feed to the ‘157 to select which “bank” of inputs is to be read.
The same multiplexing principle can be applied to analog inputs however an analog multiplexer must be used. The
CD4066, 74HC4066 and MAX4634 are examples of a device that would work for this purpose.
Using a Decoder/Demultiplexer for Multiple Outputs
A decoder is a device that outputs a “select” signal on 1 of N outputs based on the state of the selection inputs. A
demultiplexer is a device that routes an input signal to 1 of N outputs based on the state of the selection inputs.
The similarities between these two descriptions suggests why devices are often labeled decoder/demultiplexer –
depending on how you connect it, it can be used to perform either operation.
The 74HC138 and 74HC139 are two examples of a decoder/demultiplexer. The former is a single 1 of 8 device
while the latter is a dual 1 of 4 device. The circuit in Figure 2 shows how the 74HC138 can be connected to a ZX-
24 to provide 8 select or strobe signals using only 4 processor outputs. Pins 18 to 20 provide the 1 of N selection
code that determines which of the 8 outputs of the ‘138 will go low when the device is properly enabled. The ‘138
has three enable inputs: two active low and one active high. In this example, we’ve connected one of the active low
enable inputs to pin 17 of the ZX-24 with two remaining enable inputs hard wired to their active states. When pin
17 of the ZX-24 goes low, one of the eight ‘138 outputs will go low depending on the A2-A0 inputs.
The outputs of the ‘138 could be used as an active low device select signal to an external circuit that enables the
device to perform its function. If a device requires an active high select signal, the signal will need to be inverted
before using it. The outputs of the ‘138 could also be used with edge-sensitive devices like flip-flops, shift registers
or counters. When used this way the signal is commonly called a strobe or clock signal.
Note the pullup resistor used on the ZX output that drives the enable input. This resistor ensures that there will be
no false outputs from the decoder during processor resets.
Copyright © 2005 Elba Corp.
Published November 2005
Free Datasheet http://www.datasheet4u.net/