If statement VHDL中频问题

If statement VHDL中频问题,if-statement,vhdl,If Statement,Vhdl,我正在努力学习VHDL,但进展不太顺利 我写了这段代码 library IEEE; use IEEE.bit_1164.ALL; use IEEE.bit_ARITH.ALL; use IEEE.bit_UNSIGNED.ALL; entity Switch_led is port( Switch_0: in bit; Switch_1: in bit; Switch_2: in bit; Switch_3: in bit; Switch_4: in

我正在努力学习VHDL,但进展不太顺利

我写了这段代码

library IEEE;
use IEEE.bit_1164.ALL;
use IEEE.bit_ARITH.ALL;
use IEEE.bit_UNSIGNED.ALL;


entity Switch_led is
port(
    Switch_0: in bit;
    Switch_1: in bit;
    Switch_2: in bit;
    Switch_3: in bit;
    Switch_4: in bit;
    Switch_5: in bit;
    Switch_6: in bit;
    Switch_7: in bit;

    Led_0: out bit;
    Led_1: out bit;
    Led_2: out bit;
    Led_3: out bit;
    Led_4: out bit;
    Led_5: out bit;
    Led_6: out bit;
    Led_7: out bit
                        );
end Switch_led;

architecture Behavioral of Switch_led is

begin

    if Switch_0 = '1' then 
    Led_0 <= 1;

    elsif Switch_1 = '1' then 
    Led_1 <= 1;

    elsif Switch_2 = '1' then 
    Led_2 <= 1;

    elsif Switch_3 = '1' then 
    Led_3 <= 1;

    elsif Switch_4 = '1' then 
    Led_4 <= 1;

    elsif Switch_5 = '1' then 
    Led_5 <= 1;

    elsif Switch_6 = '1' then 
    Led_6 <= 1;

    elsif Switch_7 = '1' then 
    Led_7 <= 1;
    end if;

end Behavioral;
IEEE库;
使用IEEE.bit_1164.ALL;
使用IEEE.bit_ARITH.ALL;
使用IEEE.bit_UNSIGNED.ALL;
实体开关指示灯亮起
港口(
开关_0:in位;
开关_1:in位;
开关_2:in位;
开关_3:in位;
开关_4:in位;
开关_5:in位;
开关_6:in位;
开关_7:in位;
Led_0:输出位;
Led_1:输出位;
Led_2:输出位;
Led_3:输出位;
Led_4:输出位;
Led_5:输出位;
Led_6:输出位;
Led_7:输出位
);
终端开关(发光二极管),;
开关led的结构是
开始
如果开关_0='1',则

Led_0包标准中给出了类型位的枚举名称

type BIT is ('0', '1');
这类任务:

Led_0 <= 1;
(您可以使用std_逻辑)

因为提到开关和LED,您应该知道,您只有一个值分配给任何LED,它们将继续(最左边的位值),如果在FPGA中成功合成和实现,它们将保持打开状态

Led_0 <= Switch_0;  -- as a concurrent signal assignment statement.
然后,在适合并发语句的位置(而不是在流程语句中),存在与if语句等效的并发信号分配语句:


Led_0除了David的全面回答之外,我想我应该补充一点,VHDL对数组类型有很好的支持,知道如何使用它们是编写更紧凑代码的基础

一维位数组称为位向量。因为您可以一次为位向量中的所有值赋值,所以您的代码可以变得简单得多:

entity switches_to_leds is
    port (
        switches: in bit_vector(7 downto 0);
        leds: out bit_vector(7 downto 0)
    );
end;

architecture behavior of switches_to_leds is
begin
    leds <= switches;
end;
实体切换到指示灯为
港口(
开关:位_向量(7到0);
LED:输出位_矢量(7到0)
);
结束;
开关\u至\u LED的架构行为为
开始

LED您需要准确地向我们显示错误消息的内容。然后如何在约束文件/.ucf.中添加管脚。。您如何知道交换机1位于H18等处?这是一个摘录自我所讨论的旧ucf文件:NET“led”LOC=“ae22”| IOSTANDARD=LVTTL;净“led”LOC=“ae21”| IOSTANDARD=LVTTL;净“led”LOC=“ag21”| IOSTANDARD=LVTTL;我想你会明白的。无论如何,这是一种依赖于工具或供应商的格式,而不是VHDL。更简单的是,
Led\0
-- IEEE.bit_1164.ALL;
-- use IEEE.bit_ARITH.ALL;
-- use IEEE.bit_UNSIGNED.ALL;
Led_0 <= Switch_0;  -- as a concurrent signal assignment statement.
if Switch_0 = '1' then 
        Led_0 <= '1';
else
        Led_0 <= '0';
end if;
Led_0 <= '1'  when Switch_0 = '1' else '0';
entity switches_to_leds is
    port (
        switches: in bit_vector(7 downto 0);
        leds: out bit_vector(7 downto 0)
    );
end;

architecture behavior of switches_to_leds is
begin
    leds <= switches;
end;