Added a 74HC595 shift register
A abstract base class for 74HC595 shift registers without reset and output-enable functionality.
This commit is contained in:
parent
4685956e82
commit
9f8ad33723
27
ShiftRegister.cpp
Normal file
27
ShiftRegister.cpp
Normal 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
18
ShiftRegister.h
Normal 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();
|
||||
};
|
||||
|
Reference in New Issue
Block a user