• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC not working | ATMEGA16A | C++ AVRStudio

Thread starter #1
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;
}
 
Thread starter #2
any one????? please help me out.
 

misterT

Well-Known Member
Most Helpful Member
#4
Thread starter #5

Latest threads

EE World Online Articles

Loading

 
Top