title: showing float numbers in lcd with avr micro & Avrstudio
body: <p>I have witen one Avrstudio V6 progam (c code ) for showing Pt100 temp in lcd, So i read value from ACDW correctly, but when i do some mathematical operation on this value, i could not show it's Float Value on lcd. </p>
  
  <p>The simple program is showing one float value in LCD, the lcd library which i am using is from <a href="https://electrosome.com/interfacing-lcd-atmega32-microcontroller-atmel-studio/" rel="nofollow noreferrer">LCD Library</a></p>
  
  <p>the main code is :</p>
  
  <pre><code>#include &lt;avr/io.h&gt;
  #include &lt;avr/interrupt.h&gt;
   #include &lt;stdlib.h&gt;
  //#define F_CPU 16000000UL
  #define F_CPU 8000000
  #include &lt;util/delay.h&gt;
  #define ADC_VREF_TYPE 0x40
  //#include "adc_new.h"
  #define D4 eS_PORTC4
  #define D5 eS_PORTC5
  #define D6 eS_PORTC6
  #define D7 eS_PORTC7
  #define RS eS_PORTC2
  #define EN eS_PORTC3
  #include "lcd.h" //Can be download from the bottom of this article
  //  Constants and variables
  //*****************************************************************************
  // Input: Square wave on ICP PIN
  // This program determines the pulse width of a square wave and if the pulse width is greater than 40 us
  //than PD4 goes higher ,if its smaller than PD4 is low.
  
  //---------------------------------------------------------//
  void LCD_0(void)
  {
      /*
  ' Lcd module connections
  dim LCD_RS as sbit at PORTc2_bit
  dim LCD_EN as sbit at PORTc3_bit
  dim LCD_D4 as sbit at PORTc4_bit
  dim LCD_D5 as sbit at PORTc5_bit
  dim LCD_D6 as sbit at PORTc6_bit
  dim LCD_D7 as sbit at PORTc7_bit
  
  dim LCD_RS_Direction as sbit at DDc2_bit
  dim LCD_EN_Direction as sbit at DDc3_bit
  dim LCD_D4_Direction as sbit at DDc4_bit
  dim LCD_D5_Direction as sbit at DDc5_bit
  dim LCD_D6_Direction as sbit at DDc6_bit
  dim LCD_D7_Direction as sbit at DDc7_bit
  
  */
  
  DDRC = 0xFF;
  
  
  Lcd4_Init();
  Lcd4_Set_Cursor(1,1);
  Lcd4_Write_String("Elasa.ir Test"); 
  }   
  
  //http://www.geeksforgeeks.org/convert-floating-point-number-string/
  // Converts a floating point number to string.
  void ftoa(float n, char *res, int afterpoint)
  {
      // Extract integer part
      int ipart = (int)n;
  
      // Extract floating part
      float fpart = n - (float)ipart;
  
      // convert integer part to string
      int i = itoa(ipart, res, 0);
  
      // check for display option after point
      if (afterpoint != 0)
      {
          res[i] = '.';  // add dot
  
          // Get the value of fraction part upto given no.
          // of points after dot. The third parameter is needed
          // to handle cases like 233.007
          fpart = fpart * pow(10, afterpoint);
  
          itoa((int)fpart, res + i + 1, afterpoint);
      }
  }
  
  
  int main(void) {
  DDRD = (0&lt;&lt;PD4);     // put PortB bit 5 as input
  //PORTD = 0&lt;&lt;PD4;       // Enable PE4 pull-up resistor
  DDRC = 0xFF;
  //enable overflow and input capture interrupts
  
  TIMSK=0x24;
  
  /*Noise canceller, without prescaler, rising edge*/
  
  TCCR1B=0xC1;
  
  
  
  // ADC initialization
  // ADC Clock frequency: 1000.000 kHz
  // ADC Voltage Reference: Int., cap. on AREF
  ADMUX=ADC_VREF_TYPE &amp; 0xff;
  ADCSRA=0x83;_delay_ms(30);
  
  
  Lcd4_Init();
  
  Lcd4_Set_Cursor(1,1);   
  Lcd4_Write_String("Pulse width measuring:");
  //Lcd4_Set_Cursor(2,1); 
  
  //itoa(pulse_width2, str3, 10);
  
  _delay_ms(3);
  
  
  
      while(1)
      {
          //http://www.edaboard.com/thread63677.html
          char buffer22[24];
          float x = 1.5;
  
          sprintf(buffer22, "Flo %f", x);
          Lcd4_Clear();
          Lcd4_Set_Cursor(1,1);   
          Lcd4_Write_String("Temp_eda:");
          Lcd4_Set_Cursor(2,1);
          Lcd4_Write_String(buffer22);
          _delay_ms(300);
  
  
          char res[20];
          float n = 233.007;
          ftoa(n, res, 4);
  
  
          //ftoa3(myFloatStr, myFloat, 10);
          //Lcd4_Write_String(myFloatStr);
          Lcd4_Clear();
          Lcd4_Set_Cursor(1,1);   
          Lcd4_Write_String("Temp_PT100:");
          Lcd4_Set_Cursor(2,1);
          Lcd4_Write_String(res);
          _delay_ms(300);
  
      }
  }
  </code></pre>
  
  <p>So out put in proteus is here:
  <a href="https://i.stack.imgur.com/nPRwJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nPRwJ.jpg" alt="pt100"></a></p>
  
  <p>As you see the string "?" Shown in lcd insted of "1.5", So could you find the wrong part in my codes, you could see avrstudio and proteus codes here:
  <a href="https://ufile.io/51e94" rel="nofollow noreferrer">C codes</a></p>
  
  <p>or </p>
  
  <p><a href="https://drive.google.com/open?id=0B1gjqdxmIbMaaGZkdFF0cGJ6SWM" rel="nofollow noreferrer">google Drive C code</a></p>
  
  <p>Thanks A lot.</p>