?? elerun.vhd.bak
字號:
--設計一個6層電梯控制器。電梯控制器是按照乘客的要求自動上、下的裝置。
--1、每層電梯入口處設置上下請求開關,電梯內設有顧客到達層次的停站請求開關。
--2、設有電梯所處位置指示裝置以及電梯運行模式(上升或者下降)指示裝置。
--3、電梯每秒升降一層樓。
--4、電梯到達有停站請求的樓層,經過1秒電梯門打開,開門4秒后,電梯門關閉(開門指示燈滅),電梯繼續運行,直至執行完最后一個請求信號后停留在當前層。
--5、電梯能記憶電梯內外所有請求信號,并按照電梯運行規則按順序響應,每個請求信號保留至有電梯響應后消除。
--6、電梯運行規則:當電梯上升時,只響應比電梯所在位置高的上樓請求信號,由下而上逐個執行,直到最后一個上樓請求執行完畢;
--如果高層有下樓請求,則直接升到下樓請求的最高樓層,然后進入下降模式。當電梯處于下降模式時與上升正好相反
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity elerun is
port (
clk: in std_logic; --電梯時鐘
alarm: in std_logic;
reset: in std_logic; --異步置位按鍵
fuplight: in std_logic_vector (6 downto 1);--電梯外部上升請求指示燈
fdnlight: in std_logic_vector (6 downto 1);--電梯外部下降請求指示燈
stlight: in std_logic_vector (6 downto 1);--電梯內部各層請求指示燈
position: out integer range 1 to 6; --電梯位置指示
doorlight: out std_logic; --電梯門開關指示燈
clearup:out std_logic;--用于清除上升請求指示燈的信號
cleardn:out std_logic;--用于清除下降請求指示燈的信號
yanshi:in std_logic;
tiqian: in std_logic;
udsig: buffer std_logic_vector(7 downto 0) --電梯升降指示
);
end elerun;
architecture sixflift of elerun is
type lift_state is
(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,doorwait5,doorwait6,up,down,stop);
signal mylift: lift_state;
signal pos: integer range 6 downto 1;
signal udflag : std_logic;
signal posreg : integer range 1 to 6;
signal one: std_logic_vector (6 downto 1);
begin
process(reset,clk) --控制電梯狀態的進程
begin
if (reset = '1' or alarm = '1') then
mylift <= stopon1;
clearup <= '1';
cleardn <= '1';
else
if (clk 'event and clk = '1') then
case mylift is
when stopon1 =>
doorlight <= '0';
position <= 1;
mylift <= doorwait1;
clearup <= '0';
cleardn <= '0';
udsig <= "00000010";
when doorwait1 =>
if tiqian = '1' then
mylift <= doorclose;
elsif yanshi = '1' then
mylift <= doorwait1;
else
mylift <= doorwait2;
end if;
clearup <= '0';
cleardn <= '0';
when doorwait2 =>
if tiqian = '1' then
mylift <= doorclose;
elsif yanshi = '1' then
mylift <= doorwait1;
else
mylift <= doorwait3;
end if;
clearup <= '0';
cleardn <= '0';
when doorwait3 =>
if tiqian = '1' then
mylift <= doorclose;
elsif yanshi = '1' then
mylift <= doorwait1;
else
mylift <= doorwait4;
end if;
clearup <= '0';
cleardn <= '0';
when doorwait4 =>
if tiqian = '1' then
mylift <= doorclose;
elsif yanshi = '1' then
mylift <= doorwait1;
else
mylift <= doorwait5;
end if;
clearup <= '0';
cleardn <= '0';
when doorwait5 =>
if tiqian = '1' then
mylift <= doorclose;
elsif yanshi = '1' then
mylift <= doorwait1;
else
mylift <= doorwait6;
end if;
clearup <= '0';
cleardn <= '0';
when doorwait6 =>
mylift <= doorclose;
cleardn <= (not udflag);
clearup <= udflag;
when doorclose =>
doorlight <= '0';
clearup <= '0';
cleardn <= '0';
if posreg = 6 then
if (stlight = "000000" and fuplight = "000000" and fdnlight = "000000") then
mylift <= doorclose;
udsig <= "00000010";
elsif stlight > "000000" or fdnlight > "000000" or fuplight > "000000" then
mylift <= down;
udsig<="01111010";
udflag <= '1';
end if;
elsif posreg = 1 then
if (stlight = "000000" and fuplight = "000000" and fdnlight = "000000") then
mylift <= doorclose;
udsig <= "00000010";
elsif stlight > "000000" or fdnlight > "000000" or fuplight > "000000" then
mylift <= up;
udsig<="01111100";
udflag <= '0';
end if;
else
if (stlight = "000000" and fuplight = "000000" and fdnlight = "000000") then
mylift <= doorclose;
udsig <= "00000010";
elsif stlight >= (one + one) or fuplight >= (one + one) or fdnlight >= (one + one) then
mylift <= up;
udsig<="01111100";
udflag <= '0';
elsif (stlight + stlight) <= one or (fuplight + fuplight) <= one or (fdnlight + fdnlight) <= one then
mylift <= down;
udsig<="01111010";
udflag <= '1';
else
mylift <= doorclose;
end if;
end if;
when up =>
clearup <= '0';
cleardn <= '0';
if posreg < 6 and (stlight(posreg) = '1' or fuplight(posreg) = '1' or (stlight = "000000" and fdnlight(posreg) = '1'))
then mylift <= stop;
if (stlight = "000000" and fdnlight(posreg) = '1' and fuplight = "000000") then
udflag <= '1';
end if;
elsif posreg = 6 and (stlight(posreg) = '1' or fuplight(posreg) = '1' or ( fuplight = "000000" and fdnlight(posreg) = '1'))
then mylift <= stop;
elsif posreg = 6 and ( fdnlight > "000000" or fuplight > "000000") then
mylift <= stop;
else
mylift <= up;
udsig<="01111100";
udflag <= '0';
if posreg<6 then
posreg <= (posreg+1);
end if;
end if;
when down =>
clearup <= '0';
cleardn <= '0';
if posreg > 1 and (stlight(posreg) = '1' or fdnlight(posreg) = '1' or ( stlight = "000000" and fuplight(posreg) = '1' ))
then mylift <= stop;
if (stlight = "000000" and fuplight(posreg) = '1' and fdnlight = "000000") then
udflag <= '0';
end if;
elsif posreg = 1 and (stlight(posreg) = '1' or fdnlight(posreg) = '1' or ( fdnlight = "000000" and fuplight(posreg) = '1'))
then mylift <= stop;
elsif posreg = 1 and ( fdnlight > "000000" or fuplight > "000000") then
mylift <= stop;
else
mylift <= down;
udsig<="01111010";
udflag <= '1';
if posreg>1 then
posreg <= (posreg-1);
end if;
end if;
when stop =>
mylift <= dooropen;
clearup <= '0';
cleardn <= '0';
when dooropen =>
doorlight <= '1';
clearup <= '0';
cleardn <= '0';
mylift <= doorwait1;
when others =>
mylift <= doorwait1;
clearup <= '0';
cleardn <= '0';
end case;
end if;
end if;
end process ;
position <= posreg;
process(clk,posreg)
begin
if clk 'event and clk = '1' then
case posreg is
when 1 => one <= "000001";
when 2 => one <= "000010";
when 3 => one <= "000100";
when 4 => one <= "001000";
when 5 => one <= "010000";
when 6 => one <= "100000";
end case;
end if;
end process ;
end ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -