- #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发声
- {
- 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) // 写入数据
- {
- 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); // 光标归位 即光标置于左上位置
- }
- void init_LCD(void) // 初始化LCD
- {
- LCD_w_com(0x38); // LCD为两行显示8位数据线有效
- LCD_w_com(0x0c); // 显示字符 关闭光标
- LCD_w_com(0x06); // 输入方式设置 光标向右移动一位 ac-1
- gotoxy(1,0);
- for(i=0;i<=5;i++)
- {
- LCD_w_dat(test[i]);
- }
- }
- //*********叫号机 按一次一号键变量+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) /// ******叫号机程序*******
- {
- 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) // 统计等待人数
- {
- 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) // 统计客流量
- {
- 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) // 统计各窗口客流量
- {
- 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;
- }
复制代码 |