Interfacing the NXP 74HC165N Parallel-in/Serial-out Shift Register with a Microcontroller
In microcontroller applications, a common limitation is the scarcity of digital input pins. The NXP 74HC165N provides an elegant and cost-effective solution to this problem. This integrated circuit is an 8-bit parallel-in/serial-out (PISO) shift register, which allows a microcontroller to read the state of up to eight digital sensors or switches using just a few GPIO pins. This article details the principles of operation and provides a practical guide to interfacing this versatile chip.
The primary function of the 74HC165N is to convert parallel data into a serial data stream. The eight independent parallel inputs (A through H) can be set to a high or low logic level by external components, such as switches or digital outputs from other devices. The chip then transmits this data bit-by-bit to a single serial data output pin, which is read by the microcontroller. This process drastically reduces the number of I/O pins required, freeing them up for other critical tasks.
Key Control Pins and Their Functions
Successful interfacing hinges on understanding the role of each control pin:
SHIFT/LOAD (SH/LD): This is the fundamental control input. When pulled LOW, the chip loads the current state of the parallel inputs (A-H) into its internal registers. When pulled HIGH, the chip enters shift mode, and shifting occurs on the rising edge of the clock.
CLOCK (CLK): This is the shift register's clock input. On each rising edge while in shift mode, the internal data is shifted one bit, and the next bit (from the serial input) is stored. A clean, glitch-free signal from the microcontroller is essential.
SERIAL DATA INPUT (DS): This pin allows for daisy-chaining multiple 74HC165N devices. The serial output (Q7) of one register is connected to the serial input (DS) of the next. This creates a single, longer shift register, enabling the reading of 16, 24, or more inputs with the same three microcontroller pins.
SERIAL DATA OUTPUT (Q7): This is the main output pin where the serial data stream appears. The state of the first loaded bit (e.g., input H) is the first to be output.
CLOCK INHIBIT (CLK INH): When held HIGH, this pin inhibits the clock, preventing any shifting. It is often tied LOW (ground) for simplicity if not used.
A Standard Microcontroller Interface Circuit
A typical connection scheme involves the following wiring:

1. Connect the eight parallel inputs (A-H) to your switches or sensors (using pull-up or pull-down resistors as needed).
2. Connect the SH/LD pin to a microcontroller GPIO pin (e.g., Pin 1).
3. Connect the CLK pin to a second microcontroller GPIO pin (e.g., Pin 2).
4. Connect the Q7 serial output pin to a third microcontroller GPIO pin (e.g., Pin 3), configured as an input.
5. Connect CLK INH to ground and VCC and GND to the appropriate power rails.
The Software Data Reading Algorithm
The process of reading the data is straightforward and follows this sequence:
1. Preload the Registers: The microcontroller sets the SH/LD pin LOW. This latches the current state of the parallel inputs into the 74HC165N's internal registers.
2. Enable Shifting: The microcontroller sets the SH/LD pin HIGH to prepare the chip for shifting.
3. Shift and Read: The microcontroller pulses the CLK pin eight times. On each pulse (or more precisely, after each rising edge), it reads the state of the Q7 pin and stores it as the next bit in a variable. After eight clock pulses, the variable contains the state of all eight parallel inputs.
4. For daisy-chained devices, simply pulse the clock 8 x N times (where N is the number of chips) to read the entire chain.
ICGOOODFIND: The 74HC165N is an indispensable component for expanding a microcontroller's digital input capabilities. Its simple 3-wire interface, low cost, and ability to be daisy-chained make it a superior choice for projects involving a large number of buttons, switches, or digital sensors, effectively solving the problem of I/O pin scarcity.
Keywords: Shift Register, Parallel-in/Serial-out, Microcontroller Interface, GPIO Expansion, Digital Inputs.
