2019. 11. 5. 11:55ㆍavr-atmega128
Flex sensor를 이용한 예제
#include <avr/io.h>
#include
#include <util/delay.h>
#include <avr/interrupt.h>
unsigned int adc_data;
float volt;
void Putch0(char data){
while(!(UCSR1A & 0x20));
UDR1 = data;
}
void Getch0(){
while(!(UCSR1A & 0x80));
return UDR1;
}
void UART_initialize(void){
UCSR1A=0x0;
UCSR1B=0b00011000;
UCSR1C=0b00000110;
UBRR1H=0;
UBRR1L=8;
}
ISR(ADC_vect, ISR_BLOCK){
adc_data=ADC; //data를 읽어옴
volt = (float)(adc_data/1023.0)*5;
printf("\n\r Interrupt ADC Data =%d, %1.3f[Volt]",adc_data,volt);
_delay_ms(100);
}
int main(void){
char adc_channel;
FILE *fp;
fp = fdevopen(Putch0,Getch0);
cli();
DDRA=0xff;
DDRF=0x00;
UART_initialize();
adc_channel=0;
ADMUX=0x40; //REFS1=0, REFS0=1->AVCC ADLAR=0->우측배열
ADCSRA=0x87; //ADC enable ,prescaler=clk/128
ADMUX |=adc_channel; //, MUX4:0=0b00000->ADC0출력 single ended input
ADCSRA |= 0x68; //Free running mode, ADSC=1->start conversion
printf("\n\r Test start");
sei();
while(1){}
}
'avr-atmega128' 카테고리의 다른 글
Analog To Digital Converter (0) | 2019.11.02 |
---|---|
16bit Timer/Counter (0) | 2019.10.25 |
8bit Timer/Counter (0) | 2019.10.25 |
외부인터럽트 (0) | 2019.10.22 |
직렬통신 (0) | 2019.10.18 |