The MPLAB X IDE is the new graphical, integrated debugging tool set for all of Microchip’s more than 800 8-bit, 16-bit and 32-bit MCUs and digital signal controllers, and memory devices.
It includes a feature-rich editor, source-level debugger, project manager, software simulator, and supports Microchip’s popular hardware tools, such as the MPLAB ICD 3 in-circuit debugger, PICkit™ 3, and MPLAB PM3 programmer.
MPLAB IDE is a Windows Operating System (OS) software program that runs on a PC to develop applications for Microchip microcontrollers and digital signal controllers. It is called an Integrated Development Environment, or IDE, because it provides a single integrated "environment" to develop code for embedded microcontrollers. Experienced embedded systems designers may want to skip ahead to Components of MPLAB IDE.
The Object-HEX Converter creates Intel HEX files from absolute object modules.
The Mplab development tools for dsPIC offer numerous features and advantages that help you quickly and successfully develop embedded applications. They are easy to use and are guaranteed to help you achieve your design goals.
The MPLAB IDE and Debugger is the central part of the Microchip dsPIC development tools. MPLAB offers a Build Mode and a Debug Mode.
In the MPLAB Build Mode you maintain the project files and generate the application. MPLAB uses either the C30 or dsPIC ASM development tools.
In the MPLAB Debug Mode you verify your program either with a powerful CPU and peripheral simulator that connects the debugger to the target system.
The ICD2 allows you also to download your application into Flash ROM of your target system.
The MPLAB IDE combines project management, make facilities, source code editing, program debugging, and complete simulation in one powerful environment. The MPLAB development platform is easy-to-use and helping you quickly create embedded programs that work.
The MPLAB editor and debugger are integrated in a single application that provides a seamless embedded project development environment.
Use MPLAB to create your source files and organize them into a project that defines your target application.
MPLAB automatically compiles, assembles, and links your embedded application and provides a single focal point for your development efforts.
When you use the MPLAB, the project development cycle is roughly the same as it is for any other software development project.
MPLAB includes a project manager which makes it easy to design applications for a dsPIC based microcontroller. You need to perform the following steps to create a new project:
MPLAB is a standard Windows application and started by clicking on the program icon.
To create a new project file select from the MPLAB menu Project – Project Wizard…. This opens a standard Windows dialog that asks you for the new project file name.
Now we can select Next button then the window shows are selected by using the drop-down button in the device option as shown in below. Then we can select the device. Devices
Step two of the Project Wizard sets up the language tools that are used with this project. Select Microchip C30 Tool suite in the top pull down. Then you should see C30, MPLINK and MPLIB show up in the Tool suite Contents box. You can click on each one to see its location. If you installed MPLAB IDE into the default directory, the C30 compiler executable will be:
C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe
The MPLINK linker executable will be:
C:\Program Files\Microchip\MPLAB C30\bin\pic30-ld.exe
And the MPLIB librarian executable will be:
C:\Program Files\Microchip\MPLAB C30\bin\pic30-ar.exe
If these do not show up correctly, use the browse button to set them to the proper files in the MPLAB IDE subfolders.
When you are finished, click "Next >".
Step Three of the wizard allows you to name the project and put it into a folder.
This sample project will be called Mplab. Using the Browse button, place the project in a folder named Mplab. Click Next>.
Step Four of the Project Wizard allows file selection for the project. A source file has not yet been selected, so we will use an MPLAB IDE template file. The template files are simple files that can be used to start a project. They have the essential sections for any source file, and contain information that will help you write and organize your code.
These files are in the MPLAB IDE folder, which by default is in the Program Files folder on the PC.
There is one template file for each Microchip PIC micro and dsPIC device.
Choose the file named led_delay.c. If MPLAB IDE is installed in the default location, the full path to the file will be:
C:\Documents and Settings\Administrator\Desktop\Mplab\led_delay.c
Press Add>> to move the file name to the right panel, and the file name to enable this file to be copied to our project directory.
Make sure that your dialog looks like the picture above, with both check boxes checked, then press Next> to finish the Project Wizard.
The final screen of the Project Wizard is a summary showing the selected device, the tool suite and the new project file name.
After pressing the Finish button, review the Project Window on the MPLAB IDE desktop. If the Project Window is not open, then select View>Project.
Files can be added and projects saved by using the right mouse button in the project window. In case of error, files can be manually deleted by selecting them and using the right mouse click menu.
From the Project menu, we can assemble and link the current files. They don’t have any of our code in them yet, but this assures that the project is set up correctly.
To build the project, select either:
The Output window shows the result of the build process. There should be no errors on any step.
If these do not assemble and link successfully, check the following items and then build the project again:
Upon a successful build, the output file generated by the language tool will be loaded.
This file contains the object code that can be programmed into a PIC micro MCU and debugging information so that source code can be debugged and source variables can be viewed symbolically in Watch windows.
In order to test the code, software or hardware is needed that will execute the PIC micro instructions. A debug execution tool is a hardware or software tool that is used to inspect code as it executes a program (in this case led_delay.c). Hardware tools such as MPLAB ICE or MPLAB ICD 2 can execute code in real devices. If hardware is not available, the MPLAB simulator can be used to test the code. In this tutorial we can use MPLAB SIM simulator.
The simulator is a software program that runs on the PC to simulate the instructions of the PIC micro MCU.
It does not run in “real time,” since the simulator program is dependent upon the speed of the PC, the complexity of the code, overhead from the operating system and how many other tasks are running. However, the simulator accurately measures the time it would take to execute the code if it were operating in real time in an application.
Note: Other debug execution tools include MPLAB ICE 2000, MPLAB ICE 4000 and MPLAB ICD 2. These are optional hardware tools to test code on the application PC board. Most of the MPLAB IDE debugging operations are the same as the simulator, but unlike the simulator, these tools allow the target PIC micro MCU to run at full speed in the actual target application.
The status bar on the bottom of the MPLAB IDE window should change to “MPLAB SIM”.
Additional menu items should now appear in the Debugger menu. Additional toolbar icons should appear in the Debug Tool Bar.
MPLAB SIM is one of the debug engines that can be used with MPLAB. The other debug engines are hardware devices, while MPLAB SIM is a software program that runs on your PC. MPLAB SIM provides many of the same features as in-circuit emulators and in-circuit debuggers. The difference is that both in-circuit emulators and in-circuit debuggers allow the code to be run on actual silicon, and also allow target application hardware to be functional while being debugged.
MPLAB SIM has features to simulate hardware interaction with other signals and devices, and since it is running as software on the PC, it has complete information about the internal state of the simulated chip at each instruction. This is a little different from the hardware debuggers because, while they are running code at full speed, they typically cannot monitor all registers and all memory in real time.
Both MPLAB SIM and the hardware debuggers can do the traditional functions of debuggers, but due to their differences, they can have unique features of their own. This presentation will identify the functions and features of MPLAB SIM.
The debugger is a part of MPLAB IDE, and whether you are using MPLAB SIM, MPLAB ICE or MPLAB ICD 2, most operations are exactly the same. This allows you to develop code using the simulator, and then when your hardware is ready, you can use a hardware debugger to further test your code in practice without having to learn how to use a new tool.
These are the basic debug functions:
Some of these are listed here:
Complex events can be constructed to count events, so that a subroutine would have to be executed, for example, 15 times before it starts looking for a value on a pin or in a register. This kind of breakpoint allows you to describe the condition where your code misbehaves, to halt at a breakpoint or to trace code when that condition occurs. This is usually a faster way of finding bugs than simply setting simple breakpoints and stepping through your code.
MPLAB SIM is a simulator, and as a result it has certain characteristics that make it a unique debug engine. So the speed of the simulation is determined by,
Currently the maximum speed of MPLAB SIM is on the order of 10 MIPS, or 10 million instructions per second. This will be affected by how many other things are being done by your PC, by the code the simulator is running, and by the other tasks that the simulator is performing. The simulator simulates the operation of,
In order to test the application on the simulator, stimulus signals can be applied to pins and registers.
To evaluate performance, the simulator can log changing registers to files for further analysis.
Select the simulator as the debug execution tool. This is done from the Debugger>Select Tool pull down menu.
MPLAB SIM is selected as the debug engine from the Debugger menu. Note the other functions on the debug menu, such as Run, Step, and Breakpoints.
Once a debug engine is selected, the toolbar is appended with some new icons for running, halting, single stepping, and resetting the target.
The Status bar now shows some additional information.
The toolbar icons, the menus, or the hot keys listed on the menus can be used to execute the debug functions. Note that some are a little more complex, such as Reset, which actually has four types of reset actions.
Once MPLAB SIM is established as the debug engine, whenever a project is built, it is automatically loaded into the simulator’s program memory to be run and tested
One debug window is the source code window. This is actually the editor window, and breakpoints can be set by clicking on a line with the right mouse button. Single stepping with the source code window in focus will single step through the C source lines. Since you are in the editor, changes can be done quickly, and the project can be rebuilt.
The Program Memory window shows the machine code that will be executed by the simulator. Single stepping with this window in focus will allow you to step through each machine instruction.
Another window, called the Disassembly Listing window shows high level source code interspersed with machine code generated by each C statement.
You can also open up a watch window and drag the variables from your program to them to see the contents.
In order to see if the code is operating as intended, sending incrementing values out PORTC, watch the values being sent to PORTC.
Below are the menu items in the Disassembly window right mouse button menu.
Select View>Watch to bring up an empty Watch Window.
There are two pull downs on the top of the Watch Window. The one on the left labeled “Add SFR” can be used to add the Special Function Register, PORTC, into the watch. Select PORTC from the list and then click Add SFR to add it to the window.
While debugging, other windows are available to view,
The sample programs are ready for you to run. You can use the sample programs to learn how to use our tools. Additionally, you can copy the code from MPLAB samples for your own use.
The sample programs are found in...\Microchip\Examples (for Microchip C30 toolset), \Microchip\C30\Examples (for C compiler), and, \Microchip\ASM\Examples (for assembler).
Each sample program is stored in a separate folder along with project files that help you quickly build and evaluate each sample program.
In Mplab, we can generate a simple C program named LED_delay by using the Mplab Editor.
LED_delay program does nothing just high & low an I/O line within a certain time period. This program has a single source file LED_delay.C.
This small application helps you confirm that you can compile, link, and debug an application. You can perform these operations from the Mplab for Windows using the provided project file.
The only on-chip peripheral used is the I/O port line. You do not actually need a target CPU because Mplab lets you simulate the hardware required for this program.
In Mplab, applications are maintained in a project file. A project file has been created for LED_delay.c.
To load this project, select Open Project from the Project menu and open Mplab.mcp from the specific folder if we already generate the Project file. Otherwise you must generate a Project file (Refer Getting Started Chapter).
You can now edit LED_delay.C. Double click on LED_delay.C in the Files page of the Project Workspace. µVision loads and displays the contents of LED_delay.C in an editor window.
When you are ready to compile and link your project, use the Build Target command from the Project menu.
Mplab begins to translate and link the source files and creates an absolute object module that you can load into the Mplab debugger for testing. The status of the build process is listed in the Build page of the Output Window.
Once the LED_delay program is compiled and linked, you can test it with the Mplab SIM debugger. In Mplab, use the Run command from the Debug menu or toolbar. Mplab initializes the debugger and starts program execution till the main function.
During debugging Mplab will show the following output:
The PORTB registers enabling HIGH in a certain period,
The PORTB registers enabling LOW in a certain period,
we respect your privacy.