0% found this document useful (0 votes)
2 views

Lab 2.1

Lab 2.1 provides a detailed guide on creating, editing, and building projects using MPLAB® X IDE. It includes step-by-step instructions for setting up a project, adding source files, and building the project, along with exercises for manipulating files and debugging code. The lab culminates in a simple program that demonstrates LED control using a PIC microcontroller.

Uploaded by

Raj Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab 2.1

Lab 2.1 provides a detailed guide on creating, editing, and building projects using MPLAB® X IDE. It includes step-by-step instructions for setting up a project, adding source files, and building the project, along with exercises for manipulating files and debugging code. The lab culminates in a simple program that demonstrates LED control using a PIC microcontroller.

Uploaded by

Raj Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ETEC202 - Lab 2.

1
Creating an MPLAB® X Project
Purpose
Lab 2.1 shows how to create, edit, and build projects with MPLAB® X

Tools
MPLAB® X IDE (v6.00)
MPLAB® XC16 (v1.7)

Objective
A step by step walk through MPLAB® X project development. An MPLAB® X project is
created and an existing C source file is then added to the project. The lab continues with the
editing of the source file and the successful build of a project. The lab includes exercises to
demonstrate some useful file and data manipulation features of MPLAB® X.
Procedure

✓ Open MPLAB® X.

✓ Close any open projects in MPLAB® X by right clicking on the Project name and selecting
“Close”.

1. Start Project Creation


✓ Click the “New Project” icon to start the project creation process

✓ Select “Microchip Embedded” then “Standalone Project”.

✓ Click Next
2. Select the Processor

✓ Select “16-bit MCUs (PIC24)” from the ‘Family’ pull down menu, then select
“PIC24FJ256GA705” from the ‘Device’ menu.

3. Select the Hardware

✓ Select “Simulator” under Hardware tools when asked to select a tool

✓ Click Next

4. Header Selection

Debug Headers are only required for some of the 8-bit controllers with very low pin counts. If
you are using a 16-bit, 32-bit or 8-bit with more than 14 pins a header may not be needed

✓ No header is needed; select “None” Click Next


5. Select the Compiler

✓ Open the XC16 plus box, if not already open, and select an installed version of the XC16
compiler.

✓ Click Next
6. Select Project Name and Folder

✓ Click the “Browse” button and navigate to the folder where you have saved the project
files.
✓ On the line marked “Project Name” type in Lab2.1.
✓ Notice MPLAB® X filling in the Project Folder line with the path to the project folder.

✓ Click “Finish”
7. Adding files to the project

✓ The file Lab02.1.c is in the folder but not in the project. MPLAB® X must be informed
to use the code generated by Lab02.1.c in the project. To do this we will ADD the file to
the project.

✓ Right click on the “Source Files” folder in the project window

✓ Select “Add Existing Item”


✓ Highlight the ‘Lab02.1’ file in the folder Lab2.1.X\

✓ Ensure the radio button labeled “Relative” in the lower right border of the dialog box is
checked

✓ Click “Select”

Project window after the Lab02.1.c source file has been added to the project file
8. Opening the editor

✓ Double click on the Lab02.1.c file to open editor

✓ Scroll down so the main() and delay() functions are visible in the editor window

This a very simple program designed to build confidence in your ability to build a project and
run it in MPLAB® X.

Upon exiting reset, the PIC clears PORTA, then configures PORTA pins 0:7 as outputs. It then
enters an infinite loop that outputs an alternating pattern to PORTA resulting in the effect of
blinking the eight LEDs connected to PORTA. The delay function between each toggle of the
LEDs is necessary since LEDs require several ms to turn on or off, whereas the PIC can toggle in
a few hundred ns.
9. Building the Project
Click the “Clean and Build Project” icon to build the project

Lab requirement: Submit a screen shot showing the successful build.

10. Inserting an error into a project

✓ Go to the line of code in the main() function which includes LATB = 0x0055;

✓ Insert an intentional error into the source code by changing LATB to LATBOO

✓ “Click Clean and Build Project”

✓ Double click on the FIRST error message


Notice the editor window goes to the line of code containing the error

✓ Change LATBOO back to LATB

✓ Click the “Clean and Build Project” icon

✓ Click on bracket beneath the while (1) loop to observe bracket matching. Note the yellow
highlighted brackets. Bracket Matching is useful in lining up brackets to avoid errors.
11. Code Folding

✓ Click on the - (minus) sign in the code window below the main () function or the delay()
function. Code folding can make debugging sessions easier

✓ Observe that the functions hide from view for easier reading of the code

You might also like