]> www.fi.muni.cz Git - bike-lights.git/commitdiff
ADC experiments
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 8 Jun 2012 16:43:08 +0000 (18:43 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 8 Jun 2012 16:43:08 +0000 (18:43 +0200)
lights.c

index 0bedc53e2e059f070a82bdcee6e00381adeca255..49bf4ce6e23f3219f4371bb7119944325d2e8b30 100644 (file)
--- a/lights.c
+++ b/lights.c
@@ -2,7 +2,7 @@
 #include <avr/eeprom.h>
 #include <util/delay.h>
 
-char dbg[5] __attribute__((section(".eeprom")));
+uint16_t adcval EEMEM;
 
 int main(void)
 {
@@ -15,12 +15,15 @@ int main(void)
        DDRB |= _BV( PB5 );
        PORTB &= ~_BV( PB5 );
 
+       ADCSRA = _BV(ADEN) | _BV(ADATE) | _BV(ADPS1) | _BV(ADPS0);
+       ADMUX = _BV(REFS1) | _BV(MUX0);
+       ADCSRB = _BV(REFS2);
+       DIDR0 = _BV(ADC1D) | _BV(AREFD);
+
+       ADCSRA |= _BV(ADSC);
        _delay_ms(1000);
-       eeprom_write_byte(&dbg[0], TCNT1);
-       eeprom_write_byte(&dbg[1], OCR1C);
-       eeprom_write_byte(&dbg[2], OCR1D);
-       eeprom_write_byte(&dbg[3], TIFR);
-       eeprom_write_byte(&dbg[4], TCCR1B);
+       eeprom_write_word(&adcval, ADCW);
+
     DDRA |= _BV( PA0 );
     while( 1 ) { 
         PORTA |=  _BV( PA0 );