#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);
}
}
}