로그인 | 회원가입 | 주문 조회
참고자료 [ADC, ATMEGA128 0번 2번 4번 채널] ICCAVR V7용 AD컨버터 소스
글쓴이 administrator 등록일 2012-02-23 조회 8,173

#include <iom128v.h>
#include <stdio.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 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;
}

void init_adc(int ch){
  DDRF = 0x00;
  ADCSRA = 0x0f;
  ADMUX = ch;
  ADCSRA = 0x8f;
}

void adch(int ch){
  ADMUX = ch;
}

void main(void){
     int i;
  int value;
 
  uart0_init();
  init_adc(0);
  
  while(1){
    for(i=0;i<3;i++){  
      adch(i*2);
      ADCSRA |= (0x01<<ADSC);   // ADC start
      value = ADCL;             // get ADCL
      value |= ADCH<<8;         // get ADCH 
      value &=0x03ff;           
      if(i==0){
          printf("\r\n");
      }   
      printf("D[%d]: %d  ",i*2,  value);    
    }
  }
}

다음글 [ADC, ATMEGA128] AD컨버터 소스 (ICCAVR V7)
이전글 #pragma comment 에 관하여