ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

PICBASIC PRO™ Compiler 2.2 Debug Monitor Example Program

PICBASIC 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.

DEBUGMON Operation

DEBUGMON accepts several one letter commands. When it is ready for a command, it displays a "?" on the terminal screen. Once the "?" is displayed, a lower case letter may be typed on the terminal keyboard to execute a command. The current commands in DEBUGMON are as follows:

  • d - Display stack level and all bank 0 registers in hexadecimal.
  • g - Continue the program execution where it left off (Go).
  • h - Show a short Help screen.
  • m - Enter the Monitor program.
  • r - Start running the program at the Reset address (0).
  • s - Single step through one PICBASIC PRO statement.
  • t - Trace the program by displaying each BASIC statement's address in hexadecimal as it is executed, from where it left off.

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.