// A to D test code // NOTE -- You MUST MOUNT the Aref jumper #include #include //I like these definitions #define begin { #define end } signed char Ain ; //raw A to D number float Vcc = 4.95; //Vref float gain = 10; //A/D converter diffamp gain void main(void) begin //init the A to D converter // left adj /EXTERNAL Aref //!!!CONNECT Aref jumper!!!! // 10*(chan1 - chan0) ADMUX = 0b00101001; //enable ADC and set prescaler to 1/128*16MHz=125,000 //and clear interupt enable //and start a conversion ADCSR = 0b11000111; //init the UART UCSRB = 0x18; UBRRL = 103; printf("starting...\n\r"); // measure and display loop while (1) begin //get the sample Ain = ADCH; //start another conversion ADCSR.6=1; //results to hyperterm //for differential inputs the number of effective bits is //dropped because of the sign bit. // Therefore, divide the ADC value by 128 rather than 256 //also divide by the ADC differential amp gain printf("%f\n\r",(float)Ain/128.0*Vcc/gain); end end