Advertisement
martin2250

Untitled

Nov 17th, 2013
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <avr/io.h>;
  2. #include <avr/interrupt.h>
  3.  
  4. const unsigned char PS_16 = (1 << ADPS2);
  5. const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
  6. const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
  7. const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
  8.  
  9.  
  10.  
  11. void setup()
  12. {
  13.   Serial.begin(1000000);
  14.  // pinMode(A0, INPUT);
  15.  
  16.  
  17.   ADCSRA &= ~PS_128;
  18.   ADCSRA |= PS_16;
  19.  
  20.  
  21.   ADMUX |= (1 << REFS0);
  22.   ADMUX |= (1 << ADLAR); // Left adjust ADC result to allow easy 8 bit reading
  23.  
  24.   // No MUX values needed to be changed to use ADC0
  25.  
  26.   ADCSRA |= (1 << ADIE);  // Enable ADC Interrupt
  27.  
  28.   TCCR0A = 0;
  29.   TCCR0B = 0;
  30.  
  31.   ADCSRA |= (1 << 5);  // Set ADC to Free-Running Mode
  32.   ADCSRA |= (1 << ADEN);  // Enable ADC
  33.   ADCSRA |= (1 << ADSC);  // Start A2D Conversions  
  34.   while(true);
  35.    // Serial.write(analogRead(A0)>>2);
  36. }
  37.  
  38. ISR(ADC_vect)
  39. {
  40.   Serial.write(ADCH);
  41. }
  42.  
  43. void loop()
  44. {
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement