//ICC-AVR application builder : 30.10.2007 12:02:13
// Target : M128
// Crystal: 11.059Mhz

#include <iom128v.h>
#include <macros.h>

void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x00;
 PORTB = 0xe0;
 DDRB  = 0xe0;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0xe0;
 PORTE = 0x00;
 DDRE  = 0x00;
 PORTF = 0x00;
 DDRF  = 0x00;
 PORTG = 0x00;
 DDRG  = 0x18;
}

//TIMER0 initialize - prescale:8
// WGM: Normal
// desired value: 32KHz
// actual value: 32,148KHz (0,5%)
void timer0_init(void)
{
 
 TCCR0 = 0x00; //stop
 ASSR  = 0x00; //set async mode
 TCNT0 = 0xCE; //set count
 OCR0  = 0x32;
 TCCR0 = 0x02; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
 //TCNT0 = 0xD5; //reload counter value
 int tmp;
PORTB|=0b11100000;

tmp=10;
while(tmp--);

PORTB|=0b11100000;
PORTB&=~(0b00100000);//200 ns


tmp=120;
while(tmp--){}
PORTB&=~(0b01100000);

tmp=50;
while(tmp--){}; 
 
 
 PORTB&=~(0b11100000);

}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x00; //external memory
 port_init();
 timer0_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EICRB = 0x00; //extended ext ints
 EIMSK = 0x00;
 TIMSK = 0x01; //timer interrupt sources
 ETIMSK = 0x00; //extended timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

//
void main(void)
{
 init_devices();
 //insert your functional code here...
 while(1);
}

