//ICC-AVR application builder : 2012-02-22 오전 9:20:28
// Target : M128
// Crystal: 16.000Mhz
#include <iom128v.h>
#include <macros.h>
#include <stdio.h>
#include <string.h>
// printf 함수 사용시 추가할 것.
int putchar(char c)
{
while (((UCSR0A>>UDRE0)&0x01) == 0) ; // UDRE, data register empty
UDR0 = c;
return c;
}
// scanf 함수 사용시 추가할 것.
int getchar(void)
{
while ((UCSR0A & 0x80) == 0);
return UDR0;
}
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
PORTE = 0x00;
DDRE = 0x00;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x00;
DDRG = 0x00;
}
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x67; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0x18;
}
//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();
uart0_init();
MCUCR = 0x00;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//
void main(void)
{
unsigned char ch[3];
unsigned char str[3]={0,0,0};
init_devices();
//insert your functional code here...
DDRG = 0x03;
while(1){
scanf("%s",ch);
if(strcmp(ch,"abc")==0){
printf("ABC");
PORTG = 0x01;
}
if(strcmp(ch,"def")==0){
printf("DEF");
PORTG = 0x02;
}
}
}