Getting started with MPLAB7

Slides:



Advertisements
Similar presentations
Use of MPLab software Paul Cockshott. PIC KIT Get the kit Kits are locked in cupboard Get from lab supervisor Plug into the usb port on your computer.
Advertisements

Getting started with MPLAB Launch MPLAB Set Toolbar as in the next slide by clicking the leftmost icon Open a new Source file by choosing [FILE][NEW] Type.
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Introduction to HT-IDE3000 Micro-C development System Department.
The 8051 Microcontroller and Embedded Systems
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
1 An Introduction to IBM SPSS PSY450 Experimental Psychology Dr. Dwight Hennessy.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Using PDG with e2studio: Example
DEMONSTRATION FOR SIGMA DATA ACQUISITION MODULES Tempatron Ltd Data Measurements Division Darwin Close Reading RG2 0TB UK T : +44 (0) F :
Chapter 2 Software Tools and Assembly Language Syntax.
Silicon Labs ToolStick Development Platform
Vintage Computer Hardware 101 Featuring the MITS Altair 680b Bill Degnan.
CPS120: Introduction to Computer Science Compiling Your Programs Using Visual C++
ADAM2 Single Remocon MCU IDE User’s Manual S/W Integrated Development Environment - Assembler - Simulator - Code Wizard V1.0 Technical Sales Team, ETA.
Windows Tutorial Common Objects ACOS: 1, 4. Using the Taskbar 1. Using the taskbar, you can switch between open programs and between open documents within.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
Bit-DSP-MicrocontrollerTMS320F2812 Texas Instruments Incorporated European Customer Training Center University of Applied Sciences Zwickau (FH)
Renesas Technology America Inc. 1 M16C Seminars Lab 3 Creating Projects Using HEW4 14 March 2005 M16C Seminars Lab 3 Creating Projects Using HEW4 Last.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Renesas Technology America Inc. 1 SKP8CMINI Tutorial 2 Creating A New Project Using HEW.
Copyright 2006 by Timothy J. McGuire, Ph.D. 1 MIPS Assembly Language CS 333 Sam Houston State University Dr. Tim McGuire.
Copyright © 2007 by Pearson Education 1 UNIT 6A COMBINATIONAL CIRCUIT DESIGN WITH VHDL by Gregory L. Moss Click hyperlink below to select: Tutorial for.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Programming and Debugging with the Dragon and JTAG Many thanks to Dr. James Hawthorne for evaluating the Dragon system and providing the core content for.
Workshop Setup The software/hardware used in this workshop are:
Making a 24hr Timer.
Component 1.6.
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Programming and Debugging with the Dragon and JTAG
Use of MPLab software Paul Cockshott.
The first change to your project files that is needed is to change the device to the correct FPGA. This is done by going to the Assignments tab on the.
Setting up Categories, Grading Preferences and Entering Grades
UNDERSTANDING YOUR COMPUTER
Control Unit Lecture 6.
Homework Reading Machine Projects Labs
Microcontroller Applications
Microprocessor Systems Design I
Assembly Language Programming Part 3
PRU-ICSS Programming with CCS
T_C_N_L_G_ E D I D I E O Y O H I E B J I R E A A W.
Using Visual Studio with C#
EMT 348: Microcontroller Timer/counter
Variables and Arithmetic Operations
Debugging with Eclipse
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
Tim Sumner, Imperial College, Rm: 1009, x47552
Introducing the PIC Mid-Range Family and the 16F84A
BIC 10503: COMPUTER ARCHITECTURE
ECE 3567 Microcontroller Lab
Digital Chart Recorder Operation
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
EECE.3170 Microprocessor Systems Design I
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
CSC235 - Visual Studio Tutorial
File Analysis with MicroSoft DEBUG
EECE.3170 Microprocessor Systems Design I
Software Setup & Validation
DAT2343 LMC Simulator Usage © Alan T. Pinck / Algonquin College; 2003.
8051 ASSEMBLY LANGUAGE PROGRAMMING
EECE.3170 Microprocessor Systems Design I
Registers and Counters
Debugging with Eclipse
ECE 3567 Microcontrollers Lab
Presentation transcript:

