Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Experiment 1 . Introduction In this experiment, you are expected to create a project, compile and simulate it in MPLAB for PIC 1 8 F

Experiment 1. Introduction
In this experiment, you are expected to create a project, compile and simulate it in MPLAB for
PIC18F1220 Microcontroller. You need to use the same process in all future labs so it is important to
gain a solid understanding of the process and MPLAB.
Step I. Create a Project
1) Start MPLAB
2) Select menu File>New Project; in the pop up window :
* Select Categories "Microchip Embedded" and Projects "Standalone Project", Click Next
* Select Advanced 8-bit MCUs from Family list and "PIC18F1220." from Device list, Click
Next
* Click Next
* Select Simulator from the Tools Menu, Click Next
* Select mpasm(v5.82)[C:\P... from the Compile Toolchains, Click Next
* Enter Project Name, Location and folder, check Set as main project, click Finish
Note: It is recommended that you create a new project directory for each new lab experiment to
avoid the most common problem of including old files in new projects.
Step II. Add a Source File
1) Once project is created, new window pops up, on the upper left sub-window right-click on Source
Files under your project name and select New > AssemblyFile.asm.
Note: If AssemblyFile.asm is not found then click on Other, in the pop up window, click on
assembler under categories and then select AssemblyFile.asm under file types. 2) Enter a "File Name" of your choice. main.asm is always a good choice, but you can choose
something more descriptive if you like. Don't enter anything in the Folder: area. You should see a
full path under "Created File:" which should end with "\main.asm", Click "Finish"
Computer Organization and Microprocessors (ENGR 270), Version 2.5 Page 3
www.EngrCS.com
Note: On the upper-middle/right side of the window should be a tab labeled "main.asm" This is
where you'll enter your program's source code.
3) Copy the following code into the main.asm file created in the last step. Save your using menu
File>Save".
Note: All instruction must be indented. Labels and #define must start on column 1. You can indent
entire sections of text by selecting the text and hitting Tab key. 4) Enable Absolute Addressing
* Right click on the project name and select Properties
Computer Organization and Microprocessors (ENGR 270), Version 2.5 Page 4
www.EngrCS.com
* Click on mpasm (Global Options)
* Click on Unlock if not grayed out
* Click the checkbox for "Build in absolute mode"
* Click OK
Step III. Assembling a Project
1) Select menu Production>Build Main Project to assemble the code.
Notes:
*All instruction must be indented. Labels and #define must start on column 1. You can indent entire
sections of text by selecting the text and hitting Tab key.
* Select Absolute if prompted with Absolute or Relocatable code dialog box.
* The lower-right window should have a tab labeled "Output - Lab1(Build, Load)" and the bottom of
that window should include the messages "BUILD SUCCESSFUL" and "Loading Complete." Any
messages in red indicate an error and messages in blue are warning. Both have to be investigated
and corrected before a successful assembly.
2) Disassembly listing can be generated by selecting menu item
Window>Debugging>Output>Disassembly Listing File
Note: This step is only required for the report. If the menu is grayed out (not available) then rightclick on the project name and select properties. In the property window, select Loading, check
Load symbols... and Click on Apply. After the change, you need to redo step 1 to generate the
disassembled listing.
Step IV. Initializing Simulator and Debugger
Use the simulation feature of MPLAB to test the functionality of your Project by following the steps
shown:
1) In your source code listing, click on the line number next to the code line that says
"CLRF PORTA ; Initialize PORTA"
The entire line should turn red. This indicates that you've created a breakpoint at that line. Each time
the simulator is about to execute a line with a breakpoint, the simulator will pause and return control
to you.
2) Select menu "Debug>New Watch..." and under "Enter or Select Watch Expression" enter PORTA
and click OK (remember that names like "PORTA" are case-sensitive: "PORTA" is different from "PortA"). Repeat this step for PORTB and WREG.
3) Select menu Window>Simulator>Stimulus" You'll see a new tab labeled "Stimulus." Click on the
area beneath "Pin" and select RA0(which specifies bit 0 of PORTA). Click on the box under Action
and select "Toggle."
Note: Toggle means invert the value from 0 to 1 and from 1 to 0.
Computer Organization and Microprocessors (ENGR 270), Version 2.5 Page 5
www.EngrCS.com
4) Select Debug>Debug Main Project." Your main dialog box should now say something like:
i) Launching
ii) Initializing simulator
iii) User program running
iv) User program stopped
v) Breakpoint hit at line 21 in file ...
Step V. Simulation and Debugging
1) In addition to Special Function Registers, you can watch General Function Registers such as location
0x80.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

What are the APPROACHES TO HRM?

Answered: 1 week ago

Question

Choosing Your Topic Researching the Topic

Answered: 1 week ago

Question

The Power of Public Speaking Clarifying the

Answered: 1 week ago