//      AVR
//  Target  	  : ATTiny13
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h> 

//   2 
//     
unsigned char cw_dir[4]= 
{
0b00000001,
0b00000010,
0b00000100,
0b00001000
};

volatile unsigned char step_index, count_2, status;
volatile unsigned int ovftimes, step_limit;

//    0
ISR(TIMER0_OVF_vect)
{
static unsigned int count = 1;
count++;

if(count >= ovftimes) //  
{
cli(); //  

count_2++; //  - 

if(status) //  status = 1  
PORTB = cw_dir[step_index++];
else       //  
PORTB = 0x00;

if(step_index >= 4)
{
step_index = 0;
}

if(count_2 > step_limit) //  -    (step_limit)  
{
status = 0;
}

count = 0; //  
TCNT0 = 0; //    
sei(); //   
}
}

//    PB4
ISR(PB4_vect)
{
status = 1; //  
count_2 = 1;
}

int main(void)
{
DDRB = 0b00001111; // PB0, PB1, PB2, PB3 - 
PORTB = 0x00; // .   

// Disable Digital Input on PB4 (ADC2)
 DIDR0=0b00001000;

GICR |= (1 << PB4); //   
MCUCR |= (1 << ISC01); //     PB4

TCCR0 |= (1 << CS01); //   8
TCNT0 = 0; //    
TIMSK |= (1 << TOIE0); //     0

ovftimes = 100; //  

sei(); //   

while(1) 
{

step_limit = 8;

}
}
