Anda di halaman 1dari 11

What is a Microcontroller?

Microcontroller is type of microprocessor furnished in single integrated circuit and needing minimum of support chips. Its principal nature is self-sufficiency and low cost. The PIC Microcontroller PIC is a family of microcontrollers made by Microchip Technology. The original one was the PIC1650 developed by General Instruments. This device was called PIC for Programmable Intelligent Computer although it is now associated with Programmable Interface Controller. Programming the PIC Programming a PIC microcontroller requires the following tools and components: An Assembler or high-level language compiler. The software package usually includes a debugger, simulator, and other support programs. (In this lesson, we use MPLAB IDE and this software can be downloaded from the companys web site at www.microchip.com.) A hardware device called a programmer to connect the microcontroller to the computer through the serial, parallel, or USB line. (We use JDM Programmer. Serial Interface) A cable or connector to connect the programmer to the computer. A PIC microcontroller. (We use PIC16F84A)

OK. Now you have a basic idea of a Microcontroller. I think now it is time to start works. Our first program is very simple. In this lesson youll learn how to write a small program to blink a LED.

Step 01 Build a Programmer. Here is the circuit diagram of the JDM Programmer. Use an IC BASE to connect the microcontroller to the programmer because we have to connect and remove the microcontroller for several times.

Step 02 Build a small circuit to run the microcontroller. Here is the diagram. Use an IC BASE to connect the microcontroller to this circuit also.

Step 03

Code your first program with MPLAB IDE. You can free download MPLAB from the company website. Open MPLAB IDE. Start > All Programs > Microchip > MPLAB IDE

Go to Configure > Select Device

Select PIC16F84A from the Device combo box.

Click OK. To create a new file, go to File > New Enter the following code in the code window. This is the source code for the LED blink program.
;**Set up the constants** STATUS equ 03h TRISA equ 85h PORTA equ 05h CounterL equ 0Dh CounterH equ 0Eh ;**Set up the port** bsf bcf bcf STATUS,5 TRISA,0 STATUS,5

;**Turn thr LED ON** Start bsf PORTA,0

;**Delay Loop1** Loop1 decfsz CounterL,1 goto Loop1 decfsz CounterH,1 goto Loop1 ;**Turn the LED OFF** bcf ;**Delay Loop2** Loop2 decfsz CounterL,1 goto Loop2 decfsz CounterH,1 goto Loop2 goto end Start PORTA,0

Here shows only a part of the code that entered to the MP LAB.

Before you save the document, it is better to create a new folder on your hard drive to save our program. E.g. C:\Blink

Now to save the program, go to File > Save as From the save in combo box, select the Blink folder youve created before. In the File name text box, type Blink.asm Leave the other settings as default and click the save button to save your program.

Now your code window will look like this.

Here shows only a part of the code.

Now it is time to build your program. For that go to Project > Quick Build Blink.asm After few seconds, youll see the Output window. It should look like this. If you found any error massages, please check your code again.

Now open the Blink folder youve saved your program. Youll see some new files created by MPLAB IDE. You can see a file named Blink.HEX. This is the most important file that we need to program the microchip. .HEX means, this is a Hexadecimal file. OK my dear friends, youve successfully build you program with MPLAB IDE. Our next task is program the Microchip using Blink.HEX file.

Step 04 Program the Microchip. To program the microchip we need software called IC PROG. You can free download this software.

Open IC PROG Sometime you may receive an error massage when using IC PROG with Windows XP. To fix this problem, you should enable the XP driver. It is very simple. Go to Settings > Options Open the misc tab and enable the XP driver and click ok.

Restart IC PROG. Select the Hardware. Go to Settings > Hardware and select the JDM Programmer from the programmer combo box and Click OK. Connect the JDM Programmer to the Computer through the serial port. Make sure you have correctly connected the PIC16F84A microchip to the programmer. If you are using an earlier programmed microchip, you should erase the program first. For this, click the erase button of the IC PROG. A warning massage will appear and click the OK button to delete the exciting program. Now to load the Blink.HEX file youve created before with MPLAB IDE, Go to File > Open File Open the Blink.HEX file. Select the XT from the Oscillator combo box. Dont check any Fuses combo boxes. Now your IC PROG window should look like this.

Now we are ready to program the Microchip. Make sure again you have correctly connected the PIC16F84A microchip to the programmer. Click the Program all button. Click Yes to confirm. Now a progress bar will appear to show the progress.

Finally a massage will show.

Congratulation..! Youve successfully done your first Microchip job. Remove the Microchip from the programmer and connect it to the running circuit youve created in the Step 02. Connect the circuit to a proper power supply. Now the LED will blink continually. _________________________________________ Courtesy: http://pcnoweasy.googlepages.com _________________________________________ Mr. Gamini Jayasinghe Mr.Kolitha Dharmapriya Electrical and Telecommunication faculty, Moratuwa University, Sri Lanka.

Anda mungkin juga menyukai