请大家帮忙看看对不对
自己刚学
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; --超载 、关门中断、提前关门 、清除报警信号
c_u1,c_u2,c_u3,c_u4,c_u5,c_u6:in std_logic;--电梯外上升请求
c_d2,c_d3,c_d4,c_d5,c_d6,c_d7:in std_logic;--电梯外下降请求
d1,d2,d3,d4,d5,d6,d7:in std_logic; --电梯内人的请求
g1,g2,g3,g4,g5,g6,g7:in std_logic; --到达楼层信号
door:out std_logic_vector(1 downto 0); --电梯门控信号
led:out std_logic_vector(6 downto 0); --电梯所到楼层显示
led_c_u:out std_logic_vector(6 downto 0); --电梯外的人上升请求信号
led_c_d:out std_logic_vector(6 downto 0); --电梯外的人上升请求信号
led_d: out std_logic_vector(6 downto 0); --电梯内的人请求信号
kmg: out std_logic; --看门狗
ud,alarm:out std_logic;
up,down: out std_logic);
end dianti;
architecture behav of dianti is
signal d11,d22,d33,d44,d55,d66,d77:std_logic;
signal c_u11,c_u22,c_u33,c_u44,c_u55,c_u66:std_logic;
signal c_d22,c_d33,c_d44,c_d55,c_d66,c_d77:std_logic;
signal q:integer range 0 to 1; --分频
signal q1:integer range 0 to 6; --关门延时计数
signal q2:integer range 0 to 9; --看门狗计数
signal dd,cc_u,cc_d,dd_cc:std_logic_vector(6 downto 0);
signal updown:std_logic;
signal opendoor: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;kmg<='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 kmg<='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<='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 d11='1'or c_u11='1'then d11<='0';c_u11<='0';opendoor<='1';
elsif dd_cc>"0000001"then en_up<='1';opendoor<='0';
elsif dd_cc="0000000"then opendoor<='0';
end if;
elsif g2='1'then led<="0010010";
if updown='1'then
if d22='1'or c_u22='1'then d22<='0';c_u22<='0';opendoor<='1';
elsif dd_cc>"0000011"then en_up<='1';opendoor<='0';
elsif dd_cc<"0000010"then en_dw<='1';opendoor<='0';
end if;
elsif d22='1'or c_d22='1'then d22<='0';c_d22<='0';opendoor<='1';
elsif dd_cc<"0000010"then en_dw<='1';opendoor<='0';
elsif dd_cc>"0000011"then en_up<='1';opendoor<='0';
end if;
elsif g3='1'then led<="0000110";
if updown='1'then
if d33='1'or c_u33='1'then d33<='0';c_u33<='0';opendoor<='1';
elsif dd_cc>"0000111"then en_up<='1';opendoor<='0';
elsif dd_cc<"0000100"then en_dw<='1';opendoor<='0';
end if;
elsif d33='1'or c_d33='1'then d33<='0';c_d33<='0';opendoor<='1';
elsif dd_cc>"0000100"then en_up<='1';opendoor<='0';
elsif dd_cc<"0000111"then en_dw<='1';opendoor<='0';
end if;
elsif g4='1'then led<="1001100";
if updown='1'then
if d44='1'or c_u44='1'then d44<='0';c_u44<='0';opendoor<='1';
elsif dd_cc>"0001111"then en_up<='1';opendoor<='0';
elsif dd_cc<"0001000"then en_dw<='1';opendoor<='0';
end if;
elsif d44='1'or c_d44='1'then d44<='0';c_d44<='0';opendoor<='1';
elsif dd_cc>"0001000"then en_up<='1';opendoor<='0';
elsif dd_cc<"0001111"then en_dw<='1';opendoor<='0';
end if;
elsif g5='1'then led<="0100100";
if updown='1'then
if d55='1'or c_u55='1'then d55<='0';c_u55<='0';opendoor<='1';
elsif dd_cc>"0011111"then en_up<='1';opendoor<='0';
elsif dd_cc<"0010000"then en_dw<='1';opendoor<='0';
end if;
elsif d55='1'or c_d55='1'then d55<='0';c_d55<='0';opendoor<='1';
elsif dd_cc>"0010000"then en_up<='1';opendoor<='0';
elsif dd_cc<"0011111"then en_dw<='1';opendoor<='0';
end if;
elsif g6='1'then led<="0100000";
if updown='1'then
if d66='1'or c_u66='1'then d66<='0';c_u66<='0';opendoor<='1';
elsif dd_cc>"0111111"then en_up<='1';opendoor<='0';
elsif dd_cc<"0100000"then en_dw<='1';opendoor<='0';
end if;
elsif d66='1'or c_d66='1'then d66<='0';c_d66<='0';opendoor<='1';
elsif dd_cc>"0100000"then en_up<='1';opendoor<='0';
elsif dd_cc<"0111111"then en_dw<='1';opendoor<='0';
end if;
elsif g7='1'then led<="0001111";
if d77='1'or c_d77='1' then d77<='0'; c_d77<='0';opendoor<='1';
elsif dd_cc<"1000000"then en_dw<='1';opendoor<='0';
end if;
end if;
end if;
else q<=1;alarm<='0';
if d1='1'then d11<=d1;
elsif d2='1'then d22<=d2;
elsif d3='1'then d33<=d3;
elsif d4='1'then d44<=d4;
elsif d5='1'then d55<=d5;
elsif d6='1'then d66<=d6;
elsif d7='1'then d77<=d7;
end if;
if c_u1='1'then c_u11<=c_u1;
elsif c_u2='1'then c_u22<=c_u2;
elsif c_u3='1'then c_u33<=c_u3;
elsif c_u4='1'then c_u44<=c_u4;
elsif c_u5='1'then c_u55<=c_u5;
elsif c_u6='1'then c_u66<=c_u6;
end if;
if c_d2='1'then c_d22<=c_d2;
elsif c_d3='1'then c_d33<=c_d3;
elsif c_d4='1'then c_d44<=c_d4;
elsif c_d5='1'then c_d55<=c_d5;
elsif c_d6='1'then c_d66<=c_d6;
elsif c_d7='1'then c_d77<=c_d7;
end if;
dd<=d77&d66&d55&d44&d33&d22&d11; --电梯内部请求信号并置
cc_u<='0'&c_u66&c_u55&c_u44&c_u33&c_u22&c_u11;--电梯外部上升请求信号并置
cc_d<=c_d77&c_d66&c_d55&c_d44&c_d33&c_d22&'0';--电梯外部下降请求信号并置
dd_cc<=dd or cc_u or cc_d;
end if;
ud<=updown;
led_d<=dd;
led_c_u<=cc_u;
led_c_d<=cc_d;
end if;
end process;
end behav;
此帖出自
小平头技术问答
一周热门 更多>