目录
资料下载地址:单片机排队叫号系统Proteus仿真程序 有取号键和叫号键以及重复叫号键 有注释
1、前言
系统组成:STC89C52RC+Lcd1602+蜂鸣器+按键
具体介绍:
Lcd1602排队叫号系统,有取号显示窗和叫号显示窗。有取号键和叫号键以及重复叫号键。可以显示你前面有几人在等候。具体看图片上面。
2、程序
cpp
void init()//初始化
{
t0=0;
windown=0;
num=0;
buzzer=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;//定时器0
init_lcd2();
init_lcd1();
}
void main()
{
init();
while(1)
{
display_lcd2(num);
}
}
void keyscan()//按键检测
{
if(k0==0)//患者叫号按键检测
{
delay(10);//延时消抖
if(k0==0)
num++;//号码数加1
while(!k0);
delay(10);//延时消抖
while(!k0);//按键松手检测
}
if(k1==0)//一号诊室呼叫
{
delay(10);
if(k1==0)
{
if(num1<num)
{
windown=1;
num1++;
TR0=1;
num2_1=num1;
display_lcd1(num1,windown);//液晶一显示当前呼叫的号码
}
}
while(!k1);
delay(10);//延时消抖
while(!k1);//按键松手检测
}
if(k2==0)//二号诊室呼叫
{
delay(10);
if(k2==0)
{
if(num1<num)
{
windown=2;
num1++;
TR0=1;
num2_2=num1;
display_lcd1(num1,windown);//液晶一显示当前呼叫的号码
}
}
while(!k2);
delay(10);//延时消抖
while(!k2);//按键松手检测
}
if(k3==0)//三号诊室呼叫
{
delay(10);
if(k3==0)
{
if(num1<num)
{
windown=3;
num1++;
TR0=1;
num2_3=num1;
display_lcd1(num1,windown);//液晶一显示当前呼叫的号码
}
}
while(!k3);
delay(10);//延时消抖
while(!k3);//按键松手检测
}
if(k4==0)//四号诊室呼叫
{
delay(10);
if(k4==0)
{
if(num1<num)
{
windown=4;
num1++;
TR0=1;
num2_4=num1;
display_lcd1(num1,windown);//液晶一显示当前呼叫的号码
}
}
while(!k4);
delay(10);//延时消抖
while(!k4);//按键松手检测
}
if(p1==0)//一号诊室重新呼叫
{
delay(10);
if(p1==0)
{
TR0=1;
display_lcd1(num2_1,1);
}
while(!p1);
delay(10);//延时消抖
while(!p1);//按键松手检测
}
if(p2==0)//二号诊室重新呼叫
{
delay(10);
if(p2==0)
{
TR0=1;
display_lcd1(num2_2,2);
}
while(!p2);
delay(10);//延时消抖
while(!p2);//按键松手检测
}
if(p3==0)//三号诊室重新呼叫
{
delay(10);
if(p3==0)
{
TR0=1;
display_lcd1(num2_3,3);
}
while(!p3);
delay(10);//延时消抖
while(!p3);//按键松手检测
}
if(p4==0)//四号诊室重新呼叫
{
delay(10);
if(p4==0)
{
TR0=1;
display_lcd1(num2_4,4);
}
while(!p4);
delay(10);//延时消抖
while(!p4);//按键松手检测
}
}
void write_order1(uchar order)//写指令函数 液晶1
{
rs1=0;
en1=0;
P0=order;
delay(1);
en1=1;
delay(1);
en1=0;
}
void write_dat1(uchar dat)//写数据函数 液晶1
{
rs1=1;
en1=0;
P0=dat;
delay(1);
en1=1;
delay(1);
en1=0;
}
void init_lcd1()//液晶1初始化
{
write_order1(0x38);
write_order1(0x0c);
write_order1(0x06);
write_order1(0x80+1);
// write_order1(0x01);//液晶必备的一些初始化
for(i=0;i<16;i++)
write_dat1(table1_1[i]);
write_order1(0x80+0x40); //液晶显示换行
for(i=0;i<16;i++)
write_dat1(table1_2[i]);
}
void write_add1(uchar address,uchar dat)//指定地址写入数据
{
write_order1(0x80+address);
write_dat1(dat);
}
void display_lcd1(uint num1,uchar windown)//液晶1显示
{
uchar a,b,c,d;//用于液晶
a=num1/1000;
b=num1%1000/100;
c=num1%1000%100/10;
d=num1%10;
write_add1(4,table2[a]);
write_add1(5,table2[b]);
write_add1(6,table2[c]);
write_add1(7,table2[d]);
write_add1(0x40,table2[windown]);
}
void write_order2(uchar order)//写指令函数 液晶2
{
rs2=0;
en2=0;
P1=order;
delay(1);
en2=1;
delay(1);
en2=0;
}
void write_dat2(uchar dat)//写数据函数 液晶2
{
rs2=1;
en2=0;
P1=dat;
delay(1);
en2=1;
delay(1);
en2=0;
}
void init_lcd2()//液晶2初始化
{
write_order2(0x38);
write_order2(0x0c);
write_order2(0x06);
write_order2(0x80);
write_order2(0x00);
for(i=0;i<12;i++)
write_dat2(table2_2[i]);
write_order2(0x80+0x40); //液晶显示换行
for(i=0;i<12;i++)
write_dat2(table2_1[i]);
}
void write_add2(uchar address,uchar dat)//指定地址写入数据
{
write_order2(0x80+address);
write_dat2(dat);
}
void write_add3(uchar address,uchar dat)//指定地址写入数据
{
write_order2(0x80+0x40+address);
write_dat2(dat);
}
void display_lcd2(uint num)//液晶2显示
{
uchar a,b,c,d;//用于液晶
uchar e,f,g,h;//显示等待人数
a=num/1000;
b=num%1000/100;
c=num%1000%100/10;
d=num%10;
write_add2(12,table2[a]);
write_add2(13,table2[b]);
write_add2(14,table2[c]);
write_add2(15,table2[d]);
if(num!=num1) //显示前面等待的人数
{
e=(num-num1-1)/1000;
f=(num-num1-1)%1000/100;
g=(num-num1-1)%1000%100/10;
h=(num-num1-1)%10;
}
else
{
e=(num-num1)/1000;
f=(num-num1)%1000/100;
g=(num-num1)%1000%100/10;
h=(num-num1)%10;
}
write_add3(12,table2[e]);
write_add3(13,table2[f]);
write_add3(14,table2[g]);
write_add3(15,table2[h]);
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
bi(100);
if(t0>20)
{
TR0=0;
t0=0;
buzzer=1;
}
}