// Lcd pinout setting
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
//Pin Direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
#define ventilador1 PORTC.RC0
#define Piloto1 PORTC.RC1
#define Ventilador2 PORTC.RC2
//unsigned int temp=0.0,temp1=0.0 ;
char valor[16];
float temp,temp1 ;
void main() {
ADCON0=0x4D;
ADCON1=0x42;
TRISC=0x00;
PORTC=0x00;
ADC_Init();
Delay_ms(250);
Lcd_init();
Lcd_Cmd(_Lcd_Cursor_off);
Lcd_Out(1,1, "SYSTEM LADA_NIVA");
Lcd_out(2,1, " *INIC SENSORES ");
Delay_ms(1600);
Lcd_Cmd(_Lcd_Clear);
Lcd_Out(1,1, "#Escan Sensores#");
ventilador1 = 1;
Piloto1 = 1;
Ventilador2=1;
while(1){
temp=ADC_Read(0);
temp=(temp*150)/307;
FloatToStr(temp, valor);
Lcd_Out(2,1, "Temp = ");
Lcd_Out_CP(valor);
//valor=temp / 1000;
//Lcd_chr(2,1, 48+valor);
}
}
Cordial greeting
I appreciate the opportunity to be part of this community.
the question I have is that I am programming a pic 16f873a with micro c pro and when converting float to str it throws me several decimals
but I just want to keep two decimals thanks
PIC16f873a FloatToStr
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: PIC16f873a FloatToStr
Hi,
Welcome to the MikroE forum.
There's a FloatToStr_FixLen function, so you can use it instead of FloatToStr.
Please refer to its help file description.
Kind regards,
Welcome to the MikroE forum.
There's a FloatToStr_FixLen function, so you can use it instead of FloatToStr.
Please refer to its help file description.
Kind regards,
Stefan Filipović
Re: PIC16f873a FloatToStr
I would not advise to use this function. It has too many quirks and one not always can avoid them. It's also quite inconvenient - to display signed numbers with same precision one has to check the sign first and appropriately set string length.stefan.filipovic wrote:There's a FloatToStr_FixLen function, so you can use it instead of FloatToStr.
An example of what FloatToStr_FixLen set for 6 chars result gives
Code: Select all
argument result
12.34567 "12.345" OK
-12.34567 "-12.34" OK but precision differs from a positive number
1.234567 "1.234" 5 chars instead of 6
-1.234567 "-1.23" 5 chars instead of 6
0.1234567 "1.2345" ? invalid result
-0.1234567 "-1.234" ? invalid result
0.01234567 "1.2345" ? invalid result
12345.67 "12345." OK but not elegant
1234567.0 "123456" formally OK but may surprise
12345678.0 "1.2345" ? invalid result
Re: PIC16f873a FloatToStr
THANK YOU FRIENDS OF THE FORUM I HAVE ACHIEVED IT