Getting Started with Microcontrollers
Hello! Learn how to program your microcontrollers easily through our tutorial. In this tutorial, we are going to compile our first microcontroller program and then we will download it to the microcontroller
Why (do you need this)?
Familiarize with compiling and downloading new codes to the microcontroller
What (do you need)?
|Pocket AVR Programmer||1|
|Program Code (download here)|
|USBTiny Driver (driver page here <ladyada>), (driver here)|
How (to make it)?
After downloading WinAVR and installing it, download the program code and extract it in your desktop or wherever you like, you will find two files, namely:
Makefile contains the main configurations which will be used to compile and download the file, we’ll see how to play with these files later
Main.c is the actual c-language program, let us see what is inside it. Open the file using “Programmer’s Notepad” which should have got installed along with WinAVR
We are not going to go through the details of programming here (it is going to be explained in another tutorial), if you are so excited, http://www.nongnu.org/avr-libc/user-manual/ is always your friend in AVR programming.
Let us modify the code a little bit to test that everything is working as it should, go ahead and replace the number “500” with “100”, so the code will be:
Now, go to the “Tools” menu and select “[WinAVR] Make All”
After a while, you should get the following message in the Output window:
------- end --------
> Process Exit Code: 0
> Time Taken: 00:33
Great, now the code is compiled, go back to the folder where you opened the main.c, you should see new files, one of them would be “main.hex”
This is the file which will actually go to your microcontroller.
Now, let us go back to our breadboard, get your AVR Pocket programmer
The cable that comes with the programmer has three connectors, at one end you have a 10-pin connector, followed by another 10-pin connector and lastly a 6-pin connector at the other end.
Connect the first 10-pin connector to the programmer, and connect the 6-pin connector as shown below
(Note, to identify pin 1 of the connector, find the small engraved arrow on the connector, see picture below)
We’ll connect five (5) more wires for what is called an ISP programmer:
Connect up a micro-USB cable to the programmer, now your PC is connected to the microcontroller.
The programmer is connected now, let us download our new program, go back to your Programmer’s Notepad window and go to “Tools” then select “[WinAVR] Program”
You should now see the LED blinking faster than before.
With this, the doors of microcontrollers heaven have opened for you.
If you have any questions or comments, please feel free to post in the comment section below.