Illustrated is an interface circuit that allows a PC to read 16 channels of digital inputs (see the figure). The circuit is connected to the PC’s COM1 serial port directly. The same serial port also powers the circuit so that no additional power supply is needed.
There are four directly accessible input lines (pin 1, 6, 8, and 9) in a RS-232 serial port. These four lines are expanded by two dual four-input multiplexers (IC-1 and IC-2) to accept 16 inputs. The inputs can be on/off switches or open-collector/drain transistors between each input line and ground. Each of the input lines has a 100k pullup resistor to set logic high when the switch is off.
Two output lines (pins 4 and 7) control the selection of the input channels. Each line condition allows the PC to read four input channels under the control of the C program (see the listing). Output pin 4 also provides the power supply for ICs through diode D3. C1 holds the energy to power ICs when pin 4 is low. Once pin 4 is high, C1 will be charged up again. Because the serial port provides both positive and negative current outputs, two Zener diodes (D1 and D2) are used to limit the voltage range of output lines within −0.6 and +5.1 V.