DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

Similar documents
An Introduction to MPLAB Integrated Development Environment

MPLAB C18 C Compiler

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

3. Programming the STM32F4-Discovery

Digital Signal Controller (DSC) Development Tools

Fondamenti su strumenti di sviluppo per microcontrollori PIC

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

TRACE32 Debugger Getting Started... ICD Tutorial About the Tutorial... 2

Lesson 1 - Creating a C18 Project with MPLAB

Introduction to the use of the environment of Microsoft Visual Studio 2008

How to test and debug an ASP.NET application

Project Manager Editor & Debugger

CodeWarrior Development Studio for Freescale S12(X) Microcontrollers Quick Start

STEP 7 MICRO/WIN TUTORIAL. Step-1: How to open Step 7 Micro/WIN

SA-9600 Surface Area Software Manual

Lab 2-2: Exploring Threads

Training Simulator and Demo Software

Creating a Project with PSoC Designer

Hitchhiker's Guide to CodeWarrior EE371, EE475 Fall 2005

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

DRV8312-C2-KIT How to Run Guide

BIGPOND ONLINE STORAGE USER GUIDE Issue August 2005

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

2) Sharing Projects Made easy by IntelliGantt s Share Wizard, there are three share options to fit the needs of your project.

MPLAB X + CCS C Compiler Tutorial

For Introduction to Java Programming, 5E By Y. Daniel Liang

Vodafone PC SMS (Software version 4.7.1) User Manual

Tutorial for MPLAB Starter Kit for PIC18F

Building an Embedded Processor System on a Xilinx Zync FPGA (Profiling): A Tutorial

M100 System File Manager Help

Capacitive Touch Lab. Renesas Capacitive Touch Lab R8C/36T-A Family

MONITORING PERFORMANCE IN WINDOWS 7

MPLAB IDE 64-Bit USB Device Drivers Installation

Desktop, Web and Mobile Testing Tutorials

Chapter 12. Development Tools for Microcontroller Applications

Presentations and PowerPoint

E-Loader Operation Manual

What is OneDrive for Business at University of Greenwich? Accessing OneDrive from Office 365

Freescale Semiconductor, I

Start A New Project with Keil Microcontroller Development Kit Version 5 and Freescale FRDM-KL25Z

Microsoft PowerPoint 2010

Installing S500 Power Monitor Software and LabVIEW Run-time Engine

Twido Simulator - Online Help Scope What's in this Part? Twido Simulator Overview What's in this Chapter? How to Use Twido Simulator

5. Tutorial. Starting FlashCut CNC

Impact+OCR 1.1 Readme

Introduction. - Please be sure to read and understand Precautions and Introductions in CX-Simulator Operation Manual and

13 Managing Devices. Your computer is an assembly of many components from different manufacturers. LESSON OBJECTIVES

Using Microsoft Visual Studio API Reference

IT Quick Reference Guides Using Windows 7

Site Maintenance Using Dreamweaver

IPRS-7 IP/GPRS PC Receiver Software Quick Start V1.2

Altera Monitor Program

Software development and debugging for NXP ARM7 MCUs

1. Introduction Fixture exterior view Connecting the Robe Universal Interface Software update of the fixture...

Using Example Projects, Code and Scripts to Jump-Start Customers With Code Composer Studio 2.0

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

Model 288B Charge Plate Graphing Software Operators Guide

AN104 I NTEGRATING KEIL 8051 TOOLS INTO THE SILICON LABS IDE. 1. Introduction. 2. Key Points. 3. Create a Project in the Silicon Labs IDE

Using HiTOP with the HOT16x Hands-On Training Materials

S7 for Windows S7-300/400

KPN SMS mail. Send SMS as fast as !

Microsoft PowerPoint Tutorial

Introduction to LogixPro - Lab

Installing PowerLink on Windows 7 64-bit

OPERATION MANUAL. MV-410RGB Layout Editor. Version 2.1- higher

Using DAVE with MDK Version 5

User Guide for Windows 10

