-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShiftRegister.cpp
76 lines (71 loc) · 1.18 KB
/
ShiftRegister.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "SPL/Atmega16A_SPL.hpp"
class ShiftRegisterButtons
{
private:
PinSBase *_RegisterClk,*_RegisterPL,*_RegisterQ7;
public:
volatile uint16_t lastData;
ShiftRegisterButtons(PinSBase &Clk, PinSBase &PL, PinSBase &Q)
{
_RegisterClk = &Clk;
_RegisterPL = &PL;
_RegisterQ7 = &Q;
}
void Initialize()
{
_RegisterClk->AsOutput();
_RegisterPL->AsOutput();
_RegisterQ7->AsInput();
_RegisterPL->Clear();
}
uint8_t FirstReadStage()
{
_RegisterPL->Set();
asm("nop");
_RegisterPL->Clear();
uint8_t data = 0;
for (int i = 0;i < 15;i++)
{
_RegisterClk->Clear();
data <<= 1;
if (!_RegisterQ7->Check())
{
data++;
}
_RegisterClk->Set();
}
return data;
}
uint8_t SecondReadStage()
{
uint8_t data = 0;
for (int i = 0;i < 8;i++)
{
_RegisterClk->Clear();
data <<= 1;
if (!_RegisterQ7->Check())
{
data++;
}
_RegisterClk->Set();
}
return data;
}
uint16_t ReadData()
{
_RegisterPL->Set();
_RegisterPL->Clear();
lastData = 1;
for (int i = 22;i >=0;i--)
{
_RegisterClk->Clear();
lastData <<= 1;
if (!_RegisterQ7->Check())
{
lastData++;
}
_RegisterClk->Set();
}
return lastData;
}
};