Académique Documents
Professionnel Documents
Culture Documents
X IDE
Lab Manual
Cammen Chan
Alain Sorin
Ingrid Tay
Microchip Technology Inc.
v3.7 October 2013
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Trademarks
The Microchip name and logo, dsPIC, KEELOQ, KEELOQ logo,
MPLAB, PIC, PICmicro, PICSTART, PIC32 logo, rfPIC and UNI/O are
registered trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor, MXDEV,
MXLAB, SEEVAL and The Embedded Control Solutions Company are
registered trademarks of Microchip Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONO-
MONITOR, FanSense, HI-TIDE, In-Circuit Serial Programming, ICSP,
Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK,
mTouch, Omniscient Code Generation, PICC, PICC-18, PICDEM,
PICDEM.net, PICkit, PICtail, REAL ICE, fLAB, Select Mode, Total
Endurance, TSHARC, UniWinDriver, WiperLock and ZENA are trade-
marks of Microchip Technology Incorporated in the U.S.A. and other
countries.
SQTP is a service mark of Microchip Technology Incorporated in the
U.S.A.
All other trademarks mentioned herein are property of their respective
companies.
2013, Microchip Technology Incorporated
Information contained in this publication regarding device applications and
the like is provided only for your convenience and may be superseded by
updates. It is your responsibility to ensure that your application meets with
your specifications. MICROCHIP MAKES NO REPRESENTATIONS
OR WARRANTIES OF ANY KIND HETHER EXPRESS OR IMPLIED,
WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO
THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CON-
DITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability arising from
this information and its use. Use of Microchip devices in life support and/
or safety applications is entirely at the buyers risk, and the buyer agrees to
defend, indemnify and hold harmless Microchip fromany and all damages,
claims, suits, or expenses resulting fromsuch use. No licenses are con-
veyed, implicitly or otherwise, under any Microchip intellectual property
rights.
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Lab Exercise 1
Creating an MPLAB
X Project
Lab Exercise 1 shows how to create, edit, and build projects with
MPLAB
X
Purpose
MPLABX(v1.90orhigher)
MPLABXC16(v1.10or
higher)
Objective
A step by step walk through MPLAB
X project development. An
MPLAB
X
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Procedure
Project Creation
Open MPLAB
Xprojectcreaonscreen
When MPLAB
X starts it opens
the last project worked on. To
avoid confusion this lab asks to
youcloseanyopenproject
Click Next
WeareusingthePIC18F4685as
themicrocontrollerforthislab.
Select 8-bit MCUs (PIC18) from the Family pull down menu, then select
PIC18F4685 from the Device menu.
Figure1.2
SelecngtheMCUusedinaproject
Click Next
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Header Selection
Figure1.5
NamingaProject
Click Finish
Under Projects, right-click on Source Files and select New, then C
Source File
Click Finish
Figure1.6
RightclickingonSourceFilesto
createanewsourceleforthepro
ject
X project
We will now create a source code file to the project.
Itisnotnecessarytoaddlestoa
projectfolderbeforeadding
themtoaproject.Pungallthe
lesintotheprojectfoldercan
makebackingupaprojecteasy.
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Creating the main.c file
Figure1.7
Projectwindowaersourcelehas
beenaddedtoaproject
In the main.c file window, type the following as shown below, replacing the name and date
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Opening the editor
Lab1.c
Under the Projects folder, Double click on the Lab1.c file to open editor
Figure1.8
Lab1.csourceleposionedin
theeditorwindow
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Building the Project
Figure1.9
Aprojectoutputwindowaera
successfulbuildofaproject
Inserting an error into a project
Go to the line of code in the main function which includes TRISC =0x00;
Change TRIS to TRISCK and note the error indicator
Click Clean and Build Project
Change LATA to LOTTO
Click the Clean and Build Project icon to build the project
Lab01.c
Change TRISC to TRISCK
Figure1.10
Notetheexclamaonmark
showingthatthislabelisnot
recognized(unresolved)
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Figure1.11
Therstinstanceoftheerror
messagefortheunrecognized
wordTRISK
Double click on the blue error message
Notice the editor window goes to the line of code containing the error
Change TRSICK back to TRISC
Click the Clean and Build Project icon
Click on bracket beneath void main (void) to observe bracket matching
BracketMatchingisusefulinlin
ingupbracketstoavoiderrors
Note the yellow
highlighted
brackets
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Code Folding
Click on the - (minus) sign in the code window below the main () function
Observe that the functions hide from view for easier reading of the code
Codefoldingcanmakedebug
gingsessionseasier
Congratulations! You have finished creating a project!
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Connecting the hardware
Place the chip on the board
Connect VDD to +5V and VSS to ground (refer to Datasheet for pin numbers)
- shown in yellow
Place header pin set on board, and connect from header pins to the chip, per
datasheet pinout diagrams for the PIC18F4685 and the PICkit 2 (or 3) - shown
within blue
Notethatthetopandboom
+5Vandgroundrailsofthe
breadboardshouldbeconnected
together(asshownatleindia
gramabove)
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
Connecting the PICkit to the Chip
The PICkit programmer will be used to program the chip and run the file created earlier.
NotethearrowonthePICkit.This
indicatesPin1ontheprogrammer,
whichwillbeconnectedtotheVPP
pin(pin1)onthePIC18F4685chip.
Place the PICkit onto the header pins, ensuring that the arrow on the PICkit
(highlighted below) is connected, via the header pins, to pin 1 of the PIC
chip (refer to PIC18F4685 and PICkit 2 (or 3) pinout diagrams.
Place the USB connector of the PICkit into an available USB slot on the com-
puter
Making, Programming the chip, and Running the Program
After a successful build and hardware connection, Run the program by selecting Run from the menu at the top of the
window
YoucanusetheshortcutF6to
Runtheprogram.
Edited by Jude Pearse, UMaine, 1/22/14
2013 Microchip Technology Incorporated
The Programming target and Running target messages should appear in the Tasks
window:
Which output pin(s) should be at +5V?
Completing and Submitting Lab 1
1. Print the project and submit hardcopy on Monday, 1/27/14 at 11:00AM
2. At bottom of project submittal (or on back), answer any question(s) posed on the lab sheet, or in
lab.
Areasmarkedwiththeyellowques
onmarkshouldbeansweredaspart
ofthelabwriteup!
Have a lab instructor verify proper operation of the program and circuit