//ICC-AVR application builder : 2008-10-02  2:40:16
// Target : M8
// Crystal: 8.0000Mhz

#include <iom8v.h>
#include <macros.h>
#include <stdio.h>

void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
}

//UART0 initialize
// desired baud rate: 4800
// actual: baud rate:4808 (0.2%)
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = BIT(URSEL) | 0x06;
 UBRRL = 0x67; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x18;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 uart0_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

// printf Լ  ߰ .
int putchar(char c)
{
    while (((UCSRA>>UDRE)&0x01) == 0) ;  // UDRE, data register empty
        
    UDR = c;
    return c;
}

// scanf Լ  ߰ .
int getchar(void)
{
    while ((UCSRA & 0x80) == 0);
    return UDR;
}


//
void main(void)
{
 init_devices();
 //insert your functional code here...
 
 while(1){
 	printf(".");
 }
}

