|
- #include <reg52.h>
- void delay1ms(int n) //延時子程序
- {
- int k,j;
- for(k=0;k<=n;k++)
- for(j=0;j<=10;j++);
- }
- void delay1s(int n) //延時子程序
- {
- int k,j;
- for(k=0;k<=n;k++)
- for(j=0;j<=120;j++);
- }
- void SPEAKER(uint n) //蜂鳴器程序,按周期n發(fā)聲
- {
- for(i=0;i<=200;i++)
- {
- delay(10);
- BEEP=~BEEP;
- }
- BEEP=1; }// ***********************************LCD程序**********
- void delay1ms(unsigned int ms)//延時的時間不夠精確的
- {
- uint k,j;
- for(k=0;k<ms;k++)
- for(j=0;j<100;j++);
- }
- void LCD_w_com(unsigned com) //寫入指令
- {
- RW=0;
- RS=0;
- E=1;
- P0=com;
- delay1ms(40);
- E=0;
- RW=1;
- }
- void LCD_w_dat(uchar dat) // 寫入數(shù)據(jù)
- {
- RW=0;
- RS=1;
- E=1;
- P0=dat;
- delay1ms(40);
- E=0;
- RW=1;
- }
- void gotoxy(unsigned x,unsigned y) // x,y分別代表行列
- {
- if(x==1)
- LCD_w_com(0x80+y);
- else
- LCD_w_com(0xC0+y);
- }
- void clear_LCD(void)
- {
- LCD_w_com(0x01); // 清屏指令
- LCD_w_com(0x02); // 光標(biāo)歸位 即光標(biāo)置于左上位置
- }
- void init_LCD(void) // 初始化LCD
- {
- LCD_w_com(0x38); // LCD為兩行顯示8位數(shù)據(jù)線有效
- LCD_w_com(0x0c); // 顯示字符 關(guān)閉光標(biāo)
- LCD_w_com(0x06); // 輸入方式設(shè)置 光標(biāo)向右移動一位 ac-1
- gotoxy(1,0);
- for(i=0;i<=5;i++)
- {
- LCD_w_dat(test[i]);
- }
- }
- //*********叫號機(jī) 按一次一號鍵變量+1最大為10*************
- void QueueNumProcess()
- {
- rank[Length Flag]=num_count; // num_count為實時取得的號碼
- Length Flag++;
- }
- if(Length Flag>10) (void)
- {
- EA=1;
- EX0=1;
- EX1=1;
- IT0=1;
- IT1=1;
- clear_LCD();
- init_LCD();
- while(1)
- {
- delay1s(10000);
- clear_LCD();
- gotoxy(1,0);
- for(i=0;i<=5;i++)
- {
- LCD_w_dat(test[i]);
- }
- delay1s(10000);
- clear_LCD();
- prompt8[0]=Length Flag10+'0';
- prompt8[1]=Length Flag%10+'0';
- gotoxy(1,0);
- for(m=0;m<=9;m++)
- {
- LCD_w_dat(prompt8[m]);
- }
- delay1s(10000);
- clear_LCD();
- ClearNumProcess();
- prompt2[3]=(num)10+'0';
- prompt2[4]=(num)%10+'0';
- prompt3[1]=jz+'0';
- gotoxy(1,0);
- for(m=0;m<=15;m++)
- {
- LCD_w_dat(prompt2[m]);
- }
- gotoxy(2,0);
- for(m=0;m<=15;m++)
- {
- LCD_w_dat(prompt3[m]);
- }
- }
- } //**************按鍵中斷方式**********************
- void int_x0() interrupt 0
- {
- if(!key1) {jz=1;sev1++;}
- if(!key2) {jz=2;sev2++;}
- if(!key3) {jz=3;sev3++;}
- if(!key4) {jz=4;sev4++;}
- if(!key0) /// ******叫號機(jī)程序*******
- {
- while(!key0);
- if(Length Flag<=10)
- {
- clear_LCD();
- QueueNumProcess();
- prompt1[11]=(num_count)10+'0'; prompt1[12]=(num_count)%10+'0';
- num_count++;
- }
- else
- {
- clear_LCD();
- gotoxy(1,2);
- for(m=0;m<=10;m++)
- {
- LCD_w_dat(prompt4[m]);
- }
- gotoxy(2,0);
- for(m=0;m<=15;m++)
- {
- LCD_w_dat(prompt5[m]); // 提示隊列已滿
- }
- }
- key5=0;
- }
- if((!key1||!key2||!key3||!key4)&&key0) // *******消號處理******
- {
- while((!key1||!key2||!key3||!key4)&&key0);
- {
- SPEAKER(11);
- delay(200);
- SPEAKER(15);
- if(Length Flag<1)
- {
- clear_LCD();
- gotoxy(1,0);
- for(m=0;m<=15;m++)
- {
- LCD_w_dat(prompt6[m]);
- }
- gotoxy(2,0);
- for(m=0;m<=8;m++)
- {
- LCD_w_dat(prompt7[m]);
- }// 顯示隊列為空
- }
- else
- {
- clear_LCD();
- ClearNumProcess();
- prompt2[3]=(num)10+'0';
- prompt2[4]=(num)%10+'0';
- prompt3[1]=jz+'0';
- gotoxy(1,0);
- for(m=0;m<=15;m++)
- {
- LCD_w_dat(prompt2[m]);
- }
- gotoxy(2,0);
- for(m=0;m<=15;m++)
- {
- LCD_w_dat(prompt3[m]);
- }
- }
- }
- }
- }
- void int_x1() interrupt 2
- {
- if(!key5) // 統(tǒng)計等待人數(shù)
- {
- key5=1;
- clear_LCD();
- prompt8[0]=Length Flag10+'0';
- prompt8[1]=Length Flag%10+'0';
- gotoxy(1,0);
- for(m=0;m<=9;m++)
- {
- LCD_w_dat(prompt8[m]);
- }
- }
- if(!key6) // 統(tǒng)計客流量
- {
- clear_LCD();
- prompt9[7]=(sev)10+'0';
- prompt9[8]=(sev)%10+'0';
- gotoxy(1,0);
- for(m=0;m<=9;m++)
- {
- LCD_w_dat(prompt9[m]);
- }
- }
- if(!key7) // 統(tǒng)計各窗口客流量
- {
- clear_LCD();
- prompt10[5]=sev110+'0';
- prompt10[6]=sev1%10+'0';
- prompt11[5]=sev210+'0';
- prompt11[6]=sev2%10+'0';
- prompt12[5]=sev310+'0';
- prompt12[6]=sev3%10+'0';
- prompt13[5]=sev410+'0';
- prompt13[6]=sev4%10+'0';
- gotoxy(1,0);
- for(m=0;m<=7;m++)
- {
- LCD_w_dat(prompt10[m]);
- }
- gotoxy(1,8);
- for(m=0;m<=7;m++)
- {
- LCD_w_dat(prompt11[m]);
- }
- gotoxy(2,0);
- for(m=0;m<=7;m++)
- {
- LCD_w_dat(prompt12[m]);
- }
- gotoxy(2,8);
- for(m=0;m<=7;m++)
- {
- LCD_w_dat(prompt13[m]);
- }
- }
- if(!cd) // 插隊處理
- {
- clear_LCD();
- gotoxy(1,0);
- for(m=0;m<=6;m++)
- {
- LCD_w_dat(prompt14[m]);
- }
- Length Flag++;
- for(i=1;i<Length Flag;i++)
- rank[Length Flag-i]=rank[Length Flag-i-1];
- rank[0]=10;
- }
- IT1=0;
- }
復(fù)制代碼 |
|