Here's how I handle dimming multiple LEDs. The following example assumes you want 8-bit PWM, on any number of LEDs on two ports.
First, a little setup:
1) Create an array to hold the PWM value for each LED, LedValues[numberofleds].
2) Create two lookup arrays. LedToPort[numberofleds], that takes a LED # and converts it to a port # (0=A, 1=B). And LedToBit[numberofleds], that takes a LED # and converts it to a bit position within the port. For example, your LED_1 would look up to 0 and 0, and LED_2 would look up to 1 and 3.
3) Create an array PortData[2][8].
Then fill in the LedValues according to the current effect. When that's done, we do a little preprocessing.
For each LED, do the following:
Port = LedToPort[ledno]
Bit = LedToPort[ledno]
Value = LedValues[ledno]
Copy the most significant bit in Value, to the bit at position Bit in PortData[Port][0].
Copy the next significant bit in Value, to the bit at position Bit in PortData[Port][1].
And so on until you get to the least significant bit in Value, copied to PortData[Port][7].
Why do that? Because it makes PWM generation very, very easy. Select a time constant, Time. And do this:
PORTA = PortData[0][0]; PORTB = PortData[1][0]; Wait Time*128;
PORTA = PortData[0][1]; PORTB = PortData[1][1]; Wait Time*64;
PORTA = PortData[0][2]; PORTB = PortData[1][2]; Wait Time*32;
PORTA = PortData[0][3]; PORTB = PortData[1][3]; Wait Time*16;
PORTA = PortData[0][4]; PORTB = PortData[1][4]; Wait Time*8;
PORTA = PortData[0][5]; PORTB = PortData[1][5]; Wait Time*4;
PORTA = PortData[0][6]; PORTB = PortData[1][6]; Wait Time*2;
PORTA = PortData[0][7]; PORTB = PortData[1][7]; Wait Time*1; // for clarity, but can be merged with the next line; just double the wait
PORTA = PortData[0][7]; PORTB = PortData[1][7]; Wait Time*1;
PORTA = PortData[0][6]; PORTB = PortData[1][6]; Wait Time*2;
PORTA = PortData[0][5]; PORTB = PortData[1][5]; Wait Time*4;
PORTA = PortData[0][4]; PORTB = PortData[1][4]; Wait Time*8;
PORTA = PortData[0][3]; PORTB = PortData[1][3]; Wait Time*16;
PORTA = PortData[0][2]; PORTB = PortData[1][2]; Wait Time*32;
PORTA = PortData[0][1]; PORTB = PortData[1][1]; Wait Time*64;
PORTA = PortData[0][0]; PORTB = PortData[1][0]; Wait Time*128;
Congratulations, you just blasted out a full PWM cycle for every LED simultaneously. Actually, this isn't PWM exactly, but a derivative called MIBAM (Mirror Image Bit Angle Modulation). It excels at efficiently dimming large quantities of LEDs. You can read all about it here:
http://www.picbasic.co.uk/forum/showthread.php?t=10564There's an interactive Javascript tool to let you generate the MIBAM waveform for a certain value, which helped me initially understand it.