Simulating the code

After the project has been built without generating any errors, it is time to see if your program works.  To do this, you must first go to Project->Edit and Change the Development mode to the MPLAB-SIM simulator using the PIC16C505.  

Rebuild your project.

Change to the debug menu by hitting the "Swap Toolbar", , button at the upper left of the MPLab window.  Keep hitting the button until you get a menu like the one shown below.  If you are not sure what one of the buttons does, you can point to it with the mouse, and the buttons name appears in the lower left corner of the window.

Stepping through your code

You can now use the various buttons to run your code (), stop ( -- note that it sometimes takes several seconds for the processor to stop after hitting the buttons).  You can step through the code () a line at a time.  The button steps through the assembly language a line at a time, so you may have to hit it several times to step through one line of C code.  The step-over command, , is useful to step over several lines at a time. You can even watch the values of variables() as they change. 

You will probably also want to view the output pins.  To do this press the Special Functions Register button, .  You will get a window like this:

You can also animate the simulation by going to Debug->Run->Animate.

To reset the processor back to its original state use the reset button, .

Inputs to the PIC

When debugging your code you will need to simulate inputs to the PIC.  To do this go to Debug->Stimulator Stimulus->Asynchronous Stimulus.  You will get a window like the one shown below.

To assign an input to a pin, put the mouse over that input and right click.  You can then assign that button to a pin.  You can then set that pin high or low by right clicking on the button again.  In the diagram below I have set Pin RB3 to high. 

Note: Just because it says "RB3 (H)" does not mean RB3 is automatically set to high. You must click on the button once to make the output go high.  You can set these stimuli while your program is being animated so you can see it as it works.