How can I clean up my code?
I have a program where I'm sending three numbers out of the UART port. An example would be:
in1 - 10
in2 - 20
in3 - 5
On the transmitting side, the code is short and works fine. One the receiving side it's very inefficient. It seems like the case/select case would work better but I can't figure out how to implement it correctly. When I receive the numbers, it goes like this:
Code:
if b1=0 and b2=1 and b3=11 THEN GOTO ON1
if b1=0 and b2=1 and b3=12 THEN GOTO OFF1
if b1=0 and b2=3 and b3=11 THEN GOTO ON2
if b1=0 and b2=3 and b3=12 THEN GOTO OFF2
if b1=0 and b2=6 and b3=11 THEN GOTO ON3
if b1=0 and b2=6 and b3=12 THEN GOTO OFF3
if b1=0 and b2=5 and b3=11 THEN GOTO ON4
if b1=0 and b2=5 and b3=12 THEN GOTO OFF4
How can I get the PIC to just look at the three numbers and execute automatically, if that's possible? I have to sort through almost 100 different number combinations and the code is taking up way too much space. Is there an easier way?
Re: How can I clean up my code?
Use Select Case, check the value in B0 and go as you need to to check b1 and again direct until you check variable b2 OR
use 3 lookup tables to direct your code