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.

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

Status
Not open for further replies.

zalmay

Newbie level 4
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.
 

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 %
 
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.
 

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???
 

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
 

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);
 

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
 

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.
 

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

Back
Top