1004-基于51单片机的4层电梯控制系统(4)原理图、流程图、物料清单、仿真图、源代码
功能介绍:
4层电梯运行设计
1、用一个数码管显示楼层
2、电梯内外均用LED指示各楼层
3、使用电机模拟电梯运行过程,包括上下行、开门关门
有哪些资料:
1、仿真工程文件
2、源代码工程文件
3、原理图工程文件
4、流程图
5、功能介绍
6、元件清单
#include "reg51.h"
#include "74hc595.h"
#define uchar unsigned char
#define uint unsigned int
sbit out1=P2^6;//电机
sbit out2=P2^7;
sbit out3=P0^7;//门
sbit L1=P3^4;
sbit L2=P3^5;
sbit L3=P3^6;
sbit L4=P3^7;
sbit beep=P0^4;//蜂鸣器
uchar louceng=1;//当前楼层
uchar up=0xff,down=0xff;//楼层上下标志
uchar button=0;
sbit k0=P1^0;
sbit k1=P1^1;
sbit k2=P1^2;
sbit k3=P1^3;
sbit k4=P1^4;
sbit k5=P1^5;
sbit k6=P1^6;
sbit k7=P1^7;
//===================================
void key()
{
uchar i;
i=P1>>4;
down=down & P1;//存储下降按键
up=up & i; //存储上升降按键
button=button | ~P3;
button&=0x0f;
if(!k2)
button|=0x04;
if(!k1)
button|=0x02;
if(!k4)
button|=0x01;
if(!k3)
button|=0x08;
if(!k6)
button|=0x04;
if(!k5)
button|=0x02;
Hc595SendByte(up,down);//点亮楼层LED
P0=(P0 & 0xf0)+louceng;
// P3=(P3 & 0X0F)+(~button<<4);
i=button;
if(i & 0x01)
L1=0;
else
L1=1;
if(i & 0x02)
L2=0;
else
L2=1;
if(i & 0x04)
L3=0;
else
L3=1;
if(i & 0x08)
L4=0;
else
L4=1;
}
void delay(uint i)//延时
{
uchar k;
while(i--)
{
for(k=0;k<110;k++)
key();
}
}
//===================================
void main()
{
while(1)
{
key();
up=0xff;
down=0xff;
while(button & ~(0xff<<louceng-1))
{
out1=0;out2=1; //下降
delay(200);
out1=1;out2=1;
louceng--;
if(button & (0x01<<louceng-1))
{
beep=0;
delay(30);
beep=1;
out3=0; //开门
delay(200);
out3=1;
button=button & ~(0x01<<louceng-1);
down=down | (0x01<<louceng-1);
if(louceng==1)
up=up | (0x01<<louceng-1);
Hc595SendByte(up,down);
}
}
while(button & (0xff<<louceng))
{
out1=1;out2=0; //上升
delay(200);
out1=1;out2=1;
louceng++;
if(button & (0x01<<louceng-1))
{
beep=0;
delay(30);
beep=1;
out3=0; //开门
delay(200);
out3=1;