Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with code for converting 24bits from A/D and displaying them on an LCD

Status
Not open for further replies.

veioloko

Member level 1
Joined
Aug 18, 2006
Messages
36
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,288
Location
Brazil
Activity points
1,493
Hello everybody

I´m trying to convert an 24bits from a/d and display it into an lcd.

First i´m converting de 24bits to decimal, and after i add 0x30(ascii)..

however i´m having a problem

the value on the display sometimes it´s incorret, not number. it happens only where i will place X
000yxx00,

When y>=4 xx has character that is not a number.

Does anyone knows why?


Code:
char int_ascii(unsigned long int x){
unsigned char a, valor[8],cBuff[17];
unsigned long int var_aux;

valor[8]='\0';
valor[0] =  x / 10000000; //atribui o valor ASCII a dezena de milhar
var_aux = x - (valor[0] * 10000000) ;
valor[0]= valor[0]+'0';

          
valor[1] = var_aux / 1000000; //atribui o valor ASCII a milhar
var_aux -= valor[1] * 1000000;
valor[1]= valor[1]+'0';


valor[2] = var_aux / 100000; //atribui o valor ASCII a milhar
var_aux -= valor[2] * 100000;
valor[2]= valor[2]+'0';


valor[3] = var_aux / 10000; //atribui o valor ASCII a milhar
var_aux -= valor[3] * 10000;
valor[3]= valor[3]+'0';


valor[4] = var_aux / 1000; //atribui o valor ASCII a milhar
var_aux -= valor[4] * 1000;
valor[4]= valor[4]+'0';
     
valor[5] = var_aux / 100; //atribui o valor ASCII a centena
var_aux -= valor[5] * 100;
valor[5]= valor[5]+'0';

valor[6] = var_aux / 10; //atribui o valor ASCII a dezena
var_aux -= valor[6]* 10;
valor[6]= valor[6]+'0';

valor[7] = var_aux % 10  + '0'; //atribui o valor ASCII a unidade

return ((unsigned char)valor);
}

Code:
		while(!(AIPOL&0x20)) {}             // Wait for conversion
		
		result=unipolar();                 // Save Results
		
      
    sprintf(cBuff,"Med: %s",int_ascii(result)); 

     lcd_env_inst(0X80);	
     lcd_puts(cBuff); 
 
	}
 

Re: 24bits ascii lcd

Replace your int_ascii with this itostr

Code:
void itostr(unsigned int val, unsigned char *result)
{
	static char buf[12] = {0};
	int i = 10;
	
	for(; val && i ; --i, val /= 10)
			buf[i] = "0123456789"[val % 10];
	strcpy(result,&buf[i+1]);
}
 

Re: 24bits ascii lcd

Hello
thanks for the help,however i used another code,that i use the function : for....do the same as i posted but now it works,i don´t know why
 

Re: 24bits ascii lcd

hey i had the same problem.......i did try what u have written but it consumes a lot of space i think 1K of memory ...try this it consumes only 0.1K....
and try adding 48 its 30 in hex....

the prog working simple maths....a floating point no is generated by dividing it by 10...since it is converterted to int the last digit is removed....when u multiply it by 10 and subtract it from the original number u get the last single digit...
the process continues...how is the code....do msg me if it helps..
ok why 10 in the FOR loop....the max digits by a 32bit hex number is a 10 digit decimal number...


Code:
void main ()
{


int f[10];
int32 c,e;    ///it means 32 bit number

while(1)
{
c = 123456789;          ////my number is 32 bit u can change that(for testing)
for(j=0;j<10;j++)
{
e = c / 10;
f[i] = c-(10*e);
f[i]=f[i]+48;               ////48==30 in hex....(may be this is ur problem)
c=e; 
}

}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top