button_test.vhd

来自「是一些很好的FPGA设计实例」· VHDL 代码 · 共 42 行

VHD
42
字号

--**                 按键(防抖动)控制	

--文件名:button_test.vhd

--功  能:按键发声

--说  明:

--       为了便于观察将obutton接在蜂鸣器的输入端,即按下按键后蜂鸣器发出蜂鸣声;

--       ibutton接在S3处;

--       ibutton的默认电平为"1",有效电平为"0";

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity button_test is
    Port (clk : in std_logic;			  --50M的时钟频率;
	       ibutton : in std_logic;	  --按键输入;
	       obutton : out std_logic );  --经过防抖动处理过后的按键信号;
end button_test;

architecture Behavioral of button_test is

begin
process(clk,ibutton)
variable cnt : integer range 0 to 50000;
begin
   if ibutton='1' then cnt:=0;obutton<='1';
   elsif clk'event and clk='1' then	cnt:=cnt+1;
	   if cnt<25000 then obutton<='0';
		elsif cnt<50000 then obutton<='1';
		else cnt:=0;obutton<='1';
		end if;
   end if;
end process;
end Behavioral;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?