source code
module key_beep(
input sys_clk,
input sys_rst_n,
input key,
output reg beep
);
reg [19:0]cnt;
reg key_delay_20ms;
reg key_delay_20ms_last;
reg key_last;
always@(posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
begin
cnt<=20'b0;
key_last<=1;
end
else
begin
key_last<=key;
if(key_last!=key)
cnt<=20'd0;
else
cnt<=(cnt==20'd100_0000)?cnt:cnt+1;
end
end
always@(posedge sys_clk or negedge sys_rst_n)
begin
if(!sys_rst_n)
begin
key_delay_20ms<=1;
key_delay_20ms_last<=1;
end
else
begin
key_delay_20ms_last<=key_delay_20ms;
if(key_delay_20ms_last==0 && key_delay_20ms==1)
beep<=~beep;
else
beep<=beep;
if(cnt==20'd100_0000)
key_delay_20ms<=key;
else
key_delay_20ms<=key_delay_20ms;
end
end
endmodule
xdc文件
set_property -dict {PACKAGE_PIN M14 IOSTANDARD LVCMOS33} [get_ports {beep}]
set_property -dict {PACKAGE_PIN L14 IOSTANDARD LVCMOS33} [get_ports {key}]
set_property -dict {PACKAGE_PIN U18 IOSTANDARD LVCMOS33} [get_ports sys_clk]
set_property -dict {PACKAGE_PIN N16 IOSTANDARD LVCMOS33} [get_ports sys_rst_n]
标签:set,蜂鸣器,PIN,PACKAGE,sys,实验,key,按键,reg
From: https://www.cnblogs.com/xzh-personal-issue/p/17321602.html