一.系统概述
1.电梯有上行和下行功能,有一个电机通过正反转控制,分别用两个指示灯表示;
2.有开门和关门功能,有一个电机通过正反转控制,分别用两个指示灯表示;
3.电梯内部具有开门、关门按钮,带相应指示灯:
4.超重和延时报警功能,超重信号保持功能。
二.仿真概述
1. 进入仿真,数码管显示屏上会显示楼层为1楼,1楼提示灯亮起。
2. 按下上升按键电机开始运转,上升指示灯打开,到达2层相应的指示灯打开,同理相应的点击其他较高楼层的按钮就会进行相同的上楼流程,当点击较现在较低的楼层就会执行相应的下楼流程。
3. 按下超重按键就会一直亮灯提醒电梯超重。
三.程序设计
#include <REGX52.H>
#include "delay.h"
#include "key.h"
#include "Nixie.h"
#include "Timer0.h"
sbit LEDA = P3^4;
sbit LEDB = P3^5;
sbit LEDC = P3^7;
unsigned char N = 1;
unsigned char KeyNum,floor = 1;
unsigned char code z[]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};
unsigned char code f[]={0x01,0x09,0x08,0x0c,0x04,0x06,0x02,0x03};
void foreward(unsigned char n);
void reversal(unsigned char n);
void foreward2(unsigned char n);
void reversal2(unsigned char n);
void open_the_door();
void close_the_door();
void main()
{
Nixie(1,floor);
P1 = 0;
P3 &= 0xF0;
while(1)
{
KeyNum = Key();
if(KeyNum == 1)
{
floor++;
if(floor >= 1 && floor <= 2)
{
close_the_door();
reversal2(N);
LEDA = 0;
LEDB = 1;
foreward(N);
LEDA = 1;
open_the_door();
foreward2(N);
}
if(floor > 2)
{
floor = 2;
}
}
else if(KeyNum == 2)
{
floor--;
if(floor >= 1 && floor <= 2)
{
close_the_door();
reversal2(N);
LEDA = 1;
LEDB = 0;
reversal(N);
LEDB = 1;
open_the_door();
foreward2(N);
}
if(floor < 1)
{
floor = 1;
}
}
else if(KeyNum == 3) //开门
{
open_the_door();
foreward2(N);
}
else if(KeyNum == 4) //关门
{
close_the_door();
reversal2(N);
}
else if(KeyNum == 5) //模拟超重
{
LEDC = 0;
Delay(5);
LEDC = 1;
Delay(5);
LEDC = 0;
Delay(5);
LEDC = 1;
Delay(5);
LEDC = 0;
Delay(5);
LEDC = 1;
}
else
{
LEDA = 1;
LEDB = 1;
}
Nixie(1,floor);
if(floor == 1)
{
P1 &= 0x3F;
P1 |= 0x40;
}
else if(floor ==2)
{
P1 &= 0x3F;
P1 |= 0x80;
}
}
}
标签:仿真,03,floor,void,51,unsigned,char,指示灯,include
From: https://blog.csdn.net/XCHardware/article/details/140083485