AVR A/D example.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 27: | Riadok 27: | ||
} | } | ||
</source> | </source> | ||
[[CADRS Cvičenie 11|Návrat na cvičenie 11...]] | |||
[[Category: AVR]][[Category: CAD_RS]] |
Verzia z 20:10, 1. december 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
}