Programming ATMEGA 8 is difficult because Arduino by default has a pre-defined clock frequency of 16MHz.
All the delay subroutine, PWM and Baud Rate generations are calculated using this frequency.
Programming ATMEGA 8 is difficult using this configuration, as ATMEGA 8 supports maximum 8 MHz clock frequency, or If you connect crystal other than 16MHz then serial communication will not work, delays and PWM will not be exact because default programming is done on 16 MHz.
If you want to check, what is current clock frequency, you can check it by following steps: –
1. For Arduino versions less than 1.
0, press SHIFT key and click on COMPILE/ VERIFY
– For Arduino versions greater than 1.0, FILE > PREFERENCES > select COMPILATION (as shown in Fig)
– Now when you COMPILE, it will show compilation progress
– Look at the starting few lines of Arduino Compilation, check -DF_CPU=4000000L
– This is the Clock Frequency at which Arduino is compiling (i.e. 4 MHz), which is set by Me (Arduino default was 16000000L)
– The clock instructions like #define F_CPU 4000000 does not work on Arduino
– All you have to do is changing the board configuration.
Changing Frequency for Particular Arduino Board:
– If you are not using original Arduino board, or want to use the programmer to upload the program to a Chip using ISP, then you need to configure Arduino clock frequency for the crystal / clock used with the CHIP.
– To do so, open Arduino directory > Hardware > Arduino > AVR >
– Now create a backup of boards.txt
– Now open Boards.txt
– Find the board for which you want to change programming frequency
– For Example: If we you want to program ATMEGA8 IC using USBasp Programmer, having clock frequency of 4 MHz then find Arduino NG or older change atmegang.
build.f_cpu=16000000L to atmegang.build.f_cpu=4000000L and in ATmega8 section find Fuses and change it to your required Fuse values
We have set fuse values to:
– Now save the file
– Now check if the frequency is set or not, by COMPILING the program
Programming ATMEGA8 using USBasp from Arduino directly:
If you want to program ATMEGA 8 IC directly from Arduino via USBasp Programmer, then Open Arduino, write program, select Arduino NG or older
Now Select ATMEGA 8 in Processors:
Select USBasp in Programmer:
Now connect USBasp programmer with PC and click Upload using Programmer:
– That’s All – Enjoy !!!.