End of Year Sale 2014
It is currently 23 Dec 2014 01:05

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 15 Nov 2009 19:26 
Offline

Joined: 18 Jun 2008 09:28
Posts: 71
Location: France, Macon
Hello


I'm using "float to string" to have a calculation displayable on a LCD, this gets a value like this : 12.12345 ( the number is 5 digits after comma )

Quote:
FloatToStr(calculation, calc);


I would like to get the value rounded to 2 digits only after comm in order to get something like this : 12.12

Can you show me how to do this ?

Many thanks for your help,


Top
 Profile  
 
 Post subject:
PostPosted: 16 Nov 2009 00:25 
Offline

Joined: 18 Aug 2008 22:13
Posts: 926
Location: Brasil
See strncpy() function in the help file... (ANSI C String library)

BR.


Top
 Profile  
 
PostPosted: 30 Mar 2010 01:17 
Offline

Joined: 30 Mar 2010 01:08
Posts: 1
please help
i'm using "FloatTOStr" but the compilation don't work "Unresolved extern 'strcpy'".
i would like to read a value from the ADC ,convert it to String ,and displayed on LCD.
I would like to get the value rounded to 2 digits only after comma.
thanks. :)


Top
 Profile  
 
PostPosted: 08 Apr 2010 10:36 
Offline
mikroElektronika team
User avatar

Joined: 02 Dec 2009 14:16
Posts: 2138
Location: Serbia
Hello,

in installation folder of mikroC you have examples for some of microcontrollers, and for PIC16F877A,
you have example ADC on LCD.
So, look at this example, this can help you.

Also, my recommendation is to install mikroC PRO for PIC
mikroC PRO for PIC 2009 includes a set of libraries and examples intended to facilitate application development.
Routines are documented in detail and allow quick start in programming microcontrollers.

Best regards,

Losic Tihomir

_________________
mikroElektronika [Support team]


Top
 Profile  
 
PostPosted: 08 Apr 2010 11:09 
Offline

Joined: 18 Jun 2008 09:28
Posts: 71
Location: France, Macon
Thanks, but my code has been written with Mikro C , will it fully compatible with Mikro C Pro version ?

i don't want to spend long time to port it to Pro version ...

Please let me know,


Top
 Profile  
 
PostPosted: 08 Apr 2010 11:53 
Offline
mikroElektronika team
User avatar

Joined: 02 Dec 2009 14:16
Posts: 2138
Location: Serbia
Hello,

please, try this code (mikroC, PIC16F877A):
unsigned char ch;
unsigned int adc_rd;
char *text;
long tlong;

void main() {
  INTCON = 0;                              // disable all interrupts
  Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0); // Lcd_Init_EP5, see Autocomplete
  LCD_Cmd(LCD_CURSOR_OFF);                 // send command to LCD (cursor off)
  LCD_Cmd(LCD_CLEAR);                      // send command  to LCD (clear LCD)

  text = "mikroElektronika";               // assign text to string
  LCD_Out(1,1,text);                       // print string a on LCD, 1st row, 1st column
  text = "LCD example";                    // assign text to string
  LCD_Out(2,1,text);                       // print string a on LCD, 2nd row, 1st column

  ADCON1     = 0x82;                       // configure VDD as Vref, and analog channels
  TRISA      = 0xFF;                       // designate PORTA as input
  Delay_ms(2000);
  text  = "voltage:";                      // assign text to string
  while (1) {
    adc_rd  = ADC_read(2);                 // get ADC value from 2nd channel
    LCD_Out(2,1,text);                     // print string a on LCD, 2nd row, 1st column

    tlong = (long)adc_rd * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

    ch     = tlong / 1000;                 // extract volts digit
    LCD_Chr(2,9,48+ch);                    // write ASCII digit at 2nd row, 9th column
    LCD_Chr_CP('.');

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point

    ch    = tlong % 10;                    // extract 0.001 volts digit
    LCD_Chr_CP(48+ch);                     // write ASCII digit at cursor point
    LCD_Chr_CP('V');

    Delay_ms(1);
  }
}//~!

Best regards,

Losic Tihomir

_________________
mikroElektronika [Support team]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Google [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group