Getting started with MPLAB7 Launch MPLAB Open a new Source file by choosing [FILE][NEW] or clicking on the icon on the toolbar Type in your program Rules for the Microchip assembler: Comments begin with a ; Labels (names) begin in column 1 (Leftmost) and by style should be UPPERCASE Instructions should not begin in column 1 and by style should be lowercase The last directive should be end (comments can come after) Save your file [FILE][SAVE AS] on your floppy or memory stick in a folder called Myfiles Rules for file naming: Names should be not more than 32 alphanumeric characters, nor beginning with a number. An underscore is an acceptable character The extension should always be .asm; e.g. example1.asm 14 November, 2018 University of Ulster

14 November, 2018 University of Ulster

Make a new Project [Project][Project Wizard] Hit the <Next> button (left) Step One: Pick the device you are going to use as the target Hit the <Next> button (right) 14 November, 2018 University of Ulster

Hit the <Next> button (left) Step Two: Select your Language Toolsuite. In the diagram below left, this is the Microchip PIC ASseMbler Hit the <Next> button (left) Step Three: Give your project a name and where it is going to reside This is usually in the same place as you saved your source file; a:/myfiles in our example (right) Hit the <Next> button 14 November, 2018 University of Ulster

Hit the <Next> button Step Four: Find your source file, select it and hit the <Add>>> button (left) Hit the <Next> button A summary of your project is given to allow you to back up and make any alterations (right) Hit the <Finish> button to complete your project setup file example1.mcp 14 November, 2018 University of Ulster

Assemble your code by picking [PROJECT][MAKE] or hit {F10} If there are NO syntax errors then you should see something like this: 14 November, 2018 University of Ulster

Make the appropriate change(s) and reassemble {F10} If you had a syntax error (for this example I changed addlw to addwl), then something like below will occur: To correct the errors then read the error description which in this case is in line 13 “Illegal character”. Double click on error and the cursor will move to the appropriate line in the source code. The clue is the warning “Found label after column 1. (addwl)” As it did not recognise the illegal instruction addwl it thought it was a label in the wrong place. Make the appropriate change(s) and reassemble {F10} Note that sometimes the Output window will list Warnings. These are not necessarily errors, but nevertheless should be closely inspected 14 November, 2018 University of Ulster

Pick submenu [MPLAB SIM] Prepare to simulate your program by turning on MPLAB’s simulator as shown left Pick menu [Debugger] Pick submenu [MPLAB SIM] Once this is done an extra toolbar appears From left to right: Run at full simulated speed {F9} Stop running {F5} Animate at two steps per second. This can be changed using the [Debugger][Settings][Animation] menu to alter the rate 14 November, 2018 University of Ulster

Step Into simulates a single instruction each time this icon is clicked. This includes subroutines {F7} Step Over simulates a single instruction but when this is a call to a subroutine the latter executes at full simulation speed until returning to the caller {F8} Step out allows the operator to single step through a subroutine and then when satisfied, to run through to completion at full simulation rate until returned to the caller Reset the software simulator to the instruction at location h’000’ in the Program store, and various peripheral devices. {F6} This does not clear the GPR Files, but this can be done via the [Debugger][Clear Memory][GPRs] 14 November, 2018 University of Ulster

Pick menu [View][Watch] In order to see what is going on in a simulation you need to set up a Watch window to monitor the program variables and memory Pick menu [View][Watch] Add the appropriate variables, NUM and SUM in this example, using the right-hand drop down menu and clicking the <Add Symbol> button 14 November, 2018 University of Ulster

To modify a value in the Watch window: Double-click the variable’s value; e.g. NUM (left) In the resulting Modify window input the datum byte and left click the mouse The altered value is shown in the Watch window in red (right) Special-Purpose Registers, e.g. PORTA, can be monitored in the same way using the left-hand drop menu and <Add SFR> select button 14 November, 2018 University of Ulster

To change the display properties of a variable in the Watch window: Single-click anywhere in the variable’s row Right-click anywhere inside the Watch window and pick Properties The Watch properties tab allows you to change the watched variable in various number bases and sizes (e.g. as a 2-byte decimal). More than one copy of a variable can be added to the Watch window and viewed simultaneously in different number bases; e.g. binary and decimal 14 November, 2018 University of Ulster

