Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 16000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- #include "OLEDLib.h"
- char adcO0[] = "O0: xxx ";
- char adcP0[] = "P0: xxx ";
- int readKnobO0 = 0;
- int readKnobP0 = 0;
- void startRead()
- {
- ADCSRA |= (1 << ADSC); //this moves the read instruction bit to the ADC Register.
- }
- void initADC()
- {
- DDRE = 0B00111000; //external MUX pins are E 5, 4, and 3. We'll not be using these for this test.
- PORTE = 0; //we make sure that all pins on this port are low, so mux is for sure at 0.
- ADCSRA = (1 << ADEN) | (1 <<ADPS2) | (1 << ADPS1) | (1 << ADPS0); //changing the pre-scaler from 128 to 0 doesn't seem to have any effect.
- ADCSRB = (1 << MUX5); // we're only reading the bottom registers for now.
- DIDR0 = 0xff; // we should set this register to all 1s, so there is no digital input triggering.
- DIDR2 = 0xff;
- ADMUX = 0B00000000;//we want to start at input 1, and use external reference reading ADC 8.
- startRead(); // do first read, should take 25 clock cycles.
- }
- int main(void)
- {
- initADC();
- initScreen();
- /* Replace with your application code */
- while (1)
- {
- //ADMUX = 0B00000000;
- _delay_us(125);
- startRead();
- readKnobO0 = (ADC >> 2);
- numPrinter(adcO0, 4, 3, readKnobO0);
- outputS(adcO0, 0);
- ADMUX = 0B00000001;
- startRead();
- uint8_t trash = ADC;
- _delay_us(125);
- startRead();
- readKnobP0 = (ADC >> 2);
- numPrinter(adcP0, 4, 3, readKnobP0);
- outputS(adcP0, 1);
- ADMUX = 0B00000000;
- startRead();
- trash = ADC;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement