【正文】
=0000000 。 end if。 else q = q。 end if。 end process scan_freq。scan_f =39。139。 when q=1100100。end behavior。鍵盤(pán)掃描計(jì)數(shù)器電路的程序library ieee。use 。use 。use 。entity smjsq isport(clk : in std_logic。clock scan_f : in std_logic。1khz clock key_pressed : in std_logic。detect key_pressed to stop counter scan_t : out std_logic_vector(3 downto 0))。countend smjsq。architecture behavior of smjsq is signal qscan : std_logic_vector(3 downto 0)。begin scan_1:process(clk,scan_f,key_pressed )begin if (clk39。event and clk=39。139。) then if(scan_f=39。139。 and key_pressed=39。139。) then qscan = qscan+1。 end if。 end if。 end process。 scan_t = qscan。end behavior。按鍵檢測(cè)電路的程序library ieee。use 。use 。use 。entity jiance isport( col : in std_logic_vector(3 downto 0)。keybord column state scan_t : in std_logic_vector(3 downto 0)。keybord scan location row : out std_logic_vector(3 downto 0)。keybord row state key_pressed : out std_logic)。key_pressed0 unkey_pressed1end jiance。architecture behavior of jiance isbeginrow ecoding row = 1110 when scan_t(3 downto 2) = 00 else 1101 when scan_t(3 downto 2) = 01 else 1011 when scan_t(3 downto 2) = 10 else 0111。column ecoding key_pressed = col(0) when scan_t(1 downto 0) = 00 else col(1) when scan_t(1 downto 0) = 01 else col(2) when scan_t(1 downto 0) = 10 else col(3)。end behavior。按鍵抖動(dòng)消除電路的程序library ieee。use 。use 。entity xiaodou isport( key_pressed : in std_logic。 key_pressed? clk : in std_logic。 clock for synchrony scan_f : in std_logic。 1khz clock key_valid : out std_logic)。key_valid?end xiaodou。architecture behavior of xiaodou isbeginxiaodou:process(clk,scan_f,key_pressed) variable dbnq : std_logic_vector(5 downto 0)。 begin if (key_pressed=39。139。) then dbnq:=111111。unkey_pressed , counter reset at 63 elsif (clk39。event and clk=39。139。) then if scan_f =39。139。 then if dbnq/=1 then dbnq:=dbnq1。key_pressed not enough a long time end if。 counter still subtract one end if。 end if。 if dbnq=2 then key_valid=39。139。key_valid after key_pressed 1/63k second else key_valid=39。039。key_invalid end if。 end process。 end behavior。鍵盤(pán)編碼電路的程序library ieee。use 。use 。use 。entity bianma1 isport( scan_t : in std_logic_vector(3 downto 0)。keybord scan count clk , key_valid : in std_logic。 bianma : out std_logic_vector(3 downto 0))。button codeend bianma1。architecture behavior of bianma1 isbegin bianma1:process(clk)begin if(clk39。event and clk=39。139。) then if (key_valid=39。139。) then case scan_t is encoding when 0000= bianma =0001。 1 when 0001= bianma =0010。 2 when 0010= bianma =0011。 3 when 0011= bianma =1100。 c when 0100= bianma =0100。 4 when 0101= bianma =0101。 5 when 0110= bianma =0110。 6 when 0111= bianma =1101。 d when 1000= bianma =0111。 7 when 1001= bianma =1000。 8 when 1010= bianma =1001。 9 when 1011= bianma =1110。 e when 1100= bianma =1010。 a when 1101= bianma =0000。 0 when 1110= bianma =1011。 b when others = bianma = 1111。 f end case。 end if。end if。 end process。end behavior。總程序library IEEE。use 。use 。use 。ENTITY saomiaodian ISgeneric (osc_f : integer := 100 。 osc_bit : integer := 7)。for testingPORT( clk : in std_logic。 col : in std_logic_vector(3 downto 0)。 scan_t : in std_logic_vector(3 downto 0)。 key_pressed : in std_logic。 key_pressed? scan_f : out std_logic。 1khz clock scan_t : in std_logic_vector(3 downto 0)。 key_valid : out std_logic。 row , bianma : out std_logic_vector(3 downto 0))。 q : buffer std_logic_vector((osc_bit1) downto 0) )。 END saomiaodian。ARCHITECTURE arc OF saomiaodian ISsignal scan_t: std_logic_vector(3 downto 0)。signal key_pressed : std_logic。signal scan_f : std_logic。signal key_valid : std_logic。ponent fpq100to1PORT( clk : in std_logic。 clock scan_f : out std_logic。 q : buffer std_logic_vector((osc_bit1) downto 0 ))。 END ponent。 ponent smjsqPORT( clk : in std_logic。 scan_f : in std_logic。 key_pressed : in std_logic。 scan_t : out std_logic_vector(3 downto 0))。END ponent。ponent jiancePORT( col : in std_logic_vector(3 downto 0)。 scan_t : in std_logic_vector(3 downto 0)。 row : out std_logic_vector(3 downto 0)。 key_pressed : out std_logic)。END ponent。ponent xiaodouPORT( key_pressed : in std_logic。 key_pressed? clk : in std_logic。 clock for synchrony scan_f : in std_logic。 1khz clock key_valid : out std_logic)。key_valid?END ponent。ponent bianma1port( scan_t : in std_logic_vector(3 downto 0)。 clk , key_valid : in std_logic。 bianma : out std_logic_vector(3 downto 0))。END ponent。BEGINU1:fpq100to1 port map (clk , scan_f)。U2:smjsq port map (clk , scan_f, key_pressed , scan_t )。U3:jiance port map (col , scan_t , row , key_pressed )。U4:xiaodou port map (key_pressed , clk , scan_f , key_valid )。U5:bianma1 port map (scan_t , clk , key_valid , bianma )。END arc。33