micro controller theory pic18f appendix f final 1-4-11

Upload: jorge-ruballos

Post on 07-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    1/30

    407

    APPENDIX F: TUTORIAL

    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:

    MPLAB IDE v8.50.lnk

    Double click (right) on the MPLAB icon and wait until you see the following screen:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    2/30

    408 MicrocontrollerTheoryandApplicationswiththePIC18F

    Next, click on Project and then Project Wizard; the following screen will appear:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    3/30

    AppendixF:Tutorial 409

    Click Next; the following screen shot will be displayed:

    Select the device PIC18F4321, hit Next, and wait; the following will be displayed:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    4/30

    410 MicrocontrollerTheoryandApplicationswiththePIC18F

    In the Active Toolsuite, select Microchip MPASM Toolsuite, and click Next; thefollowing will be displayed:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    5/30

    AppendixF:Tutorial 411

    Select a location where all project contents will be placed. For this example, the folderwill 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:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    6/30

    412 MicrocontrollerTheoryandApplicationswiththePIC18F

    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:

    Next, click on New to see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    7/30

    AppendixF:Tutorial 413

    Click on folder, name it sum (arbitrarily chosen name), and see the following :

    Next, type in a le name such as addition (arbitrarily chosen name), and see the followingon the screen:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    8/30

    414 MicrocontrollerTheoryandApplicationswiththePIC18F

    Next, click on Save; the following screen will appear:

    Click on Next, and see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    9/30

    AppendixF:Tutorial 415

    Click on Next, and see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    10/30

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    11/30

    AppendixF:Tutorial 417

    Click on File, and then New to see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    12/30

    418 MicrocontrollerTheoryandApplicationswiththePIC18F

    Type in the program you want to assemble. The following addition program is entered:

    INCLUDE

    SUM EQU 0x50

    ORG 0x100MOVLW 0x02

    ADDLW 0x05

    MOVWF SUM

    HERE BRA HERE

    END

    After entering the program, see the following:

    Next, click on File, and Save as, and see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    13/30

    AppendixF:Tutorial 419

    Make sure you scroll up to desktop, and then click on sum (the folder that was created

    before), and see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    14/30

    420 MicrocontrollerTheoryandApplicationswiththePIC18F

    Next, double click (left) on sum to see the following:

    Delete Untitled, and enter the same le name addition with .asm extension as File name.Click on save, and see the following screen shot (notice the display changes color):

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    15/30

    AppendixF:Tutorial 421

    Next, highlight by clicking on the top (blue) section of addition.asm.mcp, and see the

    following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    16/30

    422 MicrocontrollerTheoryandApplicationswiththePIC18F

    Right click on Source Files to see the following:

    Click on Add les to see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    17/30

    AppendixF:Tutorial 423

    Click on addition.asm to see the following screen shot:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    18/30

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    19/30

    AppendixF:Tutorial 425

    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 seethe following:

    Next, click on Absolute to see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    20/30

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    21/30

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    22/30

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    23/30

    AppendixF:Tutorial 429

    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:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    24/30

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    25/30

    AppendixF: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 set breakpoint to see the following:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    26/30

    432 MicrocontrollerTheoryandApplicationswiththePIC18F

    B in red means breakpoint is inserted for MOVLW0x02. Similarly, breakpoints for

    ADDLW 0x05 and MOVWF SUM can be inserted, and the following will be displayed:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    27/30

    AppendixF:Tutorial 433

    Next, locate the Debug Toolbar. If, for some reason, Debug toolbar is missing, go to view,

    select Toolbars, click on Debug, and see the following:

    Click on the reset (rst icon from right on the Debug toolbar), move the cursor to left ofMOVLW 0x02, click on run (green arrow on left on the Debug toolbar) on Debug toolbar,

    and see that WREG is loaded with 0x02:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    28/30

    434 MicrocontrollerTheoryandApplicationswiththePIC18F

    Next, click on run to execute ADDLW 0x05, and see that the result of addition0x07 is

    loaded into WREG as follows:

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    29/30

    AppendixF: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:

    The debugging is now complete.

  • 8/6/2019 Micro Controller Theory PIC18F Appendix F Final 1-4-11

    30/30

    436 MicrocontrollerTheoryandApplicationswiththePIC18F