// ATtiny85 1 LED external event
#include<avr/io.h>
#define F_CPU 16500000UL
int i=0;
void counter_setup()
{
DDRB= 0b00001011;
//(1<<PB1)|(1<<PB0);
TCCR0A = 0X00; //TCCR0A to low for normal port operation and mode 0.
TCCR0B = 0X00; //WGM02=0
TCCR0B |= (1<<CS02)|(1<<CS01); //CS02=1, CS01=1 CS00=0 Clock on falling edge
TCNT0 = 0x00; //initializing the counter to 0
}
void counter_reset()
{
TCNT0=0x00; //reset value to 0
i=0;
}
int main()
{
counter_setup();
while(1)
{
i=TCNT0;
if ( i>=10&&i<30) // First 10 counts
{
PORTB |= (1 << PB1); //light up LED in PB1
//reset counts
}
else if ( i>=30&&i<40) // First 10 counts
{
PORTB|=(1 << PB0); //light up LED in PB0
PORTB &= ~(1 << PB1); // PBb1 Low logic at output
//counter_reset();
}
else if ( i>40) // First 10 counts
{
PORTB|=(1 << PB3); //light up LED in PB3
PORTB &= ~(1 << PB0); // PBb0 Low logic at output
// counter_reset();
}
}
}