It's unfortunate that you couldn't be troubled to take a few minutes to learn something new, because Pommie's technique is
really simple and cuts out a lot of code.
Here's an example from software I'm working on right now.
DisplayData comes from reading PortB; the 8 bits represent 8 alarm conditions. Some of those bits are normally high and an alarm condition is indicated by a low bit. Others are normally low, and an alarm condition is represented by a high bit. To account for the different conditions of the 8 monitored signals, the variable NormalMask represents the normal state of each bit.
When a bit from DisplayData doesn't match the bit in NormalMask, that bit should be set to 1 to turn the associated LED on. The comparison is easing using XOR; XOR means Exclusive Or...or in simple terms, one or the other but not both.
The code is simple:
DisplayData = DisplayData Xor NormalMask
if the DisplayData bit matches the NormalMask bit, the output is zero and the associated LED is off. If the 2 bits don't match, the output is 1 and the LED is on. Eight LEDs set in one line.
Let's say NormalMask = %00001111. The 4 high bits are normally low, and the low 4 bits are normally high.
And lets say DisplayData = %10001111. Bit 7 (on the left) is high, an alarm condition.
DisplayData Xor NormalMask = %1000000.
If my LEDs are on PortC, saying
PortC = DisplayData turns on one of the LEDs and the other 7 off.
Here's a truth table for the Xor function.
Code:
Input 1 | Input 2 | Output
0 | 0 | 0
1 | 0 | 1
1 | 0 | 1
1 | 1 | 0
Xor makes this comparison for each bit in a pair of variables. If the 2 variables being compared are dimensioned as bytes, the comparison will be for 8 bits. If the two variables are dimensioned as words, 16 bits will be compared.
For your case, say your switches are on PortB and your LEDs are on PortC.
Code:
SwitchesWere = PortB
While 1 = 1
Switches = PortB
PortC = Switches Xor SwitchesWere
SwitchesWere = Switches
DelayMS(20)
Wend
I explained previously how to get your 10 bits into word variables. This turns the LEDs on when the button is pressed and off when it's released. A little additional logic is required to toggle the LEDs....about this many more lines.
[/code]