programming register coding

void setup() {
// put your setup code here, to run once:
//for clearing the bit use & and for setting use |(or)
ADMUX = (1<<REFS0);//referance is zero
ADMUX &=(~(1<<ADLAR));//left adjust
ADCSRA |=(1<<ADEN)| (1<<ADPS1) | (1<<ADPS0);// adc enable auto trigger prescalar
ADCSRA &=(~(1<<ADPS2)) & (~(1<<ADATE)) ;
ADCSRA |=(1<<ADSC);//star conversion
ADMUX &=(~(1<<MUX3))&(~(1<<MUX2))&(~(1<<MUX1))&(~(1<<MUX0));//pin no.
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
long x;
x=ADCL;
Serial.println(x);

}

this is my code i am learning register level coding spent whole sunday but couldnot get desiered output

I am readin a0 pin using this code it gives me 0 whereas if i program it normal it gives me different out and this output is satisfactory can u help me in decoding above code

THANKS ALOT

ADCSRA  = ((1<<ADPS2) | (1<<ADATE)) ;   // this sets the two bits and zeros everything else

ADCSRA |= ((1<<ADPS2) | (1<<ADATE)) ;   // this sets the individual bits

ADCSRA &= ~((1<<ADPS2) | (1<<ADATE)) ; // this clears the individual bits
/*
 *   setup and read ADC similar to Arduino
 */ 
 
void adcInit()                           // m328p
{
  ADCSRB  = 0;
  ADMUX   = ( 1<<REFS0 );                // Vref = Vcc 
  // enable adc, prescale=128(freq=125k@16MHz)
  ADCSRA  = ( ( 1<<ADEN ) | ( 1<<ADPS2 ) | ( 1<<ADPS1 ) | ( 1<<ADPS0 ) );
} // adcInit

int16_t readAdc( uint8_t adcChan )       // m328p, 0..5 == A0..A5
{
  if( adcChan > 5 ) return -1;           // out of range
  ADMUX  |= ( adcChan );	               // set adc chan 
  ADCSRA |= ( 1<<ADSC );                 // start conversion
  while ( ADCSRA & ( 1 << ADSC ) );      // wait for conversion end, <1ms
  return ADC;                            // return result 
} // readAdc

void setup()
{
  Serial.begin( 9600 );
  Serial.println ( __FILE__ );
  adcInit();
} // setup

void loop()
{
  Serial.print( "ADC = " );
  Serial.println( readAdc( 0 ) );         // read A0
  delay( 1000 );
} // loop
void setup() {
//    :
   ADCSRA &=(~(1<<ADPS2)) &  (~(1<<ADATE)) ;
   ADCSRA |=(1<<ADSC);//star conversion
//    :
}

void loop() {
  x=ADCL;
  Serial.println(x);
}

Without checking whether all the other bits are correct or not, you have NOT set the ADC into “free running” mode, so you’d need to do a “start conversion” and “wait for conversion to complete” each time you want to read the results.

ADCSRA &=(~(1<<ADPS2)) &  (~(1<<ADATE)) ;

I think that that works out to be technically correct, but I’d much rather see it written as:

ADCSRA &= ~ ((1<<ADPS2) | (1<<ADATE)) ;