当前位置:
文档之家› VHDL硬件描述语言(2.1)
VHDL硬件描述语言(2.1)
25
例1: …… L2: loop a:=a+1; exit L2 when a >10; end loop L2; ……
26
2)for … loop 语句 ) [标号]:for 循环变量 in 离散范围 顺序处理语句; end loop [标号]; loop
特点: ①循环变量是 loop 内部自动声明的局部量,仅 在 loop 内可见;不需要指定其变化方式。 ②离散范围必须是可计算的整数范围: 整数表达式 to 整数表达式 整数表达式 downto 整数表达式
15
例:用case 语句描述四选一电路
16
例:case 语句的误用 signal value : integer range 0 to 15 ; signal out_1 : bit ; case value is -- 缺少 when条件语句 end case ; case value is -- 分支条件不包含2到15 when 0 => out_1 <= ‘1’ ; when 1 => out_1 <=‘0’ ; end case ; case value is -- 在5到10上发生重叠 when 0 to 10 => out_1 <= ‘1’ ; when 5 to 15 => out_1 <= ‘0’ ; end case ;
18
BEGIN PROCESS( A ) BEGIN CASE A(3 DOWNTO 0) IS WHEN "0000" => LED7S <= "0111111" ; -- X"3F"'0 WHEN "0001" => LED7S <= "0000110" ; -- X"06"'1 WHEN "0010" => LED7S <= "1011011" ; -- X"5B"'2 WHEN "0011" => LED7S <= "1001111" ; -- X"4F"'3 WHEN "0100" => LED7S <= "1100110" ; -- X"66"'4 WHEN "0101" => LED7S <= "1101101" ; -- X"6D"'5
27
例:用 for … loop 语句描述的8位奇校验电路
LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY P_CHECK IS PORT (a:IN STD_LOGIC_VECTOR(7 DOWNTO 0); Y:OUT STD_LOGIC); END P_CHECK; ARCHITECTURE ART OF P_CHECK IS BEGIN PROCESS(A) variable TMP:STD_LOGIC; BEGIN TMP:='1';
9
if_then_elsif 语句中隐含了优先级别的判断, 最先出现的条件优先级最高,可用于设计具有优 先级的电路。如8-3优先级编码器。 library ieee; use ieee.std_logic_1164.all; entity coder is port(input: in std_logic_vector(7 downto 0); output: out std_logic_vector(2 downto 0)); end coder;
20
例2:2输入的与门电路描述
library ieee; use ieee.std_logic_1164.all; entity and22j is port(a:in std_logic; b:in std_logic; y:out std_logic); end and22j; architecture behave of and22j is begin p1:process(a,b)
5.3 VHDL顺序语句(Sequential) 顺序语句( 顺序语句 )
ENTITY
ARCHITECTURE Process Process ports
Sequential Process Combinational Process
ports
component
硬件执行:并发执行(VHDL本质) 仿真执行:顺序执行、并发执行 分为两大类:顺序(Sequential)描述语句 并发(Concurrent)描述语句
11
elsif input(3)=‘0’ then output<=“100”; elsif input(2)=‘0’ then output<=“101”; elsif input(1)=‘0’ then output<=“110”’; else output<=“111”; end if; end process; end art;
5.3.1 转向控制语句 转向控制语句
转向控制语句通过条件控制开关决定是否执 行一条或几条语句,或重得执行一条或几条语句, 或跳过一条或几条语句。 分为五种: if 语句、case 语句、 loop 语句、next 语句、 exit 语句
3
1、 if 语句 、
if 语句执行一序列的语句,其次序依赖于一 个或多个条件的值。 1)if 语句的门闩控制 ) if 条件 then 顺序处理语句; end if ; 例: if (ena = ‘1’) then q <= d; end if; 综合后生成锁存器(latch)
17
例1:七段数码管驱动电路(电子时钟的 :七段数码管驱动电路(电子时钟的DISP) ) LIBRARY IEEE ; USE IEEE.STD_LOGIC_1164.ALL ; ENTITY segment7 IS PORT ( A : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ; LED7S : OUT STD_LOGIC_VECTOR(6 DOWNTO 0) ) ; END ; ARCHITECTURE one OF segment7 IS
19
Байду номын сангаас
WHEN "0110" => LED7S <= "1111101" ; -- X"7D"'6 WHEN "0111" => LED7S <= "0000111" ; -- X"07"'7 WHEN "1000" => LED7S <= "1111111" ; -- X"7F"'8 WHEN "1001" => LED7S <= "1101111" ; -- X"6F"'9 --WHEN "1010" => LED7S <= "1110111" ; -- X"77"'10 --WHEN "1011" => LED7S <= "1111100" ; -- X"7C"'11 --WHEN "1100" => LED7S <= "0111001" ; -- X"39"'12 --WHEN "1101" => LED7S <= "1011110" ; -- X"5E"'13 --WHEN "1110" => LED7S <= "1111001" ; -- X"79"'14 --WHEN "1111" => LED7S <= "1110001" ; -- X"71"'15 WHEN OTHERS => NULL ; END CASE ; END PROCESS ; END ;
21
variable comb:std_logic_vector(1 downto 0); begin comb:=a & b; case comb is when "00"=>y<='0'; when "01"=>y<='0'; when "10"=>y<='0'; when "11"=>y<='1'; when others=>y<='X'; end case; end process p1; end behave;
22
寄存器传输级 描述形式
例3:2输入的与门电路描述
library ieee; use ieee.std_logic_1164.all; entity and22 is port(a:in std_logic; b:in std_logic; y:out std_logic); end and22; architecture behave of and22 is begin y<=a and b;
4
条件改为时钟沿,则生成 D触发器:
5
2)if 语句的二选择控制 ) 格式: if 条件 then 顺序处理语句; else 顺序处理语句; end if ; 用条件来选择两条不同程序执行的路径。