To ‘run’ your program by single stepping: Reset the simulated PIC by either using the [Debugger][Reset][Processor reset] menu entry or the Reset icon or {F6} You can single-step the system using the Single-Step icon or else use the [Debugger] menu A green arrow will move down the source code as you step through the program and the variables will alter in the Watch window (variable values can be changed on the fly in the Watch window, as described previously) The Working register, Program Counter and values of the three flags are shown lower case for 0 and Upper case for 1 The program can be reset any time and Watched variables altered for each run. In addition right clicking in the Watch window will bring up the Properties menu and allow variables to be added or properties altered (such as changing from hex to decimal or binary) 14 November, 2018 University of Ulster

14 November, 2018 University of Ulster

To ‘run’ your program by animation First set a breakpoint by right clicking on the instruction you wish the program to stop at Click on Set Breakpoint in the resulting menu (bottom left) A red stop symbol will appear (bottom right) Do this as many times as you like to set up several breakpoints. You can run down to each one in sequence You can remove a breakpoint by right clicking and in the resulting menu clicking on Remove Breakpoint Reset the system Click on the Animate icon The program will execute a few instructions a second and stop when the breakpoint is reached. To ‘run’ at high speed then: Set up a breakpoint Use the Go icon You can use the Stop icon to halt the simulation at any time

To ‘run’ at high speed then: Set up a breakpoint Use the Go icon You can use the Stop icon to halt the simulation at any time In programs which take longer than about 18ms to execute, the simulation will halt prematurely, as the Watchdog timer is also simulated and will time-out unless your program continually clears it using the clrwdt instruction. In order to avoid this, the Watchdog timer should be disabled by activating the simulated fuse pattern Pick the [Configure][Configuration Bits] menu entry (bottom left) From the Configuration Bits (Fuse) menu (bottom right) click on the Watchdog Timer Setting and pick Off 14 November, 2018 University of Ulster

To monitor the execution time of your program using the Stopwatch Before running your program go to the [Debugger] menu and pick [StopWatch] (left) The Stopwatch window shown below appears. Cycles shows the number of internal cycles (¼ crystal frequency) as the program progresses Time is the actual time, which depends on the xtal frequency Normally both the above are zeroed on reset If the program is single-stepped or animated then the Stopwatch is updated on the fly, as is the Watch window If the run is at high speed then the final outcome is displayed when the breakpoint is reached; see next slide Note: The simulated crystal frequency may be changed from the [Debugger][Settings] menu 14 November, 2018 University of Ulster

For example for a 20MHz crystal: 14 November, 2018 University of Ulster

Highlight all instructions you wish to be logged and then right click Using the Trace memory facility For serious debugging it is useful to have a log of the state of the program as the simulation progresses. Highlight all instructions you wish to be logged and then right click In the resulting menu click on [Add Filter-in Trace] The instructions to be traced will be indicated with symbols thus: 14 November, 2018 University of Ulster

Now run the program in the usual way Single instructions can be right-clicked and added to the trace repertoire Now run the program in the usual way When finished selecting [View][Simulator Trace]. This brings up the Trace Memory window showing in each line numbered back from the breakpoint: Each instruction: e.g. in line -8 this is decfsz 0x21,f The number of cycles since reset: e.g. h’40’ (decimal 64) Address of the Source data (SA): e.g. the File contents being decremented is in File h’21’ The value of this data (SD): e.g. 02 The destination address (DA): e.g. File h’21’ The value of this destination data (DD): e.g. 01 (it has been decremented) The contents of the Trace Memory can be saved and printed etc by right clicking in the window picking [Output to File], and giving the file a name Up to around 32,000 trace lines are possible 14 November, 2018 University of Ulster

14 November, 2018 University of Ulster

During simulation you may want to monitor stimuli from the outside world which will drive the port pins when the processor is executing in a hardware environment. For example, to see how software responds to a pulse at a Parallel port. To do this you must use the Asynchronous Stimulus dialog. In the following example a value of the variable COUNT is to be incremented each time pin RB0 (that is the Interrupt pin) is pulsed. Open the Stimulus Controller window [Debugger][Stimulus Controller][New Scenario] (bottom left) The resulting window (bottom right) allows you to fill in for any set of pins what action will be taken when the operator clicks on the appropriate firing button

