|
新人求大佬解答!!
银行叫号系统。八个按键代表八个窗口,窗口号与按键号对应。排队号依次加1,加到99后,重新从1开始,按键每按一下,发三声提示音。
现在不管按哪个键都是这样显示,有没有大佬帮忙分析一下程序啊。
单片机源程序如下:
- //***********************************************************************************
- #include <STC15F2K60S2.H>
- //*********************************用户数据类型定义**********************************
- typedef unsigned char uchar;
- typedef unsigned int uint;
- static uint w;
- //*************************************用户引脚定义**********************************
- sbit beep_dr = P3^7;
- sbit key1 = P1^0;
- sbit key2 = P1^1;
- sbit key3 = P1^2;
- sbit key4 = P1^3;
- sbit key5 = P1^4;
- sbit key6 = P1^5;
- sbit key7 = P1^6;
- sbit key8 = P1^7;
- //*************************************共阳极数码管断码数组**************************
- uchar code DigSegBuff[] = //排队号
- {
- 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
- };
- uchar code WindowBuff[] = //窗口号
- {
- 0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
- };
-
- //*************************************函数声明区***********************************
- void DelayMs(uint uiXms); //有阻塞的延时函数声明
- void IniSystem(); //系统初始化函数声明
- void IniPeripherals(); //外围器件初始化函数声明
- void BeepVoice(); //蜂鸣器发出“嘀”的声音函数声明
- void MatrixKeyScan(); //按键识别函数声明
- void DigDisplay(); //数码管显示函数声明
- //*************************************主函数区************************************
- void main()
- {
- IniSystem();
- DelayMs(200);
- IniPeripherals();
- DelayMs(200);
- while(1)
- {
- DigDisplay();
- }
- }
- //*************************************函数定义区************************************
- void DelayMs(uint uiXms) //有阻塞的延时函数定义
- {
- uint i,j;
- for(i=uiXms;i>0;i--)
- {
- for(j=110;j>0;j--);
- }
- }
- void IniSystem() //系统初始化函数定义
- {
- P0 = 0xff;
- P1 = 0xff;
- P2 = 0xff;
- beep_dr = 1;
- }
- void IniPeripherals() //外围器件初始化函数定义
- {
-
- BeepVoice(); //系统发出三种提示音
- BeepVoice();
- BeepVoice();
- EA=1; //总中断允许控制位
- IT0=1; //中断触发位
- EX0=1; //外部中断允许位
- }
- void BeepVoice() //蜂鸣器发出“嘀”声函数定义
- {
- beep_dr = 0; //蜂鸣器开
- DelayMs(70);
- beep_dr = 1; // 蜂鸣器关
- DelayMs(70);
- }
-
- void MatrixKeyScan() //按键识别函数定义
- interrupt 0 //中断0 外部中断0
- {
- EX0 = 0;
- // uchar ucTemp;
- // uint w;
- while(P1 == 0xff);
- DelayMs(10);
- if(P1 != 0xff)
- {
- BeepVoice();
- BeepVoice();
- BeepVoice();
- // ucTemp = P1;
- while(P1 != 0xff)
- {
-
- if(key1==0)
- {w=1;}
- if(key2==0)
- {w=2;}
- if(key3==0)
- {w=3;}
- if(key4==0)
- {w=4;}
- if(key5==0)
- {w=5;}
- if(key6==0)
- {w=6;}
- if(key7==0)
- {w=7;}
- if(key8==0)
- {w=8;}
- }
- }
- EX0 = 1;
- }
- void DigDisplay() //数码管显示函数定义
- {
- static uint h=1;
- // static uint w=0;
- uchar ucBitCode; //定义位码
- for(P1 != 0xff)
- {
- // uint h,w;
- // MatrixKeyScan();
- ucBitCode = 0x01; //位码高电平亮
- P2 =0xc0; //显示0
- P0 =~ucBitCode;
- DelayMs(3);
- P0 = 0xff; //关闭所有数码管
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 = WindowBuff[w]; //显示窗口号
- P0 =~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 = 0xbf; //不显示
- P0 = ~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 = 0xbf; //显示“-”
- P0 = ~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 = 0xbf; //显示“-”
- P0 = ~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 = 0xbf; //不显示
- P0 = ~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 =DigSegBuff[h/10]; //显示排队号十位
- P0 =~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- P2 =DigSegBuff[h%10]; //显示排队号的个位
- P0 =~ucBitCode;
- DelayMs(3);
- P0 = 0xff;
- DelayMs(1);
- ucBitCode = ucBitCode<<1;
- h++;
- if(h>99)
- {
- h = 1;
- }
- }
- }
复制代码 |
-
1.png
(67.82 KB, 下载次数: 25)
现在不管按哪个键都是这样显示
-
2.png
(192.95 KB, 下载次数: 32)
正常要显示这个
|