标题: 单片机程序和仿真图都没有错误,仿真结果出不来,候车大厅人数检测的 [打印本页]

作者: 1923780622    时间: 2020-6-30 00:18
标题: 单片机程序和仿真图都没有错误,仿真结果出不来,候车大厅人数检测的



  1. #include <reg52.h>
  2. #include <intrins.h>#define uchar unsigned char
  3. #define uint unsigned intuint count=0;
  4. uint sudu=0;
  5. uchar time;
  6. uint num;
  7. sbit beep = P3^7;
  8. sbit key1 = P3^5;
  9. sbit key2 = P3^6;
  10. uchar dat[4]={0,1,2,3};uchar table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
  11. void delayms(unsigned int x)
  12. {
  13. unsigned char j;
  14. while(x--)
  15. {
  16. for(j=0;j<123;j++){;}
  17. }
  18. }
  19. void display ()
  20. {
  21. uchar i,dis=0x7f;
  22. for(i=0;i<4;i++)
  23. {
  24. P1=~table[dat[i]];
  25. P0=dis;
  26. dis=(dis>>1)|0x80;
  27. delayms(1);
  28. }
  29. }
  30. void process(uint i)
  31. {
  32. dat[0]=num/10;
  33. dat[1]=num%10;
  34. dat[2]=i/10;
  35. dat[3]=i%10;}
  36. void keyClear(){
  37. if(key1==0)
  38. {
  39. delayms(10);
  40. if(key1==0)
  41. {
  42. count=0;
  43. }
  44. while(!key1)
  45. {
  46. process(count);
  47. display();
  48. };
  49. }
  50. }
  51. void keySet(){
  52. if(key2==0)
  53. {
  54. delayms(10);
  55. if(key2==0)
  56. {
  57. num++;
  58. }
  59. while(!key2)
  60. {
  61. process(count);
  62. display();
  63. };
  64. }
  65. }
  66. void BJ()
  67. {
  68. if(count>=num)
  69. beep=0;
  70. else
  71. beep=1;
  72. }
  73. void main()
  74. {
  75. ET0=1;
  76. IT0=1;
  77. EX0=1;
  78. EA=1;
  79. beep=1;
  80. num=10;
  81. while(1)
  82. {
  83. keyClear();
  84. keySet();
  85. BJ();
  86. process(count);
  87. display();
  88. }
  89. }
  90. void ex0(void) interrupt 0 using 0
  91. {
  92. count++;
  93. }
复制代码


作者: man1234567    时间: 2020-7-1 08:22
传说中的电脑坏了




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