Re: Is this a case for CASE?
Hi,
Sure, you can use Select Case. Perhaps something like
Code:
Select Case (PortB & %11000000)
Case 192
SetPoint = 19
Case 128
SetPoint = 10
Case 64
SetPoint = 2
Case 0
SetPoint = 0
End Select
But I think IF-THEN will compile to less code but execute a bit slower since it will test all four conditions even if it finds a match in the first one.
Code:
PinStates = PortB & %11000000
If PinStates = 192 THEN SetPoint = 19
If PinStates = 128 THEN SetPoint = 10
If PinStates = 64 THEN SetPoint = 2
If PinStates = 0 THEN SetPoint = 0
As with most things there are several ways of doing it and these two are likely not the only ones.
/Henrik.
Re: Is this a case for CASE?
Code:
Setpoint VAR byte [4]
Setpoint[0]=0
Setpoint[1]=2
Setpoint[2]=10
Setpoint[3]=19
Main_Loop:
Setpoint[PortB>>6]
Goto Main_Loop
This is an additional solution without If/Then or Select Case.
Cheers
Al.