Devices & Components
Arduino Uno Rev3
Shift Register- Serial to Parallel
Breadboard (generic)
Resistor 220 ohm
LED (generic)
Jumper wires (generic)
Software & Tools
Arduino IDE
Project description
Code
ez_SIPO8_lib Tutorial - Relative Addressing
c_cpp
Example of relative addressing using the ez_SIPO8_lib library functions
1// 2// Tutorial 2 - use of ez_SPI8 library, 3// Relative addressing 4 - 1 x physical SIPO IC 5// The sketch demonstrates two ways in which SIPO output 6 pins 7// may be updated, individually (set_bank_pin) or in a group 8// of 9 8 pins (set_bank_SIPO), representing a single 8it SIPO 10// within a bank. 11// 12// 13 Ron D Bentley, Stafford, UK 14// April 2021 15// 16// This example and 17 code is in the public domain and 18// may be used without restriction and without 19 warranty. 20// 21 22#include <ez_SIPO8_lib.h> 23 24#define Max_SIPOs 1 // 25 two virtual SIPOs for this tutorial 26#define Max_timers 0 // no timers required 27 28// 29 initiate the class for Max SIPOs/timers required 30SIPO8 my_SIPOs(Max_SIPOs, Max_timers); 31 32int 33 bank_id; // used to keep the SIPO bank id 34 35void setup() { 36 Serial.begin(9600); 37 38 bank_id = my_SIPOs.create_bank(8, 10, 9, 1); // absolute pin addresses 0-7, relative 39 addresses 0-7 40 if (bank_id == create_bank_failure) { 41 Serial.println(F("\ 42failed 43 to create bank")); 44 Serial.flush(); 45 exit(0); 46 } 47 // print 48 the bank data for confirmation/inspection 49 my_SIPOs.print_SIPO_data(); 50} 51 52void 53 loop() { 54 // start by setting the only SIPO (0) in the bank to all outputs off/LOW 55 56 my_SIPOs.set_bank_SIPO(bank_id, 0, LOW); 57 my_SIPOs.xfer_bank(bank_id, LSBFIRST); 58 // move virtual pin statuses to real SIPO output pins 59 do { 60 // 61 62 // setup pattern for first cycle: 0b01010101 63 // note that set_bank_pin 64 uses relative addressing 65 my_SIPOs.set_bank_pin(bank_id, 0, HIGH); // least 66 significant bit/pin 67 my_SIPOs.set_bank_pin(bank_id, 1, LOW); 68 my_SIPOs.set_bank_pin(bank_id, 69 2, HIGH); 70 my_SIPOs.set_bank_pin(bank_id, 3, LOW); 71 my_SIPOs.set_bank_pin(bank_id, 72 4, HIGH); 73 my_SIPOs.set_bank_pin(bank_id, 5, LOW); 74 my_SIPOs.set_bank_pin(bank_id, 75 6, HIGH); 76 my_SIPOs.set_bank_pin(bank_id, 7, LOW); // most significant bit/pin 77 78 my_SIPOs.xfer_bank(bank_id, MSBFIRST); 79 delay(500); 80 // 81 // 82 setup reverse pattern using 8bit write function: 0b10101010 83 // note that 84 set_bank_SIPO uses relative addressing for SIPOs in the bank 85 my_SIPOs.set_bank_SIPO(bank_id, 86 0, 0b10101010); 87 my_SIPOs.xfer_bank(bank_id, MSBFIRST); 88 delay(500); 89 90 } while (true); 91} 92
ez_SIPO8_lib Tutorial - Relative Addressing
c_cpp
Example of relative addressing using the ez_SIPO8_lib library functions
1// 2// Tutorial 2 - use of ez_SPI8 library, 3// Relative addressing - 1 x physical SIPO IC 4// The sketch demonstrates two ways in which SIPO output pins 5// may be updated, individually (set_bank_pin) or in a group 6// of 8 pins (set_bank_SIPO), representing a single 8it SIPO 7// within a bank. 8// 9// Ron D Bentley, Stafford, UK 10// April 2021 11// 12// This example and code is in the public domain and 13// may be used without restriction and without warranty. 14// 15 16#include <ez_SIPO8_lib.h> 17 18#define Max_SIPOs 1 // two virtual SIPOs for this tutorial 19#define Max_timers 0 // no timers required 20 21// initiate the class for Max SIPOs/timers required 22SIPO8 my_SIPOs(Max_SIPOs, Max_timers); 23 24int bank_id; // used to keep the SIPO bank id 25 26void setup() { 27 Serial.begin(9600); 28 bank_id = my_SIPOs.create_bank(8, 10, 9, 1); // absolute pin addresses 0-7, relative addresses 0-7 29 if (bank_id == create_bank_failure) { 30 Serial.println(F("\ 31failed to create bank")); 32 Serial.flush(); 33 exit(0); 34 } 35 // print the bank data for confirmation/inspection 36 my_SIPOs.print_SIPO_data(); 37} 38 39void loop() { 40 // start by setting the only SIPO (0) in the bank to all outputs off/LOW 41 my_SIPOs.set_bank_SIPO(bank_id, 0, LOW); 42 my_SIPOs.xfer_bank(bank_id, LSBFIRST); // move virtual pin statuses to real SIPO output pins 43 do { 44 // 45 // setup pattern for first cycle: 0b01010101 46 // note that set_bank_pin uses relative addressing 47 my_SIPOs.set_bank_pin(bank_id, 0, HIGH); // least significant bit/pin 48 my_SIPOs.set_bank_pin(bank_id, 1, LOW); 49 my_SIPOs.set_bank_pin(bank_id, 2, HIGH); 50 my_SIPOs.set_bank_pin(bank_id, 3, LOW); 51 my_SIPOs.set_bank_pin(bank_id, 4, HIGH); 52 my_SIPOs.set_bank_pin(bank_id, 5, LOW); 53 my_SIPOs.set_bank_pin(bank_id, 6, HIGH); 54 my_SIPOs.set_bank_pin(bank_id, 7, LOW); // most significant bit/pin 55 my_SIPOs.xfer_bank(bank_id, MSBFIRST); 56 delay(500); 57 // 58 // setup reverse pattern using 8bit write function: 0b10101010 59 // note that set_bank_SIPO uses relative addressing for SIPOs in the bank 60 my_SIPOs.set_bank_SIPO(bank_id, 0, 0b10101010); 61 my_SIPOs.xfer_bank(bank_id, MSBFIRST); 62 delay(500); 63 } while (true); 64} 65
Downloadable files
Single SIPO Shift Register, wiring diagram
Used throughout the tutorials
Single SIPO Shift Register, wiring diagram

Comments
Only logged in users can leave comments