📄 dianti.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity dianti is
port ( clk : in std_logic; --时钟信号
full,deng,quick,clr : in std_logic;
u1,u2,u3 : in std_logic;
d2,d3,d4 : in std_logic;
n1,n2,n3,n4: in std_logic;
g1,g2,g3,g4 : in std_logic;
door : out std_logic_vector(1 downto 0);
led : out std_logic_vector(6 downto 0);
led_u : out std_logic_vector(3 downto 0); --电梯外人上升请求信号显示
led_d : out std_logic_vector(3 downto 0); --电梯外人下降请求信号显示
led_n : out std_logic_vector(3 downto 0); --电梯内请求信号显示
wrong: out std_logic; --故障报警信号
ud,alarm : out std_logic; --电梯运动方向与超载显示
up,down : out std_logic ); --电梯动作
end dianti;
architecture behav of dianti is --结构体
signal n11,n22,n33,n44:std_logic;
signal u11,u22,u33:std_logic;
signal d22,d33,d44:std_logic;
signal nn,uu,dd,u_d:std_logic_vector(3 downto 0);
signal q:integer range 0 to 1;
signal q1:integer range 0 to 6; --关门延时计数器
signal q2:integer range 0 to 3; --关门中断计数器
signal opendoor:std_logic;
signal updown:std_logic; --电梯运动方向信号寄存器
signal en_up,en_dw:std_logic; --预备上升、预备下降
begin
com:process(clk)
begin
if clk'event and clk='1' then
if clr='1' then q1<=0;q2<=0; wrong<='0'; --清除故障报警
elsif full='1' then alarm<='1'; q1<=0; --超载报警
if q1>=3 then door<="10"; --电梯门已关情况(自动开门)
else door<="00";
end if;
elsif q=1 then q<=0;alarm<='0';
if q2=3 then wrong<='1'; --故障报警
else
if opendoor='1' then door<="10";q1<=0;q2<=0;up<='0';down<='0'; --开门操作
elsif en_up='1' then --上升预操作
if deng='1' then door<="10";q1<=0;q2<=q2+1; --关门中断
elsif quick='1' then q1<=3; --提前关门
elsif q1=6 then door<="00";updown<='1';up<='1'; --关门完毕,电梯进入上升状态
elsif q1>=3 then door<="01";q1<=q1+1; --电梯进入关门状态
else q1<=q1+1;door<="00"; --电梯进入等待状态
end if;
elsif en_dw='1' then --下降预操作
if deng='1' then door<="10";q1<=0;q2<=q2+1;
elsif quick='1' then q1<=3;
elsif q1=6 then door<="00";updown<='0';down<='1';
elsif q1>=3 then door<="01";q1<=q1+1;
else q1<=q1+1;door<="00";
end if;
end if;
if g1='1' then led<="1001111";
if n11='1' or u11='1' then n11<='0'; u11<='0'; opendoor<='1';
elsif u_d>"0001" then en_up<='1'; opendoor<='0';
elsif u_d="0000" then opendoor<='0';
end if;
elsif g2='1' then led<="0010010";
if updown='1' then
if n22='1' or u22='1' then n22<='0'; u22<='0'; opendoor<='1';
elsif u_d>"0011" then en_up<='1'; opendoor<='0';
elsif u_d<"0010" then en_dw<='1'; opendoor<='0';
end if;
elsif n22='1' or d22='1' then n22<='0'; d22<='0'; opendoor<='1';
elsif u_d<"0010" then en_dw<='1'; opendoor<='0';
elsif u_d>"0011" then en_up<='1'; opendoor<='0';
end if;
elsif g3='1' then led<="0000110";
if updown='1' then
if n33='1' or u33='1' then n33<='0'; u33<='0'; opendoor<='1';
elsif u_d>"0111" then en_up<='1'; opendoor<='0';
elsif u_d<"0100" then en_dw<='1'; opendoor<='0';
end if;
elsif n33='1' or d33='1' then n33<='0'; d33<='0'; opendoor<='1';
elsif u_d<"0100" then en_dw<='1'; opendoor<='0';
elsif u_d>"0111" then en_up<='1'; opendoor<='0';
end if;
elsif g4='1' then led<="1001100";
if n44='1' or d44='1' then n44<='0'; d44<='0'; opendoor<='1';
elsif u_d<"1000" then en_dw<='1'; opendoor<='0';
end if;
else en_up<='0';en_dw<='0';
end if;
end if;
else q<=1;alarm<='0'; --清除超载报警
if n1='1' then n11<=n1; --对请求信号进行寄存
elsif n2='1' then n22<=n2;
elsif n3='1' then n33<=n3;
elsif n4='1' then n44<=n4;
end if;
if u1='1' then u11<=u1;
elsif u2='1' then u22<=u2;
elsif u3='1' then u33<=u3;
end if;
if d2='1' then d22<=d2;
elsif d3='1' then d33<=d3;
elsif d4='1' then d44<=d4;
end if;
nn<= n44&n33&n22&n11; --对所有信号的综合
uu<='0'&u33&u22&u11;
dd<=d44&d33&d22&'0';
u_d<=nn or uu or dd;
end if;
ud<=updown; --对电梯状态进行寄存
led_n<=nn; --电梯内人请求信号显示
led_u<=uu; --电梯外人上升请求信号显示
led_d<=dd; --电梯外人下降请求信号显示
end if;
end process;
end behav;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -