📄 ok003.vhd
字号:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.all;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
entity t008 is
PORT( CLK : IN STD_LOGIC;
reset : IN STD_LOGIC;
-- Open_door : IN STD_LOGIC ; --延长开门时间
-- Close_door : IN STD_LOGIC ; --提前关门
uButton : IN STD_LOGIC_VECTOR(3 DOWNTO 0); --外部向上选择
dButton : IN STD_LOGIC_VECTOR(3 DOWNTO 0); --外部选择向下
Button : IN STD_LOGIC_VECTOR(3 DOWNTO 0); --内部选择楼层
Floor : INOUT STD_LOGIC_VECTOR(2 DOWNTO 0); --可用来显示当前楼层
-- direct : out std_logic_vector (1 downto 0); --内部方向输出
Runtime : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); --显示运行时间
end;
architecture t008 of t008 is
constant low_4L:std_logic_vector(3 downto 0) := "0000";
constant low_3L:std_logic_vector(2 downto 0) := "000";
TYPE STATE_TYPE IS (S0,S1,S2,S3);
SIGNAL present_state, next_state : STATE_TYPE:=S0;
signal timer : STD_LOGIC_VECTOR( 3 downto 0);
signal cur_Floor : STD_LOGIC_VECTOR( 1 downto 0);
signal u_buffer, d_buffer, button_buffer : STD_LOGIC_VECTOR( 3 downto 0);
SIGNAL up_down : STD_LOGIC_VECTOR(1 DOWNTO 0); --内部第一位是上,二位为下
signal into5s,into8s, time_5S_out, time_8S_out: std_logic;
begin
--======================================================================
p0:process ( reset, Button,uButton,dButton)
begin
if ( reset'event and reset ='1' ) then
u_buffer <= "0000"; d_buffer <= "0000"; button_buffer <= "0000";
into5s <= '0'; into8s <= '0';
timer <= "0000"; time_5S_out <= '0'; time_8S_out <= '0';
present_state <= S0; next_state <= S0;
--cur_Floor <= "00"; --Floor <= "000";
--up_down <= "10";
else
if (ubutton(0)'event and ubutton(0) ='1') then
u_buffer(0)<='1';
end if;
if (ubutton(1)'event and ubutton(1) ='1') then
u_buffer(1)<='1';
end if;
if (ubutton(2)'event and ubutton(2) ='1') then
u_buffer(2)<='1';
end if;
if (dbutton(1)'event and ubutton(1) ='1') then
d_buffer(1)<='1';
end if;
if (dbutton(2)'event and dbutton(2) ='1') then
d_buffer(2)<='1';
end if;
if (dbutton(3)'event and dbutton(3) ='1') then
d_buffer(3)<='1';
end if;
if (button(0)'event and button(0) ='1') then
button_buffer(0)<='1';
end if;
if (button(1)'event and button(1) ='1') then
button_buffer(1)<='1';
end if;
if (button(2)'event and button(2) ='1') then
button_buffer(2)<='1';
end if;
if (button(3)'event and button(3) ='1') then
button_buffer(3)<='1';
end if;
end if;
into8s <= u_buffer(0) and u_buffer(1) and u_buffer(2) and d_buffer(1) and d_buffer(2) and d_buffer(3);
end process p0;
--======================================================================
timer:process ( CLK, into5s, into8s )
begin
if (into8s'event and into8s ='1') then
timer <= "1000";
elsif (into5s'event and into5s ='1') then
timer <= "0101";
elsif (CLK'event and CLK ='1') then
if ( timer = low_4L ) then
if ( present_state = S0 ) then
present_state <= S1;
elsif ( present_state = S1 ) then
present_state <= S2;
elsif ( present_state = S2 ) then
present_state <= S3;
else --if ( present_state = S3 ) then
present_state <= S0;
end if;
if ( into8s = '1' ) then
into8s <= '0';
time_8S_out <= '1';
end if;
if ( into5s = '1' ) then
into5s <= '0';
time_5S_out <= '1';
end if;
else
if ( into8s='1' or into5s='1' ) then
timer <= timer - '1';
end if;
end if;
--timer <= timer - '1';
end if;
end process timer;
--======================================================================
timeto5s:process ( time_5S_out )
begin
if ( into5s'event and into5s ='1') then
if ( present_state = S0 ) then
button_buffer(0) <= '0';
elsif ( present_state = S1 ) then
button_buffer(1) <= '0';
elsif ( present_state = S1 ) then
button_buffer(2) <= '0';
elsif ( present_state = S1 ) then
button_buffer(3) <= '0';
end if;
into5s <= '0';
time_5S_out <= '0';
into8s <= '1';
end if;
end process timeto5s;
--======================================================================
timeto8s:process ( time_8S_out )
begin
if ( up_down = "10" ) then
if ( cur_Floor = "1111" ) then
up_down <= "01";
else
cur_Floor <= cur_Floor + '1';
end if;
elsif ( up_down = "01" ) then
if ( cur_Floor = low_3L ) then
up_down <= "10";
else
cur_Floor <= cur_Floor - '1';
end if;
end if;
into8s <= '0';
time_8S_out <= '0';
into5s <= '1';
end process timeto8s;
--======================================================================
Show_floor: process (cur_Floor)
begin
case cur_Floor is
when "00" => Floor<="001";
when "01" => Floor<="010";
when "10" => Floor<="011";
when "11" => Floor<="100";
--default
end case ;
end process Show_floor;
--Show_time: process (timer)
--begin
-- Runtime <= timer;
--end process Show_time;
--======================================================================
--p001:process ( Button,uButton,dButton)
--begin
--end process p001;
--======================================================================
--======================================================================
end t008;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -