#include <io2313.h>
#include <interrupt.h>
#include <sig-avr.h>

/**** function prototype ****/
void PortInit(void);
/* led utilize routine */
#define LedOn() cbi(PORTB,PB0)
#define LedOff() sbi(PORTB,PB0)

unsigned char LedState = 0;

/* timer utilize routine */
void TMR0Init(void);

/**** main function ****/
int main(void)
{
	PortInit();
	TMR0Init();
	
	sei();	/* enable grobal interrupt */
	
	while(1){
		
	}
	
}

/**** interrupt function ****/
SIGNAL(SIG_OVERFLOW0)
{
	if(LedState == 0){
		LedOn();
		LedState = 1;
	}else{
		LedOff();
		LedState = 0;
	}
}

/**** sub functions ****/
void TMR0Init(void)
{
	outp(0,TCNT0);	/* clear CNT0 */
	outp(5,TCCR0);		/* set prescaler CK/1024 */
	outp(inp(TIMSK)|BV(TOIE0),TIMSK);	/* enable TMR0 interrupt */
}

void PortInit(void)
{
	outp(0x01,DDRB);
}
