原创 vhdl 4*4矩阵键盘程序

2008-11-15 20:29 6458 13 16 分类: FPGA/CPLD

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


entity key44 is
generic(width: positive :=4);
 port(clk :in std_logic;
   column : in std_logic_vector(3 downto 0);
   row : out std_logic_vector(3 downto 0);
   num : out integer range 0 to 15 );
end entity;


architecture beha of key44 is
component key is
port(clk :in std_logic;
  din : in std_logic;
  dout : out std_logic);
end component;
signal count: std_logic_vector(1 downto 0);
signal row_v,column_v: std_logic_vector(3 downto 0);
signal z : std_logic_vector(5 downto 0);
begin
 u1:for i in 0 to width-1 generate
 U1: key port map (clk,column(i),column_v(i)); --去抖
 end generate;--产生扫描信号
 process(clk)
 begin
  if(rising_edge(clk))then
   if(count="11")then
    count<="00";
   else
    count<=count+'1';
   end if; 
  end if;
 end process;
 row_v <= "1110" when count="00" else
    "1101" when count="01" else
    "1011" when count="10" else
    "0111" ;
 row<=row_v;
 z<=count&column;
 process(clk,z)--译码
 begin
  if(rising_edge(clk))then
   case z is
    when "001110" => num<=0;
    when "001101" => num<=1;
    when "001011" => num<=2;
    when "000111" => num<=3;
    when "011110" => num<=4;
    when "011101" => num<=5;
    when "011011" => num<=6;
    when "010111" => num<=7;
    when "101110" => num<=8;
    when "101101" => num<=9;
    when "101011" => num<=10;
    when "100111" => num<=11;
    when "111110" => num<=12;
    when "111101" => num<=13;
    when "111011" => num<=14;
    when "110111" => num<=15;
    when others => null;
   end case;
  end if;
  end process; 
end architecture;

文章评论3条评论)

登录后参与讨论

用户351858 2012-2-22 23:20

实体key没有啊?能把程序一起发到我邮箱吗?谢谢了,我正需要呢!342966545@qq.com

nneverli_217963090 2010-7-28 08:21

这个组件式硬件去抖的

用户195799 2009-8-19 09:37

正在学这个,楼主这程序中的component key是什么?能写出它的程序吗?谢谢。 我的邮箱:693123941@qq.com
相关推荐阅读
nneverli_217963090 2013-04-10 13:29
Intel Bus与Motorola Bus区别(Intel模式与Motorola模式的区别)
  Intel Bus与Motorola Bus区别(Intel模式与Motorola模式的区别)   在实际应用中用到的很多带并行总线的芯片的硬件连接、读写操作都分为INTERL BUS...
nneverli_217963090 2012-07-14 13:39
Replace Pioneer
www.mind-pioneer.com Replace Pioneer  ...
nneverli_217963090 2012-07-09 13:38
tny278图片
图片...
nneverli_217963090 2010-07-27 08:58
Keil 0xFD Bug
单片机到手(PS:编译软件,ISP下载软件提前两天都开始待命了),迫不及待地更新了程序,通过USB接口和复位键,ISP下载实在是太方便了。重启单片机-调整时间-OK,本应该显示“星期三”,却只显示了“...
nneverli_217963090 2010-05-24 16:53
咱又回来了。
由于工作原因,博客闲置了将近一年。重新启用。呵呵记录一下。  ...
nneverli_217963090 2009-11-13 16:32
INC指令的那点秘密!!!
不影响C标志位,哈哈,^_^,O(∩_∩)O...
我要评论
3
13
关闭 站长推荐上一条 /2 下一条