vinash
Member level 2
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:
h**p://www.atmel.com/dyn/resources/prod_documents/DOC0524.PDF .
I have written a code in C 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;
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^6==0)
ta++; }
P3_7=0;
for(m=0;m<tb;m++){
if(P3^6==1)
tb++;
}
scanled();
}
}
scanled(){
unsigned int i,flag,j;
if(tb==0){
for(i=0;i<2;i++){
flag=1-flag;
if(flag==1){
P1=a[(ta)/10];
for(j=0;j<32000;j++);
P1=0xFF;
}
if(flag==0){
P1=b[(ta)%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[(tb)/10];
for(j=0;j<32000;j++);
P1=0xFF;
}
if(flag==0){
P1=b[(tb)%10];
for(j=0;j<32000;j++);
P1=0xFF;
}
}
}
}
I really hope someone would be able to assist me as i have been desperately doing this for the past weeks without any yield. Thank you so much
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:
h**p://www.atmel.com/dyn/resources/prod_documents/DOC0524.PDF .
I have written a code in C 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;
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^6==0)
ta++; }
P3_7=0;
for(m=0;m<tb;m++){
if(P3^6==1)
tb++;
}
scanled();
}
}
scanled(){
unsigned int i,flag,j;
if(tb==0){
for(i=0;i<2;i++){
flag=1-flag;
if(flag==1){
P1=a[(ta)/10];
for(j=0;j<32000;j++);
P1=0xFF;
}
if(flag==0){
P1=b[(ta)%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[(tb)/10];
for(j=0;j<32000;j++);
P1=0xFF;
}
if(flag==0){
P1=b[(tb)%10];
for(j=0;j<32000;j++);
P1=0xFF;
}
}
}
}
I really hope someone would be able to assist me as i have been desperately doing this for the past weeks without any yield. Thank you so much