Comment on Shift register missing bits

Kalcifer@lemm.ee ⁨8⁩ ⁨months⁩ ago

The first two lines of the for loop,

byte upper_byte = input_bin >> 8;
byte lower_byte = input_bin & 0x00FF;

don’t really accomplish anything. The first line is bit shifting to the right 8, and then you write over that with all 1s. For example, starting with input_bin:

1000 0000 0000 0000
>> 8
0000 0000 1000 0000
& 0xFF
0000 0000 1111 1111

So, every time you go through a cycle of the for loop, you’ll just start with the same values in upper_byte, and lower_byte. To sequentially output each shifted value, you’ll instead want something like:

output = 0b1
for i = 0 to 17:
    shift_out(output)
    latch(high)
    output = output << 1

source
Sort:hotnewtop