[SOLVED] How to convert LCD Char to Int value ?

Status
Not open for further replies.

asking

Full Member level 5
Joined
Sep 21, 2010
Messages
279
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Visit site
Activity points
3,377
Hello,

I have some reading 3 digit value from ADC and the value shown is on LCD in the form of Characters.. now i wish to put some condition on that 3 digit value like 078 i want this value to be in int...how to convert value shown on lcd to int so i can put condition on it..to do some action...

i m reading Data from LM35 as temperature measurement. But directly i cannot use if lcd > 100 so i need to convert it to int value then i can put condition...... please advice...

Code:
a = t%10;
    lcd[2] = a + '0';

    t = t/10;
    a = t%10;
    lcd[1] = a + '0';

    t = t/10;
    a = t%10;
    lcd[0] = a + '0';

    Lcd_out(1,12,lcd);
 

character value - 0x30 or - d48 is int value. You can save the original int value to another int variable and use it for the if() condition. No need to convert char to int.
 
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
yes i got it i can take lcdint as another variable storing the value of lcd character as int value... could you please show me example... because m not fully clear how to use -d48 ?
 

'2' - 0x30 = 2 and '2' - 48 = 2. d48 is decimal 48. You don't have to store LCD character as int variable. Before you send int data to LCD it will be in int format. Just make a copy of that int and use it in if condition because I see your original int value gets modified in the int to str conversion routine.

Your t is the original int and it changes its value in the int to str conversion routine. So, save t value to iadc_val (int variable). Use iadc_val in if condition. Forget about char to int conversion.
 
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
Thanks for wonderful information of which i was unaware..
 

If you want to use the ADC integer result then it would make sense to keep it so use a second variable and keep the result there for any calculations you want to do since you change the variable t and can't be used.

If you want to convert the LCD value then use

Code:
((lcd[0]-'0')*100) + ((lcd[1]-'0')*10) + (lcd[2]-'0')
 
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…