1 in the projects tab of mplab x right click on the

This preview shows page 3 - 7 out of 18 pages.

1.) In the “Projects” tab of MPLAB X, right-click on the “Source Files” directory and select “New” → “AssemblyFile.s” Careful! There are three options that look similar. Page 3
EE 2361 - Lab # 2a ECE Department Creating a new Assembly Language File in MPLAB X 2.) Give the file a name like, “orser_lab1_core_v001”, leave Project, folder, and Create File alone. Make the name unique, as it gets confusing if there are three files open called “main.s” 3.) In some versions of MPLABX, this doesn’t add the new file to your project! It just creates an empty file and opens the file for editing. To add the file to your project: Right-click “Source Files”, select “Add Existing Item…”, click on your new file and click “Select”. It should appear in your Project under the “Source Files” heading (or complain that the file is already part of the project, in which case no harm is done). Page 4
EE 2361 - Lab # 2a ECE Department 4.) In the editor enter the following “boilerplate” text into your new source file: .include "xc.inc" ; required "boiler-plate" (BP) ;the next two lines set up the actual chip for operation - required config __CONFIG2, POSCMOD_EC & I2C1SEL_SEC & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSECME & FNOSC_FRCPLL & SOSCSEL_LPSOSC & WUTSEL_FST & IESO_OFF config __CONFIG1, WDTPS_PS1 & FWPSA_PR32 & WINDIS_OFF & FWDTEN_OFF & BKBUG_ON & GWRP_ON & GCP_ON & JTAGEN_OFF .bss ; put the following labels in RAM counter: .space 2 ; a variable that takes two bytes (we won’t use ; it for now, but put here to make this a generic ; template to be used later). stack: .space 32 ; this will be our stack area, needed for func calls .text ; BP (put the following data in ROM(program memory)) ;because we are using the C compiler to assemble our code, we need a "_main" label ;somewhere. (There's a link step that looks for it.) .global _main ;BP _main: bclr CLKDIV,#8 ;BP nop ;; --- Begin your program below here --- Code Example X: Boilerplate for ASM-only projects This boilerplate contains all the same functionality as our c-code boilerplate. There are calls to supporting library definitions with .include() and #include statements. You can see the flash configuration word declarations (__CONFIG1 and __CONFIG2). And the Clock Divider setting of 1:1 for full 16 MIPS operation (bclr CLKDIV,#8). Turn on RA0 In this part of the lab we will prepare a simple assembly program that turns on the RA0 pin. This will demonstrate some basic structures of assembly code. 1.) Just like the C-program we need to add code that configures LATA, TRISA, and AD1PCFG registers. Remember, you can’t load an immediate directly into a general file register (generic memory location): you must first use a special function register as a middle-man. 2.) Just for the sake of clarity, let us go look at how the C-program compiles the first few lines of Lab 1. a.) If you see the Lab1 Project on the left pane, under “Projects”, Right-Click on the Lab1 Project, and click “Set as Main”. Otherwise, just use File > Open Project to open it. You will later go back to your assembly project. b.) Right-Click on Lab 1 project, click Properties, select Simulator as the target Page 5
EE 2361 - Lab # 2a ECE Department c.)

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture