大家帮个忙帮我看小这个小键盘和扫描程序我有点看不懂。。。 扫描程序 ------------------------------------------------- --芳元电子工作室,版权所有,严禁用于商业用途 --实体名: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; 电路图也上传了 谢谢大家 |