module key2(key,led,clk,rst);
input key,clk,rst;
output led;
reg[17:0] cout;
always@(posedge clk)
begin
if(!rst)
cout<=12'b0;
else cout<=cout+1;
end
wire clk_5ms=&cout;
reg key_r;
always@(posedge clk)
begin
if(!rst)
key_r<=1'b1;
else if (clk_5ms)
key_r<=key;
end
reg key_r_sw;
always@(posedge clk)
key_r_sw<=key_r;
wire ledctrl=key_r_sw&(!key_r);
reg led;
always@(posedge clk or negedge rst )
begin
if(!rst)
led<=1'b0;
else if (ledctrl)
led<=~led;
end
endmodule
本来看艾米的程序,觉得自己看懂了,但是自己编完上面的程序之后,又迷茫了,觉得这样是错的,但是下载到板子上,居然能防抖。。。
|