【例3-1】 2选times New Roman">1多路选择器程序。 (P31)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-28320.png LIBRARY IEEE; --IEEE库使用说明语句USE IEEE.STD_LOGIC_1164.ALL;ENTITY mux21 IS --实体说明部分 PORT( a,b : IN STD_LOGIC; s: IN STD_LOGIC; y: OUT STD_LOGIC );END ENTITY mux21;ARCHITECTURE mux21a OF mux21 IS --结构体说明部分 BEGIN PROCESS(a,b,s) BEGIN IF s='0' THEN y<=a; ELSE y<=b; END IF; END PROCESS;END ARCHITECTURE mux21a;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-9763.png 【例3-2】 有类属说明的2输入与非门的实体描述。 (P33)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-28794.png ENTITY nand2 IS GENERIC ( t_rise : TIME := 2ns ;t_fall : TIME := 1ns ) PORT( a: IN BIT; b : IN BIT; s : OUT BIT);END ENTITY nand2;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-16768.png 【例3-3】 n输入与非门的实体描述: (P33)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-30263.png ENTITY nand_n IS GENERIC ( n : INTEGER ) ; PORT( a : IN STD_LOGIC_VECTOR(n-1 DOWNTO 0); s : OUT STD_LOGIC );END ENTITY nand_n;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-30954.png 例3-4】 半加器的完整VHDL描述,其中x、y为加数与被加数,s为和信号,c为进位信号。 (P36)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-1468.png ENTITY half_adder IS PORT( x,y : IN BIT; s: IN BIT; c: OUT BIT);END ENTITY half_adder;ARCHITECTURE dataflow OF half_adder IS BEGIN s <= x XOR y; c <= x AND y;END ARCHITECTURE dataflow;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-31287.png 【例3-5】 2选1多路选择器的行为描述程序。 (P37)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-32486.png LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY mux21 IS PORT( a,b : IN STD_LOGIC; s: IN STD_LOGIC; y: OUT STD_LOGIC );END ENTITY mux21;ARCHITECTURE behav OF mux21 IS BEGIN PROCESS(a,b,s) BEGIN IF s='0' THEN y<=a; ELSE y<=b; END IF; END PROCESS;END ARCHITECTURE behav;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-29097.png 【例3-6】 2选1多路选择器数据流描述程序。 (P36)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-24927.png LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL;ENTITY mux21 IS PORT( a,b : IN STD_LOGIC; s: IN STD_LOGIC; y: OUT STD_LOGIC );END ENTITY mux21;ARCHITECTURE dataflow OF mux21 IS BEGIN y<=(a AND (NOT s)) OR (b AND s); END ARCHITECTURE dataflow;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-6891.png 【例3-7】 2选1多路选择器结构描述程序。 (P37)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-29229.png LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL;ENTITY and21 IS PORT(i0,i1 : IN STD_LOGIC; q: OUT STD_LOGIC );END ENTITY and21;ARCHITECTURE one OF and21 IS BEGIN q<=i0 AND i1; END ARCHITECTURE one; LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL;ENTITY or21 IS PORT(i0,i1 : IN STD_LOGIC; q: OUT STD_LOGIC );END ENTITY or21;ARCHITECTURE one OF or21 IS BEGIN q<=i0 OR i1; END ARCHITECTURE one; LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL;ENTITY inv21 IS PORT(i0 : IN STD_LOGIC; q: OUT STD_LOGIC );END ENTITY inv21;ARCHITECTURE one OF inv21 IS BEGIN q<= (NOT i0); END ARCHITECTURE one; LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL;ENTITY mux21 IS PORT( a,b : IN STD_LOGIC; s: IN STD_LOGIC; y: OUT STD_LOGIC );END ENTITY mux21;ARCHITECTURE struct OF mux21 IS COMPONENT and21 PORT (i0,i1 : IN STD_LOGIC; q: OUT STD_LOGIC); END COMPONENT; COMPONENT or21 PORT (i0,i1 : IN STD_LOGIC; q: OUT STD_LOGIC); END COMPONENT; COMPONENT inv21PORT (i0: IN STD_LOGIC; q: OUT STD_LOGIC); END COMPONENT; SIGNAL tmp1,tmp2,tmp3:STD_LOGIC; BEGIN u1: and21 PORT MAP (b, s,tmp1); u2: inv21 PORT MAP(s,tmp2);u3: and21 PORT MAP (a,tmp2,tmp3); u4: or21 PORT MAP(tmp1,tmp3,y);END ARCHITECTURE struct;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-18155.png 【例3-8】 半加器的混合描述程序。 (P37)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-18067.png LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY xor21 IS PORT(i0,i1:IN STD_LOGIC; q: OUT STD_LOGIC);END ENTITY xor21;ARCHITECTURE behav OF xor21 IS BEGIN q<=i0 XOR i1; END ARCHITECTURE behav;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY half_adder IS PORT(a,b:IN STD_LOGIC; c,s: OUT STD_LOGIC);END ENTITY half_adder;ARCHITECTURE mix OF half_adder IS COMPONENT xor21 IS PORT(i0,i1:IN STD_LOGIC; q:OUT STD_LOGIC); END COMPONENT; BEGIN c <= a AND b; u1: xor21 PORT MAP(a,b,s); END ARCHITECTURE mix;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-26019.png 【例3-9】 打开一个字符文件,读出文件中的内容并关闭文件。 (P51)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-10056.png LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY readfile ISPORT( cs:IN STD_LOGIC; c: OUT CHARACTER);END ENTITY readfile; ARCHITECTURE read1 OF readfile ISBEGINPROCESS(cs)TYPE char_file IS FILE OF CHARACTER;FILE cfile : char_file;VARIABLE i : INTEGER :=0;BEGINIF(cs='1') THEN FILE_OPEN(cfile,"f:/leifr/testfile.asc",READ_MODE); WHILE NOT ENDFILE(cfile) LOOP READ(cfile,c); i := i+1; END LOOP; FILE_CLOSE(cfile);ELSEc<= '- ';END IF;END PROCESS; END ARCHITECTURE read1;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-23311.png 【例4-1】 WAIT语句示例程序。 (P65)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-5640.png cwait1 : PROCESS BEGIN y <= ( a AND b ) OR ( m XOR t ) ; z <= c NAND d ; WAIT ; -- 无限等待 END PROCESS cwait1 ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-24797.png 【例4-2】 WAIT FOR语句示例程序。 (65)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-20750.png cwait2 : PROCESS BEGIN y <= ( a AND b ) OR ( m XOR t ) ; z <= c NAND d ; WAIT FOR 10 * ( ct1 + ct2 ) ; -- 等待由该表达式计算的时间 END PROCESS cwait2 ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-670.png 【例4-3】 WAIT ON语句示例程序(二选一选择器)。 (P66)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-19190.png LIBRARY IEEE ;USE IEEE.STD_LOGIC_1164.ALL ;ENTITY mux2_1 IS PORT( data0, data1 : IN STD_LOGIC ; sel : IN STD_LOGIC ; q : OUT STD_LOGIC ) ;END mux2_1 ; ARCHITECTURE behavioral OF mux2_1 ISSIGNAL temp1, temp2, temp3 : STD_LOGIC ;BEGINcwait3 : PROCESS BEGIN temp1 <= data0 AND sel ; temp2 <= data1 AND ( NOT sel ) ; temp3 <= temp1 OR temp2 ; q <= temp3 ; WAIT ON data0, data1, q ; END PROCESS cwait3 ;END behavioral ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-28801.png 【例4-4】 WAIT ON语句和PROCESS语句中所使用的敏感信号列表的对比。 (P67)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-793.png ARCHITECTURE behavioral OF mux2_1 ISSIGNAL temp1, temp2, temp3 : STD_LOGIC ;BEGINcwait4 : PROCESS ( data0, data1, q ) BEGIN temp1 <= data0 AND sel ; temp2 <= data1 AND ( NOT sel ) ; temp3 <= temp1 OR temp2 ; q <= temp3 ; END PROCESS cwait4 ;END behavioral ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-1244.png 【例4-5】 WAIT UNTIL语句示例程序。 (P67)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-18785.png ARCHITECTURE behavioral OF example_waituntil ISSIGNAL temp : INTEGER ;BEGINcwait5 : PROCESS BEGIN M WAIT UNTIL ( ( temp + 5 ) >= 20 ) ; -- 该表达式是布尔表达式 END PROCESS cwait5 ; END behavioral ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-31508.png 【例4-6】 多条件WAIT语句的示例程序。 (P68)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-4647.png cwait6 : PROCESS BEGIN M -- 多条件WAIT语句 WAIT ON data0, data1,q UNTIL((temp + 5 ) >= 20) FOR 34 ns ; END PROCESS cwait6 ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-2717.png 【例4-7】 信号代入语句示例程序。 (P68)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-24987.png ARCHITECTURE behavioral OF example_dairu ISSIGNAL a, b, c, d,e, f : STD_LOGIC ;SIGNAL temp0, temp1, temp2, temp3, temp4, temp5 : STD_LOGIC ;BEGINcdairu : PROCESS BEGIN temp0 <= a NAND b ; -- 与非 temp1 <= c NOR d ; -- 或非 temp2 <= e XOR f AFTER 5 ns ; -- 异或门延迟 temp3 <= ( a NAND b ) NOR ( c NAND d ) ; temp4 <= ( c OR d ) NAND ( e OR f ) ; temp5 <= a XOR b XOR c XOR d XOR e XOR f ; END PROCESS cdairu ;END behavioral ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-28462.png 【例4-8】 变量赋值语句示例程序。 (P69)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-21440.png ARCHITECTURE behavioral OF example_fuzhi ISCONSTANT cvolt : REAL : = 3.3 ; -- 定义常数CONSTANT ccurrent : REAL : = 4.0 ;VARIABLE temp0, temp1 : REAL ; -- 定义变量VARIABLE temp2, temp3 : INTEGER RANGE 0 TO 255 : = 10 ;VARIABLE temp4 : STD_LOGIC_VECTOR ( 3 DOWNTO 0 ) ;VARIABLE temp5 : STD_LOGIC ;SIGNAL a : STD_LOGIC ; -- 定义信号SIGNAL b : REAL ;SIGNAL c : INTEGER ;SIGNAL d : STD_LOGIC_VECTOR ( 3 DOWNTO 0 ) ;BEGINcfuzhi : PROCESS BEGIN temp0 : = cvolt ; -- 变量直接赋值 temp1 : = ( cvolt + 1.8 ) * ccurrent ; -- 变量表达式赋值 temp2 : = c + 78 ; temp3 : = c / 5 ; -- 此时c必须是5的倍数 temp4 : = d ; temp5 : = temp4 ( 2 ) ; END PROCESS cfuzhi ;END behavioral ;file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-28506.png 【例4-9】 变量赋值和信号量代入的对比示例程序。 (P69)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-11530.png ARCHITECTURE behavioral OF example_duibi ISSIGNAL d0, d1, d2, d3 : STD_LOGIC ; -- 定义信号SIGNAL q0, q1 : STD_LOGIC ;BEGINcduibi_1 :PROCESS (d0, d1, d2, d3 ) BEGIN d2 <= d0 ; -- 信号量代入 q0 <= d2 OR d3 ; d2 <= d1 ; -- 信号量代入 q1 <= d2 OR d3 ; END PROCESS cduibi_1 ; cduibi_2 : PROCESS (d0, d1, d3 ) VARIABLE m2 : STD_LOGIC ; BEGIN m2 : = d0 ; -- 变量赋值 q0 <= m2 OR d3 ; m2 : = d1 ; -- 变量赋值 q1 <= m2 OR d3 ; END PROCESS cduibi_2 ;END behavioral ;进程cduibi_1的运行结果:q0 = d1 OR d3 并且 q1 = d1 OR d3进程cduibi_2的运行结果:q0 = d0 OR d3 而 q1 = d1 OR d3file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-15662.png 【例4-10】 采用单IF语句来描述D触发器的示例程序。 (P71)file:///C:UserswzyAppDataLocalTempksohtmlwps_clip_image-281.png LIBRARY IEEE ;USE IEEE.STD_LOGIC_1164.ALL ;ENTITY cdff1 IS PORT( d : IN STD_LOGIC ; clk : IN STD_LOGIC ; q : OUT STD_LOGIC ; qnot : OUT STD_LOGIC ) ;END cdff1 ; ARCHITECTURE dataflow OF cdff1 ISBEGINcdff_example : PROCESS ( clk ) BEGIN IF ( clk'EVENT AND clk = '1' ) THEN -- 单IF语句 q <= d ; qnot <= NOT d ; END IF ; END PROCESS cdff_example ;END dataflow ;
一周热门 更多>