ME Labs, Inc. 719-520-5323 |
PICBASIC PRO™ Compiler 2.2 Debug Monitor Example ProgramPICBASIC PRO™ version 2.2 includes hooks that may be used to create a debug monitor program. A monitor is a program that runs resident with the user program and allows the user program to be stopped, restarted, traced and data to be displayed. The new ON DEBUG instruction in PICBASIC PRO allows a monitor program to be written in BASIC. The monitor is given control between each BASIC instruction. DISABLE DEBUG and ENABLE DEBUG psuedo-ops may be used to control where a program may be diverted. A sample debug monitor program may be downloaded for an example of how it works. The ZIP file contains a text file that describes the operation of the debug monitor. Some of it is described below. But be sure to read the text file for additional information. The monitor code itself should be placed at the beginning of the BASIC program preceded by a jump around it. Or the monitor program may be a separate file that is included at the beginning of any program to be monitored, as is shown here. Immediately before each instruction, the current program address is stored into the variable DEBUG_ADDRESS and a jump to the monitor is executed. The monitor may then choose to display debugging information, wait for a user command, or simply return to the main program by jumping to the address in DEBUG_ADDRESS. These techniques are best demonstrated in a program. The PICBASIC PRO program DEBUGMON.BAS shows one way of writing a debug monitor. It should be included at the beginning of the program to be debugged. Another sample program, DBLINK.BAS, shows this. DBLINK.BAS is the sample BLINK program with the debug monitor inserted. DEBUGMON communicates with a terminal communications program running on a PC, such as Hyperterm. It uses the Hserin and Hserout instructions so it requires a PICmicro® with a hardware serial port. The default baud rate is 2400 and the TX and RX pins are PORTC.6 and PORTC.7. DBLINK includes DEBUGMON at the beginning and then follows it with simple code to turn an LED connected to PORTD.0 on and off about once a second.
The easiest way to understand the operation of DEBUGMON is to try it out with the DBLINK program. However, the "m" command may need a little additional explanation. Once the program is running (and the LED is blinking) using Go or Trace, it is necessary to have a method to get control back to the monitor so you can examine the registers or Trace addresses. Entering "m" from the terminal stops the program's execution and turns control over to the monitor. As the monitor is written in BASIC, it may be modified to provide other functionallity, such as breakpoints or elimination of the Hser commands to allow it to be used on PICmicros lacking a hardware serial port. |
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|