Sunteți pe pagina 1din 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 Users 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

PICkit 2 Starter Kit Getting Started

4. From the MPLAB IDE menu bar, select File > Open

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

2007 Microchip Technology Inc.

Page 2 of 8

PICkit 2 Starter Kit Getting Started

6. The workspace and project are opened. In the MPLAB IDE workspace, the project files are displayed in the Project Window. This window is shown below on the left. On the right is the Output Window, which displays the results from various associated tools, including the MPASM assembler under the Build tab.

7. Since the demo board PIC Microcontroller will be programmed with the PICkit 2 programming software and not MPLAB IDE, make sure the PICkit 2 is not selected as a programmer in the MPLAB IDE. Select Programmer > Select Programmer > None from the MPLAB IDE menu bar.

2007 Microchip Technology Inc.

Page 3 of 8

PICkit 2 Starter Kit Getting Started

8. Open the lesson assembly source code in an Editor by double-clicking on the file name Hello World.asm in the Project Window. Project files may easily be opened this way into an editor from the Project Window.

2007 Microchip Technology Inc.

Page 4 of 8

PICkit 2 Starter Kit Getting Started

9. 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. 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, as well as the PIC Microcontroller configuration information. The lessons set the configuration bits in the assembly code using the assembler __CONFIG directive. The bits may also be examined and changed by selecting the menu item Configure > Configuration Bits Note that each time the project is built, any changes to the configuration bits will be wiped out by the settings after the __CONFIG directive in the code.

2007 Microchip Technology Inc.

Page 5 of 8

PICkit 2 Starter Kit Getting Started

Programming the Assembled Code with the PICkit 2 Programmer.

1. The assembled firmware is now ready to program into the PIC Microcontroller. Open the PICkit 2 programming application.

2. The PICkit 2 Programmer application should detect the PICkit 2 Microcontroller Programmer and the PIC MCU on the demo board when started. It will indicated PICkit 2 found and connected in the Status Window as shown below. Since the demo board is also connected, it displays PIC Device found as well and displays the PIC MCU part number PIC16F690 as shown below.

If the PICkit 2 and demo board are both connected but not found, see the Troubleshooting chapter of the PICkit 2 Microcontroller Programmer Users Guide, and try selecting from the menu bar Tools > Check Communication. This will look for the both the PICkit 2 Microcontroller Programmer and a connected device.

3. To import the assembled hex file to program into the PIC16F690 MCU on the demo board, select File > Import Hex.

2007 Microchip Technology Inc.

Page 6 of 8

PICkit 2 Starter Kit Getting Started

4. Browse into the folder for lesson 1, Hello World and select the hex file C:\Pk2 Lessons\LPC Demo Board \1 Hello World\Hello World.HEX then click Open.

5. To program the loaded hex file into the demo board PIC16F690, select menu Programmer > Write Device. Alternatively, the Write button on the GUI may be clicked.

2007 Microchip Technology Inc.

Page 7 of 8

PICkit 2 Starter Kit Getting Started

6. The Status Window will show Programming Successful if the device was properly programmed. If there was a programming error, consult the Troubleshooting chapter of the PICkit 2 Microcontroller Programmer Users Guide.

7. To see the code execute and turn on the first LED, power needs to be applied to the demo board from the PICkit 2 Microcontroller Programmer. Select the VDD PICkit 2 On checkbox.

Next Steps

Now that Lesson projects can be opened and programmed, it is recommended to go through the 12 lessons in the Low Pin Count Demo Board Users Guide along with the PIC16F685/687/689/690 Data Sheet (DS41262). Chapter 2 of the Demo Board Users Guide gives a brief overview of the Mid-range PIC microcontroller architecture, and the lessons are covered in Chapter 3. For more information on using the PICkit 2 Programmer software, see the PICkit 2 Microcontroller Programmer Users Guide by selecting Help > PICkit 2 Users Guide from the PICkit 2 Programmer software application. The guide is also available in the Users Guides section of the PICkit Starter Kit CD-ROM To find out more about developing code in the MPLAB IDE, see the MPLAB IDE Quick Start Guide included in the Reference section of the PICkit Starter Kit CD-ROM. The most recent version of this document is also available on the included MPLAB IDE CD-ROM. Microchips Online Discussion Groups at forum.microchip.com are a good place to ask questions and get information on developing with PIC MCUs. The [Development Tools] Programmers sub-forum is the best place for PICkit 2 related topics.

2007 Microchip Technology Inc.

Page 8 of 8

S-ar putea să vă placă și