Copyright 2006 TechSmith Corporation. All Rights Reserved.

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Table Of Contents. iii

Welcome to Ipswitch Instant Messaging

CODESOFT Installation Scenarios

Appendix A. CMS(Client Management Software)

UM1969 User manual. Getting started with STM32F746G discovery software development tools. Introduction

vtcommander Installing and Starting vtcommander

Legal Notes. Regarding Trademarks KYOCERA Document Solutions Inc.

UM0036 User Manual. ST Visual Develop (STVD) Introduction. Features

How to read this guide

Internet Explorer 7. Getting Started The Internet Explorer Window. Tabs NEW! Working with the Tab Row. Microsoft QUICK Source

2-Bay Raid Sub-System Smart Removable 3.5" SATA Multiple Bay Data Storage Device User's Manual

AutoDWG DWGSee DWG Viewer. DWGSee User Guide

Xythos on Demand Quick Start Guide For Xythos Drive

Programming the On-Chip Flash on a phycore-xc161 phycore-xc167

EMBEDDED C USING CODEWARRIOR Getting Started Manual

Windows XP Pro: Basics 1

Ultra Thin Client TC-401 TC-402. Users s Guide

X-Trade Brokers Dom Maklerski S.A. XTB Expert Builder. Tutorial. Michał Zabielski

PCB Project (*.PrjPcb)

VMware Horizon FLEX User Guide

Quick Start Guide. Microsoft Publisher 2013 looks different from previous versions, so we created this guide to help you minimize the learning curve.

The Texture Mill User Guide

Code Composer Studio Development Tools v3.3. Getting Started Guide

Embroidery Fonts Plus ( EFP ) Tutorial Guide Version

Installing LearningBay Enterprise Part 2

Deposit Direct. Getting Started Guide

Adobe Acrobat 6.0 Professional

Trend Micro Incorporated reserves the right to make changes to this document and to the products described herein without notice.

Simple Computer Backup

Transcription:

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

Contents at a Glance 1. Introduction of MPLAB... 4 2. Development Tools... 5 3. Getting Started... 6 3.1. Create a Project... 8 3.2. Start MPLAB... 8 3.2.1. Create a Project File... 10 3.2.2. Select Language Tools... 12 3.2.3. Naming the Project... 13 3.2.4. Adding files to Project... 14 3.2.5. Building the Project... 18 3.2.6. Testing Code with the Simulator... 21 4. Getting Started with MPLAB SIM... 23 4.1. Starting Up MPLAB SIM... 28 5. Sample Programs... 37

5.1. LED_delay: Your first dspic C Program... 37 5.2. Mplab Project File... 38 5.3. Editing LED_delay.C... 39 5.4. Compiling and Linking LED_delay... 39 5.5. Testing LED_delay... 40

1. Introduction of MPLAB 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. 2. Development Tools 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. 3. Getting Started 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. Create a project, select the target chip from the device database, and configure the tool settings. Create source files in C or assembly. Build your application with the project manager. Correct errors in source files. Test the linked application. Debug the executable logic by watching program flow with the built-in simulator or in real time with in-circuit emulators or in-circuit debuggers. Make timing measurements with the simulator or emulator. View variables in Watch windows. Program firmware into devices with device programmers.

3.1. Create a 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: Start MPLAB and select the toolset Create a project file and select a CPU from the device database. Create a new source file and add this source file to the project. Add and configure the startup code for the dspic. Set tool options for target hardware. Build project and create a HEX file for Flash programming. 3.2. Start MPLAB MPLAB is a standard Windows application and started by clicking on the program icon.

3.2.1. Create a Project File

1 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

3.2.2. Select Language Tools 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 >. 3.2.3. Naming the Project 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>.

3.2.4. Adding files to Project 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. Note: 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. 3.2.5. Building the Project 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: Project>Build All Right-click on the project name in the project window and select Build All Click the Build All icon on the Project toolbar. However the mouse over icons to see pop-up text of what they represent. The Output window shows the result of the build process. There should be no errors on any step.

