title: ATmega16 ADC Code not working
body: <pre><code>#define F_CPU 1000000UL
  #include &lt;avr/io.h&gt;
  
  volatile uint8_t adcvalue;
  
  
  int main(void)
  {
      DDRA =0x00;
      DDRC = 0xff;
  
  // enable adc
      ADCSRA |= (1&lt;&lt;ADEN);
  // using division factor 8
      ADCSRA |= (1&lt;&lt;ADPS0) | (1&lt;&lt;ADPS1);
  
  // enable 8 bit conversion
      ADMUX |= (1&lt;&lt;ADLAR);
  // take input from PA0
      ADMUX |= (1&lt;&lt;MUX0);
  
      while (1)
      {
          // Start conversion
          ADCSRA |= (1&lt;&lt;ADSC);
  
          // wait until conversion is done
          while (ADCSRA &amp; (1&lt;&lt;ADSC));
  
          // save result to adcvalue
          adcvalue = ADCH;
  
          // show result on 8 leds connected to PORT C
          PORTC = adcvalue;       
      }
      return 0;
  }
  </code></pre>
  
  <p>The above code shall take analog value from PA0 (using potentiometer) and show digital value on 8 leds connected to PORT C. When I simulate the circuit on Proteus the leds are always on even when I change the potentiometer value and there is a message saying "[AVR AD CONVERTER]Reference Value = 0".</p>
  
  <p>Appreciate if you can help me know what is wrong.</p>