avr/shift_register/shift_register.c

34 lines
937 B
C
Raw Normal View History

2022-06-26 15:38:20 +00:00
#include <util/delay.h>
#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);
}
2022-06-26 15:38:20 +00:00
void send_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);
}
2022-06-26 15:38:20 +00:00
clear_line(&reg->output);
strobe_line(&reg->latch_clock);
}
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(&reg->output) : clear_line(&reg->output);
strobe_line(&reg->shift_clock);
}
clear_line(&reg->output);
strobe_line(&reg->latch_clock);
}