Nguyên văn bởi vubac2006
Code chỗ chọn kênh ADC cho mình xem giúp được không. Mình chủ yếu viết bằng WinAVR.
- À, bạn cố gắng gõ có dấu nhé.
#include <avr/io.h>
#include <avr/interrupt.h>
#include <compat/deprecated.h>
#include <util/delay.h>
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 1
#define ADC_VREF_TYPE 0x20
ISR(TIMER0_OVF_vect)//dinh thoi 1ms lay mau mot lan
{
TCNT0 = 0x43;
sbi(ADCSRA,ADSC);
}
unsigned char input_index;
unsigned int adc_data[2];
ISR(ADC_vect)
{
adc_data[input_index]=ADCW;
//do something
// Select next ADC input
if (++input_index <= (LAST_ADC_INPUT-FIRST_ADC_INPUT))
{
ADMUX=(FIRST_ADC_INPUT|ADC_VREF_TYPE)+input_index;//chuyen den kenh ke tiep
// Delay needed for the stabilization of the ADC input voltage
_delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
}
else
{
input_index=0;//reset kenh chuyen doi
ADMUX=(FIRST_ADC_INPUT|ADC_VREF_TYPE) + input_index;
}
}
Comment