smg.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //引脚对应P5.0~5.7: BCEDFAGH
  2. #include "Include.h"
  3. static u8 DigNum = 0;
  4. static u8 const smgduan[16] =
  5. {
  6. /*0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F,*/
  7. 0x3F,0x03,0xAD,0xAB,0x93,0xBA,0xBE,0x23,0xBF,0xBB,0xB7,0x9E,0x3C,0x8F,0xBC,0xB4
  8. //0xC0,0xFC,0x52,0x54,0x6C,0x45,0x41,0xDC,0x40,0x44,0x48,0x61,0xC3,0x70,0x43,0x4B
  9. };//显示0~F的值
  10. static u8 Smg_Arrary[] =
  11. {
  12. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0xFF
  13. };
  14. static u8 Smg_Arrary_i = 0;
  15. /*******************************************************************************
  16. * 函 数 名 : delay
  17. * 函数功能 : 延时函数,i=1时,大约延时10us
  18. *******************************************************************************/
  19. void delay ( u16 i )
  20. {
  21. while ( i-- );
  22. }
  23. void Smg_Init ( void )
  24. {
  25. }
  26. void Smg_Display(u8 Num)
  27. {
  28. DigNum = Num;
  29. }
  30. void Smg_Display_Next(void)
  31. {
  32. if(++Smg_Arrary_i >= ARRAY_SIZE(Smg_Arrary)) Smg_Arrary_i = 0;
  33. DigNum = Smg_Arrary[Smg_Arrary_i];
  34. }
  35. void Smg_Display_OnOff(bool On)
  36. {
  37. Smg_Arrary_i = (On)?(0):(ARRAY_SIZE(Smg_Arrary)-1);
  38. DigNum = Smg_Arrary[Smg_Arrary_i];
  39. }
  40. //pos:0~1
  41. //Num:0~9,
  42. void Smg_PlayOne(u8 Pos, u8 Num)
  43. {
  44. Num = (Num<=9)?(~smgduan[Num]):(0xFF);
  45. switch ( Pos ) //位选,选择点亮的数码管,
  46. {
  47. case 0:
  48. LED_DATA = 0;
  49. LED_COM1(0); //低亮
  50. LED_COM2(1);
  51. LED_DATA = Num; //发送段码
  52. break;//显示第0位
  53. case 1:
  54. LED_DATA = 0;
  55. LED_COM1(1);
  56. LED_COM2(0); //低亮
  57. LED_DATA = Num; //发送段码
  58. break;//显示第1位
  59. }
  60. }
  61. void Smg_test(void) //10ms
  62. {
  63. static u8 time = 0;
  64. #if 0
  65. static u8 Num = 0;
  66. if(time++>=100)
  67. {
  68. time = 0;
  69. LED_COM1(1);
  70. LED_COM2(1); //低亮
  71. Num++;
  72. if(Num>7) Num=0;
  73. LED_DATA = ~(1<<Num); //发送段码
  74. }
  75. #else
  76. if(time++>=50)
  77. {
  78. time = 0;
  79. DigNum += 11;
  80. if(DigNum%11 != 0) DigNum=0;
  81. if(DigNum>99) DigNum=0;
  82. }
  83. #endif
  84. }
  85. void Smg_Refrensh(void) //10ms
  86. {
  87. static u8 Step = 0;
  88. u8 units,tens;
  89. switch ( Step )
  90. {
  91. case 0 : //个位
  92. units = (DigNum<99)?(DigNum%10):(0xFF);
  93. Smg_PlayOne(0, units);
  94. Step = 1;
  95. break;
  96. case 1 : //十位
  97. tens = (DigNum<99)?((DigNum/10)%10):(0xFF);
  98. Smg_PlayOne(1, tens);
  99. Step = 0;
  100. break;
  101. }
  102. //Smg_test();
  103. }
  104. /*******************************************************************************
  105. * 函 数 名 : DigDisplay
  106. * 函数功能 : 数码管动态扫描函数,循环扫描8个数码管显示
  107. *******************************************************************************/
  108. void DigDisplay()
  109. {
  110. u8 i;
  111. for ( i = 0; i < 4; i++ )
  112. {
  113. switch ( i ) //位选,选择点亮的数码管,
  114. {
  115. case ( 0 ) :
  116. LED_COM1(0);
  117. LED_COM2(1);
  118. break;//显示第0位
  119. case ( 1 ) :
  120. LED_COM1(1);
  121. LED_COM2(0);
  122. break;//显示第1位
  123. }
  124. LED_DATA = smgduan[i]; //发送段码
  125. delay ( 100 ); //间隔一段时间扫描
  126. LED_DATA = 0x00; //消隐
  127. }
  128. }