找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1667|回复: 0
打印 上一主题 下一主题
收起左侧

封装为一个通用性数码管单片机函数,求指教哦

[复制链接]
跳转到指定楼层
楼主

原理图:


单片机源程序如下:
  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
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表