UpdatedUpdatedOctober 06 - 2017October 06 - 2017
In this tutorial we'll write a small program in Atmel Studio.
Then we'll create a .hex file and later we'll burn the .hex file into the microcontroller.
Find the connected port
- Connect the myAVR board to your computer via USB cable.
- Open device manager.
- Check Ports (COM & LPT) and find out the connected port. [In my case, I'll use COM3 Port.]
Create our first project in Atmel Studio 7
Open Atmel Studio 7 and click 'New Project...' to open the following window:
- Select 'GCC C Executable Project'.
- It's better to organize all our files in directories. So I created a directory in E:\AVR\Studio where I'll save all my future project files.
- Name and Solution name will be your project name.
- If you select 'Create directory for solution', it will create separate directory "Debug" inside your master directory where all files (Makefile, .d, .o, .mk, .eep, .elf, .hex, .lss, .map, .srec) will be created.
- Click 'Ok'.
- Now select your device family (in our case it is ATmega8A).
- Click 'Ok' again. It will start creating your project.
- There is a default main.c file. We'll always work on this file for all the projects.
avr C code
Now copy-paste the following codes.
Create .hex file
Select Build >> Build Solution (F7). If there is no mistake, you'll see 'Build succeeded' message.
Flash the .hex file
Run avrdudeGui.exe. In 'Setup' tab, select Programmer: avr911 and Port: COM3 (if you use the same board like mine, programmer is avr911, for port find out which one you are using).
- Don't do anything in 'Lock Bits', 'Fuse Bits' and 'Calibration'. If you don't know what they actually do, you might damage your microcontroller permanently!
- In 'Programming' tab, Traget Device: ATMEGA8, File Format to use: Intel Hex.
- Select the flash file (you can find the Hex file in your project directory, in my case it is E:\AVR\Studio\lab1\lab1\Debug\lab1.hex)
- Now click 'Program' (in flash section).
- When it's done, you'll see a success message in a separate window.
Now we'll connect any pin of PORT-D with any of the three ACTIVE-HIGH LEDs (Red or Green or Yellow) and connect any pin of PORT-C with the ACTIVE-LOW LED (Blue).
If you have done everything perfectly, you will see the result like the following image (the photo is underexposed so you can see the blue and red LEDs).