// +-\/-+
// Ain0 (D 5) PB5 1| |8 VCC
// Ain3 (D 3) PB3 2| |7 PB2 (D 2) INT0 Ain1
// Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1
// GND 4| |5 PB0 (D 0) pwm0
//
#include<avr/io.h>
#define F_CPU 8000000UL
#include <avr/interrupt.h>
#include<util/delay.h>
int intr_count=0;
void comp_match()
{
DDRB |= (1<<PB1); // set PB1 as output
TCCR0A=0x00;
TCCR0B=0x00;
TCCR0B |= (1<<CS00)|(1<<CS02); //prescaling with 1024
TCCR0A|=(1<<WGM01);//toggle mode and compare match mode
//OCR0A= 161; //compare value
OCR0A= 10; //compare value
TCNT0=0;
sei(); //enabling global interrupt
TIMSK|=(1<<OCIE0A);
}
ISR (TIMER0_COMPA_vect)
{
if (intr_count==90) //waiting for 100 count because to get 1 sec compare match should occur 100 times
{
PORTB^=(1<<PB1); //toggling the LED
intr_count=0; //making intr_count=0 to continue the process
}
else intr_count++; //incrementing intr_count
}
void setup()
{
comp_match();
}
void loop()
{}