34 lines
937 B
C
34 lines
937 B
C
#include <util/delay.h>
|
|
#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);
|
|
}
|
|
|
|
void send_lsb(shift_register_t *reg, uint8_t byte) {
|
|
for (uint8_t i = 0; i < 8; i++) {
|
|
byte & _BV(i) ? set_line(®->output) : clear_line(®->output);
|
|
strobe_line(®->shift_clock);
|
|
}
|
|
clear_line(®->output);
|
|
strobe_line(®->latch_clock);
|
|
}
|
|
|
|
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);
|
|
}
|
|
clear_line(®->output);
|
|
strobe_line(®->latch_clock);
|
|
}
|
|
|
|
|