0% found this document useful (0 votes)
293 views24 pages

A-Preparing: Our First Program On Mplab

This document provides instructions for creating and running a simple assembly language program using the MPLAB integrated development environment. It describes: 1) Installing and configuring MPLAB to use the PIC16F877A microcontroller. 2) Creating a new assembly file called lab1.asm that adds 4 and 5 and stores the result in memory location 0x25. 3) Compiling and running the program, then modifying it to add 7 + 4 + 8 and perform other basic arithmetic operations, storing results in various memory locations and ports.

Uploaded by

Iman Haidar
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)
293 views24 pages

A-Preparing: Our First Program On Mplab

This document provides instructions for creating and running a simple assembly language program using the MPLAB integrated development environment. It describes: 1) Installing and configuring MPLAB to use the PIC16F877A microcontroller. 2) Creating a new assembly file called lab1.asm that adds 4 and 5 and stores the result in memory location 0x25. 3) Compiling and running the program, then modifying it to add 7 + 4 + 8 and perform other basic arithmetic operations, storing results in various memory locations and ports.

Uploaded by

Iman Haidar
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/ 24

Microlab File 1 – by Joseph Massoud

OUR FIRST PROGRAM ON MPLAB

A- Preparing

1- Install MPLAB 8.9x ( it will show the icon on Desktop)

2- Create a folder in drive C on your computer and name it “microlab”

3- Open MPLAB by double clicking on the icon on the desktop

4- Press “configure” / “select device”

Then choose “PIC16877A” from the list / “OK”

1
Microlab File 1 – by Joseph Massoud

B- Creating a new file

5- Press “File” / “new”:

An untitled new window will open

2
Microlab File 1 – by Joseph Massoud

6- Save as name.asm:
 Press “Save as” and go to microlab folder;
 Write: lab1.asm in the file name (the extension .asm is obligatory).
 Press “save”

It will drive you back to the main page.

3
Microlab File 1 – by Joseph Massoud

7- You can maximize the window of lab1

So you can get the full screen

4
Microlab File 1 – by Joseph Massoud

C- Editing the program ( in this example we will copy paste)


8- Lab1 is a simple addition : it adds 4 + 5 and store the result in memory
location H’25’ (= 0x25) which is an address of the RAM of the PIC.

WE OPEN THE FILE LAB1

COPY THE FULL PROGRAM

AND PASTE IT ON MPLAB PROGRAM PAGE

5
Microlab File 1 – by Joseph Massoud

We should get the following screen (program in colored sections);


The green parts are comments (for us to read) and are not used by the compiler.

9- Save the program ( using “file”/ “save”)

6
Microlab File 1 – by Joseph Massoud

D- Compiling ( Build)

10- Build the program (compiling) using : “project”/ “Quickbuild”

11- You should get “Build succeeded”.


So you close the window.

And you return to the main page

7
Microlab File 1 – by Joseph Massoud

E- Changing the size of instructions

12- You can at anytime change the size of the instructions (for a clearer vision); the
size comes 8 by default; We recommend to make it 12 using : “edit”/”properties

Then “text”/”select font” /”size” / “ok”

8
Microlab File 1 – by Joseph Massoud

F- Additional processes:

13- Correcting syntax errors during building

 Let us assume we have some syntax (typing) errors in our program. This will
result in build failed instead of build succeeded.

 We will assume the following errors in our program ( create these errors on
your code)

Error1:
BSF STATUS, RPO instead of BSF STATUS, RP0 (using letter O instead
digit 0 )

Error 2:
MOVWF PORT D instead of MOVWF PORTD (using a space between
PORT and D)

9
Microlab File 1 – by Joseph Massoud

 We make the “Quickbuild” and we obtain :

 After we press on the first error line the system goes to main page and points to
the line of error:

10
Microlab File 1 – by Joseph Massoud

 We correct the first error (replacing RPO by RP0) , press “Quickbuild” again, and
we obtain:

 We repeat the same process for the next error (double clicking the second line of
error) :

11
Microlab File 1 – by Joseph Massoud

 It will take us to the main program pointing to the line of error

 We correct the error (PORTD as one word) and press “Quickbuild” again.

 We should have build succeeded :

12
Microlab File 1 – by Joseph Massoud

14- Closing and Reopening files

 To close MPLAB we press the red X on the top right. (Note: if we are asked to
save we choose yes).

 Reopen Mplab using the icon on desktop

 “File” / “open”

13
Microlab File 1 – by Joseph Massoud

 We select lab1 ( or lab1.asm if it appears ) and press open

 We have our file again

14
Microlab File 1 – by Joseph Massoud

G- Important theoretical notes and supporting appendix

15- Pin diagram of PIC16F877A:

15
Microlab File 1 – by Joseph Massoud

16- Memory map of PIC16F877A:

 The figure below represents memory organization of the PIC (register file map)

Datasheet page 15

16
Microlab File 1 – by Joseph Massoud

17- Status register:

 To move to Bank1 we put 1 in bit RP0 (bit5) in register Status ; To move to


Bank0 we put 0 in RP0 ; that is why we started the configuration of the program
by BSF status,RP0 (bank1) than we finished configuration by BCF status,RP0
(Bank0)

Datasheet page 19

17
Microlab File 1 – by Joseph Massoud

18- List of Instructions :

18
Microlab File 1 – by Joseph Massoud

19- Description of the instructions :

19
Microlab File 1 – by Joseph Massoud

20
Microlab File 1 – by Joseph Massoud

21
Microlab File 1 – by Joseph Massoud

22
Microlab File 1 – by Joseph Massoud

23
Microlab File 1 – by Joseph Massoud

H – Assignment 1 : ( USE CAPITAL LETTER ALL THE TIME )


20- Basic arithmetic operations:

a) Read and analyze very carefully the previous program

b) * Create a new black file and save it as lab11.asm ;

* Rewrite yourself the same program of lab1 (without


necessarily comment in green);
Be sure that INCLUDE "P16F877A.INC"
and ORG 0x00 are correctly typed.

* Make the quick build and correct yourself If any errors

c) Create a new file : lab12.asm and Write a program which


makes: 7+ 4 + 8 and save results on PORTD and in memory
location H’26’ ( instead of address H’25’).Quickbuild and
correct errors if any.

d) Create a new file lab13.asm and write a program which


makes: 9-2 and save results on PORTD and in memory location
H’27’. Quickbuild and correct errors if any.

Hint: in question (d )we use instruction SUBLW which executes L - W ( not W- L).
So this instruction handles numbers oppositely; Therefore we should load first the
number 2 to W and then write sublw with 9, in order to have 9-2

e) Create a new file : lab14.asm and Write a program which makes:


C-8+7 and save results on PORTD and in memory location H’28’
( instead of address H’25’).Quickbuild and correct errors if any.

END of file 1

24

You might also like