蛋疼, 为什么它就不动态显示了呢(89C52单片机)

2019-07-16 06:36发布

  1. #include "reg52.h"
  2. #include "intrins.h"
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. #define STOP 398
  6. //特殊寄存器申明
  7. sbit section=P2^7;
  8. sbit part=P2^6;
  9. //-----------------------
  10. uchar temp,timer_0,timer_1,hundred,ten,one;
  11. uint digital_num;
  12. /*---------(0,1,2,3,4,5,6,7,8,9)--------*/
  13. uchar code digital_list[]={
  14. 0x3f,0x06,0x5b,0x4f,0x66,
  15. 0x6d,0x7d,0x07,0x7f,0x67};
  16. /*------------------------------------*/
  17. void init();
  18. void display(uchar section_1,uchar section_2,uchar section_3,uchar section_4,uchar section_5,uchar section_6);

  19. void delay(uint x)
  20. {
  21. uchar a,b;
  22. for(a=x;a>=0;a--)
  23. for(b=110;b>=0;b--)
  24. ;
  25. }


  26. void main()
  27. {
  28. init();
  29. while(1)
  30. {
  31. // display(7,6,5,hundred,ten,one);
  32. }

  33. }

  34. void init()
  35. {
  36. digital_num=432;
  37. temp=0xfe;
  38. P1=temp;
  39. TMOD=0x11;
  40. TH0=(65536-50000)/256;
  41. TL0=(65536-50000)%256;
  42. TH1=(65536-50000)/256;
  43. TL1=(65536-50000)%256;
  44. EA=1;
  45. ET0=1;
  46. ET1=1;
  47. TR0=1;
  48. TR1=1;
  49. }

  50. void time0() interrupt 1
  51. {
  52. TH0=(65536-50000)/256;
  53. TL0=(65536-50000)%256;
  54. timer_0++;
  55. if(timer_0==10)
  56. {
  57. timer_0=0;
  58. temp=_crol_(temp,1);
  59. P1=temp;
  60. }
  61. }

  62. void time1() interrupt 3
  63. {
  64. TH1=(65536-50000)/256;
  65. TL1=(65536-50000)%256;
  66. timer_1++;
  67. //display(7,6,5,hundred,ten,one);
  68. if(timer_1==2)
  69. {
  70. timer_1=0;
  71. /*----------进行位分解------------------*/
  72. hundred=digital_num/100;
  73. ten=digital_num/10%10;
  74. one=digital_num%10;
  75. /*---------------------------------------*/
  76. digital_num--;
  77. if(digital_num==STOP)
  78. {
  79. TR0=0;
  80. TR1=0;
  81. }
  82. }
  83. }

  84. /*------------------------------------------数码管动态扫描---------------------------------------------------*/
  85. void display(uchar section_1,uchar section_2,uchar section_3,uchar section_4,uchar section_5,uchar section_6)
  86. {
  87. part=1;
  88. P0=digital_list[section_1];
  89. part=0;
  90. P0=0xff;
  91. section=1;
  92. P0=0xfe;
  93. section=0;
  94. delay(1);

  95. part=1;
  96. P0=digital_list[section_2];
  97. part=0;
  98. P0=0xff;
  99. section=1;
  100. P0=0xfd;
  101. section=0;
  102. delay(1);

  103. part=1;
  104. P0=digital_list[section_3];
  105. part=0;
  106. P0=0xff;
  107. section=1;
  108. P0=0xfb;
  109. section=0;
  110. delay(1);

  111. part=1;
  112. P0=digital_list[section_4];
  113. part=0;
  114. P0=0xff;
  115. section=1;
  116. P0=0xf7;
  117. section=0;
  118. delay(1);

  119. part=1;
  120. P0=digital_list[section_5];
  121. part=0;
  122. P0=0xff;
  123. section=1;
  124. P0=0xef;
  125. section=0;
  126. delay(1);

  127. part=1;
  128. P0=digital_list[section_6];
  129. part=0;
  130. P0=0xff;
  131. section=1;
  132. P0=0xdf;
  133. section=0;
  134. delay(1);
  135. }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。