Wednesday, June 8, 2011

§ Burn AVR Microcontroller Using Parallel Port Programmer

 Hello,
In my previous post I explain how to make AVR Parallel port programmer. Now let’s makes it in use. Requirements-
software side : WINAVR , AVRDUDE , .C file(your code), MAKEFILE
Hardware side : AVR Parallel Port Programmer, Target Board

What is WINAVR?? It is a compiler or open source software development tools for the Atmel AVR series MCUs hosted on the Windows platform. It includes the GNU GCC compiler for C and C++.
What is AVRDude?? it is a program used to burn hex code inside microcontroller. The separate setup of AVRDude for windows is not available actually it is bundled with winAVR compiler.
To burn or program AVR MCU you need a .hex file which is a machine code not human readable only understand by the MCU. WinAVR generates .hex file from code (.c) file. This hex file is then transferred inside MCU using AVR programmer. This hex code is stored in flash memory of MCU. When power gets on; MCU starts doing work according whatever code stored inside flash memory.
First Download and install the latest version of WINAVR in your system.
Target board contains MCU and power supply and ISP (In-System-Programmable) Header. This is a 5-pin header; these pins are programming pins. Different AVR chips have different pinout so please refer the datasheet of the AVR chip.AVR ISP Header has 5 pins which are-RST,MOSI,MISO,SCK,GROUND. 

AVRDude is a command line program, you have to type commands in command window for particular task; for Example -
avrdude –c <programmer type> –p <programmer ID> –p <port> –U flash:w:<PROJECT>.hex 
avrdude –c <programmer type>–p <programmer ID> –p <port> -U hfuse:w:<HFUSE>:m 
avrdude –c <programmer type> –p <programmer ID> –p <port) -U lfuse:w:<LFUSE>:m
Etc. . . .
Don’t Worry! You don’t have to remember all these types of commands, all these commands are bundled in a file called MAKEFILE you have to carry this file in the folder where your .c file is stored. You only have to type short-commands in command window for particular task.

These commands are -
-make all : to generate .hex file it also generate .map.,o..out files.
-make clean : remove the files generated from the command "make all"
-make flash : to program .hex file inside MCU.
-make fuse : to program FUSE bytes.

To calculate fuse bit use very popular AVR Fuse Bit Calculator.

NOTE : Fuses play very important role in the programming; don't try to Experiment with them without proper knowledge; otherwise you can damage your micro controller permanently!!
fuses determine how your chip will act.Refer datasheet for more details.

Step-by-step Explanation -
Step1: Install WINAVR in your System.

Step2: Type your program in notepad and save it with “.c” extension in a folder.
for Example : Program for LED blink
 #define F_CPU 1000000UL  //CPU Speed 1MHz internal
#include <avr/io.h>   
#include <util/delay.h>
void main()
{   
 DDRC = (1 << 5); //PC5 is input ; connect LED at this pin
 while(1){    //loop forever
 PORTC ^= (1 << 5); //Toggle LED at every half second


 _delay_ms(500);
}
}

Step3: Make a folder in c-drive and paste the code "blink.c" in it.
 

Step4:Now paste MAKEFILE in this folder.





Step5: Open make file and do necessary changes in user area ;like project name, MCU type, Port type etc.
 



 Use this makefile in every project,you only need to change PROJECT name and MCU name."#" symbol is for comment.Things written in right-hand side of "#" is not readable.Here fuses are commented; to make use them remove "#" symbols.Again remember calculate fuses carefully.Ones you set correct fuses you don't have to change them again.In this example i use default fuses of the chip hence no need to set them; hence commented here.

Step6: Open Command prompt.Start->Run->cmd->ok
 


 

Step7:Change directories to the location where led_blink (your project folder) is exist.


Step8: Type “make all” and press enter.

Step9:Make your Target-Board.
 

Step10:Connect ISP header in target board.


Step11: Connect Programmer to PC parallel port and power on the supply of target board.
 
 


Step12: Type "make flash" in command window.

If all thing is correct then it will show "done" message that means your chip is programmed successfully.


Troubleshooting :
Sometimes you can get this message - 

this message will appear in mostly two cases :
 1.Wire connections on breadboard is not ok, check the connections properly.
 2.Breadboard or Target board power supply is not ON.

If you want to use another AVR microcontroller to burn this code then change the MCU name in MakeFile and recompile this code, if you trying to burn this hex file in another MCU then you will get device signature error because this hex file is compiled for ATmega8.


Downloads :

Video:


                                                                                                                                 ~pratyush

7 comments:

  1. From Where We can get this 'MAKEFILE'?

    ReplyDelete
  2. Can we erase code from IC using parallel port programmer and above method?

    ReplyDelete
  3. Very nice blog...
    Great information provided. We also provide AVR Microcontroller Training in Noida. I appreciate your work.

    ReplyDelete
  4. This paragraph gives clear idea for the new viewers of blogging, Thanks you.
    AVR Microcontroller Training in Noida

    ReplyDelete

  5. Thanks for sharing this valuable information and we collected some information from this blog.
    Microcontroller Training in Noida

    ReplyDelete
  6. It is amazing and wonderful to visit your site. Thanks for sharing information; this is useful to us....


    Power BI Training in Delhi

    ReplyDelete
  7. Thanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.

    Data analytics course in Delhi
    FOR MORE INFO:

    ReplyDelete

PID Controlled Self balancing Robot using ESP8266 and MPU6050

This ROBOT is made using ESP8266 Node MCU and MPU6050 accelerometer. Motor used here is normal gear motor of 150 rpm with TB6612FNG motor dr...