library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity threelift is
port(buttonclk,liftclk,reset,f1upbutton,
f2upbutton,f2dnbutton,f3dnbutton,
stop1button,stop2button,stop3button:in std_logic;
fuplight,fdnlight,stoplight:buffer std_logic_vector(3 downto 1);
position: buffer integer range 1 to 3;
doorlight: out std_logic;
udsig: buffer std_logic
);
end threelift;
architecture art of threelift 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';
doorlight<='1'
elsif 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;doorlight<='0';
if udsig='0' then
if position=3 then
if stoplight="000" and fuplight="000" and fdnlight="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;
else null;
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 fdnlight(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;
else
end if;
else
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;
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;
else
end if;
mylift<=doorwait1;
when others=> null;
end case;
else
end if;
end process ctrlift;
ctrlight: process(reset,buttonclk,cleardn,stop1button)
begin
if reset='1' then
stoplight<="000";fuplight<="000";fdnlight<="000";
elsif 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';
else
null;
end if;
end if;
if cleardn='1' then
stoplight(position)<='0';fuplight(position)<='0';
else
if f2dnbutton='1' then fdnlight(2)<='1';
elsif f3dnbutton='1' then fdnlight(3)<='1';
else
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';
else
end if;
end if;
end process ctrlight;
end art;
这是我写的程序 不过不能实现功能 希望大家帮忙改一下啊 谢谢 。。。大侠帮忙啊~~~~~
PS:要不谁给我个新的程序也行啊 急!急!急! 在线=== |