This commit is contained in:
Christoph J. Scherr 2023-12-09 14:38:14 +01:00
parent c5bc169461
commit d21ee49106
1 changed files with 4 additions and 4 deletions

View File

@ -5,13 +5,13 @@
#include <util/delay.h>
void adc_init() {
DDRC=0x0; // does not exist but is default?
ADCSRA = (1<<ADEN)|(1<<ADPS1)|(1<<ADPS2);
ADMUX = (1<<REFS0);
DDRC=0x0; // read from port c
ADCSRA = (1<<ADEN)|(1<<ADPS1)|(1<<ADPS2); // magic enable adc
ADMUX = (1<<REFS0); // magic enable multiplexer
}
uint16_t adc_read(uint8_t channel) {
ADMUX &= 0xf0; // max channel?
ADMUX |= (channel & 0x0f); // select channel
ADMUX |= (channel & 0x0f); // select channel, max 2^4?
ADCSRA |= (1<<ADSC); // interrupt enable
while((ADCSRA&(1<<ADIF))==0); // wait for something
return ADCL + (ADCH << 8); // read