?? key.vhdl
字號:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;
entity keyval is
port(keyin:in std_logic_vector(3 downto 0); ---鍵盤輸入
keydrv:buffer std_logic_vector(3 downto 0); ---掃描輸出
clkscan: in std_logic; ---掃描時鐘,0.1ms
value:out std_logic_vector(3 downto 0); ---鍵值
pressed:out std_logic;
comp:out std_logic;
rstcode:out std_logic;
clr_out :out std_logic ---有鍵被按下標志
); ---功能鍵標志
end keyval;
architecture Behavioral of keyval is
signal t: std_logic_vector(7 downto 0);
signal dd: std_logic_vector(3 downto 0);
signal tpressed:std_logic;
constant s0:std_logic_vector(3 downto 0):="1110"; --定義狀態機編碼
constant s1:std_logic_vector(3 downto 0):="1101";
constant s2:std_logic_vector(3 downto 0):="1011";
constant s3:std_logic_vector(3 downto 0):="0111";
signal n_state:std_logic_vector(3 downto 0); ---次態
begin
t<=keydrv & keyin;
process(clkscan) ---狀態更新進程
begin
if clkscan='1' and clkscan'event then
keydrv<=n_state;
end if;
end process;
process(keydrv) ---狀態譯碼
begin
case keydrv is
when s0=>n_state<=s1;
when s1=>n_state<=s2;
when s2=>n_state<=s3;
when s3=>n_state<=s0;
when others=>n_state<=s0;
end case;
end process;
process(t,clkscan) ---譯碼
begin
if clkscan='1' and clkscan'event then
case t is
when "11101110"=>value<="0001"; tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11101101"=>value<="0010";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11101011"=>value<="0011";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11100111"=>value<="0100";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11011110"=>value<="0101";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11011101"=>value<="0110";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11011011"=>value<="0111";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "11010111"=>value<="1000";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "10111110"=>value<="1001";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "10111101"=>value<="0000";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "10111011"=>value<="1010";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "10110111"=>value<="1011";tpressed<='1'; clr_out<='0'; rstcode<='1';comp<='1';
when "01111110"=>value<="1100";clr_out<='0'; rstcode<='0';comp<='1';
when "01111101"=>value<="1101";clr_out<='0'; rstcode<='1';comp<='0';
when "01111011"=>value<="1110";clr_out<='0'; rstcode<='1';comp<='1';
when "01110111"=>value<="1111";clr_out<='1'; rstcode<='1';comp<='1';
when "11111111"=>tpressed<='0' ;
when others=> tpressed<='0'; ---value ,tpressed保持原態,相當于鎖存器
end case;
if tpressed='1' then
if dd="0011" then
pressed<=tpressed; dd<="0000";
else
dd<=dd+1;
end if;
else
pressed<=tpressed;
end if;
end if;
end process;
end Behavioral;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -