// ATtiny85   counting the tik of the timer0
// ATtiny85  74HC595
#include<avr/io.h>
#define F_CPU 8000000UL
int i = 0;

#define clkpin PB4 // clk connected to pin 11
#define latchpin PB3  // latch pin 12
#define datapin PB5 // data pin 14


void setup() {
  // Set pins to 74HC595 output
  pinMode(clkpin, OUTPUT);
  pinMode(latchpin, OUTPUT);
  pinMode(datapin, OUTPUT);
}
// set up counter0
void counter_setup()
{
  DDRB = 0b00111011; //pin as output
  ////(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
}
// set up timer0 for time delay tmdel
void timer0_config()
{
  DDRB = 0b00111011; // set PB1 as output
  TCCR0A = 0x00;           //Normal mode
  TCCR0B = 0x00;
  TCCR0B |= (1 << CS00) | (1 << CS02); //prescaling with 1024
  TCNT0 = 0;
}

void tmdel() // function to implement 500 ms time delay
{
  unsigned int k = 0;
  while (k <= 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
    k++;
  }
}

void  counter_reset()
{
  TCNT0 = 0x0;     //reset the value to 100=64;90=5A;60=3C
  // i = 0;
}

int main()
{
  //counter_setup();
  timer0_config();
  tmdel();
  //while (1)
  //{
    // i = TCNT0;
    i = 105;
    if ( i >= 60 && i <= 80)  // First 10 counts
    {
      PORTB = 0b00000010; //light up LED in PB1
      // counter_reset();
    }
    if ( i > 80 && i < 90)  // First 10 counts
    {
      while (1)
      {

        PORTB = 0b00000010;
        tmdel();
        PORTB = 0b00000000;
        tmdel();
      }

    }


    if ( i >= 90  && i <= 100) // First 10 counts
    {
      PORTB = 0b00000001;  //light up LED in PB1
    }
    if ( i > 100)
    {
      //PORTB= (1 << PB0);
      while (1)
      {
        PORTB = 0b0000001; //light up Led toggling
        tmdel();
        PORTB = 0b0000000; //light up Led toggling
        tmdel();

        PORTB &= ~(1 << PB1);
      }
      //tmdel();

      //counter_reset();
    }
//}
}








ATTINY8520PU
74HC595