View previous topic :: View next topic |
Author |
Message |
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Nov 27, 2014 4:34 pm |
|
|
Glad to hear it... You are welcome. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Fri Nov 28, 2014 1:11 pm |
|
|
now i want to display adc value on lcd. those code as
Code: | set_adc_channel(1);
delay_us(10); //-------->NOTE:AQUISITION TIME NECCESARY
battvolt=read_adc(); //reading current
delay_us(10);
battvolt= (float)(battvolt * 5)/1023.0;
lcd_gotoxy(1,1);
printf ( LCD_PutC,"Battery:\f%3.2f", battvolt);
lcd_gotoxy(12,1);
printf(LCD_PutC," VOLT \n"); |
found error as Quote: | Printf format type is invalid |
_________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Nov 28, 2014 2:57 pm |
|
|
Battvolt is declared as something other than a float. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Fri Nov 28, 2014 3:45 pm |
|
|
Ttelmah wrote: | Battvolt is declared as something other than a float. |
%3.2f is show only float only? _________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Nov 29, 2014 1:27 am |
|
|
Yes.
This is standard C. Look in the manual for printf. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Nov 29, 2014 6:51 am |
|
|
Quote: |
This is standard C. Look in the manual for printf. |
battvolt is declared as int32 battvolt . so how can printf it ? _________________ sahu
Last edited by sahu77 on Sat Nov 29, 2014 7:30 am; edited 1 time in total |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Nov 29, 2014 7:05 am |
|
|
Ttelmah wrote: | Yes.
This is standard C. Look in the manual for printf. |
battvolt is declared as int32 battvolt . so how can printf it ? _________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Nov 29, 2014 9:02 am |
|
|
%Ld
However it won't have any decimals since it is an integer number.
Use:
Code: |
battvolt=read_adc(); //reading current
battvolt= (battvolt * 500)/1024;
lcd_gotoxy(1,1);
printf ( LCD_PutC,"Battery:\f%5.2LW", battvolt);
|
This prints an integer, as a scaled value (/100 here). So the integer is made 100* larger in the earlier calculation.
Read the threads for why the correct divisor is 1024, _not_ 1023. |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Nov 29, 2014 9:09 am |
|
|
Ttelmah wrote: | %Ld
However it won't have any decimals since it is an integer number.
Use:
Code: |
battvolt=read_adc(); //reading current
battvolt= (battvolt * 500)/1024;
lcd_gotoxy(1,1);
printf ( LCD_PutC,"Battery:\f%5.2LW", battvolt);
|
This prints an integer, as a scaled value (/100 here). So the integer is made 100* larger in the earlier calculation.
Read the threads for why the correct divisor is 1024, _not_ 1023. |
can u explain me 5.2 LW ? _________________ sahu |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sat Nov 29, 2014 9:18 am |
|
|
Read the manual....
It is a printf specifier to print an integer as a 'scaled' value.
The .2, specifies how far it is to be scaled.
So the integer '100', printed with 5.2w, prints as '1.00'. Scaled by two places.
The 'L' says that the number is a _long_ integer (bigger than int8). |
|
|
|