Added a 74HC595 shift register

A abstract base class for 74HC595 shift registers without reset and
output-enable functionality.
master
mandlm 2017-02-19 12:17:54 +01:00
parent 4685956e82
commit 9f8ad33723
2 changed files with 45 additions and 0 deletions

27
ShiftRegister.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "ShiftRegister.h"
void ShiftRegister::set(uint8_t value)
{
for (uint8_t bit = 0; bit < 8; ++bit)
{
setSerialPin(value & (1 << (7 - bit)));
pulseShiftPin();
}
pulseStoragePin();
}
void ShiftRegister::pulseShiftPin()
{
setShiftPin(false);
setShiftPin(true);
setShiftPin(false);
}
void ShiftRegister::pulseStoragePin()
{
setStoragePin(false);
setStoragePin(true);
setStoragePin(false);
}

18
ShiftRegister.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <stdint.h>
class ShiftRegister
{
public:
void set(uint8_t value);
private:
virtual void setSerialPin(bool value) = 0;
virtual void setShiftPin(bool value) = 0;
virtual void setStoragePin(bool value) = 0;
void pulseShiftPin();
void pulseStoragePin();
};