GUIValf.c
上传用户:pch188
上传日期:2013-04-20
资源大小:6697k
文件大小:3k
源码类别:

微处理器开发

开发平台:

C/C++

  1. /* ********************************************************************************************************* *                                                uC/GUI *                        Universal graphic software for embedded applications * *                       (c) Copyright 2002, Micrium Inc., Weston, FL *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH * *              礐/GUI is protected by international copyright laws. Knowledge of the *              source code may not be used to write a similar product. This file may *              only be used in accordance with a license and should not be redistributed *              in any way. We appreciate your understanding and fairness. * ----------------------------------------------------------------------
  2. File        : GUIValF.C
  3. Purpose     : Displaying floating point values
  4. ----------------------------------------------------------------------
  5. Version-Date---Author-Explanation
  6. ----------------------------------------------------------------------
  7. 1.00.00 990322 RS     First release   
  8. ----------------------------------------------------------------------
  9. Known problems or limitations with current version
  10. ----------------------------------------------------------------------
  11. None.
  12. ---------------------------END-OF-HEADER------------------------------
  13. */
  14. #include "GUI_Protected.H"
  15. #include "math.h"
  16. /*
  17. *******************************************
  18. *                                         *
  19. *          Helper functions               *
  20. *                                         *
  21. *******************************************
  22. */
  23. static void _DispFloatFix(float f, char Len, char Decs, int DrawPlusSign) {
  24.   f *= GUI_Pow10[Decs];
  25.   f += 0.5;
  26.   f = (float) floor (f);
  27.   if (DrawPlusSign)
  28.     GUI_DispSDecShift((long)f, Len, Decs);
  29.   else
  30.     GUI_DispDecShift((long)f, Len, Decs);
  31. }
  32. /*
  33. *******************************************
  34. *                                         *
  35. *     optional sign display routines      *
  36. *                                         *
  37. *******************************************
  38. */
  39. void GUI_DispFloatFix(float f, char Len, char Decs) {
  40.   _DispFloatFix(f, Len, Decs, 0);
  41. }
  42. void GUI_DispFloatMin(float f, char Fract) {
  43.   char Len;
  44.   Len = GUI_Long2Len((long)f);
  45.   _DispFloatFix(f, (char)(Len+Fract+1), (char)Fract, 0);
  46. }
  47. void GUI_DispFloat(float f, char Len) {
  48.   int Decs;
  49.   Decs =  Len - GUI_Long2Len((long)f)-1;
  50.   if (Decs<0)
  51.     Decs =0;
  52.   _DispFloatFix(f, Len, (char)Decs, 0);
  53. }
  54. /*
  55. *******************************************
  56. *                                         *
  57. *    Signed display routines              *
  58. *                                         *
  59. *******************************************
  60. */
  61. void GUI_DispSFloatFix(float f, char Len, char Fract) {
  62.   _DispFloatFix (f, Len, Fract, 1);
  63. }
  64. void GUI_DispSFloatMin(float f, char Fract) {
  65.   char Len;
  66.   Len = GUI_Long2Len((long)f);
  67.   if (f>0)
  68.     Len++;
  69.   _DispFloatFix(f, (char)(Len+Fract+1), (char)Fract, 1);
  70. }