Hi all,
My current ADC configuration is such that ADLJST=0, that is ADC0H[3:0]:ADC0L[7:0]. What should I do to my code (underlined bold) below to handle both ADC0H and ADC0L ?
Thank you.
/*------------------ // ADC Conversion -------------------*/ void adcdata() { ADCINT = 0; value=0; ADBUSY = 1; ldelay(100); while(ADCINT==0); //Is conversion complete ? value = ADC0H; ldelay(900); ldelay(1000); ADCINT=0; ADBUSY=0; } /*------------------------------------------------------ // Bit Resolution: result = Voltage reference*(4095/4096) -------------------------------------------------------*/ void bit_resolution() { bit_value = 3/(4096); result = value*bit_value; } //----------------------------------------------------------------------------- // Conversion //----------------------------------------------------------------------------- void one() /*convert 1st value A.xxx */ { temp=result; temp = temp%10; a = temp+48; } void dec1() /*convert 1st decimal place value x.Bxx */ { temp=result*10; temp = temp%10; b = temp+48; } void dec2() /*convert 2nd decimal place value x.xCx */ { temp = result*100; temp = temp%10; c = temp+48; } void dec3() /*convert 3rd decimal place value x.xxD */ { temp = result*1000; temp = temp%10; d = temp+48; } void convert_all() { one(); dec1(); dec2(); dec3(); } void displayD() /* display 3 digit number */ { RS = 1; P3 = a; enable(); print(0x2E); /*display ".", ASCII code is 2E for "."*/ P3 = b; enable(); P3 = c; enable(); P3 = d; enable(); } /*------------------ // Display result -------------------*/ void result_dsp() { bit_resolution(); convert_all(); displayD(); } //----------------------------------------------------------------------------- // MAIN Routine //----------------------------------------------------------------------------- void main() { config(); lcdinit(); //Initialize LCD ADCEN = 1; //Enable ADC ldelay(5000); lcd_command(0x80); //LCD command to display on the first line voltage(); //Display "Voltage=" lcd_command(0x02); //LCD command to return the cursor home lcd_command(0xC0); //LCD command to display on the second line adcdata(); result_dsp(); print(0x56); //Display "V" ldelay(5000); }