-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path74HC595.c
44 lines (39 loc) · 1.04 KB
/
74HC595.c
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
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "74HC595.h"
#include <stdlib.h>
void ShiftRegister_74HC595_init(struct ShiftRegister_74HC595* shift, int dataPin, int clockPin, int latchPin)
{
shift->serialData_pin = dataPin;
shift->clock_pin = clockPin;
shift->latch_pin = latchPin;
gpio_init(dataPin);
gpio_init(clockPin);
gpio_init(latchPin);
gpio_set_dir(dataPin, GPIO_OUT);
gpio_set_dir(clockPin, GPIO_OUT);
gpio_set_dir(latchPin, GPIO_OUT);
}
void clock_signal(int clockPin)
{
gpio_put(clockPin, 1);
sleep_us(CLOCK_INTERVAL);
gpio_put(clockPin, 0);
sleep_us(CLOCK_INTERVAL);
}
void latchRegister(struct ShiftRegister_74HC595* shift)
{
gpio_put(shift->latch_pin, 1);
sleep_us(LATCH_INTERVAL);
gpio_put(shift->latch_pin, 0);
}
void shiftOutByte(struct ShiftRegister_74HC595* shift, uint8_t data)
{
uint8_t bit;
for (int i = 0; i < 8; i++)
{
bit = (data >> i) & 0x01;
gpio_put(shift->serialData_pin, bit);
clock_signal(shift->clock_pin);
}
}