Simple Commands

     A demonstration program for the 16F873A containing a Simple Commands decoder and example routines to enter and print single and multi-byte data values in HEX, change command bits, and control program execution from a serial port. Runs in the background and no interrupts are used to free the interrupt routine for user tasks. Command decoder and print routines are loaded in page 1 memory to free page 0 memory for the user's program. Data is sent directly to memory, but an example of a buffered load is shown. Nested menus are demonstrated for easy expansion of the command set as the project grows. Using the Simple Commands demonstration program as a starting point for program development and selecting and customizing the routines you need for your application, adding serial port commands and data entry to your PIC program is easy!

     The code was developed for the 16F873A, but can be adapted to most PIC's with a UART. Commands are similar to Motorola style @@Xnxx commands where @@ is command start, X capital letter is the command, n small letter (optional) is a sub command, and xx (optional) are HEX data characters. For Simple Commands each data entry command is for a defined number of characters, no end of line or parity is used, and no error testing is performed on the data to simplify the code.

     To allow for usage of bank 1 registers, the program relies on the high 16 registers in bank 0 having common addresses in all other banks in the 16F873A and the interrupt stack is stored there. The interrupt service routine stores W before changing to bank 0 to store STATUS, PCLATH, FSR, and executing the user interrupt code. If the high 16 registers are not common in all banks in the PIC used, don't use bank 1 registers in the background routines without disabling interrupts first as the background routine could be interrupted in either bank and W may not get saved properly.

 

     For small programs with limited commands the command decoder and print routines can be loaded in page 0 memory. For an example of using Simple Commands in page 0 memory to change or print a single variable, see the Simple Time Interval Counter with RS-232 Output.

   

Code:

Questions: