It’s easier to set 8 pins at once with the MIOS_DOUT_SRSet() function, it should be done within the SR_Service_Prepare() hook, which is called each mS before the LEDs will be updated.
Programming handling for this circuit: http://www.ucapps.de/mbhp/mbhp_doutx4_ledrings.pdf
First cycle: set D7 of the first shift register (SR1) to 0 (ground), and all other outputs of SR1 and SR2 to 1 (+5V)
As a result, only the first row of LEDs will lit, all others will close (cathode driven with +5V)
set the data outputs of SR3 and SR4 to the pattern which should be displayed by the first row
On the next cycle (1 mS after SR_Service_Prepare() has been called again), set D6 of SR1 to 0, all other to 1, and apply the pattern for the second row to SR3 and SR4
Once the 16th row has been reached, switch back to the first
So - a loop takes 16 mS. And now the trick: if a LED row is not supplied with power for 15 mS, it will continue to lit for a short moment. The brightness will be lower, but you won’t regognized that it’s switched off/on very quickly.
Btw: see the code in mm_vpot.c of the MIDIbox MM application for an example which drives 8 LED rings:
/////////////////////////////////////////////////////////////////////////////
// This function should be called from SR_Service_Prepare in main.c
// it copies the current LEDring pattern to the DOUT registers
/////////////////////////////////////////////////////////////////////////////
void MM_VPOT_LEDRing_SRHandler(void)
{
#if LEDRINGS_ENABLED
static unsigned char sr_ctr;
unsigned int anode_pattern;
// increment the counter which selects the ledring that will be visible during
// the next SRIO update cycle --- wrap at 8 (0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, ...)
sr_ctr = ++sr_ctr & 0x07;
// select the cathode of the LEDring (set the appr. pin to 0, and all others to 1)
MIOS_DOUT_SRSet(LEDRINGS_SR_CATHODES, cathode_patterns[sr_ctr]);
// set the LEDring pattern on the anodes
anode_pattern = ledring_pattern[sr_ctr];
MIOS_DOUT_SRSet(LEDRINGS_SR_ANODES_1, anode_pattern & 0xff);
MIOS_DOUT_SRSet(LEDRINGS_SR_ANODES_2, (anode_pattern >> 8) & 0xff);
#endif
}
[/code]
Best Regards, Thorsten.