大家帮个忙帮我看小这个小键盘和扫描程序我有点看不懂。。。<br />扫描程序<br />-------------------------------------------------<br />--芳元电子工作室,版权所有,严禁用于商业用途<br />--实体名:keyboard<br />--功 能:4×4键盘扫描和获得键盘值<br />--接 口:clk -时钟输入<br />-- lie -列值输入<br />-- hang-行扫描输出<br />-- qout-键盘值BCD码输出<br />--作 者:Justin Xu <br />--日 期:2005-08-16<br />-------------------------------------------------<br /><br />library ieee;<br />use ieee.std_logic_1164.all;<br />use ieee.std_logic_unsigned.all;<br />use ieee.std_logic_arith.all;<br /><br />entity keyboard is<br />port<br />(clk :in std_logic;<br /> lie :in std_logic_vector(3 downto 0);<br /> hang :out std_logic_vector(3 downto 0);<br /> qout :out std_logic_vector(3 downto 0)<br />);<br />end keyboard;<br /><br />architecture behave of keyboard is<br />signal cnt:std_logic_vector(1 downto 0);<br />signal hang_tem:std_logic_vector(3 downto 0);<br />signal tem:std_logic_vector(3 downto 0);<br />signal reg:std_logic_vector(3 downto 0);<br />begin<br />tem<=lie;<br />process(clk)<br />begin<br /> if clk'event and clk='1' then<br /> if cnt="11" then<br /> cnt<="00";<br /> else<br /> cnt<=cnt+1;<br /> end if;<br /> case cnt is<br /> when "00"=>hang_tem<="1101";<br /> if tem="1110" then<br /> reg<="0000";<br /> elsif tem="1101" then<br /> reg<="0001";<br /> elsif tem="1011" then<br /> reg<="0010";<br /> elsif tem="0111" then<br /> reg<="0011";<br /> else<br /> reg<=reg;<br /> end if;<br /> when "01"=>hang_tem<="1011";<br /> if tem="1110" then<br /> reg<="0100";<br /> elsif tem="1101" then<br /> reg<="0101";<br /> elsif tem="1011" then<br /> reg<="0110";<br /> elsif tem="0111" then<br /> reg<="0111";<br /> else<br /> reg<=reg;<br /> end if; <br /> when "10"=>hang_tem<="0111";<br /> if tem="1110" then<br /> reg<="1000";<br /> elsif tem="1101" then<br /> reg<="1001";<br /> elsif tem="1011" then<br /> reg<="1010";<br /> elsif tem="0111" then<br /> reg<="1011";<br /> else<br /> reg<=reg;<br /> end if; <br /> when "11"=>hang_tem<="1110";<br /> if tem="1110" then<br /> reg<="1100";<br /> elsif tem="1101" then<br /> reg<="1101";<br /> elsif tem="1011" then<br /> reg<="1110";<br /> elsif tem="0111" then<br /> reg<="1111";<br /> else<br /> reg<=reg;<br /> end if; <br /> when others=>hang_tem<="1111";<br /> reg<=reg;<br /> end case;<br /> end if;<br /> hang<=hang_tem;<br /> qout<=reg;<br />end process; <br />end behave;<br />电路图也上传了<br />谢谢大家 |
|