专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
基于51单片机的电梯控制系统
2019-07-15 16:27
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
18050
6
1745
各位大神,帮帮忙,本人新手,在做51
单片机
的电梯控制系统,我想请问1、怎么去控制直流电机的转速,
我想在规定时间内电机速度从零开始增加,然后逐渐减小,到达平层时变成零。
2、怎么样去获取到达平层的信息,我现在在protues
仿真
中用的是按键,手动去获取。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
大好大
2019-07-15 23:23
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define MAX_FLOOR 5//楼层高度
uchar count,count1;
uchar disnum,pwm1h,pwm2h,num,cycle,high,low;
uchar gf,b;//gf 表示目的层,b 为等待计数累加位
uint nf;//当前所在楼层
uint up_call[MAX_FLOOR],down_call[MAX_FLOOR],in_call[MAX_FLOOR];//存放呼叫事件
uchar code dis[]= {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//0-16 数码显示代码
sbit F5=P0^0; // 电梯内5 楼
sbit F4=P0^1; // 电梯内4 楼
sbit F3=P0^2; // 电梯内3 楼
sbit F2=P0^3; // 电梯内2 楼
sbit F1=P0^4; // 电梯内1 楼
sbit F1U=P0^5; //1 楼向上按钮
sbit F2U=P0^6; //2 楼向上按钮
sbit F2D=P0^7; //2 楼向下按钮
sbit F3U=P2^0; //3 楼向上按钮
sbit F3D=P2^1; //3 楼向下按钮
sbit F4U=P2^2; //4 楼向上按钮
sbit F4D=P2^3; //4 楼向下按钮
sbit F5D=P2^4; //5 楼向下按钮
sbit pwm1=P3^5; //正转控制位
sbit pwm2=P3^6; //反转控制位
sbit EN=P3^7; //L298 使能端信号
sbit YI= P3^0; //一楼霍尔输出信号
sbit ER=P3^1; //二楼霍尔输出信号
sbit SAN=P3^2; //三楼霍尔处输出信号
sbit SI=P3^3; //四楼霍尔处输出信号
sbit WU=P3^4; //五楼霍尔处输出信号
//sbit wela=P2^7; //数码管位选1
sbit RING=P2^7;
sbit U=P2^5; //上行指示灯
sbit D=P2^6; //下行指示灯
void init(); // 初始化程序
void check(); //霍尔查询楼层
void display(uchar); //显示函数
void floor(); //楼层控制函数
void downer(); //下降函数
void uper(); //上升函数
void stop(); //停车函数
void getinput(); //按键查询函数
//************************************
// 初始化函数
void init()
{
TMOD=0x11;
EA=1;
ET0=1;
ET1=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
nf=1;
pwm1=0;
pwm2=0;
U=0;
D=0;
EN=0;
YI=1;
ER=1;
SAN=1;
SI=1;
WU=1;
RING=0;
}
//******************************************
//1ms 延时程序
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
//**************************
// 停车报警等待程序
void stop()
{
U=0;
D=0;
EN=0;
pwm1=0;
pwm2=0;
while(b!=120)
{
b++;
if(b>30)
{RING=0;}
else
RING=1;
display(nf);
}
TR0=0;
RING=0;
b=0;
disnum=0;
}
//按键检测程序;
// *********************************
void getinput()
{
if(F5D==0)
{
down_call[4]=1;
}
else if(F4D==0)
{
down_call[3]=1;
}
else if(F4U==0)
{
up_call[3]=1;
}
else if(F3D==0)
{
down_call[2]=1;
}
else if(F3U==0)
{
up_call[2]=1;
}
else if(F2D==0)
{
down_call[1]=1;
}
else if(F2U==0)
{
up_call[1]=1;
}
else if(F1U==0)
{
up_call[0]=1;
}
else if(F1==0)
{
in_call[0]=1;
}
else if(F2==0)
{
in_call[1]=1;
}
else if(F3==0)
{
in_call[2]=1;
}
else if(F4==0)
{
in_call[3]=1;
}
else if(F5==0)
{
in_call[4]=1;
}
}
//**************************
//上升程序;
void uper()
{
TR0=1;
U=1;
if(nf==1&&gf==5)
{
getinput(); //电梯在一楼去往五楼查询是否有顺路乘坐
check();
if(up_call[1]||in_call[1])
{
for(high=50;high<=100;high++)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
}
up_call[1]=0;
in_call[1]=0;
nf=2;
ER=0;
display(nf);
stop(); //停车
}
if(up_call[2]||in_call[2])
{
for(high=50;high<=100;high++)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
}
up_call[2]=0;
in_call[2]=0;
nf=3;
SAN=0;
display(nf);
stop(); //停车
}
if(up_call[3]||in_call[3])
{
for(high=50;high<=100;high++)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
}
up_call[3]=0;
in_call[3]=0;
nf=4;
SI=0;
display(nf);
stop(); //停车
}
}
while(nf!=gf)
{
TR0=1;
U=1;
getinput();
check();
pwm1=1;
pwm2=0;
display(nf);
}
stop();
}
//**************************
//下降程序
void downer()
{
TR0=1;
D=1;
if(nf==5&&gf==1)
{
getinput();//电梯在5 楼去往1 楼查询是否有顺路
check();
if(down_call[3]==1||(in_call[3]==1))
{
for(high=50;high<=100;high++)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
}
down_call[3]=0;
in_call[3]=0;
nf=4;
SI=0;
display(nf);
stop();
}
if(down_call[2]==1||(in_call[2]==1))
{
for(high=50;high<=100;high++)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
}
down_call[2]=0;
in_call[2]=0;
nf=3;
SAN=0;
display(nf);
stop();
}
if(down_call[1]==1||(in_call[1]==1))
{
for(high=50;high<=100;high++)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
}
down_call[1]=0;
in_call[1]=0;
nf=2;
ER=0;
display(nf);
stop();
}
}
while(nf!=gf)
{
TR0=1;
D=1;
getinput();
check();
pwm2=1;
pwm1=0;
display(nf);
}
stop();
}
//**************************
//霍尔楼层查询
void check()
{
if(YI==0)
{
nf=1;
display(nf);
}
if(ER==0)
{
nf=2;
display(nf);
}
if(SAN==0)
{
nf=3;
display(nf);
}
if(SI==0)
{
nf=4;
display(nf);
}
if(WU==0)
{
nf=5;
display(nf);
}
}
//**************************
//电梯运行方式控制程序
void floor()
{
if(nf==1) // 电梯在一楼
{
if(down_call[4]||in_call[4]) //5 楼为目的层
{
gf=5;
uper();
down_call[4]=0;
in_call[4]=0;
}
else
if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层
{
gf=4;
uper();
down_call[3]=0;
up_call[3]=0;
in_call[3]=0;
}
else
if(down_call[1]||up_call[1]||in_call[1]) //2 楼为目的层
{
gf=2;
uper();
down_call[1]=0;
up_call[1]=0;
in_call[1]=0;
}
else
if(down_call[2]||up_call[2]||in_call[2]) //3 楼为目的层
{
gf=3;
uper();
down_call[2]=0;
up_call[2]=0;
in_call[2]=0;
}
}
if(nf==2) //电梯在二楼
{
if(down_call[4]||in_call[4]) //5 楼为目的层
{
gf=5;
uper();
down_call[4]=0;
in_call[4]=0;
}
else
if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层
{
gf=3;
uper();
down_call[3]=0;
up_call[3]=0;
in_call[3]=0;
}
else
if(down_call[2]||up_call[2]||in_call[2]) //3 楼为目的层
{
gf=3;
uper();
down_call[2]=0;
up_call[2]=0;
in_call[2]=0;
}
if(up_call[0]||in_call[0]) //1 楼为目的层
{
gf=1;
downer();
up_call[0]=0;
in_call[0]=0;
}
}
if(nf==3)//电梯在三楼
{
if(down_call[4]||in_call[4]) //5 楼为目的层
{
gf=5;
uper();
down_call[4]=0;
in_call[4]=0;
}
else
if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层
{
gf=4;
uper();
down_call[3]=0;
up_call[3]=0;
in_call[3]=0;
}
else
if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层
{
gf=2;
downer();
down_call[1]=0;
in_call[1]=0;
up_call[1]=0;
}
else
if(in_call[0]||up_call[0]) //1 楼为目的层
{
gf=1;
downer();
in_call[0]=0;
up_call[0]=0;
}
}
if(nf==4)//电梯在四楼
{
if(in_call[4]||down_call[4]) //5 楼为目的层
{
gf=5;
uper();
in_call[4]=0;
down_call[4]=0;
}
else
if(in_call[2]||up_call[2]||down_call[2]) //3 楼为目的层
{
gf=3;
downer();
in_call[2]=0;
up_call[2]=0;
down_call[2]=0;
}
else
if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层
{
gf=2;
downer();
down_call[1]=0;
in_call[1]=0;
up_call[1]=0;
}
else
if(in_call[0]||up_call[0]) //1 楼为目的层
{
gf=1;
downer();
in_call[0]=0;
up_call[0]=0;
}
}
if(nf==5)//电梯在五楼
{
if(in_call[3]||up_call[3]||down_call[3]) //4 楼为目的层
{
gf=4;
downer();
in_call[3]=0;
up_call[3]=0;
down_call[3]=0;
}
else
if(in_call[2]||up_call[2]||down_call[2]) //3 楼为目的层
{
gf=3;
downer();
in_call[2]=0;
up_call[2]=0;
down_call[2]=0;
}
else
if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层
{
gf=2;
downer();
down_call[1]=0;
in_call[1]=0;
up_call[1]=0;
}
else
if(in_call[0]||up_call[0]) //1 楼为目的层
{
gf=1;
downer();
in_call[0]=0;
up_call[0]=0;
}
}
}
//显示函数
//*************************************
void display(uchar nf)
{
P1=dis[nf];
delay(5);
}
//主函数
//**************************************
void main()
{
init();
getinput();
while(1)
{
getinput();
check();
floor();
display(nf);
}
}
//中断定时计数程序
//***********************************
void t0(void) interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
disnum++;
if(disnum==1000)
{
disnum=0;
}
}
}
//************************************
void t1(void) interrupt 3 using 1
{
TH1=(65536-100)/256;
TL1=(65536-100)%256;
count1++;
EN=1;
}
加载中...
查看其它6个回答
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
#define uchar unsigned char
#define uint unsigned int
#define MAX_FLOOR 5//楼层高度
uchar count,count1;
uchar disnum,pwm1h,pwm2h,num,cycle,high,low;
uchar gf,b;//gf 表示目的层,b 为等待计数累加位
uint nf;//当前所在楼层
uint up_call[MAX_FLOOR],down_call[MAX_FLOOR],in_call[MAX_FLOOR];//存放呼叫事件
uchar code dis[]= {0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};//0-16 数码显示代码
sbit F5=P0^0; // 电梯内5 楼
sbit F4=P0^1; // 电梯内4 楼
sbit F3=P0^2; // 电梯内3 楼
sbit F2=P0^3; // 电梯内2 楼
sbit F1=P0^4; // 电梯内1 楼
sbit F1U=P0^5; //1 楼向上按钮
sbit F2U=P0^6; //2 楼向上按钮
sbit F2D=P0^7; //2 楼向下按钮
sbit F3U=P2^0; //3 楼向上按钮
sbit F3D=P2^1; //3 楼向下按钮
sbit F4U=P2^2; //4 楼向上按钮
sbit F4D=P2^3; //4 楼向下按钮
sbit F5D=P2^4; //5 楼向下按钮
sbit pwm1=P3^5; //正转控制位
sbit pwm2=P3^6; //反转控制位
sbit EN=P3^7; //L298 使能端信号
sbit YI= P3^0; //一楼霍尔输出信号
sbit ER=P3^1; //二楼霍尔输出信号
sbit SAN=P3^2; //三楼霍尔处输出信号
sbit SI=P3^3; //四楼霍尔处输出信号
sbit WU=P3^4; //五楼霍尔处输出信号
//sbit wela=P2^7; //数码管位选1
sbit RING=P2^7;
sbit U=P2^5; //上行指示灯
sbit D=P2^6; //下行指示灯
void init(); // 初始化程序
void check(); //霍尔查询楼层
void display(uchar); //显示函数
void floor(); //楼层控制函数
void downer(); //下降函数
void uper(); //上升函数
void stop(); //停车函数
void getinput(); //按键查询函数
//************************************
// 初始化函数
void init()
{
TMOD=0x11;
EA=1;
ET0=1;
ET1=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
nf=1;
pwm1=0;
pwm2=0;
U=0;
D=0;
EN=0;
YI=1;
ER=1;
SAN=1;
SI=1;
WU=1;
RING=0;
}
//******************************************
//1ms 延时程序
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
//**************************
// 停车报警等待程序
void stop()
{
U=0;
D=0;
EN=0;
pwm1=0;
pwm2=0;
while(b!=120)
{
b++;
if(b>30)
{RING=0;}
else
RING=1;
display(nf);
}
TR0=0;
RING=0;
b=0;
disnum=0;
}
//按键检测程序;
// *********************************
void getinput()
{
if(F5D==0)
{
down_call[4]=1;
}
else if(F4D==0)
{
down_call[3]=1;
}
else if(F4U==0)
{
up_call[3]=1;
}
else if(F3D==0)
{
down_call[2]=1;
}
else if(F3U==0)
{
up_call[2]=1;
}
else if(F2D==0)
{
down_call[1]=1;
}
else if(F2U==0)
{
up_call[1]=1;
}
else if(F1U==0)
{
up_call[0]=1;
}
else if(F1==0)
{
in_call[0]=1;
}
else if(F2==0)
{
in_call[1]=1;
}
else if(F3==0)
{
in_call[2]=1;
}
else if(F4==0)
{
in_call[3]=1;
}
else if(F5==0)
{
in_call[4]=1;
}
}
//**************************
//上升程序;
void uper()
{
TR0=1;
U=1;
if(nf==1&&gf==5)
{
getinput(); //电梯在一楼去往五楼查询是否有顺路乘坐
check();
if(up_call[1]||in_call[1])
{
for(high=50;high<=100;high++)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
}
up_call[1]=0;
in_call[1]=0;
nf=2;
ER=0;
display(nf);
stop(); //停车
}
if(up_call[2]||in_call[2])
{
for(high=50;high<=100;high++)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
}
up_call[2]=0;
in_call[2]=0;
nf=3;
SAN=0;
display(nf);
stop(); //停车
}
if(up_call[3]||in_call[3])
{
for(high=50;high<=100;high++)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm2=0;
pwm1=1;
delay(high);
pwm1=0;
low=cycle-high;
delay(low);
}
}
up_call[3]=0;
in_call[3]=0;
nf=4;
SI=0;
display(nf);
stop(); //停车
}
}
while(nf!=gf)
{
TR0=1;
U=1;
getinput();
check();
pwm1=1;
pwm2=0;
display(nf);
}
stop();
}
//**************************
//下降程序
void downer()
{
TR0=1;
D=1;
if(nf==5&&gf==1)
{
getinput();//电梯在5 楼去往1 楼查询是否有顺路
check();
if(down_call[3]==1||(in_call[3]==1))
{
for(high=50;high<=100;high++)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
}
down_call[3]=0;
in_call[3]=0;
nf=4;
SI=0;
display(nf);
stop();
}
if(down_call[2]==1||(in_call[2]==1))
{
for(high=50;high<=100;high++)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
}
down_call[2]=0;
in_call[2]=0;
nf=3;
SAN=0;
display(nf);
stop();
}
if(down_call[1]==1||(in_call[1]==1))
{
for(high=50;high<=100;high++)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
if(high<=50)
{
for(high=50;high>=0;high--)
{
pwm1=0;
pwm2=1;
delay(high);
pwm2=0;
low=cycle-high;
delay(low);
}
}
down_call[1]=0;
in_call[1]=0;
nf=2;
ER=0;
display(nf);
stop();
}
}
while(nf!=gf)
{
TR0=1;
D=1;
getinput();
check();
pwm2=1;
pwm1=0;
display(nf);
}
stop();
}
//**************************
//霍尔楼层查询
void check()
{
if(YI==0)
{
nf=1;
display(nf);
}
if(ER==0)
{
nf=2;
display(nf);
}
if(SAN==0)
{
nf=3;
display(nf);
}
if(SI==0)
{
nf=4;
display(nf);
}
if(WU==0)
{
nf=5;
display(nf);
}
}
//**************************
//电梯运行方式控制程序
void floor()
{
if(nf==1) // 电梯在一楼
{
if(down_call[4]||in_call[4]) //5 楼为目的层
{
gf=5;
uper();
down_call[4]=0;
in_call[4]=0;
}
else
if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层
{
gf=4;
uper();
down_call[3]=0;
up_call[3]=0;
in_call[3]=0;
}
else
if(down_call[1]||up_call[1]||in_call[1]) //2 楼为目的层
{
gf=2;
uper();
down_call[1]=0;
up_call[1]=0;
in_call[1]=0;
}
else
if(down_call[2]||up_call[2]||in_call[2]) //3 楼为目的层
{
gf=3;
uper();
down_call[2]=0;
up_call[2]=0;
in_call[2]=0;
}
}
if(nf==2) //电梯在二楼
{
if(down_call[4]||in_call[4]) //5 楼为目的层
{
gf=5;
uper();
down_call[4]=0;
in_call[4]=0;
}
else
if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层
{
gf=3;
uper();
down_call[3]=0;
up_call[3]=0;
in_call[3]=0;
}
else
if(down_call[2]||up_call[2]||in_call[2]) //3 楼为目的层
{
gf=3;
uper();
down_call[2]=0;
up_call[2]=0;
in_call[2]=0;
}
if(up_call[0]||in_call[0]) //1 楼为目的层
{
gf=1;
downer();
up_call[0]=0;
in_call[0]=0;
}
}
if(nf==3)//电梯在三楼
{
if(down_call[4]||in_call[4]) //5 楼为目的层
{
gf=5;
uper();
down_call[4]=0;
in_call[4]=0;
}
else
if(down_call[3]||up_call[3]||in_call[3]) //4 楼为目的层
{
gf=4;
uper();
down_call[3]=0;
up_call[3]=0;
in_call[3]=0;
}
else
if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层
{
gf=2;
downer();
down_call[1]=0;
in_call[1]=0;
up_call[1]=0;
}
else
if(in_call[0]||up_call[0]) //1 楼为目的层
{
gf=1;
downer();
in_call[0]=0;
up_call[0]=0;
}
}
if(nf==4)//电梯在四楼
{
if(in_call[4]||down_call[4]) //5 楼为目的层
{
gf=5;
uper();
in_call[4]=0;
down_call[4]=0;
}
else
if(in_call[2]||up_call[2]||down_call[2]) //3 楼为目的层
{
gf=3;
downer();
in_call[2]=0;
up_call[2]=0;
down_call[2]=0;
}
else
if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层
{
gf=2;
downer();
down_call[1]=0;
in_call[1]=0;
up_call[1]=0;
}
else
if(in_call[0]||up_call[0]) //1 楼为目的层
{
gf=1;
downer();
in_call[0]=0;
up_call[0]=0;
}
}
if(nf==5)//电梯在五楼
{
if(in_call[3]||up_call[3]||down_call[3]) //4 楼为目的层
{
gf=4;
downer();
in_call[3]=0;
up_call[3]=0;
down_call[3]=0;
}
else
if(in_call[2]||up_call[2]||down_call[2]) //3 楼为目的层
{
gf=3;
downer();
in_call[2]=0;
up_call[2]=0;
down_call[2]=0;
}
else
if(down_call[1]||in_call[1]||up_call[1]) //2 楼为目的层
{
gf=2;
downer();
down_call[1]=0;
in_call[1]=0;
up_call[1]=0;
}
else
if(in_call[0]||up_call[0]) //1 楼为目的层
{
gf=1;
downer();
in_call[0]=0;
up_call[0]=0;
}
}
}
//显示函数
//*************************************
void display(uchar nf)
{
P1=dis[nf];
delay(5);
}
//主函数
//**************************************
void main()
{
init();
getinput();
while(1)
{
getinput();
check();
floor();
display(nf);
}
}
//中断定时计数程序
//***********************************
void t0(void) interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
disnum++;
if(disnum==1000)
{
disnum=0;
}
}
}
//************************************
void t1(void) interrupt 3 using 1
{
TH1=(65536-100)/256;
TL1=(65536-100)%256;
count1++;
EN=1;
}
一周热门 更多>