找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1174|回复: 1
收起左侧

单片机排队叫号系统 程序有错误 求分析

[复制链接]
ID:741328 发表于 2020-5-4 17:03 | 显示全部楼层 |阅读模式
新人求大佬解答!!
银行叫号系统。八个按键代表八个窗口,窗口号与按键号对应。排队号依次加1,加到99后,重新从1开始,按键每按一下,发三声提示音。
现在不管按哪个键都是这样显示,有没有大佬帮忙分析一下程序啊。

单片机源程序如下:
  1. //***********************************************************************************
  2. #include <STC15F2K60S2.H>
  3. //*********************************用户数据类型定义**********************************
  4. typedef unsigned char uchar;
  5. typedef unsigned int uint;
  6. static uint w;
  7. //*************************************用户引脚定义**********************************
  8. sbit beep_dr = P3^7;
  9. sbit key1 = P1^0;
  10. sbit key2 = P1^1;
  11. sbit key3 = P1^2;
  12. sbit key4 = P1^3;
  13. sbit key5 = P1^4;
  14. sbit key6 = P1^5;
  15. sbit key7 = P1^6;
  16. sbit key8 = P1^7;
  17. //*************************************共阳极数码管断码数组**************************
  18. uchar code DigSegBuff[] =         //排队号
  19. {
  20.     0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
  21. };
  22. uchar code WindowBuff[] =        //窗口号
  23. {
  24.     0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
  25. };

  26. //*************************************函数声明区***********************************
  27. void DelayMs(uint uiXms);    //有阻塞的延时函数声明
  28. void IniSystem();                 //系统初始化函数声明
  29. void IniPeripherals();             //外围器件初始化函数声明
  30. void BeepVoice();                 //蜂鸣器发出“嘀”的声音函数声明
  31. void MatrixKeyScan();             //按键识别函数声明
  32. void DigDisplay();           //数码管显示函数声明                                                         
  33. //*************************************主函数区************************************
  34. void main()
  35. {
  36.           IniSystem();
  37.           DelayMs(200);
  38.           IniPeripherals();
  39.           DelayMs(200);
  40.           while(1)
  41.           {
  42.                        DigDisplay();
  43.           }
  44. }
  45. //*************************************函数定义区************************************
  46. void DelayMs(uint uiXms)    //有阻塞的延时函数定义
  47. {
  48.     uint i,j;
  49.         for(i=uiXms;i>0;i--)
  50.         {
  51.             for(j=110;j>0;j--);
  52.         }
  53. }

  54. void IniSystem()           //系统初始化函数定义
  55. {
  56.         P0 = 0xff;
  57.                 P1 = 0xff;
  58.                 P2 = 0xff;        
  59.             beep_dr = 1;
  60. }

  61. void IniPeripherals()       //外围器件初始化函数定义
  62. {
  63.    
  64.           BeepVoice();                    //系统发出三种提示音
  65.           BeepVoice();
  66.           BeepVoice();
  67.           EA=1;         //总中断允许控制位
  68.           IT0=1;          //中断触发位
  69.           EX0=1;         //外部中断允许位
  70. }

  71. void BeepVoice()            //蜂鸣器发出“嘀”声函数定义
  72. {
  73.     beep_dr = 0;                //蜂鸣器开
  74.         DelayMs(70);
  75.         beep_dr = 1;                // 蜂鸣器关
  76.         DelayMs(70);
  77. }


  78. void MatrixKeyScan()            //按键识别函数定义
  79. interrupt 0                         //中断0   外部中断0
  80. {
  81.     EX0 = 0;
  82. //    uchar ucTemp;
  83. //        uint w;
  84.     while(P1 == 0xff);
  85.         DelayMs(10);                  
  86.         if(P1 != 0xff)
  87.         {
  88.             BeepVoice();
  89.                 BeepVoice();
  90.                 BeepVoice();
  91. //            ucTemp = P1;
  92.                 while(P1 != 0xff)
  93.                 {
  94.                     
  95.                         if(key1==0)
  96.                         {w=1;}
  97.                         if(key2==0)
  98.                         {w=2;}
  99.                         if(key3==0)
  100.                         {w=3;}
  101.                         if(key4==0)
  102.                         {w=4;}
  103.                         if(key5==0)
  104.                         {w=5;}
  105.                         if(key6==0)
  106.                         {w=6;}
  107.                         if(key7==0)
  108.                         {w=7;}
  109.                         if(key8==0)
  110.                         {w=8;}
  111.                 }
  112.         }
  113. EX0 = 1;
  114. }         

  115. void DigDisplay()           //数码管显示函数定义
  116. {
  117.     static uint h=1;
  118. //        static uint w=0;
  119.         uchar ucBitCode;                //定义位码  
  120.     for(P1 != 0xff)
  121.         {
  122. //            uint h,w;
  123. //                MatrixKeyScan();
  124.             ucBitCode = 0x01;  //位码高电平亮
  125.         P2 =0xc0;         //显示0
  126.                 P0 =~ucBitCode;
  127.                 DelayMs(3);              
  128.             P0 = 0xff;                    //关闭所有数码管
  129.                 DelayMs(1);
  130.                 ucBitCode = ucBitCode<<1;


  131.                 P2 = WindowBuff[w];   //显示窗口号
  132.                 P0 =~ucBitCode;
  133.                 DelayMs(3);
  134.             P0 = 0xff;
  135.                 DelayMs(1);
  136.                 ucBitCode = ucBitCode<<1;

  137.                 P2 = 0xbf;                                 //不显示
  138.                 P0 = ~ucBitCode;
  139.                 DelayMs(3);
  140.                 P0 = 0xff;
  141.                 DelayMs(1);                                 
  142.             ucBitCode = ucBitCode<<1;     

  143.                 P2 = 0xbf;                          //显示“-”
  144.                 P0 = ~ucBitCode;
  145.                 DelayMs(3);
  146.                 P0 = 0xff;
  147.                 DelayMs(1);
  148.                 ucBitCode = ucBitCode<<1;

  149.                 P2 = 0xbf;                          //显示“-”
  150.                 P0 = ~ucBitCode;
  151.                 DelayMs(3);
  152.                 P0 = 0xff;
  153.                 DelayMs(1);
  154.                 ucBitCode = ucBitCode<<1;

  155.                 P2 = 0xbf;                                 //不显示
  156.                 P0 = ~ucBitCode;
  157.                 DelayMs(3);
  158.                 P0 = 0xff;
  159.                 DelayMs(1);                                 
  160.             ucBitCode = ucBitCode<<1;


  161.                 P2 =DigSegBuff[h/10];   //显示排队号十位
  162.                 P0 =~ucBitCode;
  163.                 DelayMs(3);
  164.             P0 = 0xff;
  165.                 DelayMs(1);
  166.                 ucBitCode = ucBitCode<<1;

  167.                 P2 =DigSegBuff[h%10];   //显示排队号的个位
  168.                 P0 =~ucBitCode;
  169.                 DelayMs(3);
  170.             P0 = 0xff;
  171.                 DelayMs(1);
  172.                 ucBitCode = ucBitCode<<1;            
  173.                 h++;
  174.             if(h>99)
  175.                 {
  176.                     h = 1;
  177.                 }
  178.         }
  179. }
复制代码

现在不管按哪个键都是这样显示

现在不管按哪个键都是这样显示

正常要显示这个

正常要显示这个
回复

使用道具 举报

ID:593646 发表于 2020-5-4 19:51 | 显示全部楼层
我的解决思路:一个个问题差过去,先选一个按键按下一直不变的话,不用按键,直接改代码,让数码管全部显示1,如果还是没效果,连接看一看,程序显示函数查一查
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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