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 and also i am not able to compile, the compiler says something like "scanled auto segment too large". 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;
sbit COMP_INP = P3^6;
static int ta,tb;
void delay(char 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){
ta=tb=0;
P3_7=1;
for(m=0;m<=tc;m++){
if(COMP_INP==0)
ta++;
}
delay(7);
P3_7=0;
for(m=0;m<td;m++){
if(COMP_INP==1)
tb++;
}
delay(7);
scanled();
}
}
scanled(){
unsigned int i,flag,r,q;
char voltage1[79]={0,0,0,1,1,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,15,15,16,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,21,21,21,22,22,22,22,23,23,23,23,24,24};
char voltage2[79]={50,49,49,48,48,47,47,46,46,45,45,45,44,44,43,43,43,42,42,41,41,41,40,40,39,39,39,38,38,38,37,37,37,36,36,36,35,35,35,34,34,34,33,33,33,32,32,32,31,31,31,31,30,30,30,29,29,29,29,28,28,28,27,27,27,27,26,26,26,26,25,25,25,25,25,24,24,24,24};
if(tb==0){
q=voltage1[ta];
for(i=0;i<2;i++){
flag=1-i;
if(flag==1){
P1=a[q/10];
delay(1);
P1=0xFF;
}
if(flag==0){
P1=b[q%10];
delay(1);
P1=0xFF;
}
}
}
if(ta==0){
r=voltage2[tb];
for(i=0;i<2;i++){
flag=1-i;
if(flag==1){
P1=a[r/10];
delay(1);
P1=0xFF;
}
if(flag==0){
P1=b[r%10];
delay(1);
P1=0xFF;
}
}
}
}
void delay(char count)
{
char j,l;
for(j=0;j<= count;j++)
{
for (l=0;l<=120;l++);
}
}
I really hope someone would be able to help. Thank you.
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 and also i am not able to compile, the compiler says something like "scanled auto segment too large". 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;
sbit COMP_INP = P3^6;
static int ta,tb;
void delay(char 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){
ta=tb=0;
P3_7=1;
for(m=0;m<=tc;m++){
if(COMP_INP==0)
ta++;
}
delay(7);
P3_7=0;
for(m=0;m<td;m++){
if(COMP_INP==1)
tb++;
}
delay(7);
scanled();
}
}
scanled(){
unsigned int i,flag,r,q;
char voltage1[79]={0,0,0,1,1,2,2,3,3,4,4,4,5,5,6,6,6,7,7,8,8,8,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,15,15,16,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,21,21,21,22,22,22,22,23,23,23,23,24,24};
char voltage2[79]={50,49,49,48,48,47,47,46,46,45,45,45,44,44,43,43,43,42,42,41,41,41,40,40,39,39,39,38,38,38,37,37,37,36,36,36,35,35,35,34,34,34,33,33,33,32,32,32,31,31,31,31,30,30,30,29,29,29,29,28,28,28,27,27,27,27,26,26,26,26,25,25,25,25,25,24,24,24,24};
if(tb==0){
q=voltage1[ta];
for(i=0;i<2;i++){
flag=1-i;
if(flag==1){
P1=a[q/10];
delay(1);
P1=0xFF;
}
if(flag==0){
P1=b[q%10];
delay(1);
P1=0xFF;
}
}
}
if(ta==0){
r=voltage2[tb];
for(i=0;i<2;i++){
flag=1-i;
if(flag==1){
P1=a[r/10];
delay(1);
P1=0xFF;
}
if(flag==0){
P1=b[r%10];
delay(1);
P1=0xFF;
}
}
}
}
void delay(char count)
{
char j,l;
for(j=0;j<= count;j++)
{
for (l=0;l<=120;l++);
}
}
I really hope someone would be able to help. Thank you.