Sunday, April 12, 2009

Learn PIC Assembly Language Part - 3

MPLAB Setup for building the project

This section will teach you how to configure MPLAB IDE for building an assembly language program. Install MPLAB IDE in C:\Program Files. After installing MPLAB IDE , you can see the MPLAB IDE icon on the desktop. All the installed files will be found in the folder ‘Microchip’ in the directory C:\Program Files. You can download MPLAB IDE for free from microchip website. Various versions are avilable. For example MPLAB IDE v 7.50 , MPLAB IDE v 8.0 and MPLAB IDE 8.2 etc. I am explaining here MPLAB IDE v 7.50 .

For opening MPLAB IDE, click the MPLAB IDE desktop icon or from Programs -> Microchip -> MPLAB IDE.

On clicking MPLAB IDE, the IDE will be opened with two windows named ‘Untitled Workspace’ and ‘Output’. Then to start an new project, choose ‘Project Wizard’ and then click ‘Next’. Now you can see one pop up menu appearing, which will help you to complete project set up.

Step 1: Select 18F452 from the device drop down list and click ‘Next’.

Step 2: From the active tool suite, choose ‘Microchip MPASM Tool Suite ‘. Then Select the ‘Tool Suite Content’ and their location and click ‘Next’.

The default locations of the Tool Suite Contents are as follows:

MPASM Assembler (mpasmwin.exe) – C:\Program Files\Microchip\MPASM Suite\MPASWIN.exe

MPLINK Object Linker (mplink.exe) - C:\Program Files\Microchip\MPASM Suite\mplink.exe

MPLIB Librarian (mplib.exe) - C:\Program Files\Microchip\MPASM Suite\mplib.exe

There are default locations provided you have installed MPLAB IDE in C:\Program Files

Step 3: Then Enter the project name ( Eg. PicProject) you want, and make a project directory. Lets the project directory be C:\PIC Tutorials. Your source codes and other project specific files will be stored in this directory.

Step 4: You can add anu existing files to your project. Since you are starting your project for the first time, there may not exist previous files, so dont add anything. Simply skip and click ‘Next’.
After clicking ‘Next’ , you can see summary with project parameters.

Device : PIC18F452

Tool Suite : Microchip MPASM Tool Suite

File : Your choosen location. Eg: C:\PIC Tutorials

Then click ‘Finish’.

Now a project window appears on the top left by the name PicProject.mcp. Now the project set up is halfway done.

Now you need to write your program. For that go to ‘Files’ and clcick ‘New’. Now an untitled blank window will appear with the cursor blinking.Type your program there. Type this sample program there. Dont worry about the mnemonics and language syntax. I will expalin those programs in my next session.

Assembly Language program 1:

list p = 18F452

#include < P18F452.INC >

org 00000 H

goto Start

org 0002A H

Start : MOVLW 0x02

MOVWF 0x01,0

MOVLW 0x03

ADDWF 0x01,0,0

MOVWF 0x01,0

end

Please dont worry about the program logic or the mnemonics. I will expalin it later in my next session. At present my aim is to give you an overview about MPLAB Project set up.

After typing the program save your file ( Give one name program1.asm) in the project directory C:\PIC Tutorials. Now you have saved your file. Your assembly code will appear in different colours according to the syntax.
Your next task is to Add this source code file program1.asm to the project PicProject.mcp.

For that click project window PicProject.mcp. Down the PicProject.mcp, you have to right click the ‘Source File’ and click ‘Add Files’. Then go to your project directory and choose the file program1.asm and click open. Now you can see program1.asm added below the ‘Source File ‘ directory.

The next step is to add device specific .INC file to the project. Then right click on ‘Header Files’ and then go to the directory where MPLAB IDE is installed (C:\Program Files\Microchip ) . Then click MPASM Suite. Now click the .INC file of 18F452 and click open. In this folder you can find the device specific .INC files of all other PIC microcontrollers. Now you can see P18F452.INC added under the ‘Header File’ section.

Since in this project, you are not using multiple source files, there exist no need to add linker scripts. Also you are not using the library now. So dont touch these sections now. Leave it as such it is.

Now your project is ready. Go to ‘Project’ and click ‘Build All’ option or click the ‘Build All’ icon. Now you can see ‘Output Window’ . In the ‘Output Window’ under the ‘Build’ section,you can see the process of building, result, warning, errors etc.
On ‘Build All’ you can see a green status bar saying ASSEMBLY SUCCEEDED or otherwise in red with ASSEMBLY FAILED.

Some warning will be given in the output window like..

1. Found Directive in column 1

2. Found OPCODE in column 1

3. Found Label after column 1

The general thumb rule is that

1. All labels should be in column 1

2. All directives and OPCODES should be in column 2 ( After a TAB )

Now it will show BUILD SUCCEEDED with date and time.

Now you have studied how to build a project.

My next section will explain you about how to use a simulator to see the output without using the actual hardware or programmer or the PIC Microcontroller. Before that you need to study the PIC Assembly Language Program.

A couple of my next sessions will teach you assembly language programming. Once after that I will explain you how to use MPLAB Simulator, MPLAB SIM to see the output. After completing this step, we can move to actual hardware and microcontroller set up. Till that time, please concentrate on my assembly language programs.

No comments: