Hi, I am using AT89C4051 to utilize it as an AD Converter for an application as a two digit Voltmeter. I am following the circuit design given in the following address: httpp://http://www.atmel.com/dyn/resources/prod_documents/DOC0524.PDF . I have written a code in C (modified) and it does not work. It would be very helpful if someone were to help me if there are any mistakes in my code. My code is: #include<AT89x051.h> #define TON 79; #define TOFF 79; unsigned int ta,tb; void delay(int count); char a[10]={0x07,0x17,0x27,0x37,0x47,0x57,0x67,0x77,0x87,0x97}; char b[10]={0x0B,0x1B,0x2B,0x3B,0x4B,0x5B,0x6B,0x7B,0x8B,0x9B}; scanled(); void main(void) { int td,tc,m; tc=TON; td=TOFF while(1){ P3_7=1; for(m=0;m<tc;m++){ if(P3&0x40==0) ta++; } delay(3); P3_7=0; for(m=0;m<td;m++){ if(P3&0x40==1) tb++; } tb=tb+td; delay(3); scanled(); } } scanled(){ unsigned int i,flag=0,j; static unsigned int k,h; k=ta; h=tb; if(tb==0){ for(i=0;i<2;i++){ flag=1-flag; if(flag==1){ P1=a[(k)/10]; for(j=0;j<32000;j++); P1=0xFF; } if(flag==0){ P1=b[(k)%10]; for(j=0;j<32000;j++); P1=0xFF; } } } else if(ta==0){ for(i=0;i<2;i++){ flag=1-flag; if(flag==1){ P1=a[(h)/10]; for(j=0;j<32000;j++); P1=0xFF; } if(flag==0){ P1=b[(h)%10]; for(j=0;j<32000;j++); P1=0xFF; } } } } void delay(int count) { int j,l; for(j=0;j<= count;j++) { for (l=0;l<=120;l++); } } Please do note that i am not using the lookup table. That is why i did not include that in my code. I just want to know the number of counts. From the number of counts, i could refer to the lookup table manually and get the voltage output. Really do appreciate your help. Thank you.
does not show the input voltage as it is supposed to WHAT does it show? Erik