#include <avr/io.h>
#include <avr/interrupt.h>

unsigned WaitCounter = 0;
uint8_t iHzCounter = 0;
uint8_t beepCounter = 0;
uint8_t ReadyLightStatus = 0;
uint8_t beepUBeep = 0;



ISR(TIMER0_COMP_vect)
{
    PORTB |= 0x80;
    PORTB ^= 0x01;
    iHzCounter++;
    beepCounter++;

    if (beepCounter > 50) {
	beepCounter = 0;
	if (beepUBeep == 0) {
	    beepUBeep = 1;
	    PORTB |= 0x02;
	} else {
	    beepUBeep = 0;
	    PORTB &= ~0x02;
	}
    }
    if (iHzCounter >= 125) {	//т.е. 1 мсек
	iHzCounter = 0;
	WaitCounter++;
	if (WaitCounter >= 500)	{ //т.е. каждые 500 мсек
	    WaitCounter = 0;
	    if (ReadyLightStatus == 1) {
		PORTB |= 0x04;
		ReadyLightStatus = 0;
	    } else {
		PORTB &= ~0x04;
		ReadyLightStatus = 1;
	    }
	}
    }
    PORTB &= ~0x80;
}


int main(void)
{
    DDRB = 0x8F;
    ASSR = 0x00;
    TCCR0 = 0x04 | (1 << WGM01);
    TCNT0 = 0x00;
    OCR0 = 0;
    TIMSK = (1 << OCIE0);
    sei();
    for (;;);
}
