打印

大家帮个忙帮我看小这个小键盘和扫描程序我有点看不懂。

[复制链接]
1785|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
风中De舞者|  楼主 | 2007-8-22 11:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大家帮个忙帮我看小这个小键盘和扫描程序我有点看不懂。。。
扫描程序
-------------------------------------------------
--芳元电子工作室,版权所有,严禁用于商业用途
--实体名:keyboard
--功  能:4×4键盘扫描和获得键盘值
--接  口:clk -时钟输入
--        lie -列值输入
--        hang-行扫描输出
--        qout-键盘值BCD码输出
--作  者:Justin Xu 
--日  期:2005-08-16
-------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity keyboard is
port
(clk  :in  std_logic;
 lie  :in  std_logic_vector(3 downto 0);
 hang :out std_logic_vector(3 downto 0);
 qout :out std_logic_vector(3 downto 0)
);
end keyboard;

architecture behave of keyboard is
signal cnt:std_logic_vector(1 downto 0);
signal hang_tem:std_logic_vector(3 downto 0);
signal tem:std_logic_vector(3 downto 0);
signal reg:std_logic_vector(3 downto 0);
begin
tem<=lie;
process(clk)
begin
  if clk'event and clk='1' then
     if cnt="11" then
        cnt<="00";
     else
        cnt<=cnt+1;
     end if;
     case cnt is
       when "00"=>hang_tem<="1101";
                  if tem="1110" then
                     reg<="0000";
                  elsif tem="1101" then
                     reg<="0001";
                  elsif tem="1011" then
                     reg<="0010";
                  elsif tem="0111" then
                     reg<="0011";
                  else
                     reg<=reg;
                  end if;
       when "01"=>hang_tem<="1011";
                  if tem="1110" then
                     reg<="0100";
                  elsif tem="1101" then
                     reg<="0101";
                  elsif tem="1011" then
                     reg<="0110";
                  elsif tem="0111" then
                     reg<="0111";
                  else
                     reg<=reg;
                  end if;      
       when "10"=>hang_tem<="0111";
                  if tem="1110" then
                     reg<="1000";
                  elsif tem="1101" then
                     reg<="1001";
                  elsif tem="1011" then
                     reg<="1010";
                  elsif tem="0111" then
                     reg<="1011";
                  else
                     reg<=reg;
                  end if;        
       when "11"=>hang_tem<="1110";
                  if tem="1110" then
                     reg<="1100";
                  elsif tem="1101" then
                     reg<="1101";
                  elsif tem="1011" then
                     reg<="1110";
                  elsif tem="0111" then
                     reg<="1111";
                  else
                     reg<=reg;
                  end if;        
       when others=>hang_tem<="1111";
                    reg<=reg;
     end case;
   end if;
   hang<=hang_tem;
   qout<=reg;
end process; 
end behave;
电路图也上传了
谢谢大家

相关帖子

沙发
dadong| | 2007-8-25 12:53 | 只看该作者

我给你加个注释,嘿嘿

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity keyboard is               --由hang输出扫描信号,此时监听lie信号,来判断是什么键按下。
port
(clk  :in  std_logic;
lie  :in  std_logic_vector(3 downto 0);
hang :out std_logic_vector(3 downto 0);
qout :out std_logic_vector(3 downto 0)
);
end keyboard;

architecture behave of keyboard is
signal cnt:std_logic_vector(1 downto 0);--扫描哪一行
signal hang_tem:std_logic_vector(3 downto 0);--hang的缓存,当成hang好了
signal tem:std_logic_vector(3 downto 0);--lie的输入缓存,当成lie
signal reg:std_logic_vector(3 downto 0);--翻译成的bcd码
begin
tem<=lie;
process(clk)
begin
  if clk'event and clk='1' then  --扫描每一行为一个状态
     if cnt="11" then
        cnt<="00";
     else
        cnt<=cnt+1;
     end if;
     case cnt is
       when "00"=>hang_tem<="1101";  --扫描hang3
                  if tem="1110" then  -- 如果按下sw11,
                     reg<="0000";     --bcd为0
                  elsif tem="1101" then   --如果按下sw10
                     reg<="0001";       --bcd为1
                  elsif tem="1011" then   --如果按下sw9
                     reg<="0010";   -- bcd为2
                  elsif tem="0111" then
                     reg<="0011";
                  else
                     reg<=reg;
                  end if;
       when "01"=>hang_tem<="1011";    --剩下的不用我说了吧,这是扫描hang2
                  if tem="1110" then
                     reg<="0100";
                  elsif tem="1101" then
                     reg<="0101";
                  elsif tem="1011" then
                     reg<="0110";
                  elsif tem="0111" then
                     reg<="0111";
                  else
                     reg<=reg;
                  end if;      
       when "10"=>hang_tem<="0111";
                  if tem="1110" then
                     reg<="1000";
                  elsif tem="1101" then
                     reg<="1001";
                  elsif tem="1011" then
                     reg<="1010";
                  elsif tem="0111" then
                     reg<="1011";
                  else
                     reg<=reg;
                  end if;        
       when "11"=>hang_tem<="1110";
                  if tem="1110" then
                     reg<="1100";
                  elsif tem="1101" then
                     reg<="1101";
                  elsif tem="1011" then
                     reg<="1110";
                  elsif tem="0111" then
                     reg<="1111";
                  else
                     reg<=reg;
                  end if;        
       when others=>hang_tem<="1111";
                    reg<=reg;
     end case;
   end if;
   hang<=hang_tem;
   qout<=reg;
end process; 
end behave;

使用特权

评论回复
板凳
风中De舞者|  楼主 | 2007-8-25 13:59 | 只看该作者

搞明白了 谢谢了

搞明白了  谢谢了

使用特权

评论回复
地板
guocai_yao| | 2007-8-29 23:56 | 只看该作者

疑问

上面的程序好像没有去抖啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

287

帖子

1

粉丝