新人求大佬解答!!
銀行叫號系統。八個按鍵代表八個窗口,窗口號與按鍵號對應。排隊號依次加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;
- }
- }
- }
復制代碼 |