Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Lcd should not display 001% i want to display 1%

Status
Not open for further replies.

zalmay

Newbie level 4
Joined
Mar 27, 2009
Messages
7
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
pakistan peshawar
Activity points
1,345
Can some one please help me out i am working on a pic micro controller project.i am new to controller so i have a problem

i want the lcd to show me 1 % instead of showing 001% or 10% instead of showing 010% and so on.

I want the lcd not to display any zero on left hand side.
 

saeed_pk

Full Member level 4
Joined
May 20, 2006
Messages
238
Helped
35
Reputation
68
Reaction score
27
Trophy points
1,308
Location
Islamabad, Pakistan
Activity points
2,667
how do u convert your integer data to ASCII String
if you use printf or sprintf() it replaces zeros with space so you will not see 010 %
 

zalmay

Newbie level 4
Joined
Mar 27, 2009
Messages
7
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
pakistan peshawar
Activity points
1,345
thanks saeed brother;
i am converting integer by adding 48 to the data hence getting ASCII value.i havn't used printf rather i have used built in command LCD_OUT in micro-c.
 

zalmay

Newbie level 4
Joined
Mar 27, 2009
Messages
7
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Location
pakistan peshawar
Activity points
1,345
thanks
i am using the if statement but it is not working. i have coded in micro-c something like;

if(parameter[0]==0) then ..... else LCD_OUT(row,col,parameter) the if condition never becomes true else statment is executed all the times.

---------- Post added at 07:35 ---------- Previous post was at 05:55 ----------

hi everyone;
finally i got the statement right it is like
if(parameter[0]==48) then... 48 because parameter is an ASCII value and 48 in ASCII for 0 in decimal so condition becomes true now.but another problem is that parameter has three values like parameter[0],parameter[1],parameter[2].now i want only the ascii value of parameter[2] to display i m using
LCD_OUT(row,col,parameter[2]) but it gives a blank value.
any solution for this problem???
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
I'm not sure how LCD_OUT works in your compiler, maybe it expects a null terminated string, in that case you need to make an array of four char and set the last one to null (parameter[3]=0)
And you code is not clear, I understand that you add value 48 to convert a number to the ascii representation but I can't understand if you are doing something wrong.

Alex
 

thunderboympm

Full Member level 5
Joined
Sep 17, 2007
Messages
244
Helped
32
Reputation
64
Reaction score
29
Trophy points
1,308
Location
Malappuram, India
Activity points
2,468
thanks
i am using the if statement but it is not working. i have coded in micro-c something like;

if(parameter[0]==0) then ..... else LCD_OUT(row,col,parameter) the if condition never becomes true else statment is executed all the times.

---------- Post added at 07:35 ---------- Previous post was at 05:55 ----------

hi everyone;
finally i got the statement right it is like
if(parameter[0]==48) then... 48 because parameter is an ASCII value and 48 in ASCII for 0 in decimal so condition becomes true now.but another problem is that parameter has three values like parameter[0],parameter[1],parameter[2].now i want only the ascii value of parameter[2] to display i m using
LCD_OUT(row,col,parameter[2]) but it gives a blank value.
any solution for this problem???
dear friend,
that is all berden. The better option i suggest is using sprintf() function. That function will do all you want
Syntax
unsigned char temp[6]
sprintf(tmp,"%d", <the integer value>);
lcd_out(tmp);
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
The better option i suggest is using sprintf() function
Easier is not always better, sprintf may be easier but it also takes a lot of space, it is not a bad idea to learn to use other way especially to convert a 3 digit number to a string.

Alex
 

ZASto

Advanced Member level 3
Joined
Jan 9, 2008
Messages
760
Helped
149
Reputation
303
Reaction score
135
Trophy points
1,323
Location
Messy Corner, 44°47'31.56"N, 20°28'9.16"E
Activity points
5,159
Code:
Select Value
    Case > 99
        Print At Row, Col, Dec Value, "%"

    Case > 9
        Print At Row, Col, " ", Dec Value, "%" ' One leading space

    Case Else
        Print At Row, Col, "  ", Dec Value, "%" ' Two leading spaces
End Select
This easy transcribed to any programming language such as C or Pascal.

The given code is "quick and dirty" one written in Proton+. It assumes that the "%" sign mis at the fixed position.
 

thunderboympm

Full Member level 5
Joined
Sep 17, 2007
Messages
244
Helped
32
Reputation
64
Reaction score
29
Trophy points
1,308
Location
Malappuram, India
Activity points
2,468
Easier is not always better, sprintf may be easier but it also takes a lot of space, it is not a bad idea to learn to use other way especially to convert a 3 digit number to a string.

Alex
i agree with that, i think O/P is more important than the memory. Right?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top