Advertisement
halfordC

Untitled

Aug 13th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #define F_CPU 16000000UL
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4. #include "OLEDLib.h"
  5.  
  6. char adcO0[] = "O0: xxx             ";
  7. char adcP0[] = "P0: xxx             ";
  8. int readKnobO0 = 0;
  9. int readKnobP0 = 0;
  10.  
  11.  
  12. void startRead()
  13. {
  14.     ADCSRA |= (1 << ADSC); //this moves the read instruction bit to the ADC Register.
  15. }
  16. void initADC()
  17. {
  18.     DDRE = 0B00111000; //external MUX pins are E 5, 4, and 3. We'll not be using these for this test.
  19.     PORTE = 0; //we make sure that all pins on this port are low, so mux is for sure at 0.
  20.    
  21.     ADCSRA = (1 <<  ADEN) | (1 <<ADPS2) | (1 << ADPS1) | (1 << ADPS0); //changing the pre-scaler from 128 to 0 doesn't seem to have any effect.
  22.     ADCSRB = (1 << MUX5); // we're only reading the bottom registers for now.
  23.     DIDR0 = 0xff; // we should set this register to all 1s, so there is no digital input triggering.
  24.     DIDR2 = 0xff;
  25.     ADMUX = 0B00000000;//we want to start at input 1, and use external reference reading ADC 8.
  26.     startRead(); // do first read, should take 25 clock cycles.
  27. }
  28.  
  29. int main(void)
  30. {
  31.     initADC();
  32.     initScreen();
  33.    
  34.     /* Replace with your application code */
  35.     while (1)
  36.     {
  37.         //ADMUX = 0B00000000;
  38.         _delay_us(125);
  39.         startRead();
  40.         readKnobO0 = (ADC >> 2);
  41.         numPrinter(adcO0, 4, 3, readKnobO0);
  42.         outputS(adcO0, 0);
  43.        
  44.         ADMUX = 0B00000001;
  45.         startRead();
  46.         uint8_t trash = ADC;
  47.         _delay_us(125);
  48.         startRead();
  49.         readKnobP0 = (ADC >> 2);
  50.         numPrinter(adcP0, 4, 3, readKnobP0);
  51.         outputS(adcP0, 1);
  52.        
  53.         ADMUX = 0B00000000;
  54.         startRead();
  55.         trash = ADC;
  56.        
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement