ctrl.vhd
来自「用PLC程序编写十字路口的交通灯」· VHDL 代码 · 共 45 行
VHD
45 行
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity ctrl is
port(clk,spe:in std_logic;
en:out std_logic);
end;
architecture behave of ctrl is
type states is(s3,s2,s1,s0);
signal current_state,next_state:states;
begin
com:process(spe,current_state)
begin
case current_state is
when s0=> en <='0';
if spe='1' then next_state<=s0;
else next_state<=s1;
end if;
when s1=> en <='1';
if spe='1' then next_state<=s2;
else next_state<=s1;
end if;
when s2=> en <='1';
if spe='1' then next_state<=s2;
else next_state<=s3;
end if;
when s3=> en <='0';
if spe='1' then next_state<=s0;
else next_state<=s3;
end if;
end case;
end process;
synch: process(clk)
begin
if clk'event and clk='1' then
current_state<=next_state;
end if;
end process;
end behave;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?