inital version

This commit is contained in:
2020-05-27 20:38:58 +02:00
commit 7b936642ad
21 changed files with 1850 additions and 0 deletions

43
shiftreg.h Normal file
View File

@ -0,0 +1,43 @@
#pragma once
#include <util/delay.h>
template <int BITS> class ShiftReg
{
private:
static constexpr int BYTES = (BITS % 8 == 0) ? (BITS/8) : (BITS/8+1);
volatile unsigned char *_port;
const unsigned char _pinSer;
const unsigned char _pinSerClk;
const unsigned char _pinRClk;
public:
ShiftReg(volatile unsigned char* const port, const unsigned char pinSer, const unsigned char pinSerClk, const unsigned char pinRClk):
_port(port), _pinSer(pinSer), _pinSerClk(pinSerClk), _pinRClk(pinRClk)
{
clear();
}
void write(const unsigned char * const in)
{
*_port &= ~((1<<_pinSer) | (1<<_pinSerClk));
*_port |= 1<<_pinRClk;
for(unsigned char i = 0; i < BITS; ++i)
{
*_port &= ~(1 << _pinSerClk);
in[i/8] & (1<<(i%8)) ? (*_port |= (1 << _pinSer)) : (*_port &= ~(1 << _pinSer));
*_port |= (1 << _pinSerClk);
}
*_port &= ~(1<<_pinRClk);
}
void clear()
{
*_port &= ~((1<<_pinSer) | (1<<_pinSerClk));
*_port |= 1<<_pinRClk;
for(unsigned char i = 0; i < BITS; ++i)
{
*_port &= ~(1 << _pinSerClk);
*_port |= (1 << _pinSerClk);
}
*_port &= ~(1<<_pinRClk);
}
};