Optionally enter a comment for each row Click on the Pin/SFR tab and select the appropriate pin (bottom left). You can repeat for each row Repeat for the Action column and select the appropriate action (bottom mid) Under the width and units columns enter the width or the event (1 bottom right) Under the Units column enter the duration units (cycles, ns, µs, ms or s) Optionally enter a comment for each row The next slide shows the situation where the RB0/INT pin has been fired six times (COUNT = 0x06) 14 November, 2018 University of Ulster

14 November, 2018 University of Ulster

Using MPLAB7 with the CCS C compiler Launch MPLAB Open a new Source file by choosing [FILE][NEW] Type in your program Save your file [FILE][SAVE AS] on your floppy/memory stick in a subfolder called myfiles Rules for file naming: Names should not be more than 32 alphanumeric characters, not beginning with a number, underscore is acceptable character The extension should always be .c; e.g. example16.c 14 November, 2018 University of Ulster

Make a new Project [Project][Project Wizard] in the normal way At step 2 select the CCS compiler as the toolsuite; see below left When complete you should have a summary similar to bottom right 14 November, 2018 University of Ulster

Compile your code by picking [Project][Compile] or hit {F10} If there are NO syntax errors then you should see something like this: 14 November, 2018 University of Ulster

Make the appropriate change(s) and compile {F10}. If you had a syntax error (For this example I changed count++; to cuont++;), then something like below will occur: If your Output window does not appear then ensure that [View][Output] is ticked. To correct the errors then read the error description which in this case is in line 9 “Unidentified identifier cuont”. Double click on this error line and the cursor will move to the appropriate line in the source code. Make the appropriate change(s) and compile {F10}. Many errors are not so easy to locate as this. Look out for comments with a start /* and no closing */!!! 14 November, 2018 University of Ulster

You can use a Watch window to monitor a C program in the same way as an assembly-level program, as shown below Variables, such as n, which are outside their scope at the execution line, will be annotated as such in the Watch window 14 November, 2018 University of Ulster

Using the PICSTART+ programmer Once you have written and assembled/compiled your code and verified its action using the simulator, you need to blast the code into a real PIC MCU’s Program store and run the code in real hardware. The following description assumes that the PICSTART+ is plugged into serial port COM1 (or COM2) of a PC, not necessarily the one you created the software on. If MPLAB7 has not been set up to recognise the PICSTART+ then follow the procedure below to intialise the setup. Ensure that the Power LED on the PICSTART+ is illuminated. From the [Programmer] menu pick [Select Programmer][1 PICSTART Plus] 14 November, 2018 University of Ulster

Again, from the [Programmer] menu pick [Enable Programmer]. 14 November, 2018 University of Ulster

Entering [Programmer][Settings…] allows you to alter some properties of the PICSTART+. Once the configuration has been set, it will be remembered for future sessions. As shown (bottom left) you can change the serial COM port. If you choose Auto select Memory range (bottom right) then only locations in your Program store that need programming will be blasted.

If you have configured the Configuration fuses in your source program (using __config – see below – or #fuses) then the fuse options will be automatically set up. If you wish to set these up manually (not recommended) then use the [Configure] menu and select [Configuration Bits…] as shown below and click on the setting(s) you wish to alter. 14 November, 2018 University of Ulster

If your program has been developed on the computer connected to your PICSTART+ then ignore the next points! If your program had no syntax errors then a .hex file will have been generated; this file contains all the machine code information needed for the blasting process. A typical .hex file looks like this: :020000040000FA :100000008601051483167E308500860183128518CB :10001000072820088600051000000514851C0E28FE :020020000728AF :02400E00613F10 :00000001FF Bring your .hex file over to the PICSTART+ PC and use [File][Import] to load your file into the machine. 14 November, 2018 University of Ulster

To blast your code into the PIC MCU use the [Programmer][Program] option (there are other options, such as [Verify] to check the contents of the PIC MCU’s Program store with the code in the .hex file). The Output window (bottom right) gives the address range blasted and whether the blast was successful. If the Output window does not display, then go to [View][Output].