VHDL语法格式 下载本文

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

when 条件值 => 顺序语句; ......

when others => 顺序语句; end case; for_loop 语句 [标号]:

for 循环变量 in 值 to 值 loop; 顺序语句; end loop [标号]; 时钟边沿描述 上升沿 时钟?event and时钟 = ?1??| rising_edge (时钟) 下降沿 时钟?event and时钟 =?0??| falling_edge (时钟)

程序基本结构

-- 主程序与元件程序在同一文件work1.vhd中, library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; -- 主程序

entity 实体名 is --实体名必须与文件名相同 port (端口声明; ); end entity work1;

architecture struc of work1 is

[声明语句;] --常量,变量,信号,元件,函数等 begin 并行语句;

end architecture struc;

电路描述方式

行为描述方式 以用状态机描述电路为典型 数据流 ( 寄存器 ) 描述方式 即用逻辑表达式描述电路

VHDL语法格式 6

结构描述方式 以用元件复用的方式描述电路为典型

VHDL语法格式 7

下篇 复合元素和状态机

目录

元件 ---------- 1 单文件元件 2 多文件元件 函数 ---------- 3 单文件函数 4 多文件函数 过程 ---------- 5 单文件过程 6 多文件过程

moorl 状态机 -- 7 二进程moorl状态机 8 三进程moorl状态机 meaky 状态机 -- 9 二进程mealy状态机 10 三进程mealy状态机

状态机实例 ---- 11 交通灯之一

12 交通灯之二 附录 ---------- 13 状态转移图

14 用户库的格式和用法

单文件元件

-- 主程序与元件程序在同一文件work1.vhd中, library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; -- 主程序 entity work1 is

port ( r,s,t,u : in std_logic; v : out std_logic ); end entity work1;

architecture struc of work1 is

component ym -- 将实体ym声明为元件 port ( a,b : in std_logic; c : out std_logic

);

end component ym;

component hm -- 将实体hm声明为元件 port ( a,b : in std_logic; c : out std_logic );

end component hm;

signal temp1,temp2 : std_logic; begin

u1 : ym port map ( r, s, temp1 ); -- 元件例化 u2 : ym port map ( t, u, temp2 ); u3 : hm port map ( temp1, temp2, v ); end architecture struc; -- ym元件实体定义程序

8

VHDL语法格式

library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity ym is

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

architecture ym1 of ym is begin

c <= a and b; end architecture ym1; -- hm元件实体定义程序 library ieee;

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;

多文件元件

-- 主程序文件和定义元件的程序文件都要添加到工程中 -- 主程序文件zhu_map.vhd,不需要声明用户库文件 ...

library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity zhu_map is

port ( r,s,t,u : in std_logic; v : out std_logic );

end entity zhu_map;

architecture niu of zhu_map is component ym

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

9

VHDL语法格式

end component ym;

component hm

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

end component hm;

signal temp1,temp2 : std_logic; begin

u1 : ym port map ( r, s, temp1 ); -- 元件例化 u2 : ym port map ( t, u, temp2 ); u3 : hm port map ( temp1, temp2, v ); end architecture niu; -- 定义元件实体的程序文件 -- ym元件实体定义程序 library ieee;

use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;

entity ym is

port ( a,b : in std_logic; c : out std_logic

); end entity ym;

architecture ym1 of ym is begin

c <= a and b; end architecture ym1; -- hm元件实体定义程序 library ieee;

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;

单文件函数

10

VHDL语法格式