首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >键盘编码器为什么有8个状态?

键盘编码器为什么有8个状态?
EN

Stack Overflow用户
提问于 2014-05-06 12:48:12
回答 1查看 743关注 0票数 0

我需要用vhdl编码一个键盘编码器。我在考虑用4个州来实现它。在columnn1扫描row1,row2,row2,row4时。在我看来,这样的州应该够了,但我从互联网上找到的一个例子表明,有8个州是这样的:

代码语言:javascript
复制
key_scanner_sm : process (clk)
  begin  -- process key_scanner
    if clk'event and clk = '1' then

      if state_inc = '1' then

        -- reset scan_complete
        scan_complete <= '0';

        case key_state is

          when pulse_row_1 =>
            key_read  <= (others => '0');
            key_row   <= "0001";
            key_state <= read_row_1;

          when read_row_1 =>
            case key_col is
              when "0001" => key_read <= X"31";  -- 1
              when "0010" => key_read <= X"32";  -- 2
              when "0100" => key_read <= X"33";  -- 3
              when "1000" => key_read <= X"41";  -- A
              when others => null;
            end case;
            key_state <= pulse_row_2;

          when pulse_row_2 =>
            key_row   <= "0010";
            key_state <= read_row_2;

          when read_row_2 =>
            case key_col is
              when "0001" => key_read <= X"34";  -- 4
              when "0010" => key_read <= X"35";  -- 5
              when "0100" => key_read <= X"36";  -- 6
              when "1000" => key_read <= X"42";  -- B
              when others => null;
            end case;
            key_state <= pulse_row_3;

          when pulse_row_3 =>
            key_row   <= "0100";
            key_state <= read_row_3;

          when read_row_3 =>
            case key_col is
              when "0001" => key_read <= X"37";  -- 7
              when "0010" => key_read <= X"38";  -- 8
              when "0100" => key_read <= X"39";  -- 9
              when "1000" => key_read <= X"43";  -- C
              when others => null;
            end case;
            key_state <= pulse_row_4;

          when pulse_row_4 =>
            key_row   <= "1000";
            key_state <= read_row_4;

          when read_row_4 =>
            case key_col is
              when "0001" => key_read <= X"2A";  -- *
              when "0010" => key_read <= X"30";  -- 0
              when "0100" => key_read <= X"23";  -- #
              when "1000" => key_read <= X"44";  -- D
              when others => null;
            end case;
            key_state     <= pulse_row_1;
            scan_complete <= '1';

          when others => null;
        end case;

      end if;
    end if;
  end process key_scanner_sm;

这背后有什么好的理由,有人知道吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-06 14:28:55

您提供的示例需要额外的状态,因为它是作为单个case语句实现的。对key_row的分配需要一个额外的周期才能生效,然后才能读取key_col。因为这是一个简单的循环扫描,所以可以通过从前面的pulse_row_n状态分配key_row的下一个值来消除read_row_n状态。

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

https://stackoverflow.com/questions/23495212

复制
相关文章

相似问题

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