28 lines
724 B
C
28 lines
724 B
C
|
#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_byte_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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void shift_out(shift_register_t *reg, uint8_t byte) {
|
||
|
send_byte_lsb(reg, byte);
|
||
|
clear_line(®->output);
|
||
|
strobe_line(®->latch_clock);
|
||
|
}
|
||
|
|
||
|
|