AVR A/D example.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 2: | Riadok 2: | ||
#include <avr/io.h> | #include <avr/io.h> | ||
void adc_init(void); // A/D converter initialization | |||
void adc_init(void); | |||
int main(void) | int main(void) | ||
{ | { | ||
unsigned int buffer; | |||
adc_init(); // Init A/D converter | |||
while (1) | |||
{ | |||
ADCSRA |= (1<<ADSC); // Start A/D conversion | |||
while ( !(ADCSRA & (1<<ADIF)) /* Do nothing */ ; // Wait until AD not finished | |||
buffer = (ADCH<<8) | ADCL; // Then, read result | |||
} | |||
} | |||
void adc_init(void) // A/D converter initialization | |||
void adc_init(void) | |||
{ | { | ||
ADMUX = 0; // Ref: external, Channel 0 (ADC0) | |||
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1); // A/D ON, prescaler = 64, | |||
SFIOR = 0; // Specialfunctions OFF | |||
} | } | ||
</source> | </source> |
Verzia z 23:04, 30. november 2008
#include <avr/io.h>
void adc_init(void); // A/D converter initialization
int main(void)
{
unsigned int buffer;
adc_init(); // Init A/D converter
while (1)
{
ADCSRA |= (1<<ADSC); // Start A/D conversion
while ( !(ADCSRA & (1<<ADIF)) /* Do nothing */ ; // Wait until AD not finished
buffer = (ADCH<<8) | ADCL; // Then, read result
}
}
void adc_init(void) // A/D converter initialization
{
ADMUX = 0; // Ref: external, Channel 0 (ADC0)
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1); // A/D ON, prescaler = 64,
SFIOR = 0; // Specialfunctions OFF
}