Note: If these do not assemble and link successfully, check the following items and then build the project again: Check the spelling and format of the code entered in the editor window. Make sure the new variables and the special function registers, TRISC and PORTC, are in upper case. If the assembler reported errors in the Output window, double click on the error and MPLAB IDE will open the corresponding line in the source code with a green arrow in the left margin of the source code window. Check that the correct compiler (Microchip C30 Compiler) and linker for PIC micro devices are being used. Select Project>Set Language Tool Locations. Click on the plus boxes to expand the Microchip C30 tool suite and its executables. Click Microchip C30 Compiler (pic30-gcc.exe) and review their location in the display. If the location is correct, click Cancel. If it is not, change it and then click OK. The default search paths can be empty.

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. 3.2.6. Testing Code with the Simulator 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.

4. Getting Started with MPLAB SIM 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. Debugger Menu Toolbar Buttons Hot Key Run F9 Halt F5 Animate Step Into F7 Step Over F8 Step Out Of Reset F6

These are the basic debug functions: Reset the target, in order to restart the application. Execute the code so the program can be tested to verify it functions as designed. Halt the code at breakpoints While halted at breakpoints examine and modify memory and variables to analyze and debug the application code. Single Step through code to closely inspect how it executes. This allows the engineer to go through code one instruction (or one C statement) at a time while monitoring affected variables, registers and flags. Single stepping essentially zooms in on code to ensure that it operates correctly in complex and critical sections with ranges of variable values and under various test conditions. Most debuggers also have additional features to help analyze and debug the application.

Some of these are listed here: Watch points group and monitor selected variables and memory locations into a convenient, custom readout. Trace buffers capture the streams of instructions executed and reveal the contents of changing register values. A Stopwatch can time a section of code. Routines can be optimized, and critical code timing can be accurately measured and adjusted. Complex breakpoints offer a method for establishing breakpoints or for gathering data in the trace buffer based upon multiple conditions. Simple breakpoints allow setting breakpoints in the source code or anywhere in program memory. Complex breakpoints allow getting a breakpoint on a condition such as, After the main routine called Refresh Display executes then

wait for subroutine Read Temp to execute. Then break if the variable named Temperature is greater than 20. 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, How fast your PC executes, The complexity of the current simulation, and The number of other tasks executing on your PC.

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, The core CPU and its internal registers, Memory, and Many of it peripherals. 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. 4.1. Starting Up MPLAB SIM 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. MPLAB SIM shows as the current debug engine.

The simulated processor is listed, in this case the dspic30f4011, Then the program counters, The W register, The current state of the internal CPU flags and The current selected file register bank.

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.

Set or remove a breakpoint at the currently-selected line. Enable/Disable a breakpoint at the currentlyselected line. Run the program to the current cursor location. S e t P C a t C u r s o r Set the program counter (PC) to the cursor location. C opy selected text to clipboard. Select text by (1) clicking and dragging mouse over text or (2) clicking at the beginning of text and shift-clicking at the end of text. Select all text in the window. O u tpu t t o F ile. 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, register memory, stack memory, and Non-volatile data memory areas.

5. Sample Programs 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. 5.1. LED_delay: Your first dspic C 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. 5.2. Mplab Project File 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).

5.3. Editing LED_delay.C 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. 5.4. Compiling and Linking LED_delay 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. 5.5. Testing LED_delay 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.

Debugger Menu Toolbar Buttons Hot Key Run F9 Halt F5 Animate Step Into F7 Step Over F8 Step Out Of Reset F6 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,

Did you enjoy the read? Pantech solutions creates information packed technical documents like this one every month. And our website is a rich and trusted resource used by a vibrant online community of more than 1,00,000 members from organization of all shapes and sizes.

What do we sell? Our products range from Various Microcontroller development boards, DSP Boards, FPGA/CPLD boards, Communication Kits, Power electronics, Basic electronics, Robotics, Sensors, Electronic components and much more. Our goal is to make finding the parts and information you need easier and affordable so you can create awesome projects and training from Basic to Cutting edge technology.