avr/shift_register/reg.c

28 lines
724 B
C
Raw Normal View History

#include <base.h>
#include <reg.h>
void shift_register_initialize(shift_register_t *reg) {
set_line_direction(&reg->output, LINE_OUT);
set_line_direction(&reg->shift_clock, LINE_OUT);
set_line_direction(&reg->latch_clock, LINE_OUT);
clear_line(&reg->output);
clear_line(&reg->shift_clock);
clear_line(&reg->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(&reg->output) : clear_line(&reg->output);
strobe_line(&reg->shift_clock);
}
}
void shift_out(shift_register_t *reg, uint8_t byte) {
send_byte_lsb(reg, byte);
clear_line(&reg->output);
strobe_line(&reg->latch_clock);
}