EDA编程题

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

编程题

(程序书上很多,大家看书上的)

1、设计3线-8线译码器,如图所示

DECODER

其中ENA是译码器的使能控制输入端,当ENA=0时,译码器不能工作,8线输出Y[7..0]=00000000,(译码器的输出有效电平为高电平):当ENA=1时,译码器工作,C、B、A是3线数据输入端,译码器处于工作状态时,当CBA=000时,Y[7..0]=00000001(即Y[0]=1);当CBA=001时,Y[7..0]=00000010(即Y[1]=1);以此类推。

LIBRARY IEEE;

USE IEEE.STD_LOGIC_1164.ALL;

ENTITY Decoder IS

PORT(A,B,C,ENA:IN BIT;

Y:OUT BIT_VECTOR(7 DOWNTO 0));

END Decoder;

ARCHITECTURE one OF Decoder IS

BEGIN

PROCESS(A,B,C,ENA)

V ARIABLE CBA:BIT_VECTOR(2 DOWNTO 0);

BEGIN

CBA:=(C& B& A);

IF ENA='0' THEN y <= "00000000";

ELSE CASE CBA IS

WHEN "000" => Y <= "00000001";

WHEN "001" => Y <= "00000010";

WHEN "010" => Y<= "00000100";

WHEN "011" => Y <= "00001000";

WHEN "100" => Y <= "00010000";

WHEN "101" => Y<= "00100000";

WHEN "110" => Y <= "01000000";

WHEN "111" => Y <= "10000000";

WHEN OTHERS=>NULL;

END CASE;

END IF;

END PROCESS;

END one;

2、设计一个9人表决电路,参加表决的有9人,同意为1,不同意为0,同意者过半则表决通过,绿指示灯亮(输出信号LED=’1’表示);表决不通过则红指示灯亮(输出信号LED=’0’表示)。

libraryieee;

use ieee.std_logic_1164.all;

entitybiaojue is

port ( a: in std_logic_vector (8downto 0);

led:outstd_logic);

end;

architecturebehav of biaojue is

begin

process(a)

variabletmp:integer range 0 to 9;

begin

tmp:=0;

for i in 0 to 8 loop

if a(i)='1' then tmp:=tmp+1;

end if;

end loop;

iftmp>4 then led<='1';

else led<='0';

end if;

end process;

end;

3、设计8位并行输入串行输出左移位寄存器如图所示,其中,clk是时钟信号;rst是异步清零信号,高电平有效;load是置数信号,高电平有效,Din[7..0]为并行输入数据,qb为串行输出数据。

libraryieee;

use ieee.std_logic_1164.all;

entityshflt is

port(clk,rst,load:instd_logic;

din:instd_logic_vector(7 downto 0);

qb:outstd_logic);

end;

architecturebehav of shfrt is

begin

process(clk,rst,load)

variable reg8:std_logic_vector(7 downto 0);

begin

if rst=’1’ then reg8:=”00000000”;

elsifclk'event and clk='1' then

if load='1' then reg8:=din;

else reg8(7 downto 1):=reg8(6 downto0);

end if;

end if;

qb<=reg8(7);

end process;

end;

4.用VHDL设计16位全减器电路首先设计一个4位全减器,然后用元件例化语句设计16位全减器

(1)4位全减器

libraryieee;

use ieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entity sub4 is

port(a,b:instd_logic_vector(3 downto 0);

cin:instd_logic;

cha:outstd_logic_vector(3 downto 0);

c_out:outstd_logic);

end;

architecture one of sub4 is

signalaa,bb,ss:std_logic_vector(4 downto 0);

begin

aa<='0'&a;

bb<='0'&b;

ss<=aa-bb-cin;

cha<=ss(3 downto 0);

相关文档
最新文档