0% found this document useful (0 votes)
10 views10 pages

2023 Fall Microcomputer Laboratory Exp 1

Uploaded by

erengoculu
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)
10 views10 pages

2023 Fall Microcomputer Laboratory Exp 1

Uploaded by

erengoculu
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/ 10

Microcomputer

Laboratory
Experiment # 1 MPLAB X
IDE & Simulator

2023 Fall
OBJECTIVE
The objective of this experiment is to practice and verify the basics of building project
on MPLAB X IDE v5.00 The following chapter will cover required information about MPLAB X
IDE v5.00 .

PROCEDURE
Creating A Project

1. Create a new project using File -> New Project and select Microchip Embedded –
Standalone Project , as shown in New Project window. Then click next button. Select
Device window will appear.

2. Choose Mid range 8-bit MCUs in family section and select PIC16F877A in device
section. Then click next button. Select Tool window will appear.
3. Through this lab two options will be used; Simulator and PICkit2. In simulator mode,
registers’ content can be viewed in binary, hexadecimal and decimal types. It’s useful
to work on simulator first. In PICkit2 mode, in circuit debugging can be used on training
kits. For this experiment choose simulator. Then click next button. Select Compiler
window will appear.
4. Although, different compilers can be installed, in this course default compiler mpasm
will be used. Choose mpasm and click next button to proceed. Select Project Name
and Folder window will appear.

5. Write a valid project name i.e. “Experiment_1” and choose “D:” drive for project
location. Then click finish button.
6. Create a new file by right clicking Source Files on the project window and left click on
New and then Other. New File window will appear.

7. Choose Assembler and AssemblyFile.asm then click next. In the next window write a
valid name for assembly file then click finish button. Process of creating a new project
is completed.
Assembly Code

Copy this code into the created assembly file and compile it (you should see Build
Successful prompt).

LIST p=16f877a ;PIC16F877 device is selected.

INCLUDE "p16f877a.inc" ;assume this line as adding library of MCU.


__CONFIG h'3F31' ;configuration bits are assigned.

sayi1 equ 0x20 ;registers (sayi1, sayi2, sayi3) are defined


sayi2 equ 0x21 ;and their addresses equal to (0x20, 0x21,
sayi3 equ 0xA0 ;0xA0) respectively.

org 0x00 ;this line indicates the starting point


;of the code.
movlw b'00000000' ;number 0x00 is moved into the working register.
movwf STATUS ;content of the working register is transferred
;into the STATUS register. This way, bank0 is
;selected.

banksel sayi1 ;bank of sayi1 is selected.


clrf sayi1 ;content of sayi1 is cleared.
clrf sayi2 ;content of sayi2 is cleared.
clrf PORTD ;content of PORTD is cleared.
movlw b'10001000' ;number 0x88 is moved into the working register.
movwf sayi1 ;content of the working register is transferred
;into the sayi1. content of sayi1 is 0x88 now.
movlw h'8F'
movwf sayi2 ;content of sayi2 is 0x8F now.
addwf sayi1,W ;sayi1 is added to working register.
;(h'88'+h'8F') result of the addition is
;transfered into working register.

banksel sayi3 ;bank of sayi3 is selected.


clrf sayi3 ;content of sayi3 is cleared.
movwf sayi3 ;content of working register is transferred
;into sayi3. Sayi3 is equal to result now.

banksel TRISD
clrf TRISD ;content of TRISD is cleared. Pins of PORTD
;register are selected as output.
banksel sayi3
movf sayi3,W ;content of sayi3 is transferred into
;working register.

banksel PORTD
clrf PORTD
movwf PORTD ;PORTD is equal to result of the addition.
end ;with this line program ends.

Compile & Simulation

1. Compile the assembly code by clicking hammer & broom symbol. If there isn’t any
syntax error, “BUILD SUCCESSFUL” prompt will be appeared.

2. Click Debug Main Project button to start simulation. Simulation will be on running
mode.

3. Pause the simulation with pause button and then click reset button to start
the code from the beginning. Simulation can be run, step by step with step into button

.
4. Content of the registers can be viewed on Variables tab by creating watches. Add new
watches by clicking Create New Watch button . New Watch window will be
appeared.

5. The registers defined by the user can be added by using their addresses, i.e. sayi1 is
added.

6. Special function registers can be added by selecting SFR’s, i.e. PORTD is added.
7. In the end of the program, contents of the registers are shown in the figure below.

8. Simulation can be stopped with Finish Debugger Session button .

Changing Project Tool

Project tool can be changed by using Run -> Set Project Configuration -> Customize
selection. After this selection choose hardware tool as PICkit2. Now experiment set can be
used with MPLAB X IDE.

Stimulus

1. Input signals can be stimulated in the simulator by using Window -> Simulator ->
Stimulus. Stimulus tab will be appeared below editor page.
2. Add clock stimulus in clock stimulus tab by using add a row button. Choose desired
pin and other properties. In debugging mode apply stimulus with apply synchronous
stimulus button.

You might also like