What is a Microcontroller?

fiercebunΗλεκτρονική - Συσκευές

2 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

68 εμφανίσεις



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 microc
ontrollers 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.”



Progra
mming 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 company’s
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. Seri
al 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 you’ll learn how to write a smal
l 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 t
imes.



Step 02

Build a small ci
rcuit 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 > M
PLAB IDE



Go to
Configure > Se
lect 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


STATUS,5

bcf


TRISA,0

bcf


STATUS,5



;**Turn thr LED ON**



Start


bsf


PORT
A,0






;**Delay Loop1**



Loop1


decfsz


CounterL,1



goto


Loop1



decfsz


CounterH,1



goto


Loop1





;**Turn the LED OFF**







bcf


PORTA,0



;**Delay Loop2**



Loop2


decfsz


CounterL,1



goto


Loop2



decfsz


CounterH,1



goto


Loo
p2






goto


Start






end










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 ne
w 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 you’ve created before.


In the File name text box, type
Blink.asm


Leave the other sett
ings 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, you’ll 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 you’ve saved your program. You’ll 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, t
his is a Hexadecimal file.



OK my dear friends, you’ve 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 drive
r

and click ok.





Resta
rt 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 PIC16F
84A 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 you’ve created before with MPLAB IDE,

Go to
File > Open File





Open the
Blink.HEX
file.



Select the
XT

from the Oscillator combo box.


Don’t 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..! You’ve successfully done your first Micr
ochip job.



Remove the Microchip from the programmer and connect it to the running circuit you’ve created
in the Step 02.



Connect the circuit to a proper power supply. Now the LED will blink continually.





_________________________________________

Cou
rtesy:
http://pcnoweasy.googlepages.com


_________________________________________


Mr. Gamini Jayasinghe

Mr.Kolitha Dharmapriya



Electrical and Telecommunication faculty,

Moratuwa University,

Sri Lanka.