ok, first i think there was good reason to keep the same color leds anodes on a single sr... as a result you are wasting a lot of bits in your color arrays, and cycles setting pins instead of whole registers as a byte at once. but aside from that, anywhere i see the same code (or similar code) repeated i look for a better way. there are rare cases where you need to trade code efficiency for execution efficiency, but i don't think these cases fall under that umbrella. note that i haven't compiled these so it's likely there are some typos... where you have:
matrix_2[_MATRIX_SONG_COLUMN][0] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][1] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][2] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][3] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][4] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][5] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][6] = 0x30;
matrix_2[_MATRIX_SONG_COLUMN][7] = 0x30;
switch(evnt1-0x10)
{
case 0: // SONG 1
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 1: // SONG 2
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 2: // SONG 3
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 3: // SONG 4
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 4: // SONG 5
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 5: // SONG 6
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 6: // SONG 7
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
case 7: // SONG 8
matrix_2[_MATRIX_SONG_COLUMN][evnt1-0x10] = evnt2;
break;
default:
//matrix_2[evnt1-0x10][evnt0-0x90] = evnt2;
break;
}
i would have:
int i;
unsigned char songIdx = evnt1-0x10;
for(i=0; i<8; i++)
{
if(i == songIdx)
matrix_2[_MATRIX_SONG_COLUMN][i] = evnt2
else
matrix_2[_MATRIX_SONG_COLUMN][i] = 0x30;
}
where you have:
void DisplayLED(unsigned char column, unsigned char color) __wparam
{
switch(color)
{
case 0x00: //OFF
MIOS_DOUT_PinSet(column+8, 0);
MIOS_DOUT_PinSet(column+8+8, 0);
MIOS_DOUT_PinSet(column+8+16, 0);
break;
case 0x10: // RED
MIOS_DOUT_PinSet(column+8, 1);
MIOS_DOUT_PinSet(column+8+8, 0);
MIOS_DOUT_PinSet(column+8+16, 0);
break;
case 0x20: // GREEN
MIOS_DOUT_PinSet(column+8, 0);
MIOS_DOUT_PinSet(column+8+8, 1);
MIOS_DOUT_PinSet(column+8+16, 0);
break;
case 0x30: // BLUE
MIOS_DOUT_PinSet(column+8, 0);
MIOS_DOUT_PinSet(column+8+8, 0);
MIOS_DOUT_PinSet(column+8+16, 1);
break;
case 0x40: // CYAN
MIOS_DOUT_PinSet(column+8, 0);
MIOS_DOUT_PinSet(column+8+8, 1);
MIOS_DOUT_PinSet(column+8+16, 1);
break;
case 0x50: // MAGENTA
MIOS_DOUT_PinSet(column+8, 1);
MIOS_DOUT_PinSet(column+8+8, 0);
MIOS_DOUT_PinSet(column+8+16, 1);
break;
case 0x60: // YELLOW
MIOS_DOUT_PinSet(column+8, 1);
MIOS_DOUT_PinSet(column+8+8, 1);
MIOS_DOUT_PinSet(column+8+16, 0);
break;
case 0x70: // WHITE
MIOS_DOUT_PinSet(column+8, 1);
MIOS_DOUT_PinSet(column+8+8, 1);
MIOS_DOUT_PinSet(column+8+16, 1);
break;
default:
break;
}
}
i would have:
void DisplayLED(unsigned char column, unsigned char color) __wparam
{
color >>= 4;
MIOS_DOUT_PinSet(column+8, (color & 0x01));
color >>= 1;
MIOS_DOUT_PinSet(column+8+8, (color & 0x01));
color >>= 1;
MIOS_DOUT_PinSet(column+8+16, (color & 0x01));
}
where you have:
void SR_Service_Prepare(void) __wparam
{
static unsigned char row;
static unsigned int x;
row = ++row & 0x0F;
MIOS_DOUT_SRSet(0, 0);
MIOS_DOUT_SRSet(4, 0);
switch(row)
{
case 0 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 1 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 2 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 3 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 4 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 5 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 6 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
case 7 :
{
MIOS_DOUT_PinSet1(row);
MIOS_DOUT_PinSet1(row+32);
for (x = 0; x < 8; x++)
{
DisplayLED(x, matrix_1[row][x]);
DisplayLED(x+32, matrix_2[row][x]);
}
break;
}
default :
{
break;
}
}
}
i would have:
void SR_Service_Prepare(void) __wparam
{
static unsigned char row;
unsigned int x; //edit* just noticed, no reason for this to be static
row = ++row & 0x07; //<-- here you were cycling 16 rows i think you meant 8, no?
//this would have resulted in a 6.25% duty cycle (vs 12.5%).
//note that the duomatrix uses a 25% duty cycle
MIOS_DOUT_SRSet(MATRIX1_DOUT_START, 0);//<-- hardwire bad, napster good. define constants
MIOS_DOUT_SRSet(MATRIX2_DOUT_START, 0);// so you can move your matrix in the chain
MIOS_DOUT_PinSet1(row + (MATRIX1_DOUT_START * 8));
MIOS_DOUT_PinSet1(row + (MATRIX2_DOUT_START * 8));
for (x = 0; x < 8; x++)
{
DisplayLED(x + (MATRIX1_DOUT_START * 8), matrix_1[row][x]);
DisplayLED(x + (MATRIX2_DOUT_START * 8), matrix_2[row][x]);
}
}