COUNT : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)); END RPLCONT;
ARCHITECTURE RPLCONT OF RPLCONT IS COMPONENT DFF1
PORT (CLK,D:IN STD_LOGIC; Q,QB:OUT STD_LOGIC); END COMPONENT;
SIGNAL COUNT_IN_BAR:STD_LOGIC_VECTOR(4 DOWNTO 0); BEGIN
COUNT_IN_BAR(0)<=CLK;
GEN1:FOR I IN 0 TO 3 GENERATE;
U:DFF1 PORT MAP (CLK=> (COUNT_IN_BAR(i) ) , D=>(COUNT_IN_BAR(i+1)) , Q=> ( COUNT(i)),QB=> (COUNT_IN_BAR(i+1)) ); END GENERATE; END RPLCONT;
19. 在下面横线上填上合适的语句,完成 8 位数字比较器的设计。 ENTITY COMP IS
PORT (A,B: IN (integer )RANGE 0 T0 ( 7 ) ; AEQUALB, AGREATB, ALESSB : OUT BIT); END COMP;
ARCHITECTURE BEHAVE OF COMP IS BEGIN
AEQUALB<=?1? WHEN A=B ELSE?0?; AGREATB<=?1? WHEN A>B ELSE?0?; ALESSB<=?1? WHEN A<B ELSE?0?; END BEHAVE;
20. 在下面横线上填上合适的语句,完成一个8 位分频器的设计。 LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY PULSE IS PORT (
CLK : IN STD_LOGIC;
D : IN STD_LOGIC_VECTOR (7 DOWNTO 0); FOUT : OUT STD_LOGIC ); END;
ARCHITECTURE ONE OF PULSE IS SIGNAL FULL : STD_LOGIC; BEGIN
P_REG: PROCESS(CLK)
(signal )CNT8 : STD_LOGIC_VECTOR(7 DOWNTO 0); BEGIN
IF CLK?EVENT AND CLK = ?1? THEN
IF CNT8 = \ CNT8 := (”00000000” ); --当 CNT8 计数计满时,输入数据 D 被同步预置给计数器
FULL <= '1'; --同时使溢出标志信号 FULL输出为高电平 ELSE CNT8 := (cnt8+1 ) ; --否则继续作加 1 计数 FULL <= '0'; --且输出溢出标志信号 FULL为低电平 END IF; END IF;
END PROCESS P_REG;
P_DIV: PROCESS(full )
VARIABLE CNT2 : STD_LOGIC; BEGIN
IF FULL'EVENT AND FULL = '1' THEN CNT2 <=(not CNT2 ); --如果溢出标志信号 FULL为高电平,D 触发器输出取反 IF CNT2 = '1' THEN FOUT <= '1'; ELSE FOUT <= '0'; END IF; END IF; END PROCESS P_DIV; END;
21. 在下面横线上填上合适的语句,完成一个10 线-4线优先编码器的设计。 LIBRARY IEEE ;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY CODER IS PORT (DIN : IN STD_LOGIC_VECTOR(9 DOWNTO 0); OUTPUT : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ); END CODER;
ARCHITECTURE BEHAV OF CODER IS
SIGNAL SIN : STD_LOGIC_VECTOR(3 DOWNTO 0); BEGIN
PROCESS (din) BEGIN
IF (DIN(9)='0') THEN SIN <= \ ( if )(DIN(8)=?0?) THEN SIN <= \ ELSIF (DIN(7)='0') THEN SIN <= \ SIN <= \ELSIF (DIN(5)='0') THEN SIN <= \ SIN <= \ELSIF (DIN(3)='0') THEN SIN <= \ SIN <= \ELSIF (DIN(1)='0') THEN SIN <= \ ELSE SIN <= (”0000” ) ; ( end if ); END PROCESS ; OUTPUT <= SIN ; END BEHAV;
22. 在下面横线上填上合适的语句,完成下参数可定制带计数使能异步复位计数器的 VHDL 设计。
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL; USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY COUNTER_N IS (GENERIC) (WIDTH : INTEGER := 8); PORT(DATA : IN STD_LOGIC_VECTOR (WIDTH-1DOWNTO 0); LOAD, EN, CLK, RST : IN STD_LOGIC;
Q : OUT STD_LOGIC_VECTOR ((WIDTH-1)DOWNTO 0));
END COUNTER_N;
ARCHITECTURE BEHAVE OF COUNTER_N IS
SIGNAL COUNT : STD_LOGIC_VECTOR (WIDTH-1 DOWNTO 0); BEGIN
PROCESS(CLK, RST) BEGIN
IF RST = '1' THENCOUNT <= (others=>’0’ ) ; ―― 清零 ELSIF CLK?EVENT AND CLK = ?1? THEN ―― 边沿检测 IF LOAD = '1' THEN COUNT <= DATA;
( elsif ) EN = '1' THEN COUNT <= COUNT + 1; END( if ) ; END IF;
END PROCESS; Q <= COUNT; END BEHAVE;
23. 在下面横线上填上合适的语句,完成简易彩灯控制电路的 VHDL 设计。 说明:在 EDA 实验箱上利用 OUT1~OUT8 共 8 个发光二极管实现从左到右再从右到左循环,依次仅有 一只 LED 不亮的简单跑马灯。 LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL; USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY TEST2 IS PORT (CLK1HZ:IN STD_LOGIC; LED:OUT STD_LOGIC_VECTOR(7 DOWNTO 0)); END TEST2;
ARCHITECTURE BEHA OF TEST2 IS
SIGNAL COUNT1:STD_LOGIC_VECTOR (3 DOWNTO 0); BEGINP1:PROCESS (CLK1HZ) BEGIN
IF (CLK1HZ'EVENT AND CLK1HZ='1') THEN IF(COUNT1=\
THEN COUNT1<=\ COUNT1<= (COUNT1+1 ) ; END IF; END IF;
END PROCESS;
P2:PROCESS(count1 ) BEGIN
CASE COUNT1 IS
WHEN\WHEN\ WHEN \ WHEN \ WHEN \
WHEN \ WHEN \ WHEN \ END CASE; END PROCESS; END ARCHITECTURE BEHA; 24. 在下面横线上填上合适的语句,完成 3人表决器的设计。 ENTITY maj IS
PORT(a,b,c : IN BIT; m : OUT BIT); END maj;
ARCHITECTURE structure OF maj IS --declare components used in architecture
COMPONENT and2 PORT(in1, in2 : IN BIT; out1 : OUT BIT); END COMPONENT;
COMPONENT or3 PORT(in1, in2, in3 : IN BIT; out1 : OUT BIT); END (COMPONENT) ; SIGNAL w1, w2, w3 : BIT; BEGIN
gate1 : and2 PORT MAP (a, b, w1);
gate2 : and2 PORT MAP (b, ( c ) , w2); gate3 : and2 PORT MAP (( a ) , c, w3);
gate4 : or3 PORT MAP (w1, w2, w3, ( m ) ); END structure;
25. 在下面横线上填上合适的语句,完成同步17 进制计数器的设计。 LIBRARY ieee;
USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.ALL; ENTITY counter17 IS
PORT( clk, rst: IN std_logic; ch, c: OUT std_logic;
qb1, qa1: OUT std_logic_vector(3 DOWNTO 0)); END;
ARCHITECTURE behav OF counter17 IS
SIGNAL qb, qa: std_logic_vector(3 DOWNTO 0); SIGNAL cin: std_logic; BEGIN qb1<=qb; qa1<=qa;
PROCESS(clk) BEGIN
IF clk'event AND clk='1' THEN
IF ( rst=?1? )OR (qb=1 AND qa=6) THEN qa<=\
ELSIF ( qb<=“0001” ) THEN cin<='1'; qa<=qa+1; ELSE qa<= (“0000” ) ; cin<='0'; END IF;
END IF;
END PROCESS; PROCESS(cin, clk) BEGIN
IF clk'event AND clk='1' THEN IF (qb=1 AND qa=6) THEN qb<=\ ELSE c<='0'; END IF;
IF (qa=6 and qb=0 ) THEN qb<=qb+1; END IF; END IF; END PROCESS; ch<=cin; END;
26. 在下面横线上填上合适的语句,完成单时钟同步十六进制加/减计数器的设计。 LIBRARY ieee;
USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.ALL; ENTITY counter IS
PORT(clk, en, ld, ud, d0, d1, d2, d3:IN std_logic;
c:OUT std_logic; q:OUT std_logic_vector(3 DOWNTO 0)); END;
ARCHITECTURE bev OF counter IS
SIGNAL y, d:std_logic_vector(3 DOWNTO 0); BEGIN
PROCESS(clk, en, ld, ud) BEGIN
d<= (D0 &D1 & D2 & D3 ); IF ld=?0? THEN y<=d; c<=?0?; ELSIF(clk?event AND clk=?1?) THEN IF en=?0? THEN IF ud=?0? THEN IF y= (“1111” ) THEN y<=”0000”; c<=?1?;
ELSE y<=y+1; c<=?0?; END IF;
ELSIF ud=?1? THEN IF y= (“0000” ) THEN y<=”1111”; c<=?1?; ELSE y<=y-1; c<=?0?; END IF; END IF;
ELSIF en=?1? THEN y<= ( Y ) ; END IF; END IF;
END PROCESS; q<=y; END;
27. 在下面横线上填上合适的语句,完成一个具有三态输出的双 4选 1数据选择器的设计。