I have a device that is completely controlled via RS-232. The commands to make the PIC do something, like read ADC, change levels of output pins, read SPI devices, etc. is all controlled by 3 letter commands from a PC. I use the HW uart on the PIC chip to load the data into a circular buffer and then look for a cr as a terminator. Then in my code I used multiple IF/THEN lines to match a valid command and then a subroutine to perform the action. The part that bothers me is the multiple IF/THEN about 20 of them that look like this:
IF chrbuf(0)="R" AND chrbuf(1)="T" AND chrbuf(2)="F" THEN GOSUB xxxxx
.
.
Is there a better or cleaner way to decode the three letter commands than using long multiple IF/THEN statements?
Terry
Bookmarks