[原创] msp430 数码管程序,附电路图

littleshrimp   2014-7-23 16:19 楼主
新写的MSP430g2231数码管程序,附上原理图。 MSP430G2553 数码管的PCB.jpg
  1. #include "msp430.h"
  2. #include <stdint.h>
  3. #include "led.h"
  4. uint16_t t = 0,h = 0;
  5. uint32_t i = 0;;
  6. int main( void )
  7. {
  8. // Stop watchdog timer to prevent time out reset
  9. WDTCTL = WDTPW + WDTHOLD;
  10. LED_PORT_INIT();
  11. while(1)
  12. {
  13. if(i++%100==0)
  14. {
  15. setValue(t++,h++,0);
  16. }
  17. ledDisplay();
  18. // ledClearPartNumberValue();//消除残影
  19. __delay_cycles(500);
  20. }
  21. }
  1. #include "led.h"
  2. uint8_t fseg[]={0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
  3. uint16_t tube1,tube2;
  4. uint8_t ledTwinkle = 0;//LED是否闪烁
  5. uint8_t ledTwinkleFlag = 0;//LED闪烁标志
  6. uint8_t showLed = 1;//LED是否显示
  7. uint8_t ledUnitCount = 1;//LED显示单元
  8. uint8_t displayUnitValue = 0;//LED单元数值
  9. void delay_us(uint16_t us)
  10. {
  11. }
  12. void setValue(uint16_t t,uint16_t h,uint8_t twinkle)
  13. {
  14. ledTwinkle = twinkle;
  15. tube1 = t;
  16. tube2 = h;
  17. }
  18. void putByte(uint8_t b)
  19. {
  20. uint8_t i;
  21. for(i=0;i<8;i++)
  22. {
  23. if(b&0x080)
  24. {
  25. DIO_H;
  26. }
  27. else
  28. {
  29. DIO_L;
  30. }
  31. b<<=1;
  32. delay_us(1);
  33. SCLK_H;
  34. delay_us(1);
  35. SCLK_L;
  36. delay_us(1);
  37. }
  38. }
  39. void show(void)
  40. {
  41. RCLK_H;
  42. delay_us(1);
  43. RCLK_L;
  44. delay_us(1);
  45. }
  46. void putNumber(uint8_t num,uint8_t bit)
  47. {
  48. putByte(~(1<<(7-bit)));
  49. putByte(fseg[num]|((bit == 2 || bit==6 )?0x80:0x00));
  50. show();
  51. }
  52. void refurbish(void)
  53. {
  54. }
  55. //清除残影
  56. void ledClearPartNumberValue(void)
  57. {
  58. putByte(0);
  59. putByte(0);
  60. show();
  61. }
  62. //设置小数点
  63. void ledSetPartDotValue(uint8_t dot)
  64. {
  65. }
  66. //设置显示单元
  67. void ledSetUnit(uint8_t unit)
  68. {
  69. switch(unit)
  70. {
  71. case 0:
  72. break;
  73. case 1:
  74. break;
  75. case 2:
  76. break;
  77. case 3:;
  78. break;
  79. }
  80. }
  81. //刷新数据
  82. void ledDisplay(void)
  83. {
  84. // ledClearPartNumberValue();//清除残影
  85. if(showLed && (ledTwinkle == 0 || ledTwinkleFlag))//判断显示标志
  86. {
  87. switch(ledUnitCount)
  88. {
  89. case 0:
  90. displayUnitValue = tube2%10;//个位
  91. break;
  92. case 1:
  93. displayUnitValue = (tube2%100)/10;//十位
  94. break;
  95. case 2:
  96. displayUnitValue = (tube2%1000)/100;//百位
  97. break;
  98. case 3:
  99. displayUnitValue = (tube2%10000)/1000;//千位
  100. break;
  101. case 4:
  102. displayUnitValue = tube1%10;//个位
  103. break;
  104. case 5:
  105. displayUnitValue = (tube1%100)/10;//十位
  106. break;
  107. case 6:
  108. displayUnitValue = (tube1%1000)/100;//百位
  109. break;
  110. case 7:
  111. displayUnitValue = (tube1%10000)/1000;//千位
  112. break;
  113. }
  114. putNumber(displayUnitValue,ledUnitCount);//显示单元数值
  115. if(ledUnitCount++>=7) ledUnitCount = 0;//下一单元
  116. }
  117. }
  118. //使能LED显示
  119. void ledEnable(void)
  120. {
  121. showLed = 1;
  122. }
  123. //禁能LED显示
  124. void ledDisable(void)
  125. {
  126. showLed = 0;
  127. }
  128. void SetLedTwinkle(uint8_t twinkle)
  129. {
  130. ledTwinkle = twinkle;
  131. }
  132. void test(uint8_t n)
  133. {
  134. putNumber(n,n);
  135. show();
  136. }
eeworld.com.msp430.code @msp430g2553 数码管.rar (160.28 KB)
(下载次数: 12, 2014-7-23 16:18 上传)
IMG_20140723_162245240_HDR.jpg 本帖最后由 littleshrimp 于 2014-7-23 16:28 编辑
虾扯蛋,蛋扯虾,虾扯蛋扯虾

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复