8mhz clock speed

Please i need a code that i can use to generate a clock speed of 8mhz on arduino mega using arduino ide, pls i need your assistance

8 millihertz? 0.008 Hz?
Or 8 MegaHertz? 8,000,000 Hz?

Fast PWM on ATmega328, up to 8MHz

// A sketch that creates an 8MHz, 50% duty cycle PWM and a 250KHz,
// 6bit resolution PWM with varying duty cycle (changes every 5μs
// or about every period.

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  pinMode(3, OUTPUT); // output pin for OCR2B
  pinMode(5, OUTPUT); // output pin for OCR0B

  // Set up the 250KHz output
  TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);
  OCR2A = 63;
  OCR2B = 0;

  // Set up the 8MHz output
  TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM01) | _BV(WGM00);
  TCCR0B = _BV(WGM02) | _BV(CS00);
  OCR0A = 1;
  OCR0B = 0;

  // Make the 250KHz rolling
  while (1) {
  _delay_us(5);
  if ( OCR2B < 63 )
    OCR2B += 5;
  else
    OCR2B = 0;
  }
}

Thank u sir, but i have 2 questions
1.can this code be used on arduino ide(because of the int main)?
2.can i use it on arduino mega?

CrossRoads:
8 millihertz? 0.008 Hz?
Or 8 MegaHertz? 8,000,000 Hz?

just reading that hurts.

the frequency am getting is 2mhz

mshelia1:
Please i need a code that i can use to generate a clock speed of 8mhz on arduino mega using arduino ide, pls i need your assistance

You could bootload it to run at 8MHz and use an 8MHz crystal (if you need a more exact clock than the internal source). Would you like a link or links to do that?