How can I change the frequency of my ATmega168?
The clock source in AVR is set by fuses that can be changed by an external programmer (the same one you use to load the HEX file), they can set the clock source to internal RC, external clock, crystal etc.
Here is a fuse calculator that may come handy http://www.engbedded.com/fusecalc

After setting the clock source fuses you can change the clock prescaler to get a lower core frequency, ATmega48/88/168/328 have a CLKDIV8 fuse that controls the default loaded value to CLKPR (Clock prescale register) to either


clk/1  
clk/8


Apart from that default loaded value you can change the clock prescale at will during runtime, all you need is to include the following header

#include &lt;avr/power.h&gt;


and call the following function with the appropriate value you want to use

   clock_prescale_set(clock_div_1),    // divide by 1, for example with 20MHz clock result      20MHz
   clock_prescale_set(clock_div_2),    // divide by 2, for example with 20MHz clock result      10MHz
   clock_prescale_set(clock_div_4),    // divide by 4, for example with 20MHz clock result       5MHz
   clock_prescale_set(clock_div_8),    // divide by 8, for example with 20MHz clock result     2.5MHz
   clock_prescale_set(clock_div_16),   // divide by 16, for example with 20MHz clock result   1.25MHz
   clock_prescale_set(clock_div_32),   // divide by 32, for example with 20MHz clock result  0.625MHz
   clock_prescale_set(clock_div_64),   // divide by 64, for example with 20MHz clock result  0.312MHz
   clock_prescale_set(lock_div_128),   // divide by 128 for example with 20MHz clock result  0.156MHz
   clock_prescale_set(clock_div_256),  // divide by 256, for example with 20MHz clock result 0.078MHz


power.h manual