series shift register (SN
extra digital output pins
most/least significant bit
data pin
latch pin: after calling shift_out() the shift register internally contains new value. To update output pins you must pull LATCH high. This is sometimes called latching on pulsing the latch. Note that it is not enough to hold LATCH high. Data transfer happens on transition from low to high. This is also called rising edge. Code for a led binary counter from 0 to 65535 would look like the following:
int main(void) {
for(uint16_t i = 0; i < 0xffff; i++) {
/* Shift high byte first to shift registers. */
shift_out(i >> 8);
shift_out(i & 0xff);
/* Pulse latch to transfer data from shift registers */
/* to storage registers. */
digital_write(LATCH, LOW);
digital_write(LATCH, HIGH);
_delay_ms(50);
}
return 0;
}
clock pin : Clock is an constant high- low signal used to synchronize data transfer. Each time Clock goes high 2 things happen. Current value in shift register gets shifted left by one. Last bit is dropped out. First bit will be set to current value of Data. to write a byte to shift register this has to happen eight times in a loop. ( the clock pin is toggled once the data has been received )
define LATCH B0
define CLOCK B1
define DATA B2
void shift_out(uint8_t data) {
for(uint8_t i = 0; i < 8; i++) {
/* Write bit to data port. */
if (0 == (data & _BV(7 - i))) {
digital_write(DATA, LOW);
} else {
digital_write(DATA, HIGH);
}
/* Pulse clock input to write next bit. */
digital_write(CLOCK, LOW);
digital_write(CLOCK, HIGH);
}
series shift register (SN extra digital output pins most/least significant bit data pin latch pin: after calling shift_out() the shift register internally contains new value. To update output pins you must pull LATCH high. This is sometimes called latching on pulsing the latch. Note that it is not enough to hold LATCH high. Data transfer happens on transition from low to high. This is also called rising edge. Code for a led binary counter from 0 to 65535 would look like the following: int main(void) {
} clock pin : Clock is an constant high- low signal used to synchronize data transfer. Each time Clock goes high 2 things happen. Current value in shift register gets shifted left by one. Last bit is dropped out. First bit will be set to current value of Data. to write a byte to shift register this has to happen eight times in a loop. ( the clock pin is toggled once the data has been received )
define LATCH B0
define CLOCK B1
define DATA B2
void shift_out(uint8_t data) { for(uint8_t i = 0; i < 8; i++) { /* Write bit to data port. */ if (0 == (data & _BV(7 - i))) { digital_write(DATA, LOW); } else { digital_write(DATA, HIGH); }
}