AVR A/D example.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Nová stránka: #include <avr/io.h> →Analog/Digital Wandler initialisieren: void adc_init(void); int main(void) { unsigned int buffer; →A/D - Wandler initialisieren: adc_init(); w... |
Bez shrnutí editace |
||
(5 medziľahlých úprav od rovnakého používateľa nie je zobrazených.) | |||
Riadok 1: | Riadok 1: | ||
Jednoduchý prevod na vyžiadanie: | |||
<source lang="c"> | |||
#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))); // Wait until AD not finished | |||
buffer = ADC; // Then, read result (ADCH<<8) | ADCL) | |||
} | |||
} | |||
void adc_init(void) // A/D converter initialization | |||
{ | |||
ADMUX = 0b01000100; // Ref: external, Channel 4 (ADC4) - NTC | |||
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // =0b10000111, A/D ON, prescaler = 128 | |||
} | |||
</source> | |||
[[A/D_prevodník|Návrat na cvičenie...]] | |||
[[Category: AVR]][[Category: MIPS]][[Category: CAD_RS]] | |||
Aktuálna revízia z 07:38, 15. apríl 2021
Jednoduchý prevod na vyžiadanie:
#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))); // Wait until AD not finished
buffer = ADC; // Then, read result (ADCH<<8) | ADCL)
}
}
void adc_init(void) // A/D converter initialization
{
ADMUX = 0b01000100; // Ref: external, Channel 4 (ADC4) - NTC
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); // =0b10000111, A/D ON, prescaler = 128
}