title: Dividing with/without using floats in C
body: <p>Below is the main function I wrote in C (for PIC18F8722 microprocessor) attempting to drive 2 multiplexing 7 segments displays at a specific frequency set by the unsigned int function <code>get_ADC_value()</code>.  The displays also display the current multiplexing frequency. This frequency range is set by <code>#define</code> to be in the range LAB_Fmin and LAB_Fmax and must scale as the <code>get_ADC_value()</code> increases or decreases from 0 to 255.</p>
  
  <p>This code however does not work as I think there is implicit conversion from <code>int</code> to <code>float</code> at <code>freq =</code>.</p>
  
  <p>The challenge is to fix this error with floats and to find an alternative using only integer types (<code>int</code>, <code>char</code>...).</p>
  
  <pre><code> while (1) {
  
     unsigned int x, y, z;
     float freq, delay;
  
      x = get_ADC_value(); 
      y = x &amp; 0b00001111;
      z = (x &amp; 0b11110000) &gt;&gt; 4 ;
  
      freq = LAB_Fmin + (((LAB_Fmax) - (LAB_Fmin))/ 255)*x ;
      delay = 1/(freq*1000); // convert hZ to ms delay accurately
  
      LATF = int_to_SSD(y); 
      LATH = 0b11111110; //enable 7seg U1
      for (unsigned int i = 0; i&lt;(delay) ; i++){ 
          Delay10TCYx(250); //1ms delay
      }
  
      LATF = int_to_SSD(z); 
      LATH = 0b11111101; //enable 7seg U2
      for (unsigned int j = 0; j&lt;(delay) ; j++){
          Delay10TCYx(250); //1ms delay
      }
  }
  </code></pre>