21.08.2013 Views

Embedded Systems Design with the Atmel AVR Microcontroller Part II

Embedded Systems Design with the Atmel AVR Microcontroller Part II

Embedded Systems Design with the Atmel AVR Microcontroller Part II

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8.4. CIRCUIT DIAGRAM 259<br />

unsigned int binary_weighted_voltage, binary_weighted_voltage_low;<br />

unsigned int binary_weighted_voltage_high;//weighted binary voltage<br />

ADMUX = channel; //Select channel<br />

ADCSRA |= 0x43; //Start conversion<br />

//Set ADC module prescalar<br />

//to 8 critical for<br />

//accurate ADC results<br />

while (!(ADCSRA & 0x10)); //Check if conversion is ready<br />

ADCSRA |= 0x10;<br />

//Clear conv rdy flag - set <strong>the</strong> bit<br />

binary_weighted_voltage_low = ADCL;<br />

//Read 8 low bits first (important)<br />

//Read 2 high bits, multiply by 256<br />

binary_weighted_voltage_high = ((unsigned int)(ADCH

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!