summaryrefslogtreecommitdiff
path: root/n/avr
diff options
context:
space:
mode:
authorburg2005-04-02 23:38:02 +0000
committerburg2005-04-02 23:38:02 +0000
commit758187cf08f95b343756fcd803f9be05928802f3 (patch)
treec42ea6de153c154f0be242435753089cf417f3c6 /n/avr
parent97305fb8dc697a68e959a3367e3091039188cdc0 (diff)
Correction des erreurs
Diffstat (limited to 'n/avr')
-rw-r--r--n/avr/adc/adc.c55
-rw-r--r--n/avr/adc/test_adc.c5
2 files changed, 24 insertions, 36 deletions
diff --git a/n/avr/adc/adc.c b/n/avr/adc/adc.c
index d7b3581..1ebed72 100644
--- a/n/avr/adc/adc.c
+++ b/n/avr/adc/adc.c
@@ -21,6 +21,7 @@
* Email: <burg@efrei.fr>
* }}} */
#include "adc.h"
+#include "n/avr/utils/utils.h"
#include <avr/io.h>
#include <avr/signal.h>
@@ -33,66 +34,50 @@
# warning "adc: not tested on this chip."
#endif
+/* Different name on ATmega8535. */
+#if defined (__AVR_ATmega8535__)
+#define ADCSR ADCSRA
+#endif
/* +AutoDec */
/* -AutoDec */
-/* CONF:
- * 0x40 AVCC with external capacitor at AREF pin
- * 0xC0 Internal 2.56V Voltage Reference with external capacitor at AREF
- * pin
- */
-
-#define CONF 0xC0
-
/** Initialise adc. */
void
adc_init (void)
{
- ADMUX = CONF;
-#if defined (__AVR_ATmega8535__)
- ADCSRA = ADEN | 0x7;
-#else
- ADCSR = ADEN | 0x7;
-#endif
+ /* REFS = 01: AVCC with external capacitor at AREF pin.
+ * 11: Internal 2.56V Voltage Reference with external capacitor
+ * at AREF pin. */
+ ADMUX = regv (REFS1, REFS0, ADLAR, MUX4, MUX3, MUX2, MUX1, MUX0,
+ 1, 1, 0, 0, 0, 0, 0, 0);
+ /* Adc enabled. */
+ ADCSR = regv (ADEN, ADSC, ADATE, ADIF, ADIE, ADPS2, ADPS1, ADPS0,
+ 1, 0, 0, 0, 0, 0, 0, 0);
}
-/** Choose and start mesure on adc line */
+/** Choose and start mesure on adc line. */
void
adc_start (uint8_t d)
{
- // Choose adc
- ADMUX = CONF | ( d & 0x07);
+ /* Choose adc. */
+ ADMUX |= d & 0x07;
/* ADEN active l'adc
* ADSC demarre la mesure */
-#if defined (__AVR_ATmega8535__)
- ADCSRA |= ADSC;
-#else
- ADCSR |= ADSC;
-#endif
+ ADCSR |= _BV (ADSC);
}
-/** check on finish mesure */
+/** Return a value different of zero if finished. */
uint8_t
adc_checkf (void)
{
- // return != than zero when convertion is complete
-#if defined (__AVR_ATmega8535__)
- return ADCSRA & ADIF;
-#else
- return ADCSR & ADIF;
-#endif
+ return !(ADCSR & _BV (ADSC));
}
-/** Read mesure */
+/** Read mesure. */
uint16_t
adc_read (void)
{
-#if defined (__AVR_ATmega8535__)
- ADCSRA &= ~ADIF;
-#else
- ADCSR &= ~ADIF;
-#endif
return ADCW;
}
diff --git a/n/avr/adc/test_adc.c b/n/avr/adc/test_adc.c
index 6e7d420..407bc71 100644
--- a/n/avr/adc/test_adc.c
+++ b/n/avr/adc/test_adc.c
@@ -56,7 +56,10 @@ main (void)
/* Attente active sur adc jusqu'a ce que la valeur soit disponible
* */
- while (adc_checkf !=0);
+ while (adc_checkf() !=0)
+ {
+ rs232_putc ('.');
+ }
/*Lit la valeur puis l'envoit */
proto_send1w('m',adc_read());