Start with WINAVR
Instruction Manual to Start with AVT "Plug & Play Kit" with WINAVR
1. Winavr Download and Installtion
Winavr is a opensource and free available software. Download winavr from the link http://sourceforge.net/projects/winavr/ and install it.
2. USBASP/Usbtiny Driver installation
· Connect usbasp/USBTiny programmer to usb port of your computer. Computer will detect usb device and will show dialog box as shown below.
· Click button Yes, this time only, then click next button. The wizard will display next dialog box as shown below
· Click on the Install from specified location button→next
· Now the wizard will ask for windriver folder as shown below
· Browse the win-driver folder wherever you have→ next
· Now the installation starts and will take some time (few seconds).A message will display on the bottom right corner of taskbar as shown below.
Now USBASP/UsbTiny driver is installed and you are ready to download data to the microcontroller.
3. How to start a new project
· Create a new folder and name it whatever you want.
· Start menu→ All programs→ winavr→ Programmers Notepad
· In programmers notepad window, click on File menu→ new→ c/c++
· Click on File menu→Save As
· Save this fie in project folder, name the file as main.c
· Generate a Makefile (discussed in subsequent topic) in same folder
· Open Makefile in programmer’s Notepad
· Make five changes in Make file
· Write your code in main.c
Note: Files needed for successful compilation main.c and Makefile.
4. How to generate MakeFile
· Simplest way to get a Make file: Copy a Makefile from any old project to your new project folder.
· If you don’t have any Make file in your computer, you need to generate it.
· Click on :StartàAll ProgramsàWINAVR*******àMFile[WINAVR]
· A window will appear with lots of text written on it.
· Click on FileàSave As
· Save this file in your Project folder (don’t change the file name)
5. Five changes in Makefile
Variables | Default | Modified | |
1 | MCU name Line #44 | # MCU name MCU = atmega128 | # MCU name MCU = atmega32 |
2 | Processor frequency Line #65 | F_CPU = 8000000 | F_CPU = 4000000 |
3 | Add extra include file (If you are including extra header files) Line #83 | SRC = $(TARGET).c | SRC = $(TARGET).c lcd_lib.c(for lcd display place lcd_lib .c separated by space) |
4 | AVRDUDE programmer Name Line #276 | AVRDUDE_PROGRAMMER = STK500 | AVRDUDE_PROGRAMMER = usbasp |
5 | AVRDUDE port Name Line #279 | AVRDUDE_PORT = COM1 | AVRDUDE_PORT = usb |
6. How to compile and Transfer your program
Note: Connect the usbasp programmer to the usb port of your computer and the other end of the programmer to the BRiCS’ plug & play AVR kit.
· Write your complete code in file main.c using programmer’s Notepad
· Click on toolà [WINAVR]Make All to compile your code. If there is no error in your code, it will generate a main.hex file in your project folder. Output window will look like figure as below.
Note: If the Process Exit Code is 0, code has compiled successfully but it does not ensure that your code is right and free from logical errors.
· Click on toolà[WINAVR]program to download your code to micro-controller using USBASP programmer
· When the hex file is downloaded in to microcontroller, in the output window you will see the lines as shown in above figure.
· If you are using parallel port connector use ponyprog to downloadmain.hex file
7. How to use Ponyprog
· Install ponyprog on your computer
· Run ponyprog using link in start menu
· Click OK on all windows appears
· Click Setupàcalibration
· Wait for popup window
· Click on OK(on popup window)
· Click on DeviceàAVR microàAtmega32 to select your device
· Click SetupàInterface setup…
· A setup window will appear
· Select parallel
· Select AVR ISP I/O (the one bellow parallel option)
· Select lpt1
· Click Probe to check your programmer. It will show OK if programmer is connected and everything is OK.
· Click OK
· Click OK
· Open your main.hex file using: FileàOpen Device File.
· It will show lots of hex numbers in window
· Download your code to micro-controller using: Commandàwrite all
· Wait for successful download
8. Sample code to blink LEDs on port B and port D:
#include <avr/io.h> // header file
#include <util/delay.h> // header file
int main(void) // main function
{
DDRB=0xFF; //port B enabled
DDRD=0xFF; //port D enabled
int i=0; //A variable i and enabled to 0
while (1)
{
for(i=1;i<256;i=i*2){PORTB=i;_delay_ms(100);} //port B pins will be on from 1 to 8 after every 100 miliseconds
for(i=1;i<256;i=i*2){PORTD=i;_delay_ms(100);} //port B pins will be on from 1 to 8 after every 100 miliseconds
}
return 0; //return nothing to main function
}
9. Sample code to print string on 16*2 LCD screen:
#include <avr/io.h> // header file
#include <util/delay.h> // header file
#include "lcd_lib.h" //extra header file included for LCD
int main(void) // main function
{
LCDinit(); //Initializes LCD
LCDclr(); //Clears LCD
while (1)
{
LCDGotoXY(5,0); //Cursor to (5,0) position
LCDstring("BRiCS",5); //Outputs string to LCD
_delay_ms(10); //delay of 10 miliseconds
LCDGotoXY(0,1); //Cursor to (0,1) position
LCDstring("A Step Towards Future",21); //Outputs string to LCD
LCDshiftRight(1); //shift by 1 character Right
_delay_ms(100); //delay of 10 miliseconds
}
return 0; //return nothing to main function
}