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:in std_logic;--
按键时钟信号
liftclk:in std_logic;--
电梯时钟信号
reset:in std_logic;--
异步复位端口
f1upbutton:in std_logic;--
一层上升请求端?/p>
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);--
电梯模式(上升或下降)信?/p>
end threelift;
architecture art of threelift is--
结构?/p>
type lift_state is--
定义十个状?/p>
(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop);
signal mylift:lift_state;
signal clearup:std_logic;--
上升和停站请求清除信?/p>
signal cleardn:std_logic;--
下降和停站请求清除信?/p>
begin
controlift:process(reset,liftclk)--
状态机进程
variable pos:integer range 3 downto 1;
begin
if reset='1' then
mylift <= stopon1;--
异步复位,电梯的初始状态为一层开门状?/p>
clearup <= '0';
cleardn <= '0';
pos:=1;
position<=1;
else
if liftclk'event and liftclk='1' then
case mylift is
when stopon1 => doorlight <= '0';