Write a snippet of C code that will enable the ADC to contin

Write a snippet of C code that will enable the ADC to continuously run as fast as possible and cause an interrupt after every conversion. Write only the initialization code using atmega328p?

Solution

#include<avr\\io.h>

#include<avr\\interrupt.h>

ISR(ADC_vect)

{

PORTD = ADCL; // give the low byte to PORTD

PORTB = ADCH; // give the high byte to PORTB

ADCSRA | =(1<<ADSC); // start conversion

}

int main (void)

{
DDRB = 0XFF; // make PORT B an output

DDRD = 0XFF; // make PORT D an output

DDRA = 0; // make PORT A an input

SEI(); enable interrupts

ADCSRA = 0X8F; // ck/128

ADMUX = 0XC0; right justified data

ADCSRA | = (1<<ADSC); // start conversion

WHILE(1); wait forever

RETURN 0;

}

Write a snippet of C code that will enable the ADC to continuously run as fast as possible and cause an interrupt after every conversion. Write only the initial

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site