You are on page 1of 8

Opening Lesson 1 in MPLAB® IDE and programming with the PICkit™ 2 Microcontroller Programmer software

Overview

PICkit™ 2 Starter Kit Getting Started

This document provides a guide to opening, assembling, and programming the first of the 12 PICkit™ 2 Lessons. This edition covers programming the device using the PICkit 2 Microcontroller Programmer PC application. The steps will also apply to working with the remaining lessons. The lessons themselves are an introduction to programming the PIC® Microcontroller Mid-range architecture and the lesson text can be found in the Low Pin Count Demo Board User’s Guide for the Starter Kit.
Opening & Building 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 8

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

On the right is the Output Window. In the MPLAB IDE workspace. Select Programmer > Select Programmer > None from the MPLAB IDE menu bar. make sure the PICkit 2 is not selected as a programmer in the MPLAB IDE. including the MPASM assembler under the “Build” tab. The workspace and project are opened. the project files are displayed in the Project Window. which displays the results from various associated tools. Page 3 of 8 . Since the demo board PIC Microcontroller will be programmed with the PICkit 2 programming software and not MPLAB IDE. This window is shown below on the left.PICkit™ 2 Starter Kit Getting Started 6. 7. © 2007 Microchip Technology Inc.

Page 4 of 8 . © 2007 Microchip Technology Inc.PICkit™ 2 Starter Kit Getting Started 8.asm in the Project Window. Open the lesson assembly source code in an Editor by double-clicking on the file name Hello World. 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. Page 5 of 8 . © 2007 Microchip Technology Inc. The lessons set the configuration bits in the assembly code using the assembler “__CONFIG” directive. Build the project assembly code into a hex file by selecting menu Project > Build All. 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. The results of the build will display in the Output Window under the “Build” tab.PICkit™ 2 Starter Kit Getting Started 9. as well as the PIC Microcontroller configuration information. any changes to the configuration bits will be wiped out by the settings after the “__CONFIG” directive in the code.

The PICkit 2 Programmer application should detect the PICkit 2 Microcontroller Programmer and the PIC MCU on the demo board when started. Since the demo board is also connected. and try selecting from the menu bar Tools > Check Communication. select File > Import Hex. it displays “PIC Device found” as well and displays the PIC MCU part number PIC16F690 as shown below. 3. Open the PICkit 2 programming application. The assembled firmware is now ready to program into the PIC Microcontroller. Page 6 of 8 . 2. 1. It will indicated “PICkit 2 found and connected” in the Status Window as shown below.PICkit™ 2 Starter Kit Getting Started Programming the Assembled Code with the PICkit 2 Programmer. This will look for the both the PICkit 2 Microcontroller Programmer and a connected device. © 2007 Microchip Technology Inc. see the Troubleshooting chapter of the PICkit 2 Microcontroller Programmer User’s Guide. To import the assembled hex file to program into the PIC16F690 MCU on the demo board. If the PICkit 2 and demo board are both connected but not found.

To program the loaded hex file into the demo board PIC16F690. Page 7 of 8 . 5. Browse into the folder for lesson 1. Alternatively.PICkit™ 2 Starter Kit Getting Started 4. the Write button on the GUI may be clicked. © 2007 Microchip Technology Inc. select menu Programmer > Write Device.HEX then click Open. “Hello World” and select the hex file C:\Pk2 Lessons\LPC Demo Board \1 Hello World\Hello World.

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). and the lessons are covered in Chapter 3. Next Steps Now that Lesson projects can be opened and programmed. The guide is also available in the “User’s Guides” section of the PICkit Starter Kit CD-ROM To find out more about developing code in the MPLAB IDE. see the PICkit 2 Microcontroller Programmer User’s Guide by selecting Help > PICkit 2 User’s Guide from the PICkit 2 Programmer software application. For more information on using the PICkit 2 Programmer software. © 2007 Microchip Technology Inc.microchip. To see the code execute and turn on the first LED. consult the Troubleshooting chapter of the PICkit 2 Microcontroller Programmer User’s Guide. The Status Window will show “Programming Successful” if the device was properly programmed. The [Development Tools] – Programmers sub-forum is the best place for PICkit 2 related topics. The most recent version of this document is also available on the included MPLAB IDE CD-ROM. Select the VDD PICkit 2 “On” checkbox. If there was a programming error. see the MPLAB® IDE Quick Start Guide included in the “Reference” section of the PICkit Starter Kit CD-ROM. power needs to be applied to the demo board from the PICkit 2 Microcontroller Programmer. Page 8 of 8 .com are a good place to ask questions and get information on developing with PIC MCUs. Chapter 2 of the Demo Board User’s Guide gives a brief overview of the Mid-range PIC microcontroller architecture. Microchip’s Online Discussion Groups at forum.PICkit™ 2 Starter Kit Getting Started 6. 7.