We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I am currently trying to modify an existing code to display 12 bit data (C8051F206) instead of 8 bit data (C8051F226).
When I download the existing codes and run the program, my LCD is able to display some values. However, when I modify the program to display 12 bit data, the LCD just show 0.000V when I adjusted the ADC input. May I know what is different in the ADC configuration that I have to change ? What is wrong with my 12 bit code?
8-bit code:
//----------------------------------------------------------------------------- // Global CONSTANTS //----------------------------------------------------------------------------- unsigned int q,value,temp; unsigned char a,b,c,d; float bit_value,result; /*------------------ // ADC Conversion -------------------*/ void adcdata() { ADCINT = 0; ADBUSY = 1; ldelay(100); while(ADCINT==0); value = ADC0L; value = value*256; ldelay(900); ldelay(1000); ADCINT=0; ADBUSY=0; } /*------------------------------------------------------ // Bit Resolution: result = Voltage reference*(255/256) -------------------------------------------------------*/ void bit_resolution() { bit_value = 3.2/(256); result = value*bit_value; }
My 12 bit code (Left justified ADCOH:ADCOL):
//----------------------------------------------------------------------------- // Global CONSTANTS //----------------------------------------------------------------------------- unsigned int q,value,value1,temp,totvalue; unsigned char a,b,c,d,e; /*------------------ // ADC Conversion -------------------*/ void adcdata() { ADCINT = 0; value=0; ADBUSY = 1; ldelay(100); while(ADCINT==0); value = ADC0L; e= 0x0F & ADC0H; value1=e; totvalue= value + value1*256; ldelay(900); ldelay(1000); ADCINT=0; ADBUSY=0; } Appreciate if anyone could help. Thanks!!
Hey thanks!
It was my mistake in the syntax. You are right about the float issue. Also, my analog input pin was faulty. After I reconfigured another pin as input, it worked.