Saturday, February 7, 2015

"HELLO WORLD" IN AVR - LED BLINKING & WRITING / SIMULATING YOUR FIRST PROGRAM

Hello & welcome to the first tutorial on AVR

This tutorial is focused on imparting basic AVR knowledge to folks interested in beginning in embedded systems & robotics.

The very first post is on the "HELLO WORLD" in robotics (specifically AVR).
I'd suggest you kindly clear your basics of digital electronics before starting this tutorial.
Also learn to read data sheets of basic IC's such as the following:


  1. 555 timer.
  2. max232
  3. opamp 741
  4. lm35
  5. adc0804
  6. ATtiny
& our first microcontroller  ATMEGA 16.
FOR beginning the set of tutorials, we'll download "WINAVR setup" & install it onto the desktop. & open the PROGRAMMER's NOTEPAD.



1) select file->new->c/c++ file to compose your first AVR program
2) write the given program & save it at a desired location in a separate folder

3) Now find the makefile & edit it.


4) to Edit makefile, select the desired F_CPU speed (Preferably 8000000 or 16000000) & also change the TARGET FILE NAME to the name of your own progam saved with programmer's notepad. & then save the makefile using File->save as on top left of makefile. SAVE THE MAKEFILE IN THE SAME FOLDER AS YOUR PROGRAM.C . 
5) After storing your own program file & makefile in the same folder. Click on Make Clean & Make All.
check for ZERO ERRORS in the dialog box below. & proceed.
Congrats, You have compiled your first AVR PROGRAM USING PROGRAMMER'S NOTEPAD.

6) Your project Folder will appear similar to this after step 5. It will have the "program.c" file as well as makefile & the "program.hex" file. & a bunch of other files whose use we'll discuss in the coming tutorials.

& Now , moving on to our next software Proteus. Its an animated software simulation method of your circuits.
Google this Software. You'll find plenty of good download links with FULL SETUP (SOFTWARE + CRACK+ LICENSE KEY). So Download & install the setup using the "HOW TO TEXT FILE".
7)Using the part list library within Proteus. Make the connections & Construct this basic circuit. 
8) Save the design file for your ease in the same folder as your AVR project folder. I advise you make a folder for each project in the coming tutorials & save it with the title name of your project.
eg. :  LED_BLINKER_TEST folder
              > LED_BLINKER.c
              >LED_BLINKER.hex
              >LED_BLINKER.dsn
              >makefile



9)Now lets add the hex program to the Proteus circuit for software simulation. for that click
SOURCE->Add/remove source file-> & select the target processor as the microcontroller in the design. for our design we chose atmega16. & click new to select the source file . CLICK & SELECT THE .HEX FILE from the project folder & proceed.

10) Now after adding the Hex file to design. click Execute & the click on the green Play button on the bottom left to Simulate. & use pause/play/stop button as & when you require.
After following all steps properly, You'll see the Animated led glowing after a specific delay.



Next, we'll Focus On BURNING the program to a real hardware using AVRDUDE .
Open AVRDUDE GUI & make the following settings:
i.e set your controller(we are using atmega16), programmer/burner (i am using usbasb), com port(check for ComPort by looking into the device manager for New hardware. This will pop up everytime you connect a new controller/device to your pc ), high fuse & low fuse.
Select the hex file & execute.

As my device is not connected to the machine. you see the message below.

 




when you connect your device , you'll see it in the device manager.
while programming, select the same COM PORT (COM3 in this case ) while programming.





You may use a common AVR burner hardware & connect the controller on a development board or breadboard & program the controller to see the led connected to C- bit 1, blinking.








































For all of you who are yet confused about the fuses , i'll do a separate comprehensive tutorial on 
  • AVR FUSES of some common AVR controllers.
  • TIMERS /DELAYS & INTERRUPTS
  • SERIAL & PARALLEL COMMUNICATION

Also feel free to ask any doubts regarding the projects.







-Abhirup :)

1 comment: