2022-06-26 15:38:20 +00:00
|
|
|
#include <util/delay.h>
|
2022-06-26 03:35:14 +00:00
|
|
|
#include <base.h>
|
|
|
|
#include <reg.h>
|
|
|
|
|
|
|
|
void shift_register_initialize(shift_register_t *reg) {
|
|
|
|
set_line_direction(®->output, LINE_OUT);
|
|
|
|
set_line_direction(®->shift_clock, LINE_OUT);
|
|
|
|
set_line_direction(®->latch_clock, LINE_OUT);
|
|
|
|
|
|
|
|
clear_line(®->output);
|
|
|
|
clear_line(®->shift_clock);
|
|
|
|
clear_line(®->latch_clock);
|
|
|
|
}
|
|
|
|
|
2022-06-26 15:38:20 +00:00
|
|
|
void send_lsb(shift_register_t *reg, uint8_t byte) {
|
2022-06-26 03:35:14 +00:00
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
|
|
|
byte & _BV(i) ? set_line(®->output) : clear_line(®->output);
|
|
|
|
strobe_line(®->shift_clock);
|
|
|
|
}
|
2022-06-26 15:38:20 +00:00
|
|
|
clear_line(®->output);
|
|
|
|
strobe_line(®->latch_clock);
|
2022-06-26 03:35:14 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 15:38:20 +00:00
|
|
|
void send_msb(shift_register_t *reg, uint8_t byte) {
|
|
|
|
for (int8_t i = 7; i >= 0; i--) {
|
|
|
|
byte & _BV(i) ? set_line(®->output) : clear_line(®->output);
|
|
|
|
strobe_line(®->shift_clock);
|
|
|
|
}
|
2022-06-26 03:35:14 +00:00
|
|
|
clear_line(®->output);
|
|
|
|
strobe_line(®->latch_clock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|