로그인 | 회원가입 | 주문 조회
참고자료 스트링을 받아서 비교하여 사용하기
글쓴이 administrator 등록일 2012-02-22 조회 7,974

//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;
 }
 }
}

다음글 atmega2560 서보예제 (ICCAVR V7)
이전글 AD-JTAG V1.1 입니다.