Note: 1st see main components of programming a micro controller "blog" for better understanding
Installation of Software and
Programming
This tutorial will show you how
to install the software required for programming and how to program an At Mega 16
micro-controller.
Installing the Required
Software and Drivers:
The contents of the programmer
support CD include the following:
1)
USBasp Driver (Programmer device driver S/W)
2)
At Mega 16 Datasheet
3)
Installation and Programming Tutorials
4)
Make File
5) WINAVR Installation File (Programming S/W)
Contents of the
support CD
Once we have written our C
code, programming a micro-controller involves two discreet steps.
1)
The code in high level C language must be converted into low-level (hex code)
which can be understood by the micro-controller.
2) This hex code must be ported
or burnt into the micro-controller.
WINAVR is the software required
to convert the code written in our high-level language (C Language) into hex
code and burn it into the micro-controller.
Let us see how to install
WINAVR. If you are not using the support CD, then you will first need to
download the setup file. Double click on the installation file of WINAVR and
install it in a preferred location.
Once WINAVR is installed, we
will proceed to install the driver of the USBdude programmer. In order to do
this, first open Device Manager on your computer.
Plug in the programmer into the
USB port of your computer. You will find the Programmer added to the list of
devices attached to the computer. However, it will tell you that the driver for
USBtiny was not installed correctly.
(Download
and) Right click on the USBdude in the device manager and select ‘update
device driver’. You will have to manually browse the folder location to
identify the folder containing the device driver. Browse through to the folder
named USBdude Driver. The folder contains drivers for all the configurations of
windows computers. You need not select the driver specifically. Your computer
will choose the right driver from the folder. Once you have directed to the
folder, click ‘Update’.
Device Manager before installation of driver
Device manager after
installation of driver
You have now
installed the driver of the USBasp programmer.
Once WINAVR and USBdude are
both installed on your computer, you will not require the setup and driver
files again.
Now, whenever you want to write
a new code, you may follow the steps given below. The aforementioned steps are
not required to be repeated.
Now, let us see how to connect the programmer to
the AtMega16 micro-controller.
Connecting
the programmer to the micro-controller:
Fig :-
AVR DUDE Programmer
When we program a
micro-controller, we must always make sure that each specific programming pin
of the programmer is connected to each programming pin of the micro-controller
we want to program.
This USBdude programmer is
designed in such a way that it’s six programming pins and the six programming
pins of the AtMega16 mirco-controller are in order. Hence, we can directly
program an AtMega16 micro-controller on a breadboard using this programmer
without using any wires.
If you have
to program a micro-controller with different configuration of programming pins,
you will have to connect the programming pins of the programmer to those of the
micro-controller using wires.
The six programming pins of any
micro-controller (MOSI, MISO, SCK, RESET, Vcc and GND) can be found in its
datasheet. The datasheet of the AtMega16 micro-controller has been provided in
this support CD.
Ensure that the Ground (GND)
pin of the programmer is connected to the GND pin of the microcontroller, the
Vcc pin of the programmer is connected to the Vcc pin of the micro-controller
and so on.
Note: If can be seen that the micro-controller is being powered
by the programmer while it is being programmed (as the power pins of the
programmer and the micro-controller are connected). Similarly, after the
micro-controller is programmed, we can use the programmer itself to power the
micro-controller. The programmer in turn is being powered by your computer.
However, the amount of current that the programmer can provide is limited. It
is, therefore, not recommended to power the circuit using the programmer.
The GND pin
of the AtMega16 micro-controller is its 11th pin and the MOSI pin is the 6th
pin. This is how the micro-controller and the programmer sit on the breadboard
when you want to program the micro-controller.
_________________________________________________________________________________
Programming the
Micro-controller:
Now, we may
proceed to write the C code. We will write our code in a software called Programmers
Notepad (pn.exe) which automatically installs when you install WINAVR.
Create a separate folder with an appropriate name. Go to the folder where
WINAVR was installed. In the WINAVR folder, select the pn folder.
In this folder, open the pn.exe file. You can also find this file in the
WINAVR folder in the All Programs menu when you open START.
This opens the ‘Programmer’s
Notepad’, a commonly used editing software for programming.
Write your C code in the
programmer’s notepad and save the file in the new folder with a “.c”
extension. For example, if your program is called main, you
will have to save it as main.c
In order to program the
micro-controller successfully, we have to pass on certain information about the
hardware we are using to the compiler. We do this with the help of a MakeFile.
You will find this MakeFile in the Support CD or in the ‘Resources’ tab.
Open this MakeFile with
Programmer’s notepad. It will open as
a separate tab in addition to the tab containing your C code.
Save this MakeFile in the same
folder as your C code. This step is very important and is often
forgotten by
beginners. Next, we need to modify certain parameters of the MakeFile.
Generally, we will modify only
three parameters of the Makefile;
1) The microcontroller used:
Change it to atmege16 (all small and no gaps)
#MCU name
MCU = atmega16
2) The TARGET (referring to the
code to be burnt): Change it to the <name of your C code> without the .c
extension
#Target File name
(without extension)
TARGET=my program
3) The programmer used: Change
it to usbtiny (all small and no gaps).
AVRDUDE_PROGRAMMER=usbasp
Save the Makefile and the code.
Remember, the MakeFile and the C code should be in the same folder.
Now we are ready to compile and
burn the code. Go to Tools in the menu and select ‘Make All’.
This command converts the C
code into the hex code. On completion of this process, the output
window says ‘Process Exit Code
0’. This indicates that the hex file has been generated without any errors. You
will now find the generated hex file in the folder which had your C code and
the MakeFile.
Next, go to Tools in the
menu and select ‘Program’. This command burns the hex code from your
computer into the micro-controller. You can see the progress of this process in
the output window. The code is first written onto the micro-controller and is
then read, by the programmer. This is done to check for any errors that might
have occurred during writing the code.
On
completion of this write process, the output window says ‘Process Exit Code 0’.
This indicates that the write operation has been completed without any errors.
No comments:
Post a Comment