ADC not working | ATMEGA16A | C++ AVRStudio

ikelectro

Member
Here is the code below. the code does not working with my hardware but with the same hardware ASM code is working. The result always same in C++.
Code:
/*



#define F_CPU 4000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>


int main(void)
{   DDRB = 0xFF;            //PORTB AS OUT PUT
    DDRA =0;                //PORTA AS INPUT OF ADC
    ADCSRA = 0x87;        //initiazing ADC   
    ADMUX = 0xC0;
 
       
    _delay_ms(2000);    //delay for 2seconds
   
   
    while(1)
    {
    ADCSRA |=1<<ADSC;
    while (( ADCSRA&(1<<ADIF))==0);
   
    int z = ADCL;
    _delay_ms(20);        //delay for 20mili seconds
   
    int x = z%10;
    PORTB = 12;
    _delay_ms(1000);
    PORTB = x;            //3rd digit
    _delay_ms(1000);
   
    int a=z/10;
     unsigned short int b=a%10;
    PORTB = 13;
    _delay_ms(1000);   
    PORTB = b;            //2nd digit
    _delay_ms(1000);
   
unsigned short int c =a/10;
    PORTB =14;
    _delay_ms(1000);
    PORTB = c;            //1st digit
    _delay_ms(15000);
    
      }
      return 0;
}
 
any one????? please help me out.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…