This article describes in detail for beginners how to write a program into the AVR microcontroller. It does not deal with writing program, but only programming (writing) of the final file to the AVR. It is also suitable for those who do not want to write a program themselves, but only put the file (downloaded from somewhere) into their AVR.
Procedure - hardware:
To program the AVR you need some hardware and some software :). Hardware or a programmer is a device that allows the communication between PC and AVR. The simplest way for ISP programming hardware is only the LPT connector (male), cable, 4 resistors and power supply about 5V. All the hardware you can easily build yourself for example in a breadboard. Examples of most frequent AVR's programming schematics are shown in the diagrams below. If the target device will use crystal, connect it (and also the C1 and C2) during programming. You can also use the universal value of crystal, 4MHz. Connection of other AVR is similar. Always in search datasheet for pins: MISO, MOSI, SCK and RESET (and for XTAL2 and XTAL1 when crystal is used). Connect your programmer to the LPT port of your PC.
Procedure - Software:
You will also need some software. Download and install PonyProg (I used version v2.07c BETA). This allows you to write programs into AVR and setting the configuration bits. After the first startup of PonyProg, you must correctly set the communications port. Select Parallel, Avr ISP I/O, LPT1. Before writing the program into AVR, you must select the type of the microcontroller (AVR micro and ATtiny... orA Tmega...). There is also an option "AVR Auto", but I do not recommend it - configuration bits setting does not work then. Open the file you want to write to AVR. The AVR needs the compiled file with .HEX extension. The tutorials on the Internet (including mine) usually offer the file for download. Make sure the programming circuit with AVR is connected to the LPT and the power is on. Then click on the "Write Device" button and confirm. Your program will be written into the AVR. You should see the "Write successful". Then you have to set up and write the configuration bits (writion only the program is not enough!). Open the settings window (Security and Configuration Bits), set the appropriate bits . Bits have to be set as the appropriate design requires. I usually publish the printscreen of the window. Carefully check the setting before writing. Beginners are strongly discouraged to play with setting of these bits - AVR could get blocked (stop communicating). Warning - writing the bits is done by clicking on Write button, not the
The whole procedure is illustrated on the images below.
After programming and setting the bits, AVR microcontroller can be connected to the target circuit and tested. If an error messages appears while you are trying to write the program or configuration bits, you probably defined the improper port for PonyProg, improper type of AVR, did not connect the LPT connector, PonyProg does not have access to the port, programming circuit is wired wrong, there is no power, no crystal or capacitors (where the crystal should be present), your AVR is faulty or you've allready blocked it by wrong bits setting :).