Hi,
Try splitting up the long logical expressions, like:
/Henrik.Code:A: IF DATAIN[2]=$2D THEN IF DATAIN[3]=$A1 THEN IF DATAIN[4]=$00 THEN IF DATAIN[5]=$CD THEN IF DATAIN[6]=$C2 THEN X[0]=1 ENDIF ENDIF ENDIF ENDIF ELSE X[0]=0 ENDIF RETURN
Hi,
Try splitting up the long logical expressions, like:
/Henrik.Code:A: IF DATAIN[2]=$2D THEN IF DATAIN[3]=$A1 THEN IF DATAIN[4]=$00 THEN IF DATAIN[5]=$CD THEN IF DATAIN[6]=$C2 THEN X[0]=1 ENDIF ENDIF ENDIF ENDIF ELSE X[0]=0 ENDIF RETURN
MANY THANKS MY BROTHER HenrikOlsson FOR REPLY
WHAT YOU THINK ABOUT
SELECT CASE
HOW CAN I USE ?
You're welcome, but there's no need to SHOUT all the time ;-)
SELECT CASE might give you "neater" code but I've found it usually produces larger code than IF-THEN constructs and in this particular case I don't think Select Case is of any use to you.
Another thing that might be worth a try is to do the extract the values from the array into temporary variables first, then run your comparisons. Something like:Code:TempA = DataIn[2] TempB = DataIn[3] TempC = DataIn[4] TempD = DataIn[5] TempC = DataIn[6] GOSUB A GOSUB B 'And so on A: If TempA = xx THEN If TempB = xx THEN 'and so on
I'm sure there are more you can do depending on exactly what it is you're trying to achieve.
/Henrik.
Are you sure this is not the reason for the slow code?
After all, no matter how you code the checks, the pic will not take a noticable time to process that. If it compiled to 1000 lines of code, @4Mhz clock it would only take 1mSecCode:HSERIN [WAIT($07,$06), str DATAIN\7]
What clock speed?
-Bert
The glass is not half full or half empty, Its twice as big as needed for the job!
http://foamcasualty.com/ - Warbird R/C scratch building with foam!
Hi,
Of course it doesn't, sorry about that. Try this instead:And please stop SHOUTING all the time, it's hard to read!Code:A: X[0]=0 IF DATAIN[2]=$2D THEN IF DATAIN[3]=$A1 THEN IF DATAIN[4]=$00 THEN IF DATAIN[5]=$CD THEN IF DATAIN[6]=$C2 THEN X[0]=1 ENDIF ENDIF ENDIF ENDIF ENDIF RETURN
Bookmarks