Not sure why you're using the shift register instead of three MCU pins. In any case, this is called multiplexing, or scanned, LEDs, and is a very common configuration (since the number of resistors and pins varies O(log N) with the number of LEDs, instead of O(N)).
Human vision has trouble seeing anything faster than about 10 ms, and can put up with a lot slower. Note that TVs are often scanning the screen at 50 or 60 Hz. So if you scan a lot faster than that, nobody will notice.
In your shift register case, you set up an interrupt to go off every so often, say 1000 Hz (1 ms intervals). This gives you about 330 scans per second (frequency divided by number of LEDs; you want to keep this number over 100 Hz or so). Each interrupt, the pins are updated and the shift register shifted. The code would probably look like this:
int ledNum = 0;
int colorLED[3] = {0}; // Sets all elements to 0.
// Colors: black = 0, red = 1, green = 2, yellow = 3,
// blue = 4, magenta = 5, cyan = 6, white = 7
Interrupt()
{
// Load a 1 into the SR if this is the start of the cycle.
if(ledNum == 0)
SR_D = 1;
else
SR_D = 0;
// Set the color.
PORTA = (PORTA & ~7) | (colorLED[ledNum] & 7);
// Clock the shift register.
SR_CLK = 1;
SR_CLK = 0;
// Update for next loop.
ledNum = ledNum + 1;
if(ledNum == 3)
ledNum = 0;
}
Note this only gives you 8 colors. For more, you'll need to increase your scanning rate because you'll be switching the LEDs with PWM. Example code for 4 bits per color, which gives 4096 colors and needs 15X the interrupt rate (15 kHz, or 0.067 ms):
int ledNum = 0;
int pwmStep = 0;
int colorLED[3] = {0}; // Sets all elements to 0.
Interrupt()
{
// Load a 1 into the SR if this is the start of the cycle.
if(step == 0)
{
if(ledNum == 0)
SR_D = 1;
else
SR_D = 0;
// Clock the shift register.
SR_CLK = 1;
SR_CLK = 0;
}
// Set the color.
int reg = PORTA & ~7;
if((colorLED[ledNum] & 0xF) > step)
reg |= 1;
if(((colorLED[ledNum] >> 4) & 0xF) > step)
reg |= 2;
if(((colorLED[ledNum] >> 8) & 0xF) > step)
reg |= 4;
PORTA = colorLED[ledNum];
// Update for next loop.
if(step == 0)
{
ledNum = ledNum + 1;
if(ledNum == 3)
ledNum = 0;
}
// Next PWM step
step = step + 1;
if(step == 15)
step = 0;
}
Note that the number of steps in PWM is the same as the maximum value, not one higher. So four bits, which can represent 0-15, needs 15 steps, not 16.
Optimizations are, of course, left as an exercise for the reader.
One final thing to check is that the shift register pin is actually capable of sinking the current from three LEDs at once, given your resistor values. If not, you'll need to get some FETs or BJTs to switch the LEDs' common-cathode pins.