+1(978)310-4246 credencewriters@gmail.com


Lab 8: Shift Registers
Extract relevant information from a shift register data sheet.
Implement serial data transfer from the Arduino to the 74HC595 shift register.
Use an Arduino Uno microcontroller and a 74HC595 8-bit shift register to independently
control 8 LEDs using only 3 Arduino digital output pins.
Arduino Uno microcontroller and USB cable
74HC595 8-bit shift register
8xLEDs, resistors, and wires
1. Read the Appendix to these instructions.
2. Go to https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftout/ and
read about the shiftOut() command, including the example code.
3. Read the required lab work below.
Required lab work
1. Based on what you learned from the Appendix, wire the shift register to receive serial
data from the Arduino and control 8 LEDs. Refer to the following figure when
connecting the shift register.
Serial input pin: connect to one of
the digital I/O pins of Arduino
8 Outputs, each connected to
one LED and resistor
GND to be active
Latch pin: connect to one of
the digital I/O pins of Arduino
Clock pin: connect to one of
the digital I/O pins of Arduino
HIGH (+5V) to deactive
Connected to GND of Arduino
Leave unconnected
2. Q0~Q7 are the 8 output pins of the shift register. After the 8-bit shift is completed, they
take logic HIGH if holding bit 1 and logic LOW if holding bit 0. Connect each of Q0~Q7
to one LED. The LED is used as a visible indicator of whether that output is holding 1 or
0. Make sure you use current limiting resistors to limit the current to 10mA to
protect LED. Given that the value of logic HIGH is 5V, the resistor should have at least
300ohm. You can use 330ohm in your kit.
In addition, as LED is a directional element, you should connect its long foot (Anode) to
higher voltage and its shorter foot (Cathode) to GND to light it up.
3. Write Arduino code to shift data into the shift register and light up the LEDs
sequentially, with a delay of 1 second between each light. Make sure that at most 1 LED
can be ON at any moment. Use the function shiftOut() to shift the data. Refer to
https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftout/ for
detailed instructions of the function and example. Demonstrate to the lab instructor or
TA. Write 2 different codes, one for “LSBFIRST” option, one for “MSBFIRST”
4. Upload your answers to the following questions to Canvas:
(1) In order to have an LED ON/OFF pattern ON ON OFF OFF OFF OFF OFF OFF,
what value should you use in shiftOut(dataPin, latchPin, LSBFIRST, Value) and
shiftOut(dataPin, latchPin, MSBFIRST, Value), respectively?
(2) How do you write codes if you want to display 0~15 sequentially? Suppose OFF
represents bit value 0, and ON represents bit value 1, so that 0 is represented as all
Hint: The key is to make it right what value should be shifted into the register. For example,
if we just want the LED connected to Q1 is ON, we should have logic
at the output pins. ShiftOut() function offers two orders to shift a binary number
b7b6b5b4b3b2b1b0 into Q0Q1Q2Q3Q4Q5Q6Q7: MSBFIRST and LSBFIRST. No matter which
order is chosen, the bits are always shifted into Q0 first. If “MSBFIRST” is chose, b7 will be
shifted into Q0 first, and the final result will be Q0Q1Q2Q3Q4Q5Q6Q7 = b0b1b2b3b4b5b6b7; if
“LSBFIRST” is used, b0 will be shifted into Q0 first, and the final result will be
Q0Q1Q2Q3Q4Q5Q6Q7= b7b6b5b4b3b2b1b0. So in order to achieve the above ON/OFF pattern,
we should shift 0000 00102 into the register with “MSBFIRST”, or 0100 00002 into the
register with “LSBFIRST”.
But note that the “value” argument of the shiftOut() function is in decimal format, so we
need to convert the binary number into its decimal format first: 0000 00102 → 2 or 0100
00002 → 64. Therefore, in order to achieve the above ON/OFF pattern, we should have
shiftOut(dataPin, latchPin, MSBFIRST, 2); OR
shiftOut(dataPin, latchPin, LSBFIRST, 64);
Shift Register Basics
Before introducing the hardware, we will introduce the concept of a bit shift. A bit shift is an
operation applied to the binary representation of an integer. Bits can be shifted to the left or the
right. Upon shifting the bits to the right, the rightmost bit will shift out of the number, each bit
preceding it will shift into the empty space left by its previous inhabitant, and the leftmost bit
(MSB) will be filled with new data. Figure 1 illustrates this for the 8-bit binary number
00010111, which then becomes 00001011 after shifting in a zero.
Figure 1: Arithmetic Right Shift
Figure 2 illustrates a left shift of the same number 00010111, which then becomes 00101110
after shifting a zero bit into the LSB.
Figure 2: Arithmetic Left Shift
The 74HC595 Shift Register
The shift register works through something called “synchronous serial communication,” i.e. you
can pulse one pin up and down thereby communicating a data byte to the register bit by bit. It’s
by pulsing second pin, the clock pin, that you delineate between bits. Once the whole byte is
transmitted to the register, the logic HIGH or LOW voltages would be detected in each of the
individual output pins of the register. This is the “parallel output” part, having all the pins do
what you want them to do all at once.
Fig. 3 shows the datasheet of 74HC595.
Fig. 3: Datasheet of 74HC595
Particularly, pins 1-7 and 15 are the 8 output pins, with pin 15 (Q0) outputting the very first bit that
is shifted in.
Pin 14 (DS) is the serial data input. When shifting bit by bit, logic HIGH or LOW is given to pin
14 to determine whether bit 1 or 0 is shifted into the register.
Pin 11 (SH_CP) is the shift register clock pin. When pin 11 is first set to logic LOW and then to
logic HIGH (i.e., creating a rising edge in signal), one bit given in pin 14 (input) is read into the
shift register.
Pin 12 (ST_CP) is the shift register latch pin. When it is first set to logic LOW, the shifted-in bits
are stored into an internal memory; when it is then set to logic HIGH, the data stored in the
internal memory will be moved to the 8 output pins (pin 15, pins 1-7).
Pin 10 and pin 13 need to be kept active when functioning the serial input and parallel output, thus
both being set to logic LOW (connected to GND from Arduino).
For more explanations, you could read the official link:

Purchase answer to see full

error: Content is protected !!