-
Notifications
You must be signed in to change notification settings - Fork 0
/
SR74HC595.cpp
68 lines (57 loc) · 1.42 KB
/
SR74HC595.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
#include "SR74HC595.h"
/////////////////////////////////////////////////INSTANT/INIT DEFINITION/////////////////////////////////////////////////
SR74HC595::SR74HC595(uint8_t _Data,uint8_t _Clk, uint8_t _Latch)
{
datapin = _Data;
clkpin = _Clk;
latchpin = _Latch;
initializePins();
}
////////////////////////////////////////////////////PRIVATE DEFINITION////////////////////////////////////////////////////
void SR74HC595::initializePins()
{
pinMode(datapin,OUTPUT);
pinMode(clkpin,OUTPUT);
pinMode(latchpin,OUTPUT);
digitalWrite(datapin,LOW);
digitalWrite(clkpin,LOW);
digitalWrite(latchpin,LOW);
}
void SR74HC595::clock()
{
digitalWrite(clkpin,HIGH);
delayMicroseconds(500);
digitalWrite(clkpin,LOW);
delayMicroseconds(500);
}
void SR74HC595::store()
{
digitalWrite(latchpin,HIGH);
delay(5);
digitalWrite(latchpin,LOW);
delay(5);
}
void SR74HC595::serialToParallel()
{
for(int8_t i=7;i>=0;i--)
{
digitalWrite(datapin,((dataRegister>>i) & 0x01));
clock();
}
}
////////////////////////////////////////////////////PUBLIC DEFINITION////////////////////////////////////////////////////
void SR74HC595::sendToShiftRegister(uint8_t* data,uint8_t srNos) // send data to shift register
{
for(uint8_t i=0;i<srNos;i++)
{
dataRegister = data[i];
serialToParallel();
}
store();
}
void SR74HC595::sendToShiftRegister(uint8_t data) // send data to shift register
{
dataRegister = data;
serialToParallel();
store();
}