Getting Started with HI-TECH C Tools for the PIC10/12/16 TM MCU Family and Microchip’s PICDEM 2 PLUS Board and MPLAB R ICD 2
Document number: QSGM100
Copyright (C) 2008 HI-TECH Software. All Rights Reserved. Printed in Australia. MPLAB and PIC are registered trademarks of Microchip Technology Inc. PICDEM is a trademark of Microchip Technology Inc. Produced on: September18, 2008 HI-TECH Software Pty. Ltd. ACN 002 724 549 45 Colebard Street West Acacia Ridge QLD 4110 Australia email: email@example.com web: http://microchip.htsoft.com ftp: ftp://www.htsoft.com
This guide is intended to introduce you to the HI-TECH C PRO for the PIC10/12/16 MCU Family compiler and its use in Microchip’s MPLAB IDE. Code will be produced for theMicrochip PICDEM 2 PLUS demo board, running a PIC16F877A MCU device. Programming will be performed via a Microchip MPLAB ICD 2 in-circuit debugger. Code will be written to ﬂash the 4 LEDs on the board. This guide will illustrate the following points. • Setting up MPLAB IDE projects to use the HI-TECH C compiler; • Compiling for Microchip’s MPLAB ICD 2 debugger; • Becoming familiar with HI-TECH C sourcecode and the HI-TECH C PRO for the PIC10/12/16 MCU Family; • Accessing special function registers; • Writing interrupt code; and • Deﬁning code in more than one source ﬁle.
1.1 Before you Begin
The following chapters assume that you have already installed Microchip’s MPLAB IDE. Microchip use special drivers to communicate with the MPLAB ICD 2. Microchip have documentation relating toinstallation of the IDE and drivers.
Before you Begin
You will also need to have installed the HI-TECH C PRO for the PIC10/12/16 MCU Family compiler. You can use the fully licensed, demo or Lite version of this compiler with this guide. The compiler should be installed after ﬁrst installing MPLAB IDE. The compiler installer will automatically install the Universal Toolsuite pluginfor MPLAB IDE that allows the IDE to drive the compiler. You will need to follow the Microchip documentation to set up the hardware connections from your PC to the MPLAB ICD 2, and from the MPLAB ICD 2 to the PICDEM 2 board. Ensure that the 16F877A device is installed in the PICDEM 2 board.
Setting up a Project in MPLAB IDE
Begin by running MPLAB IDE. The ﬁrst step to usingMPLAB IDE is to open a project. We don’t have an existing project to open so we will need to create a new one. The easiest way to do that is use the Project Wizard in MPLAB IDE. Select the Project Wizard menu item from the Project pull-down menu as illustrated in Figure 2.1.
In the dialog that opens, click Next to move to the chip selection dialog. Select a PIC16F877A device as shown in Figure2.2 then click Next.
The next dialog is where you get to specify the toolsuite associated with the project. You are not associating the project with any one particular compiler, but rather specifying that you will be using one of the HI-TECH C compilers for Microchip devices. Once the project has been created, you
Figure 2.1: Initiating the MPLAB IDE Project Wizard
Setting up aProject in MPLAB IDE
Figure 2.2: Selecting the target device
Figure 2.3: Selecting the HI-TECH toolsuite
can specify the compiler version that you will use, and you can change the compiler version without having to re-create the project. To use the HI-TECH Family of compilers you must select HI-TECH Universal Toolsuite as the Active Toolsuite in this dialog, as shown in Figure 2.3. Noticethat the Toolsuite Contents area shows the generic name HI-TECH ANSI C Compiler. Notice also the path shown in the Location area. This path is not important and you do not need to edit it to point to the compiler location. The Universal Toolsuite determines the location of the installed compilers via other means. Click Next.
In the next dialog you can specify the name and location of the...