EEGR-417-001, Micro Applications, Spring, '08

Using MPLAB and the PIC Kit 2

Note that MPLAB is available on all PCs in the Computer Engineering Lab.

At the FILE tab, OPEN an .asm file.  SAVE AS whatever you want.  Please save to your Flash Drive.  Note that the extension must be .asm.

Edit the file as appropriate.  Periodically SAVE.

At the CONFIGURE tab, DEVICE, set to PIC16F887.

At the PROJECT tab, QUICK BUILD.  Note any errors.  Click on the Error message and this should bring you back to that point in the code.  Note that some warnings could be serious.  For example;

	DECFSZ NUM_MS
	
will generate a warning.  Correct this;

        DECFSZ NUM_MS, F
        
Warnings will also be generated when you use an SFR which is not on register page 0.  You cannot remove these warnings.  Just be sure you have configured for the appropropriate page.  For example;

	BSF STATUS, RP0
	....
	BCF STATUS, RP0
	
Note that all of the above may be done on any machine in the lab.

***********************

Now, get on a PC which has a PICKit 2 In Circuit Debugger.  Power your circuitry including the target PIC16F887 and connect the five leads from the In Circuit Debugger.

From the DEBUGGER tab, SELECT TOOL, PIC Kit 2.  From the DEBUGGER tab, CONNECT to the debugger.  From the DEBUGGER tab, PROGRAM.

(Note that if you get "Unable to Enter Debugger Mode", you may have to use the PROGRAMMER tab.  Select PIC Kit 2 and ERASE the target.  Then, go back to the DEBUGGER, CONNECT and PROGRAM).

Note that after you have assembled, a .lst file is generated.  Use the VIEW tab to view the the disassembled listing.

With the .LST file in view, from the DEBUGGER tab, use the Run, Halt, Reset, Step Over and Step into functions.

At the VIEW tab, note that you can view the Special Function Registers, the File Registers (all RAM) and a number of other things.

At some point, you may have to edit the original .asm file.  Use the WINDOW tab.  Then go through the PROJECT - Quick Build, DEBUGGER - connect, DEBUGGER - program sequences.

*************************

It is important you not lose sight of what you are doing.  In class I attempted to write an assembly file.  We manually used a table to generate the machine language.  This is what would be programmed into the processor's memory.

This is precisely what you are doing with the PC.  Generate a .asm file.  Quick Build generates the machine language.  Program downloads this to the target processor.

**************************

When you are done debugging your design, you may wish to actually realize the product.

Use the PROGRAMMER tab.  Program.

Disconnect the PIC Kit 2.  Add a 10K resistor between term 1 and +5 VDC.  You now have a standalone design to amaze your parents, cure world hunger and make you millions.