📄 dianti.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity tl is
port(buttonclk:in std_logic;
liftclk:in std_logic;
reset:in std_logic;
f1upbutton:in std_logic;
f2upbutton:in std_logic;
f2dnbutton:in std_logic;
f3dnbutton:in std_logic;
fuplight:buffer std_logic_vector(3 downto 1);
fdnlight:buffer std_logic_vector(3 downto 1);
stop1button,stop2button,stop3button:in std_logic;
stoplight:buffer std_logic_vector(3 downto 1);
position:buffer integer range 1 to 3;
doorlight:out std_logic;
udsig:buffer std_logic);
end tl;
architecture a of tl is
type lift_state is
(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop);
signal mylift:lift_state;
signal clearup:std_logic;
signal cleardn:std_logic;
begin
ctrlift:process(reset,liftclk)
variable pos:integer range 3 downto 1;
begin
if reset='1' then
mylift<=stopon1;
clearup<='0';
cleardn<='0';
else
if liftclk'event and liftclk='1' then
case mylift is
when stopon1=>
doorlight<='1';
position<=1;pos:=1;
mylift<=doorwait1;
when doorwait1=>
mylift<=doorwait2;
when doorwait2=>
clearup<='0';
cleardn<='0';
mylift<=doorwait3;
when doorwait3=>
mylift<=doorwait4;
when doorwait4=>
mylift<=doorclose;
when doorclose=>
doorlight<='0';
if udsig='0' then
if position=3 then
if
stoplight="000" and fuplight="000" then
udsig<='1';
mylift<=doorclose;
else udsig<='1';mylift<=down;
end if;
elsif position=2 then
if
stoplight="000" and fuplight="000" and fdnlight="000" then
udsig<='0';
mylift<=doorclose;
elsif
stoplight(3)='1' or (stoplight(3)='0' and fdnlight(3)='1') then
udsig<='0';
mylift<=up;
else udsig<='1';mylift<=down;
end if;
elsif position=1 then
if
stoplight="000" and fuplight="000" and fdnlight="000" then
udsig<='0';
mylift<=doorclose;
else udsig<='0';mylift<=up;
end if;
end if;
elsif udsig='1' then
if position=1 then
if
stoplight="000" and fuplight="000" and fdnlight="000" then
udsig<='0';
mylift<=doorclose;
else udsig<='0';mylift<=up;
end if;
elsif position=2 then
if
stoplight="000" and fuplight="000" and fdnlight="000" then
udsig<='1';
mylift<=doorclose;
elsif
stoplight(1)='1' or (stoplight(1)='0' and fuplight(1)='1')
then
udsig<='1';
mylift<=down;
else udsig<='0';mylift<=up;
end if;
elsif position=3 then
if
stoplight="000" and fuplight="000" and fdnlight="000" then
udsig<='1';
mylift<=doorclose;
else udsig<='1'; mylift<=down;
end if;
end if;
end if;
when up=>
position<=position+1;
pos:=pos+1;
if pos<3 and (stoplight(pos)='1' or fdnlight(pos)='1')
then mylift<=stop;
elsif pos=3 and (stoplight(pos)='1' or fdnlight(pos)='1')
then mylift<=stop;
else mylift<=doorclose;
end if;
when down=>
position<=position-1;
pos:=pos-1;
if pos>1 and (stoplight(pos)='1' or fdnlight(pos)='1')
then mylift<=stop;
elsif pos=1 and (stoplight(pos)='1' or fdnlight(pos)='1')
then mylift<=stop;
else mylift<=doorclose;
end if;
when stop=>
mylift<=dooropen;
when dooropen=>
doorlight<='1';
if udsig='0' then
if
position<=2 and (stoplight(position)='1' or fdnlight(position)='1') then
clearup<='1';
else clearup<='1';cleardn<='1';
end if;
elsif udsig='1' then
if
position>=2 and (stoplight(position)='1' or fdnlight(position)='1') then
cleardn<='1';
else clearup<='1';cleardn<='1';
end if;
end if;
mylift<=doorwait1;
end case;
end if;
end if;
end process ctrlift;
ctrlight:process(reset,buttonclk)
begin
if reset='1' then
stoplight<="000";fuplight<="000";fdnlight<="000";
else
if buttonclk'event and buttonclk='1' then
if clearup='1' then
stoplight(position)<='0';fuplight(position)<='0';
else
if f1upbutton='1' then fuplight(1)<='1';
elsif f2upbutton='1' then fuplight(2)<='1';
end if;
end if;
if cleardn='1' then
stoplight(position)<='0';fdnlight(position)<='0';
else
if f2dnbutton='1' then fdnlight(1)<='1';
elsif f3dnbutton='1' then fdnlight(3)<='1';
end if;
end if;
if stop1button='1' then stoplight(1)<='1';
elsif stop2button='1' then stoplight(2)<='1';
elsif stop3button='1' then stoplight(3)<='1';
end if;
end if;
end if;
end process ctrlight;
end a;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -