There are lots of different ways... not nescessarilly better, just different...
Take a look at this example posted OMG!!! Three years ago!!!
http://www.picbasic.co.uk/forum/showthread.php?t=573
It does pretty much what you're doing, receiving a command string terminated by a CR, then parsing that string for embedded commands to act upon... just another angle on the same theme...
So, as another example, if all your commands are say 3 characters long each, then stick them all together into your program as a long string
(who says you can't build strings with PICBasic!!!) with a separator character between them (you can have that "string" in EEPROM, or within your program code)... eg...
Code:
iRobotActions:
ASM
db 0x00,"HUG" ; Greeting
db 0x00,"EAT" ; Recharge Batteries
db 0x00,"FLY" ; Go Somewhere
db 0x00,"KIL" ; Prime Directive
db 0x00,"RTM" ; Learn
db 0x00,"SEX" ; Have Fun
db 0x00,"DIE" ; Wait for armageddon
ENDASM
...then simply scan that "string" to find the position of the command you seek (which in turn will give you a number based on the position of that command within the string). Then armed with that number you can then simply use your case statement (or even a bunch of simple IF's). This basically gives you unlimited scope for your embedded commands.
nb. You need a separator between the commands, otherwise a random jumble like 'EXD' as the last two characters of 'SEX' and the first of 'DIE' would return a result.
Bookmarks