Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Best way to make a command set?

Status
Not open for further replies.

ChriX

Member
I'm currently building a little robot (I suppose I could call it that) based around a PIC and driven via an RS232 port of a PC, via Bluetooth using one of the SparkFun modules.

I was wondering if anyone had any links to, or advice on creating a command set, so I can send 0xCC<cr> (for example) and the PIC does one thing, and 0xC0<cr> and it does another.

Currently I'm receiving a character, and testing to see if it is one I should be responding to by subtracting and then testing for zero. I only have 2 commands at the moment but I could end up with a huge list of things that it has to go through before it finds the right one, which doesn't seem like good practise to me.

Thanks in advance for any help.
 
ChriX said:
I'm currently building a little robot (I suppose I could call it that) based around a PIC and driven via an RS232 port of a PC, via Bluetooth using one of the SparkFun modules.

I was wondering if anyone had any links to, or advice on creating a command set, so I can send 0xCC<cr> (for example) and the PIC does one thing, and 0xC0<cr> and it does another.

Currently I'm receiving a character, and testing to see if it is one I should be responding to by subtracting and then testing for zero. I only have 2 commands at the moment but I could end up with a huge list of things that it has to go through before it finds the right one, which doesn't seem like good practise to me.

Thanks in advance for any help.

Use a jump table, and values 0 to the size of your table. If you don't want to send such low characters use higher ones and subtract to make them zero and above.

For example, 16 commands, 0xC0 to 0xCF, subtract 0xC0 and you have 0-15 for your jump table - it's important to keep the table an even number of bits, then you can ANDLW the value first, to make sure it can't jump out of the table (which would be a BAD! thing).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top