Trying to learn how to display a simulated piece counter on a 4 digit 7 segment display (for a cybersecurity demo lab). This is for OpenPLC runtime on a Raspberry Pi 4, where 3 of the gpio pins are connected to a single 74HC595 shift register. The 8 outputs of the 595 are connected to a common anode 7 segment LED display.
The CTU counter variable is stored and converted to BCD.
2 questions:
1) how do I split the BCD word into 4 nibbles and process each in a loop? can you address them as an array?
2) how would I send 8 bits to the shift register?
There are 3 pins used to send from the controller to the 595:
DS is the data bits
SH_CP is the shift register clock
ST_CP is the storage latch to activate the outputs all at once with the stored register
So the process would be as follows:
for each of the 8 bits
Set DS data pin for current bit to proper value
Set the SH_CP shift pin high
Set the SH_CP shift pin low
after all 8 bits are sent set the ST_CP latch pin high to active new value on the outputs
set ST_CP latch pin back to low
Note: I realize this is basically what a 7447 IC does for you, but I don't have one and I'm trying to learn. 🙂
Also I have studied many examples from Arduino code that does this (for example SevSegShift). I understand these C or C++ examples but now how to do this in LD or ST.
Thanks!
example sending 11000011 to the 595 shift register and triggering the latch to outputs:
example C++ code for arduino (credit and thanks to bridystone on github sevsegshift):