/*****************************************************
Chip type               : ATtiny13A
AVR Core Clock frequency: 9,600000 MHz
*****************************************************/

#include <tiny13a.h>

#define s_step 376



unsigned char c;
flash unsigned char s_table [s_step/2]=
{0,2,4,6,8,10,12,14,16,18,21,23,25,27,29,31,33,35,37,39,41,
43,45,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,
86,88,90,92,94,96,98,100,102,104,105,107,109,111,113,115,117,119,120,122,124,
126,128,130,131,133,135,137,138,140,142,144,145,147,149,150,152,154,155,157,159,160,
162,164,165,167,168,170,171,173,174,176,177,179,180,182,183,185,186,187,189,190,192,
193,194,196,197,198,199,201,202,203,204,206,207,208,209,210,211,213,214,215,216,217,
218,219,220,221,222,223,224,225,226,227,227,228,229,230,231,232,232,233,234,235,235,
236,237,238,238,239,239,240,241,241,242,242,243,243,244,244,245,245,246,246,246,247,
247,247,248,248,248,249,249,249,249,250,250,250,250,250,250,250,250,250,250,250};

void t0_cfg()
{
 TCCR0A=0;
 TCCR0A=0; TCCR0A|=1<<COM0A1|1<<COM0B0|1<<COM0B1|1<<WGM00;
 TCCR0B=0;TCCR0B|=1<<CS00;
 TIMSK0|=1<<OCIE0A;
}
void ports_cfg()
{
 PORTB=0b11101000;
 DDRB =0b11100011;
}

interrupt [TIM0_COMPA] void timer0_compa_isr(void)
{
 static bit dir;
 
 if(!c)                                          
 {
 dir=1;c=1; 
 TCCR0A=0; TCCR0A|=1<<COM0A1|1<<COM0A0|1<<COM0B1|1<<WGM00;
 TIMSK0=0; TIMSK0|=1<<OCIE0B; 
 }
 else if((dir)&&(c<s_step/2-1)){OCR0A=s_table[c]; OCR0B=s_table[c]+4; c++;}
 else {c--; OCR0A=s_table[c]; OCR0B=s_table[c]+4; dir=0;}   
}

interrupt [TIM0_COMPB] void timer0_compb_isr(void)
{
 static bit dir;
 
 if(!c)                                          
 {
 dir=1;c=1; 
 TCCR0A=0; TCCR0A|=1<<COM0A1|1<<COM0B1|1<<COM0B0|1<<WGM00;
 TIMSK0=0; TIMSK0|=1<<OCIE0A;
 }
 else if((dir)&&(c<s_step/2-1)){OCR0B=s_table[c]; OCR0A=s_table[c]+4; c++;}
 else {c--; OCR0B=s_table[c]; OCR0A=s_table[c]+4; dir=0;}  
}


void main(void)
{
ports_cfg();
t0_cfg();



// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif
// Watchdog Timer Prescaler: OSC/2k
#pragma optsize-
WDTCR=0x18;
WDTCR=0x08;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

#asm("sei")

while (1)
      {      
       #asm("wdr")
      }
}
