Created
April 10, 2014 04:20
-
-
Save brightcloudy/10342266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
int main(void) { | |
cli(); // disable interrupts for prescaler set | |
CLKPR = (1 << CLKPCE); // set prescaler 1x | |
CLKPR = 0; | |
sei(); | |
DDRD |= (1 << 0) | (1 << 1); //portd0 portd1 output | |
PORTD &= ~(1 << 0); //ensure portd0 low | |
DDRB |= (1 << 1); //portb1 (ocr1a) output | |
PRR &= ~(1 << PRADC); //ensure adc power is on | |
ADCSRA |= (1 << ADEN) | (1 << ADIE) | (1 << ADATE); //adc interrupt | |
ADCSRB = 0; //free running mode | |
ADMUX = 0; //zero admux to ensure selection of adc0 | |
ADMUX |= (1 << ADLAR) | (1 << REFS0); //left-adjust adc result | |
ADCSRA |= (1 << ADSC); //start conversion | |
TCCR1A |= (1 << COM1A0); //ocr1a compare on toggle | |
OCR1A = 1024; | |
TCCR1B |= (1 << CS10) | (1 << WGM12); //timer1 ctc mode /1 scale | |
for (;;) { | |
} | |
} | |
ISR(ADC_vect) { | |
OCR1A = ADCH; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment