Is there a better way...


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  2. #2
    Join Date
    Nov 2005
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    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.
    Could you please help with how to search this string to get the location number?
    Many Thanks
    Steve

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    db?? nah... grandma tricks, there's a better way, use the following...

    http://www.pbpgroup.com/modules/wfse...p?articleid=10
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,140


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    db?? nah... grandma tricks...
    Hmm, from the avatar I don't think Melanie is so much old grandma...!

    Ioannis

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    yeah i know... just kidding a little bit

    I figure the 'Embedded Strings in code space' stuff will be somehow easy to implement, and will eat less code space.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts