Continue to Site

How to display Real number ??

Status
Not open for further replies.

ee_cchac

Member level 1
Member level 1
Joined
Sep 7, 2004
Messages
40
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
390
dear all,

i now facing a simple problem.....when i going to calculate the means of a set of value. i was able to find the means...but it is an integer....i try to force it to float...double....but all result in error value.
my h/w as follow:

AT86RF211 development kit. with MCUs AT90LS8535

code is as follow:

unsigned int a;
float intx;

for ( int i =0; i <9 ; i++)
a= a+a;
x= x/a;

x sow only an integer....but i want real number...


i wonder the reason is due to the LCD display....what should i do ??? help....please...
 

It is not clear.


unsigned int a;
float intx;

for ( int i =0; i <9 ; i++)
a= a+a;
x= x/a;

Where is the x declaration?
If in the second line, then should be just "float x".

Best regards,
Varuzhan
 

code as follow :
//////////////////////////////////////////
unsigned int a;
float x;

for ( int i =0; i <9 ; i++)
a= a+a;
x= x/a;
///////////////////////////////////////////


i want the display to be in real number format......how to solve it ?
 

- put braces
- initialize variables first
 

So, doesn't matter,

would anyone tell me how to calculate the real number is ok....

i just want to display a real number. however, i wm not going to display computer screen. i want to display it onto my dev. kit.

so thz
 

Maybe the problem is how you output your real number. You can use

printf("%3.2f", x);

This will output three digits before and two after the decimal point.

I use CodeVision AVR, and by redefinng the putchar() function, can use the printf() with any kind of output device. It can be LCD display, UART and so on.

Varuzhan
 

Thank You for yr reply...and..how about using IAR ?

is it still work ? and i am using a function to release the output on LCD display....i can only pass a parameter into that function.....any good suggestion to solve my problem ?
 

I never worked with IAR, but I think, that this trick with redefined putchar(), works with other compilers too. I use it as well in Kail for LPC2129 programming. My
Codevision code:

// Write a character to the USART Transmitter or LCD

void putchar(char c)
{
if (PrintToLCDb)
lcd_putchar(LCD_Code(c));
else if (PrintToUSART1) {
putchar1(c);
delay_ms(10);
}
else {
while ((UCSR0A & DATA_REGISTER_EMPTY)==0);
EN0 = 1;
UDR0=c;
while ((UCSR0A & TX_COMPLETE) == 0);
EN0 = 0;
UCSR0A |= TX_COMPLETE;
}
}

using PrintToLCD and PrintToUSART1 variables, you can force
the printf() to work with any output device.

Varuzhan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top