Académique Documents
Professionnel Documents
Culture Documents
1.1 Introduction Learning how to program the PIC microcontroller using the C language is advantageous to any embedded programmer. This section will provide the necessary steps on how to install the MPLAB IDE with the PICC-lite C compiler for PIC microcontrollers. The MPLAB IDE will provide the development environment for the C program from which the PICC-lite C compiler can be invoke to generate the machine code (i.e HEX file).
Step 1. Download the free MPLAB IDE from the Microchip website and install.
STEP 2. Download the free student version of the H-Tech PICC-lite compiler either from the Microchip website or the Hi-tech website. After download, install the compiler.
To test the installed MPLAB and PICC-lite, we will create a blinker project using the PIC16F84a microcontroller chip. First, open the MPLAB IDE by double-clicking on the MPLAB icon on your windows desktop
or click on Start >> Programs >> Microchip >> MPLAB IDE as shown in figure below.
To create a new project, select Project >> Project Wizard. A Project Wizard window will appear. Click Next and choose the device in the drop-down menu. We will select the PIC16F84a chip.
In the Active Toolsuite drop-down menu, select the PICC-lite toolsuite. Click Next.
Choose an appropriate name for the project. In this example, blinker will be the name of the project. Save the project in a desired directory and click Next.
We will be prompt to add any existing files to the project. Since we dont have any existing file, simply click Next.
The final screen on the Project Wizard is a summary of the previous selections. Click Finish.
The project workspace below will appear. Only the Project window is visible at this time.
Our next step is to create a new C source file. Click the New button (or press CTRL+N) and a blank editor window will appear as shown below.
Now, type the example C source code below for the blinker project.
#include <pic.h>
void main( ) { TRISB & = ~0x01; PORTB & = ~0x01; //initialize RB0 pin as output //LED is initially off
//infinite loop
10
11
Now, add the blinker.c file to the project. To do this, select Project >> Add Files to Project, and locate and the blinker.c. Click Open.
12
In the project window, the blinker.c file will now be listed under Source Files.
13
We are now ready to compile the blinker.c program. In the Project menu, select Build. An Output window will diplay the build process. It will indicate whether the build process is successful or not, as well as some other build statistics. In this example, the build process or the blinker project is successful, with no warnings or errors.
14
A successful build process will generate several output files in the project directory. The most important output file is .hex file since this the actual binary code that will run inside the microcontroller. In the figure below, the blinker.hex is visible and can now be programmed to the microcontroller using the appropriate hardware programmer.
15
Review
A blinker project is the probably the simplest microcontroller program, equivalent to the Hello World program of many high-level language. The blinker program runs inside the microcontroller and causes an LED connected to one output pin of the microcontroller to blink. (i.e. turn on/off say, every second)