📄 state_s3.vhd
字号:
--在上面的例子中,系统的状态转移图是已知的,我们可以根据系统的
--状态转移图方便的写出VHDL代码。还有一种情况,系统的状态转移图
--是未知的,或者程序的状态转移图很复杂,不能够根据程序轻易的画
--出状态转移图,这时我们可以借助EDA软件来分析程序的状态转移图,
--假设含有状态转移图的VHDL代码如下:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
ENTITY state_s3 IS
PORT(
clock: in std_logic;
reset : in std_logic;
control: in std_logic;
y: out integer range 0 to 3--如果不约束y的范围,输出管脚将有32位。
);
END state_s3;
ARCHITECTURE rtl OF state_s3 IS
TYPE state_type IS(st0, st1, st2, st3);
SIGNAL currentstate,nextstate : state_type;
BEGIN
seq: process(clock,reset)
begin
if (reset='1') then
currentstate<=st0;
elsif clock'event and clock='1' then
currentstate<=nextstate;
end if;
end process seq;
comb: process (control,currentstate)
begin
case currentstate is
when st0=> nextstate<=st1;
when st1=> if (control='1') then
nextstate<=st2;
else
nextstate<=st3;
end if;
when st2=> nextstate<=st3;
when st3=> nextstate<=st0;
when others=> nextstate<=st0;
end case;
end process comb;
with currentstate select
y <= 0 when st0,
1 when st1,
2 when st2,
3 when st3,
0 when others;
end rtl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -