upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

analog.h 923B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef _analog_h_included__
  2. #define _analog_h_included__
  3. #include <stdint.h>
  4. void analogReference(uint8_t mode);
  5. int16_t analogRead(uint8_t pin);
  6. int16_t adc_read(uint8_t mux);
  7. #define ADC_REF_POWER (1<<REFS0)
  8. #define ADC_REF_INTERNAL ((1<<REFS1) | (1<<REFS0))
  9. #define ADC_REF_EXTERNAL (0)
  10. // These prescaler values are for high speed mode, ADHSM = 1
  11. #if F_CPU == 16000000L
  12. #define ADC_PRESCALER ((1<<ADPS2) | (1<<ADPS1))
  13. #elif F_CPU == 8000000L
  14. #define ADC_PRESCALER ((1<<ADPS2) | (1<<ADPS0))
  15. #elif F_CPU == 4000000L
  16. #define ADC_PRESCALER ((1<<ADPS2))
  17. #elif F_CPU == 2000000L
  18. #define ADC_PRESCALER ((1<<ADPS1) | (1<<ADPS0))
  19. #elif F_CPU == 1000000L
  20. #define ADC_PRESCALER ((1<<ADPS1))
  21. #else
  22. #define ADC_PRESCALER ((1<<ADPS0))
  23. #endif
  24. // some avr-libc versions do not properly define ADHSM
  25. #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  26. #if !defined(ADHSM)
  27. #define ADHSM (7)
  28. #endif
  29. #endif
  30. #endif