Академический Документы
Профессиональный Документы
Культура Документы
FOR ASSEMBLING
AND DEBUGGING
A PIC18F ASSEMBLY
LANGUAGE PROGRAM
USING THE MPLAB
Assembling PIC18F assembly language program using MPLAB
First, download the latest versions of the MPLAB assembler and C18 compiler from the
Microchip website www.microchip.com. After installing and downloading the program,
you will see the following icon on your desktop:
Double click (right) on the MPLAB icon and wait until you see the following screen:
407
408 Microcontroller Theory and Applications with the PIC18F
Next, click on ‘Project’ and then ‘Project Wizard’; the following screen will appear:
Appendix F: Tutorial 409
Select the device PIC18F4321, hit Next, and wait; the following will be displayed:
410 Microcontroller Theory and Applications with the PIC18F
In the ‘Active Toolsuite’, select ‘Microchip MPASM Toolsuite’, and click Next; the
following will be displayed:
Appendix F: Tutorial 411
Select a location where all project contents will be placed. For this example, the folder
will be placed on the desktop (arbitrarily chosen). Go to the desktop directory, make a new
folder, and name the folder. In order to do this, click on ‘Browse’, and select desktop:
412 Microcontroller Theory and Applications with the PIC18F
Next, create a new folder by clicking on the icon (second yellow icon from right on top
row) or by right clicking on the mouse on the above window; see the following screen:
Click on folder, name it ‘sum’ (arbitrarily chosen name), and see the following :
Next, type in a file name such as addition (arbitrarily chosen name), and see the following
on the screen:
414 Microcontroller Theory and Applications with the PIC18F
INCLUDE <P18F4321.INC>
SUM EQU 0x50
ORG 0x100
MOVLW 0x02
ADDLW 0x05
MOVWF SUM
HERE BRA HERE
END
Next, click on File, and Save as, and see the following:
Appendix F: Tutorial 419
Make sure you scroll up to desktop, and then click on sum (the folder that was created
before), and see the following:
420 Microcontroller Theory and Applications with the PIC18F
Next, double click (left) on sum to see the following:
Delete Untitled, and enter the same file name ‘addition’ with .asm extension as File name.
Click on save, and see the following screen shot (notice the display changes color):
Appendix F: Tutorial 421
Next, highlight by clicking on the top (blue) section of addition.asm.mcp, and see the
following:
422 Microcontroller Theory and Applications with the PIC18F
Right click on Source Files to see the following:
Note that addition.asm is listed under Source Files. Next, click on Project and then build
all (or only the ‘Build All’ icon, second icon on top right of the Debug toolbar), and see
the following:
This means that the assembling the program is successful. Next the result will be verified
using the debugger.
Click on Debugger, Select Tool, and then MPLAB SIM to see the following display:
Appendix F: Tutorial 427
On the Watch list, you can now include WREG and SUM to monitor their contents. For
example, to add WREG, scroll down to WREG by using the arrow beside ADCON0, and
then click on Add SFR to see the following display:
430 Microcontroller Theory and Applications with the PIC18F
Next, scroll down using arrow beside Add Symbol, select SUM, and then click on Add
Symbol to see the following display:
Appendix F: Tutorial 431
Note that SUM with address 0x50 along with contents is displayed.
In order to enter breakpoint for MOVLW 0x02, right click beside MOVLW to see:
Click on the reset (first icon from right on the Debug toolbar), move the cursor to left of
MOVLW 0x02, click on run (green arrow on left on the Debug toolbar) on Debug toolbar,
and see that WREG is loaded with 0x02:
434 Microcontroller Theory and Applications with the PIC18F
Next, click on run to execute ADDLW 0x05, and see that the result of addition0x07 is
loaded into WREG as follows:
Appendix F: Tutorial 435
Finally, click on Animate (double green arrow on the Debug tool) to execute MOVWF
SUM to see that the result 0x07 is stored in SUM (address 0x50) as follows: