VHDL语法格式 下载本文

内容发布更新时间 : 2024/5/18 5:56:58星期一 下面是文章的全部内容请认真阅读。

when s1 => if din = '0' then dout <= '0'; next_state <= s0; else

dout <= '0'; next_state <= s2; end if; when s2 => if din = '0' then dout <= '1'; next_state <= s2; else

dout <= '0'; next_state <= s3; end if; when s3 => if din = '0' then dout <= '0';

next_state <= s3; else

dout <= '1'; next_state <= s1; end if; end case; end process;

state_reg:

process -- 更新当前状态 begin

wait until clock'event and clock = '1'; present_state <= next_state; end process; end behaviou;

VHDL语法格式 21

附录1 : 状态转移图 moorl 状态机 输出 ? 现态 次态 ? 现态 + 输入

DIN=0 Moorl状态机-- 输出取决于现态 次态取决于现态和输入S0DOUT=001DIN=1DIN=1S3DOUT=111DIN=0S1DOUT=011DIN=0DIN=1DIN=1S2DOUT=101DIN=0

mealy 状态机 输出 ? 现态 + 输入 次态 ? 现态 + 输入

VHDL语法格式 22

DIN=0(DOUT=000) Mealy状态机-- 次态和输出都取决于 现态和输入 DIN=1(DOUT=111)S0 DIN=1(DOUT=001)S3 DIN=0(DOUT=110S1 DIN=0(DOUT=010) DIN=1(DOUT=101) DIN=1(DOUT=011)S2 DIN=0(DOUT=100)??

附录2 : 用户库的格式和用法 -- 为叙述方便,将这个文件命名为niu_library.vhd。

-- 元件例化时 ① 将文件niu_library.vhd加入到工程中。

-- ② 在主程序的architecture ... of ... is之后,bigen之前,将库中的实体声明为元件。 -- 调用函数和过程时 ① 将文件niu_library.vhd加入到工程中。

-- ② 在主程序文件的开头加上包声明,格式为use work. niu_package.all; ,其中, niu_package -- 是要调用的函数或过程所在包的名称。

-- 以下定义作为元件引用的实体 library ieee; -- ym实体 use ieee.std_logic_1164.all;

entity ym is

port ( a,b : in std_logic;

c : out std_logic ); end entity ym;

architecture ym1 of ym is begin

23

VHDL语法格式

c <= a and b; end architecture ym1;

library ieee; -- hm实体 use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity hm is

port ( a,b : in std_logic; c : out std_logic ); end entity hm;

architecture hm1 of hm is begin c <= a or b; end architecture hm1;

-- 以下定义过程和函数 library ieee;

use ieee.std_logic_1164.all; -- 用packge“封装”声明 package niu_package is

procedure jfq ( din1, din2 : in integer range 0 to 31; dout : out integer range 0 to 31 ); -- 过程

function ls_xj ( d1, d2: in std_logic_vector( 0 to 3 ) ) return std_logic_vector; -- 函数 end niu_package;

-- 用package body“封装”程序体 package body niu_package is

procedure jfq ( din1, din2 : in integer range 0 to 31;

dout : out integer range 0 to 31

) is -- 过程 begin

dout := din1 + din2; end jfq;

function ls_xj ( d1, d2 : in std_logic_vector( 0 to 3 ) ) return std_logic_vector is -- 函数

VHDL语法格式 24

variable temp : std_logic_vector( 0 to 3 ); begin

temp := d1 and d2;

return temp; end function; end niu_package;■

VHDL语法格式 25