Devices & Components
Arduino Uno Rev3
Resistor 220 ohm
5 mm LED: Red
Shift Register- Serial to Parallel
Solderless Breadboard Half Size
Tactile Switch, Top Actuated
Development Kit Accessory, Jumper Wire Kit
Jumper wires (generic)
Breadboard (generic)
Software & Tools
Arduino IDE
Project description
Code
74HC595 Programmatic Master Reset Sketch
c_cpp
To show the operation of the 74HC595 shift register master reset (MR) function.
1// 2// 74HC595 Programmatic Master Reset 3// 4// Ron Bentley, Stafford UK 5// February 2022 6// 7// This example and code is in the public domain and may be used without 8// restriction and without warranty. 9// 10// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11// Example sketch - Demonstration of Programmatic Control of the 12// 74HC595 Shift Register Master Reset(MR) Function 13// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 14// 15// Objective of the sketch 16// ^^^^^^^^^^^^^^^^^^^^^^^ 17// To show the operation of the 74HC595 shift register master reset (MR) 18// function. 19// 20// Approach 21// ^^^^^^^^ 22// To achieve our objective, we need to bring the SIPO IC's master reset pin 23// (MR, but often labelled SRCLR)under programmatic control. 24// For this, we allocate a digital microcontroller pin and connect this to the 25// MR (SRCLR) pin of the SIPO IC. 26// 27// By lowering and raising the signal level of this pin (LOW/HIGH, 0/+5v) 28// we are able to produce a complete SIPO IC reset as necessary. 29// To show this operation the sketch uses a simply connected button switch 30// to toggle the SIPO IC's master reset function and noramal SIPO IC updates. 31// 32// The sketch uses two libraries: 33// 1. the ez_switch_lib library to define and control a simply connected 34// button switch, and 35// 2. the ez_SIPO8_lib library to define and control a single 74HC595 36// shift register. 37// These libraries may be accessed and downloaded via the ARDUINO Project Hub: 38// 39// 1. ez_switch_lib library- 40// https://create.arduino.cc/projecthub/ronbentley1/a-switch-library-for-arduino-dfbe40?ref=user&ref_id=1455180&offset=17 41// 42// 2. ez_SIPO8_li library- 43// https://create.arduino.cc/projecthub/ronbentley1/command-control-of-multiple-serial-in-parallel-out-ics-3e0b1a?ref=user&ref_id=1455180&offset=16 44// 45// If you wish to read a primer for SIPO ICs/shift registers then have a look at the link below: 46// https://lastminuteengineers.com/74hc595-shift-register-arduino-tutorial/ 47// 48// **** 49// declare SIPO IC data 50#include <ez_SIPO8_lib.h> 51 52SIPO8 my_SIPOs(1, 0); // configure for one SIPO IC, no timers for this sketch 53 54uint16_t bank_id; 55 56#define data_pin 8 57#define latch_pin 9 58#define clock_pin 10 59#define IC_MR_pin 11 60 61bool IC_MR_status; 62 63// **** 64// Declare switch data 65#include <ez_switch_lib.h> 66 67Switches my_switch(1); // establish just one switch for this sketch 68 69int switch_id; 70 71#define my_switch_pin 12 72 73void setup() { 74 // **** 75 // Set up switch - a button switch, simply wired without a pulldown resistor 76 switch_id = 77 my_switch.add_switch(button_switch, my_switch_pin, circuit_C2); // add & configure the switch 78 79 // **** 80 // Deal with initialisation of the MR reset pin 81 pinMode(IC_MR_pin, OUTPUT); 82 IC_MR_status = HIGH; // start with a HIGH signal, ie IC active status, ready for data 83 digitalWrite(IC_MR_pin, IC_MR_status); 84 85 // **** 86 // Set up the SIPO - one SIPO IC in this bank on these control pins: 87 bank_id = 88 my_SIPOs.create_bank(data_pin, clock_pin, latch_pin, 1); 89 // Now set all of the IC's output pins HIGH (LEDs on) 90 my_SIPOs.set_all_array_pins(HIGH); 91 my_SIPOs.xfer_array(MSBFIRST); 92} 93 94void loop() { 95 do { 96 // Only process if the button switch has been toggled. 97 // Alternative switch presses perform direct programmatic IC shift 98 // register master resets and normal IC updates, respectively 99 if (my_switch.read_switch(switch_id) == switched) { 100 // Button switch actuated 101 IC_MR_status = !IC_MR_status; // invert current IC_MR_status and process 102 if (IC_MR_status == LOW) { 103 // Request to programmatically reset the SIPO IC via the MR pin, so reset the 104 // IC shift register and ensure output ports also reflect cleared status by 105 // toggling latch pin 106 digitalWrite(IC_MR_pin, LOW); // reset IC - drop MR reset pin +5v signal 107 digitalWrite(IC_MR_pin, HIGH); // set IC back to active status 108 digitalWrite(latch_pin, LOW); // indicate an update from shift register to output required 109 digitalWrite(latch_pin, HIGH); // action transfer of register reset state to the outputs 110 } else { 111 // Normal update the SIPO with all outputs raised HIGH 112 my_SIPOs.set_all_array_pins(HIGH); 113 my_SIPOs.xfer_array(MSBFIRST); // send update to all output ports 114 } 115 } 116 } while (true); 117} 118
Downloadable files
Operation of the 74HC595 Master Reset Sketch
Operation of the 74HC595 Master Reset Sketch
Operation of the 74HC595 Master Reset Sketch
74HC595 Wiring Schematic
74HC595 wiring schematic with simply connected button switch for programmatic control
74HC595 Wiring Schematic

Comments
Only logged in users can leave comments