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.

Display float Value By Using sprintf command on 7-seg display.

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,493
Please let know that the sprint command can separate the numbers to individuals characters like,

Code:
char buff[10];
double f = 12.3;

//buff[0] = 1
//buff[1] = 2
//buff[2] = .
//buff[3] = 3

and then in main body 

main()
{
sprint(buff , "%f" , f);
Print(buff[0]);     // This Print function use to display any integer value on 7-seg display
}

I did like this but it cannot do this.
 

sprintf() itself doesn't separate characters, you'll choose a more specific format like %4.1f and use elementary C character operations to cut the buff string into individual characters.
 

hello,


What is your compiler ?
and Print function is your own function or library ?

the function Print is usualy associated to an UART , are you sure it can drive 7 segment display ?

buff[0] contains only one caractere
use a format for sprintf
buff size must be greater .. try with


Code:
char buff[30];
float f=12.3;

main()
{
sprintf(buff,"3.1f",f);
Print(buff);
while(1);
}
 
AVR studio 4

Print function is my own function for separating digits and send to 7-seg display.

- - - Updated - - -

I tried with it but it shows only buff[0] value not others buff[1]....buff[3].

Code:
char buff[30];
float f=33.2;

main()
{
sprintf(buff,"3.1f",f);
Print(buff[0]);
while(1);
}

The Print function display exact value which enter in it.
Print(124 or any upto 999 but not float)
The 7-display shows 124.
 

did you try with Print(buff);
buff as pointer ...not a char of table buff
do you have the "." (point) on your 7 seg display ?
How many digit on display ?
you can manage your value by multiply by 10
and send 1234
and after light on the point at the right place ..
 
AVR studio 4
The Print function display exact value which enter in it.
Print(124 or any upto 999 but not float)
The 7-display shows 124.
if you Print() function is expecting an integer parameter
Code:
Print(buff[0]);
will just print the ASCII code of the character in buff[0]
you require a version of Print() which takes a char array as a parameter and prints the string contained in the array, e.g. something like
Code:
void lcdString(char *string)
{
	while (*string)
	  lcdPutchar(*string++);
}
then use it so
Code:
sprintf(buff,"%3.1f",f);
lcdString(buff);
 

Dear paulfjujo,

1)did you try with Print(buff);
2)buff as pointer ...not a char of table buff
3)do you have the "." (point) on your 7 seg display ?
4)How many digit on display ?
5)you can manage your value by multiply by 10
and send 1234
and after light on the point at the right place ..

1) Yes I tried with Print(buff) but it displays garbage value
3) I have also use point "." in my 7-seg display because I want to display float values 00.0 to 999
4) Three digits display.
5) This method I used but not satisfied.

I want to sprint command.

- - - Updated - - -

Dear horace1,

I am using three 7-segment displays and want to display values like this below.

00.0-00.1-00.2-----00.9-----01.0-01.1-01.2-----01.9---02.0-02.1-----02.9-03.0---
---09.0----09.9-10.0-10.1-10.2------20.0-----90.0----99.0---99.8-99.9-100-101-102-103---
----200---500---800--900---980---999
then roll over to 00.0

- - - Updated - - -

Dear FvM,

How to implement "elementary C character operations to cut the buff string into individual characters."?
 

do you have a function to print a string to your LCD display?
if not how does your Print() function work?
do you write seperate characters to each LCD individually?
 

Can anyone know that how to convert float value into integer value.

Means: if float value is 12.34 then convert and store int part in a=12 and float part in b=34.
 

If I'm following this correctly, what you are asking for is each digit to be held in it's own address and TWO strings of digits to be created, one the integer part of the value and the other the fractional part.

So try this:
sprintf(IntegerPart,"%02d",value);
sprintf(FractionPart,"%02d",value % 10);

The individual digits can then be read as IntegerPart[0] and IntegerPart[1] and the fractional part as FractionPart[0] and FractionPart[1].

You will have to do some conversion on the result to turn it into a segment pattern.

Brian.
 
Presumed the compiler supports float format, wouldn't it be easier to print the whole number with sprintf(buf,"%5.2f",fvalue) and cut the string in the middle (at the '.' character)?
 

I remember that the CVAVR compiler has buildin library support sprintf with float and double.
But it should be set by manual before compiling.It is usual in Preference setting page.
Well,if your compiler is not support sprintf with float and double.Re-write the sprintf function by yourself,convert float into string,separate each character into visible character can display in segmentx7 display.
For example as follow:
float=3.1415
convert it into string: char *p="3.1415";
then
p[0]='3';
p[1]='.',
p[2]='1',
p[3]='4',
p[4]='1',
p[5]='5',
p[6]='\0',

then show your character into 7-segment with easy.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top