/*
 * PWMTest.c
 *
 * Created: 2013.10.23. 15:52:02
 *  Author: User
 */ 


#include <avr/io.h>
#include <avr/interrupt.h>

volatile int threshold;

int init()
{

	TCCR0A |= (1<<WGM00) | (1<<COM0A0) |(1<<WGM01);
	TCCR0B  |= (1<<CS02) |(1<<WGM02) ;
	DDRD = 0b10000000;
	DDRB = 0b00000011;
	PORTB &= ~(1<<PINB0);
	TIMSK0 |=(1<<OCIE0A) | (1<<TOIE0);
	EIMSK |=(1<<INT0);
	EICRA |=(1<<ISC01);
	sei();
	OCR0A = 79;
	PORTD = (1<<2);
	threshold =4;
	
}

int main(void)
{
init();
int threshold_local;

    while(1)
    {
	if (TCNT0 >=3 && TCNT0 <=9)
		{
			threshold_local = threshold;
			if (TCNT0 >= threshold_local  && bit_is_set(PORTB, PINB1)) PORTB &= ~(1<<PINB1);
		
		}
		
	}
	
}

ISR (TIMER0_COMPA_vect)
{
	PORTB =0xff;
}


ISR (INT0_vect)
{
	threshold =8;
	PORTD |= (1<<PIND7);
}