// ATtiny85 2 LED Blink time delay 500ms with timer0
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
//////////////////// timer config insertion
void timer_config()
{
DDRB =0b00010111; // set PB1 as output
//DDRB =0b00000010; // set only PB1 as output pin
TCCR0A=0x00; //Normal mode
TCCR0B=0x00;
TCCR0B |= (1<<CS00)|(1<<CS02); //prescaling with 1024
TCNT0=0;
}
void tmdel()
{
unsigned int i=0;
while(i<=14) // number of itter is 15 to reach 500 ms time delay
{
while((TIFR & (1 << TOV0) )==0);//Waiting for 0-255 and flag to raise
TIFR|=(1<<TOV0); //Clear the flag
i++; //increment by one
}
}
/////////// timer config insertion
int main(void)
{
//DDRB |= (1<<PB1);
// DDRB |= (1<<PB0);
//DDRB=0b00000011;//pb0 and pb1 as out
timer_config();
while (1)
{
PORTB = (1<<PB1);
// _delay_ms(500);
tmdel();
PORTB &= ~(1<<PB1);
// _delay_ms(500);
tmdel();
PORTB = (1<<PB0);
tmdel();
// _delay_ms(500);
PORTB &= ~(1<<PB0);
tmdel();
PORTB = (1<<PB2);
tmdel();
PORTB &= ~(1<<PB2);
tmdel();
PORTB = (1<<PB4);
tmdel();
PORTB &= ~(1<<PB4);
tmdel();
// _delay_ms(500);
}
}