首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >VHDL: with-select表示多个值

VHDL: with-select表示多个值
EN

Stack Overflow用户
提问于 2013-03-10 02:39:33
回答 2查看 48.4K关注 0票数 6

我有以下代码(它对按下的按钮的编号进行编码):

代码语言:javascript
运行
复制
with buttons select
  tmp <= "000" when x"1",
         "001" when x"2",
         "010" when x"4",  
         "011" when x"8",
         "100" when others;
code <= input(1 downto 0);
error <= input(2);

我尝试在不使用tmp signal的情况下重写它。有可能吗?以下代码不起作用:

代码语言:javascript
运行
复制
with buttons select
  error & code <= "000" when x"1",
                  "001" when x"2",
                  "010" when x"4",  
                  "011" when x"8",
                  "100" when others;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-10 04:08:57

您可以使用case来代替with select:

代码语言:javascript
运行
复制
my_process_name : process(buttons)
begin
  case buttons is
    when x"1" =>
      error <= '0';
      code  <= "00";
    when x"2" =>
      error <= '0';
      code  <= "01";
    when x"4" =>
      error <= '0';
      code  <= "10";
    when x"8" =>
      error <= '0';
      code  <= "11";
    when others =>
      error <= '1';
      code  <= "00";
  end case;
end process;
票数 5
EN

Stack Overflow用户

发布于 2018-05-16 00:30:20

或者,您可以将其编写为2个单独的with/when语句:

代码语言:javascript
运行
复制
with buttons select
  error <= '0' when x"1",
           '0' when x"2",
           '0' when x"4",  
           '0' when x"8",
           '1' when others;
with buttons select
  code <= "00" when x"1",
          "01" when x"2",
          "10" when x"4",  
          "11" when x"8",
          "00" when others;

或者:

代码语言:javascript
运行
复制
error <= '0' when (buttons = X"1" or buttons = X"2" buttons = X"4" buttons = X"8") else '1'; 
code <= "00" when buttons = X"1" else "01" when buttons = X"2" else "10" when buttons = X"4" else "11" when buttons = X"8" else "00"; 

VHDL是一种编译语言或综合语言。只要合成工具创建了相关的逻辑构造,任何格式都可以。其余的是系统学,允许代码被理解和维护。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15314463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档