Hello guys, this is my first post

I am trying to address and control my 9 LEDs which are on RC1, RC2, RC3, RC4, RC5, RD0, RD1, RD2 and RD3 with my switches that are plugged in on my RB0 to RB7 and RD7 on my 18f452 chip.

It is going to be 32 LEDs if I can figure out the code for this proto 9 LEDs. I wrote some kind of pseudo code to work out my algorithm as well. I am sharing it below, you are going to have an idea afterwards presumably.

on press switch
if it is the first one that is pressed
if the led that is addressing this switch is on
take the led's address and put it in a variable
check if two rows up or down or left or right of any LEDs is on or off
if on
take this led's address and put it in another variable
check if one row up or down or left or right of any LED to this is on or off
if on
break
if off
check if those leds are in a horizontal or a vertical position
if true
get the address of the led and get the switch's address of this LED and store in var3
if false
break;
if off
break;
if off
break


if it is the second one that is pressed
if the led that is addressing this switch is on
break;
if off
get the value from the var3 and light the LED according to this number
get the value from var1 and var2 and turn them off



// end


so this is the pseudo code I have, can anyone advice what path I should follow here.

Thanks in advance.
ilteris.