GUI_AddDec.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        : GUIVAL.C
  3. Purpose     : Routines to display values as dec, binary or hex
  4. ----------------------------------------------------------------------
  5. */
  6. #include "GUI_Protected.H"
  7. #include "GUIDebug.h"
  8. #include "string.h"
  9. /*********************************************************************
  10. *
  11. *       Public data
  12. *
  13. **********************************************************************
  14. */
  15. const U32 GUI_Pow10[10] = {
  16.   1 , 10, 100, 1000, 10000,
  17.   100000, 1000000, 10000000, 100000000, 1000000000
  18. };
  19. /*********************************************************************
  20. *
  21. *       Static routines
  22. *
  23. **********************************************************************
  24. */
  25. static int _Check_NegLong(I32 *pv, char**ps) {
  26.   if (*pv<0) {
  27.     *(*ps)++ = '-';
  28.     *pv = -*pv;
  29.     return 1;
  30.   }
  31.   return 0;
  32. }
  33. /*********************************************************************
  34. *
  35. *       Module internal routines
  36. *
  37. **********************************************************************
  38. */
  39. int GUI_Long2Len(I32 vSign) {
  40.   int Len = 1;
  41.   I32 v = (vSign>0) ? vSign : -vSign;
  42.   while (( ((U32)v) >= GUI_Pow10[Len]) && (Len <9))
  43.     Len++;
  44.   if (vSign<0)
  45. Len++;
  46.   return Len;
  47. }
  48. long GUI_AddSign(long v, char**ps) {
  49.   char c;
  50.   if (v<0) {
  51.     c = '-';
  52.     v = -v;
  53.   } else {
  54.     c = '+';
  55.   }
  56.   *(*ps)++ = c;
  57.   **ps     = '';
  58.   return v;
  59. }
  60. /*********************************************************************
  61. *
  62. *       Public routines
  63. *
  64. **********************************************************************
  65. */
  66. /*********************************************************************
  67. *
  68. *       Decimal GUI_Add...  routines
  69. */
  70. void GUI_AddDecShift(I32 v, U8 Len, U8 Shift, char**ps) {
  71.   char c;
  72.   long d;
  73.   #ifndef _CM16C
  74.     Len -= _Check_NegLong(&v, ps); /* TASKING: Tool internal error S003: asertion failed - please report */
  75.   #else
  76.     if (v<0) {
  77.       *(*ps)++ = '-';
  78.       v = -v;
  79.     }
  80.   #endif
  81.   if (Shift) Len--;
  82. #if GUI_DEBUG_LEVEL >1
  83.   if (Len>9) {
  84.     Len=9;
  85.     GUI_DEBUG_ERROROUT("Can not display more than 9 dec. digits");
  86.   }
  87. #endif
  88.   if ((U32)v >= GUI_Pow10[Len])
  89. v = GUI_Pow10[Len]-1;
  90.   while (Len) {
  91.     if (Len--==Shift)
  92.       *(*ps)++ = GUI_DecChar;
  93.     d = GUI_Pow10[Len];
  94.     c = (char) (v/d);
  95.     v -= c*d;
  96.     *(*ps)++ = c+'0';
  97.   }
  98.   **ps = 0;
  99. }
  100. void GUI_AddDec(I32 v, U8 Len, char**ps) {
  101.   GUI_AddDecShift(v, Len, 0, ps);
  102. }
  103. void GUI_AddDecMin(I32 v, char**ps) {
  104.   U8 Len = GUI_Long2Len(v);
  105.   GUI_AddDecShift(v, Len, 0, ps);
  106. }