标题: 封装为一个通用性数码管单片机函数,求指教哦 [打印本页]

作者: rrrlll    时间: 2017-11-19 12:01
标题: 封装为一个通用性数码管单片机函数,求指教哦

原理图:


单片机源程序如下:
  1. #ifndef _DEFINE_H_
  2. #define _DEFINE_H_
  3. #include <intrins.h>
  4. //定义数据
  5. unsigned char Seg_Yang_Led_Table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  6. //定义函数
  7. void Delay1ms()  //@11.0592MHz
  8. {
  9. unsigned char i, j;
  10. _nop_();
  11. _nop_();
  12. _nop_();
  13. i = 11;
  14. j = 190;
  15. do
  16. {
  17.   while (--j);
  18. } while (--i);
  19. }
  20. void TestSeg()
  21. {
  22. P2 |= 0xc0;      
  23. P0 = 0x80;     
  24. P2 &= ~(0xc0);   
  25. P0 = 0xff;   
  26. P2 |= 0xe0;   
  27. P0 =  Seg_Yang_Led_Table[0];
  28. P2 &= ~(0xe0);   
  29. P0 = 0x00;   
  30. Delay1ms();
  31. P2 |= 0xc0;      
  32. P0 = 0x40;     
  33. P2 &= ~(0xc0);   
  34. P0 = 0xff;   
  35. P2 |= 0xe0;   
  36. P0 =  Seg_Yang_Led_Table[1];
  37. P2 &= ~(0xe0);   
  38. P0 = 0x00;   
  39. Delay1ms();
  40. P2 |= 0xc0;      
  41. P0 = 0x20;     
  42. P2 &= ~(0xc0);   
  43. P0 = 0xff;   
  44. P2 |= 0xe0;   
  45. P0 =  Seg_Yang_Led_Table[2];
  46. P2 &= ~(0xe0);   
  47. P0 = 0x00;   
  48. Delay1ms();
  49. P2 |= 0xc0;      
  50. P0 = 0x10;     
  51. P2 &= ~(0xc0);   
  52. P0 = 0xff;   
  53. P2 |= 0xe0;   
  54. P0 =  Seg_Yang_Led_Table[3];
  55. P2 &= ~(0xe0);   
  56. P0 = 0x00;   
  57. Delay1ms();
  58. P2 |= 0xc0;      
  59. P0 = 0x08;     
  60. P2 &= ~(0xc0);   
  61. P0 = 0xff;   
  62. P2 |= 0xe0;   
  63. P0 =  Seg_Yang_Led_Table[4];
  64. P2 &= ~(0xe0);   
  65. P0 = 0x00;   
  66. Delay1ms();
  67.   
  68. P2 |= 0xc0;      
  69. P0 = 0x04;     
  70. P2 &= ~(0xc0);   
  71. P0 = 0xff;   
  72. P2 |= 0xe0;   
  73. P0 =  Seg_Yang_Led_Table[5];
  74. P2 &= ~(0xe0);   
  75. P0 = 0x00;   
  76. Delay1ms();
  77. P2 |= 0xc0;      
  78. P0 = 0x02;     
  79. P2 &= ~(0xc0);   
  80. P0 = 0xff;   
  81. P2 |= 0xe0;   
  82. P0 =  Seg_Yang_Led_Table[6];
  83. P2 &= ~(0xe0);   
  84. P0 = 0x00;   
  85. Delay1ms();
  86.   
  87. P2 |= 0xc0;      
  88. P0 = 0x01;     
  89. P2 &= ~(0xc0);   
  90. P0 = 0xff;   
  91. P2 |= 0xe0;   
  92. P0 =  Seg_Yang_Led_Table[7];
  93. P2 &= ~(0xe0);   
  94. P0 = 0x00;   
  95. Delay1ms();
  96. }
  97. #endif
复制代码







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1