A Quick Introduction toMPLAB SIMWelcome to this web seminar, “A Quick Introduction to MPLAB SIM.”My name is Darrel Johansen and I’m a manager in the Development Toolsgroup at Microchip.Page 1
What Is MPLAB SIM?OAfree component of MPLAB IDEAn Introduction to Microchip Development Tools2The centerpiece of our tool set is the software MPLAB IntegratedDevelopment Environment, or “IDE.”MPLAB IDE has enjoyed many years of use and evolution, trackingMicrochip’s expanding catalog of microcontrollers and digital signalcontrollers.One of the most popular elements of MPLAB is the software simulator,MPLAB SIM.This component, like the MPLAB IDE is free.Page 2
What Is MPLAB SIM?OAfree component of MPLAB IDEO A software simulator that runs onyour PCAn Introduction to Microchip Development Tools3The simulator runs on your PC to simulate the actions of the various PIC anddsPIC microcontrollers.Page 3
What Is MPLAB SIM?OAfree component of MPLAB IDEO A software simulator that runs onyour PCO A verifier for your softwareAn Introduction to Microchip Development Tools4You can verify your software routines execute as designed Page 4
What Is MPLAB SIM?OAfree component of MPLAB IDEO A software simulator that runs onyour PCO A verifier for your softwareO A debugger to test your codeAn Introduction to Microchip Development Tools5 and debug, test and inspect your code.Page 5
What Is MPLAB SIM?OAfree component of MPLAB IDEO A software simulator that runs onyour PCO A verifier for your softwareO A debugger to test your codeO An optimizer to improve yourapplicationAn Introduction to Microchip Development Tools6MPLAB SIM helps you optimize your application with timing tools, trace tools, and various graphical analyzers.Page 6
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools7We’ll cover the basic elements of the simulator in this web seminar,including: How to configure MPLAB IDE to use MPLAB SIM as the current debugger How to run your code in MPLAB SIM halting at a breakpoint How to single step through your code How to set watchpoints on data variables in your code How to run and halt your code How to use a stimulus to simulate external inputs to your hardware How to use the DEBUG variable to make conditional code executionwhile debugging How to insert fprintf statements in your code to monitor the executingroutines How to measure the execution time of your code, and How to record code as it executes, capturing its history in a buffer to bereviewed.Page 7
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools8Page 8
Starting MPLAB SIMMPLAB DesktopAn Introduction to Microchip Development Tools9You should already be familiar with MPLAB IDE before going through thisseminar. You might want to watch the “Introduction to MPLAB” seminar first.The MPLAB IDE desktop has all the standard Windows features: menus, toolbars with icons, and a status bar at the bottom.Page 9
Starting MPLAB SIMDebugger Select ToolAn Introduction to Microchip Development Tools10To select the simulator, select the Debugger pull down menu, and scroll to“Select Tool” Page 10
Starting MPLAB SIMDebugger Select ToolAn Introduction to Microchip Development Tools11A sub menu pops up Page 11
Starting MPLAB SIMDebugger Select Tool MPLAB SIMAn Introduction to Microchip Development Tools12Scroll down to select MPLAB SIM.Page 12
Starting MPLAB SIMProjectsAn Introduction to Microchip Development Tools13Now the status bar shows MPLAB SIM as the current debugging tool.-- MPLAB deals with applications as “projects.” -Projects are the source files that are used to build the application along withcompilers, assemblers and linkers to “build” the firmware for the application.In this project are three files, “main.c.” “delay.c,” and an assembly file,“int devices.s.”All will be compiled using the MPLAB C compiler and its tool suite for thedsPIC family of digital signal controllers, but this process is the same for theother families of Microchip microprocessors.For more information on setting up a project, see the “Introduction toMPLAB” seminar referenced earlier.Page 13
Starting MPLAB SIMBuild ProjectAn Introduction to Microchip Development Tools14When all the source code is correctly written and the project configuredproperly, click the build icon on the toolbar to compile the files.Page 14
Starting MPLAB SIMBuild ProjectAn Introduction to Microchip Development Tools15If the project builds with no errors, the output window will show “buildsucceeded.”Page 15
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools16Page 16
BreakpointSet BreakpointAn Introduction to Microchip Development Tools17Open a source file for editing or debugging by double clicking on the filename in the project window,After a project successfully builds, position the cursor on the desired line,And click the right mouse button to bring up a menu to set a breakpoint.Page 17
BreakpointAn Introduction to Microchip Development Tools18In the source file the breakpoint is shown by the red symbol with the letter“B”Page 18
Run to BreakpointAn Introduction to Microchip Development Tools19Pressing the “Run” icon, starts the simulation, stopping at the breakpoint.The green arrow on top of the red “B” shows the current program counterlocation at the breakpoint set in the function “main.”Page 19
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools20Page 20
Single StepAn Introduction to Microchip Development Tools21Pressing the “step” icon, single steps one line in the code.Page 21
Step AgainAn Introduction to Microchip Development Tools22Page 22
Step AgainAn Introduction to Microchip Development Tools23Page 23
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools24Page 24
WatchpointsView WatchAn Introduction to Microchip Development Tools25Watch windows inspect variables in your code. Select the Watch windowfrom the View menu.Page 25
WatchpointsSelect Variables to WatchAn Introduction to Microchip Development Tools26Use the right pull down list to see symbols, select the variables to watch Page 26
WatchpointsAdd Variables to Watch WindowAn Introduction to Microchip Development Tools27 then press the Add Symbol button to enter them in the watch window list.Now when the program is halted or stepped, the variables will show changedvalues in red.Page 27
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools28Page 28
RunAn Introduction to Microchip Development Tools29Pressing the “run” icon lets the processor continue running the code from thecurrent breakpoint.The status bar at the bottom disappears and is replaced by a “running”progress bar.Page 29
RunAn Introduction to Microchip Development Tools30Page 30
RunAn Introduction to Microchip Development Tools31Page 31
RunAn Introduction to Microchip Development Tools32Page 32
RunAn Introduction to Microchip Development Tools33Page 33
RunAn Introduction to Microchip Development Tools34Page 34
RunAn Introduction to Microchip Development Tools35Page 35
RunAn Introduction to Microchip Development Tools36Page 36
RunAn Introduction to Microchip Development Tools37Page 37
RunAn Introduction to Microchip Development Tools38Page 38
HaltAn Introduction to Microchip Development Tools39Selecting the “Halt” icon stops program execution at the current programcounter location, just as if it encountered a breakpoint at that instruction inthe code.Page 39
HaltAn Introduction to Microchip Development Tools40In this code, after pressing single step, the green arrow does not advance.The code is in a “while” loop, waiting for a switch on port pin RD7 to go high.Page 40
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools41Page 41
StimulusDebugger Stimulus New WorkbookAn Introduction to Microchip Development Tools42The action of the switch on pin RD7 can be simulated with a stimulusfunction.MPLAB SIM can respond to the action of external hardware, such asswitches, with the stimulus functions.The stimulus dialog is accessed from the Debugger pull down, scroll to“Stimulus” and create a “New workbook.”Page 42
StimulusStimulus DialogAn Introduction to Microchip Development Tools43The stimulus workbook has tabs for the various types of stimulus.Page 43
StimulusStimulus DialogAn Introduction to Microchip Development Tools44There are six tabs, offering a options to apply stimulus to the simulator,Page 44
StimulusStimulus DialogAn Introduction to Microchip Development Tools45Regular, repeating waveforms, lists of voltage levels, events from files, andsequences of data values can be injected into registers and applied toexternal pins.Page 45
StimulusAsynchronous StimulusAn Introduction to Microchip Development Tools46The “asynchronous” stimulus tab can be used to simulate the action ofpressing a switch.Page 46
StimulusSet PinAn Introduction to Microchip Development Tools47Click on the PIN/SFR column to select the pin RD7.Page 47
StimulusSet ActionAn Introduction to Microchip Development Tools48In the “Action” column, set the action for the pin to pulse high when pressed.Page 48
StimulusSet TimeAn Introduction to Microchip Development Tools49In the width column, a somewhat arbitrary value of “5” makes the pulse last 5cycles, just ensuring the pulse lasts beyond a single instruction.Page 49
StimulusFire StimulusAn Introduction to Microchip Development Tools50Press the “Fire” button to apply the pulse to the RD7 pin.The output window logs the action.Page 50
StimulusStepAn Introduction to Microchip Development Tools51Press the single step key to go forward,into the Delay routine.Page 51
StimulusDelayAn Introduction to Microchip Development Tools52The next step enters the delay routine.Delay routines such as this are often used to slow things down so that adisplay can be seen by the human eye, for instance.When simulating, which runs at a slower speed than the actual processor,these delays are often not needed.While using the simulator, we just need to know that the delay routine iscalled, but we don’t want to step through thousands of iterations of the delayloop.Page 52
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools53Page 53
DEBUGAn Introduction to Microchip Development Tools54Use the variable underscore-underscore DEBUG to change the way thedelay loop operates while debugging using the simulator.To modify the delay routine to operate differently while debugging, but retainits function in the application add an #ifdef function to check the state of thevariable underscore-underscore DEBUG.If the variable underscore-underscore DEBUG exists, then we’ll skip thethousands of loops in the delay routine, and just exit.Page 54
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools55Page 55
fprintfInclude stdio.hAn Introduction to Microchip Development Tools56Additionally an fprintf function can print out a message to remind us that thedelay routine operates differently while debugging with the simulator.In order to use the printf routine to echo that the delay routine executed (butin a different way when debugging) the stdio.h file must be included.Page 56
fprintfInclude stdio.hAn Introduction to Microchip Development Tools57Page 57
fprintfBuild Options – MPLAB LINK30An Introduction to Microchip Development Tools58A couple of other things need to be set up to use fprintf.Under the Project menu are the build options.Page 58
fprintfSet HeapAn Introduction to Microchip Development Tools59The MPLAB LINK30 tab needs to generate a heap to handle the characterstorage for fprintf.256 bytes is ample for any message we need to print out.Page 59
fprintfDebugger Simulator SettingsAn Introduction to Microchip Development Tools60Messages from an embedded controller must come from a peripheral deviceon that controller.The UART needs to be configured to send I/O to the Output window.The simulator settings dialog is on the Debugger menu.Page 60
fprintfEnable UartAn Introduction to Microchip Development Tools61Check the box to enable the UART I/O Page 61
fprintfOutput to WindowAn Introduction to Microchip Development Tools62 and check this button to see its messages in the Output window.Page 62
fprintfOutput MessageAn Introduction to Microchip Development Tools63Now as you go through your code, you’ll see the fprintf string in the outputwindow each time the delay function is called.Page 63
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools64Page 64
StopwatchDebugger StopwatchAn Introduction to Microchip Development Tools65MPLAB SIM has tools to analyze how the code is running.The stopwatch can time the execution of code.While stopped at a breakpoint, select the stopwatch from the Debuggermenu, then press the “Zero” button to clear its contents to get ready for ameasurement.Page 65
StopwatchAn Introduction to Microchip Development Tools66Run to the next breakpoint, and the stopwatch accurately measures theinstruction time in cycles and microseconds.Page 66
Topics Covered inThis Web SeminarOOOOOOOOOOStarting MPLAB SIMRunning to a breakpointSingle steppingSetting watchpointsRunning and haltingUsing a stimulusUsing the DEBUG variableUsing fprintf statements to debugMeasuring routine execution time with thestopwatchTracing code as it executesAn Introduction to Microchip Development Tools67Page 67
TraceDebugger SettingsAn Introduction to Microchip Development Tools68Another way to optimize code is to use the trace analyzer.While setting breakpoints and single-stepping through code is one way tosee how your code is functioning, an alternative is to use the trace facilitiesof MPLAB SIM to record instructions as they execute while the simulator isrunning.Use the Debugger menu to select the Settings dialog, and enable the “TraceAll” checkbox.Page 68
TraceAn Introduction to Microchip Development Tools69Press run, then halt, or stop at a breakpoint, and view the trace window fromthe View menu.The upper half of the trace window shows the instruction flow.When you click on an instruction there Page 69
TraceAn Introduction to Microchip Development Tools70 the corresponding section from the source code is shown in the lower half.Trace is useful to see how you got to a certain point in your code.Page 70
Download MPLAB and Try It!WWW.MICROCHIP.COM/MPLABAn Introduction to Microchip Development Tools71That’s a quick tour of the simulator. We hope this will give you a fewpointers and you’ll explore these and other simulator features.If you haven’t already done it, now is the time to get started with MPLABIDE.Go to our web site at www.microchip.com/mplab and download your freecopy of MPLAB software.This is the end of our presentation.Thank you for your time.Page 71
Starting MPLAB SIM MPLAB Desktop You should already be familiar with MPLAB IDE before going through this seminar. You might want to watch the “Introduction to MPLAB” seminar first. The MPLAB IDE desktop has all the standard
MPLAB X CCS C Compiler Tutorial How to install the CCS C Compiler inside MPLAB X Before the CCS C Compiler can be used inside MPLAB X, the CCS C MPLAB X Plug-in must be installed. This process can be done inside MPLAB X. 1. Launch MPLAB X. 2. From the MPLAB X menu, select Tools - Plugins 3.
MPLAB C18 C Compiler The layout of this document: –Installing MPLAB C18: A step-by-step guide through the installation process of MPLAB C18 Compiler. –Configuring MPLAB IDE: MPLAB IDE setup for use with MPLAB C18. Basics of MPLAB IDE configuration to run your Program
MPLAB SIM MPLAB ICE 2000 MPLAB ICD 2 MPLAB ICE 4000 MPLAB IDE Debugger The other debug engines are hardware devices, while MPLAB SIM is a software program, running on your PC. MPLAB SIM provides many of the same features as in-circuit emulators and in-circuit debuggers.
Chapter 1: MPLAB IDE Preview – An overview of what MPLAB IDE is and how it works. Chapter 2: MPLAB IDE Installation – How to install MPLAB IDE on your computer. Chapter 3: Getting Started with MPLAB IDE – A Tutorial – How to begin using MPLAB IDE. Chapter 4: MPLAB IDE Projects Tuto
MPLAB X IDE The latest information on Microchip MPLAB X IDE, the Windows Integrated Development Environment for dev elopment systems tools. This list is focused on the MPLAB IDE, MPLAB ID E Project Manager, MPLAB Editor and MPLAB SIM simu
MPLAB Harmony provides a MPLAB Harmony Configurator (MHC) MPLAB X IDE plug-in that can be installed in MPLAB X IDE to help you create your own MPLAB Harmony applications. To create a new MPLAB
MPLAB Harmony provides a convenient MPLAB X IDE plug-in configuration utility, the MPLAB Harmony Configurator (MHC), which you can use to easily create MPLAB Harmony-based projects. This tutorial will show you how to use the MHC to quickly create your first MPLAB Harmony application using the following steps: Step 1: Create a New Project
Methods, Optimization in Operations Research, Advance Discrete Mathematics, Engineering Mathematics I–III, Advanced Mathematics, and the like. He is also on the editorial board and a reviewer of .