VHDL鍵盤問題 |
缺席
|
w10789173
一般會員 ![]() ![]() 發表:1 回覆:0 積分:0 註冊:2008-02-09 發送簡訊給我 |
各位大大,想請問一下,我現在要做,當我鍵盤連續輸入,結果只取最後一個鍵盤輸入的值
這是一個自動控制鍵盤的控制器,我可以先輸入數字,然後再輸入指令,我的機器就會動那個指令n次 例如,先按5再按前進,自東車就會前進5次,如果只按前進,則自動車會自動前進1次(預設值) 當我遇到連續輸入字數時,我不管要輸入多少數字,永遠取最後一個的數字當動作次數 現在我卡在不知道如何判別這種機制,希望有高手可以給我一點提示幫我解決,謝謝! library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ENTITY key_controller IS PORT( clk : IN std_logic; col : OUT std_logic_vector ( 3 DOWNTO 0 ); key_out : OUT std_logic; row : IN std_logic_vector ( 3 DOWNTO 0 ); digit : OUT std_logic_vector ( 5 DOWNTO 0 ) ); END key_controller ; architecture behavioral of key_controller is signal clkm : std_logic; signal key_pressed : std_logic; signal key_valid : std_logic := '0'; signal dbnq : std_logic_vector( 6 downto 0 ) := ( others => '0' ); --debounce signal scan_cnt : std_logic_vector( 3 downto 0 ) := ( others => '0' ); signal cmd_buf : std_logic_vector( 2 downto 0 ) := ( others => '0' ); signal num_buf : std_logic_vector( 2 downto 0 ) := ( others => '0' ); begin count : process( clk ) begin if rising_edge( clk ) then count_t <= count_t 1; end if; clkm <= count_t( 15 ); --scaning clock generaterd end process; ----------------------------------------------- keyboard: process( clkm, scan_cnt, key_pressed ) begin --scan_cnt is a 4 bit up scan counter case scan_cnt( 3 downto 2 ) is --keypad column scaning, decoder functional when "00" => col <= "0111"; when "01" => col <= "1011"; when "10" => col <= "1101"; when "11" => col <= "1110"; when others => col <= "1111"; end case; --------------------------------------------- case scan_cnt( 1 downto 0 ) is --keypad row scaning, mux functional when "00" => key_pressed <= row(0); when "01" => key_pressed <= row(1); when "10" => key_pressed <= row(2); when "11" => key_pressed <= row(3); when others => null; end case; ---------------------------------------------------------------- if rising_edge( clkm ) then if key_pressed = '1' then --no key_pressed in, continue to scan scan_cnt <= scan_cnt 1; dbnq <= "1111111"; elsif key_pressed = '0' then --key_pressed in dbnq <= dbnq - 1; end if; ----- debounce if dbnq = "1001111" then --key_pressed debounce key_valid <= '1'; else key_valid <= '0'; end if; end if; -- scan_out <= scan_cnt; end process; --------------------------------------------------------------------------- keycode : process( clk, scan_cnt, key_valid ) begin ------------- asynchronous expression if key_valid'event and key_valid = '1' then if scan_cnt( 3 ) = '1' then cmd_flag <= '1'; cmd_buf <= scan( 2 downto 0 ); --command store into ram elsif scan_cnt( 3 ) = '0' then num_flag <= '1'; num_buf <= scan( 2 downto 0 ); --numeric store into ram else num_buf <= "000", --numeric store into ram cmd_buf <= "000"; --numeric store into ram num_fleg <= '0'; cmd_fleg <= '0'; end if; digit <= cmd_buf & num_buf; -- out of key controller end if; end process; ------------------- key_out <= key_valid; digit <= seg4bit; end behavioral; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |