PDA

View Full Version : Tracing code in MPLAB Sim



ErnieM
- 4th August 2005, 22:30
I've got my PIC Bacic Pro compiler working inside MPLAB. So far, so good. My first 'Hello World' test code is blinking my LEDs on the PICKit board.

HORAY!

Next step is to back up and inspect the code, I've always counted on a code walk thru under the MPLAB Simulator as a necessary reality check.

The question is what is the best way to set this up? The Disassembly listing would be nice, each Basic line is in there, commented in the code flow, but only a portion of the asm statements are there, the current line pointer can dissapear to somewhere in this 7,000+ line listing. The Program Memory window has every asm statement there, but not the basic comments.

Both these windows can be open to see every Basic and asm stetement, but its a bit clumsy.

Any other suggestions?

Bruce
- 5th August 2005, 01:21
Here's a tip I don't think a lot of people using PBP are aware of. This lets you view the entire PBP program in pure assembler & even shows each sub-routines label.

Download the latest version of MPLAB, and compile your code with MPASM.

Start MPLAB, and select the target PIC you compiled for & osc speed.

Click File, then Import. Locate the .COD file NOT the .hex file.

Example: blink.bas was compiled. Locate & import blink.cod.

Click View >> Program Memory. You'll see the full assembler file on-screen.

Right click in the Program Memory window, roll down & click on Properties.

Make sure there's a check mark next to Disassembly & Label, and move label to the top by highlighting Label, and cicking the Move Up button. This places each routies name or label on the left just like it would normally appear in your source code.

Now you can simulate, watch everything happen, and even print the full assembly listing in a format you can read.

You can't compile with PBP from within MPLAB doing it like this, but it's a lot easier to follow during simulation, and reading the assembler code PBP produces.

rhino
- 5th August 2005, 04:38
Nice tip Bruce!

ErnieM
- 8th August 2005, 16:00
While it is true you cannot compile with PBP from within MPLAB, you CAN use PBPW, which is the windows version of the PIC Basic Pro compiler. This means you can write, compile, simulate, and program your device all from the same IDE (and for those of us moving from MPLAB assembly, this is an environment we're quite familiar with).

Make sure you've installed the MPLAB plug-in. When you're starting a new PBP project in MPLAB using the Project Wizard, just pick the "microEngineering PicBasic Toolsuite" ("microEngineering PicBasic Pro Toolsuite" if you have it) and browse for PBPW.EXE (not PBP.EXE).

You will also get full text highlighting of your basic code.

One thing I like is using MPLAB to help set configuration bits. Use the MPLAB configure bits menu to make the settings as you wish. The configuration word will be displayed under "Value." Then copy this number into your program like so:

@ __config 0x3FC4 ; configuration bits

No messy lookups for what function sets what bit. You will need to comment out the standard __config statement in the PBP .INC file or azn error will result. I've also added a message reminding me I've changed the .INC file in case later I assume I've set it.

Including the COD file is a help, gives a bit more info to the Program Memory window. Still, I'll keep it and the Disassembly Listing window open for code walking. It helps to see which Basic line is being executed.