Nuffnang Ads

Monday, January 19, 2015

Learn Microcontroller PIC : Lesson 1 - Introduction to PIC

If you are new to microcontroller, that not the problem . Because this will guide you how to use it. 

So, What is microcontroller? To answer this, you may see this link : microcontroller (from wikipedia) or you also can find it in other sources. For me, understand what is microcontroller is important but not its history because we are focus on the its application.

Now, I introduce PIC microconroller ,PIC (from wikipedia). 

Before start, we need some components:
HARDWARE :
1) 1 - PIC16F877A
2) 2 - 33pF Ceramic Capacitor
3) 1 - 10k ohm resistor (0.25W)
4) 1 - 20MHz crystal 
5) 1 - PICKIT2 (Uic00b programmer)
6) 1 - Breadboard 
7) 1 - LED (any colour but with low current)(tips : not ultra bright LED or big size LED)
8) 1 - 1k ohm resistor (0.25W)
9) Multimeter (optional)
10) some wire (single core) --> 

SOFTWARE :
1) MPLAB or MPLABX 

Ok, when you prepare all the material. You are ready to start learn.

Procedure :

Connect the circuit as show in the below :


#Important : The MCLR pin is a pin to reset (Hardware reset)  the program in the PIC. The PIC will reset when the MCLR pin receive '0' or GND.
After you connect the circuit, let we install MPLAB or MPLABX. The installation tutorial for MPLAB or MPLABX  . The installation will take some time. 

When you done install, you can start to program the PIC . Before that, are we forgot something? Erh ......... Oh ya ... how to connect programmer to PIC? Ok, this can refer to the datasheet of the UIC00b programmer. To solve this, first we need to know what pin should we need to connect? According to the datasheet of the UIC00b page 7. 
From the picture above, that are 6 pin are used which is pin 3, 4, 5, 6, 7, 8, 9. But for our application, pin 9 is unused. If you are not good on soldering , you may can buy this :

 Or you can build your own one . This I will teach you later (maybe in next post) .

When you are connect the UIC00b programmer to your circuit and plug in the USB to your computer. Now you can start program. First , you can follow this tutorial (MPLAB) or (MPLABX).

At here, you may know how to program PIC to light up a LED.

This is the program :

#include <htc.h>
#define _XTAL_FREQ 20000000 // tell PIC the value of the crystal
__CONFIG(0x3F32); // configuration bits

void main() // main program
{
TRISD = 0; //this is to set the pin direction : 0 for output , 1 for input 
RD1 = 1; // this is to set the pin : to light up LED
while (1); // this is must because the PIC program is infinite loop
}

From here, you should know how to program PIC and its basic connection. And have a nice day.

No comments:

Post a Comment