You are on page 1of 7

Opening & Programming Lesson 1 in MPLAB® IDE

Overview

PICkit™ 2 Starter Kit Getting Started

A subset of PICkit™ 2 supported PIC® Microcontroller devices may be programmed from directly within the MPLAB® IDE. For a list of devices supported directly, see the MPLAB® IDE Readme file for PICkit™ 2, found in C:\Program Files\Microchip\MPLAB
IDE\Readmes.

This document provides a guide to opening, assembling, and programming the first of the 12 PICkit 2 Lessons in the MPLAB IDE. The steps will also apply to working with the remaining lessons. The lessons themselves are an introduction to programming the PIC Microcontroller Midrange architecture and the lesson text can be found in the Low Pin Count Demo Board User’s Guide for the Starter Kit.
Opening Lesson 1 in MPLAB IDE 1. Ensure the appropriate lessons for the Low Pin Count Demo Board have been installed. The

default install directory is C:\Pk2 Lessons\LPC Demo Board for the Starter Kit. Note: MPLAB IDE has a limitation on path length to the assembly file. If the lessons are installed with a path longer than the default it may cause problems building in MPLAB IDE. 2. Connect the PICkit 2 Microcontroller Programmer to the PC with the included USB cable. Plug the 6-pin header on the demo board into the PICkit 2 ICSP™ connector.

3. Start MPLAB IDE.

© 2007 Microchip Technology Inc.

Page 1 of 7

asm) and the include file (. linker scripts. the active programmer and/or debugger. © 2007 Microchip Technology Inc. include files. “Hello World” and select the workspace file C:\Pk2 Lessons\LPC Demo Board\01 Hello World\Hello World. etc. select File > Open Workspace… A “workspace” contains information on the selected device (set by Configure > Select Device…). Page 2 of 7 . and only have two files: the assembly code file (. 4.mcw then click Open. The workspace is also associated with a “project”.) along with associated language (compiler) tools and build options. and other IDE configuration settings. which contains the files needed to build an application (source code. Browse into the folder for lesson 1.INC). open windows and their location. The lesson workspace should already be set up for the PIC MCU on the included demo board. The lesson projects use the MPASM™ assembler to build the assembly source code.PICkit™ 2 Starter Kit Getting Started (MPLAB) From the MPLAB IDE menu bar.

the project files are displayed in the Project Window. (Continued on next page…) © 2007 Microchip Technology Inc. On the right is the Output Window. including the MPASM assembler under the “Build” tab and the PICkit 2 under the “PICkit 2” tab (not yet shown). This window is shown below on the left. In the MPLAB IDE workspace. which displays the results from various associated tools. The project workspace is opened.PICkit™ 2 Starter Kit Getting Started (MPLAB) 5. Page 3 of 7 .

In the MPLAB IDE menu. and that the target microcontroller (in this case a PIC16F690 on the Low Pin Count Demo Board) was found. Page 4 of 7 . If the PICkit 2 or demo board was not plugged in.PICkit™ 2 Starter Kit Getting Started (MPLAB) Connecting to the PICkit 2 Microncontroller Programmer 1. connect them and select the MPLAB IDE menu Programmer > Connect to try connecting again.) The Output Window shows connection to the PICkit 2 Microcontroller Programmer. (It may already be selected in the workspace. select Programmer > Select Programmer > PICkit 2. 2. Select the PICkit 2 Microcontroller Programmer as the programming tool. © 2007 Microchip Technology Inc. reselecting it will not cause a problem.

Open the lesson assembly source code in an Editor by double-clicking on the file name Hello World. Page 5 of 7 .PICkit™ 2 Starter Kit Getting Started (MPLAB) Build and Program Lesson 1 in MPLAB IDE 1. © 2007 Microchip Technology Inc.asm in the Project Window. Project files may easily be opened this way into an editor from the Project Window.

The bits may also be examined and changed by selecting the menu item Configure > Configuration Bits… Note that each time the project is built. Build the project assembly code into a hex file by selecting menu Project > Build All. The results of the build will display in the Output Window under the “Build” tab. The lessons set the configuration bits in the assembly code using the assembler “__CONFIG” directive. If there are no errors it will display “BUILD SUCCEEDED” This creates a hex file in the project directory that contains the machine instructions for the assembled code.PICkit™ 2 Starter Kit Getting Started (MPLAB) 2. any changes to the configuration bits will be wiped out by the settings after the “__CONFIG” directive in the code. Page 6 of 7 . © 2007 Microchip Technology Inc. as well as the PIC Microcontroller configuration information.

it is recommended to go through the 12 lessons in the Low Pin Count Demo Board User’s Guide along with the PIC16F685/687/689/690 Data Sheet (DS41262). it would be necessary to select Programmer > Release from Reset before the programmed code would begin executing. the first LED on the demo board will light up. IMPORTANT: When programming through the MPLAB IDE and using the Low Pin Count Demo Board. To allow the button to be used. Chapter 2 of the Demo Board User’s Guide gives a brief overview of the Mid-range PIC microcontroller architecture. select Programmer > Program. Page 7 of 7 .microchip. select the “Settings” tab and check ‘3-State on “Release from Reset”’ & “Run after a successful program”. The assembled firmware is now ready to program into the PIC Microcontroller. which MPLAB IDE drives on the PICkit 2 ICSP header. The [Development Tools] – Programmers sub-forum is the best place for PICkit 2 related topics. Once programming is complete.PICkit™ 2 Starter Kit Getting Started (MPLAB) 3. see the MPLAB IDE Quick Start Guide included in the “Reference” section of the PICkit Starter Kit CD-ROM. To find out more about developing code in the MPLAB IDE. select Programmer > Settings. The PICkit 2 was already selected and connected to as the programmer in “Connecting to the PICkit 2 Microncontroller Programmer” Step 1. To program the demo board MCU. and the lessons are covered in Chapter 3. In the lesson code. the by default the Lessons will not recognize the demo board switch as it is connected to the digital input on the /MCLR pin. the PIC MCU configuration is set so the /MCLR pin is not active. In the dialog. The results of the programming operation will appear in the Output Window. The most recent version of this document is also available on the included MPLAB IDE CD-ROM. Microchip’s Online Discussion Groups at forum. © 2007 Microchip Technology Inc. For a MCU where /MCLR is active.com are a good place to ask questions and get information on developing with PIC MCUs. Next Steps Now that Lesson projects can be opened and programmed.