这是另外两个模块。
//////////////////////////////////////////////////////////////////////////////////
// Module Name: key_conmand
//////////////////////////////////////////////////////////////////////////////////
module key_conmand(
input [3:0]button,
input clk,
output reg [1:0]cmd,
output reg en=0
);
reg [3:0]signal_temp=0;
wire [3:0]signal;
always@(posedge clk)
begin
if(signal!=signal_temp)
begin
case (signal[3:0])
4'b0001: begin cmd[1:0]<=0; end //四种,暂停播放,上下曲
4'b0010: begin cmd[1:0]<=1; end
4'b0100: begin cmd[1:0]<=2; end
4'b1000: begin cmd[1:0]<=3; end
default: begin cmd[1:0]<=0; end
endcase
en<=1;
end
else
begin
en<=0;
end
end
key_check play(
.clk(clk),
.key(button[0]),
.led(signal[0])
);
key_check stop(
.clk(clk),
.key(button[1]),
.led(signal[1])
);
key_check back(
.clk(clk),
.key(button[2]),
.led(signal[2])
);
key_check next(
.clk(clk),
.key(button[3]),
.led(signal[3])
);
endmodule
//////////////////////////////////////////////////////////////////////////////////
// Module Name: key_check
//////////////////////////////////////////////////////////////////////////////////
module key_check(
input clk ,
input rst_n,
input key,
output reg led
);
//-------------------------------------
reg[3:0] keyr;
always @(posedge clk )
begin
if (!rst_n) begin keyr <= 4'b1111;end
else begin keyr <= {keyr[2:0],key};end
end
wire key_pos = keyr[2] & ~keyr[3];
wire key_neg = ~keyr[2] & keyr[3];
//-------------------------------------
reg[19:0] cnt;
begin
if (!rst_n) begin cnt <= 20'd0;end
else if(key_pos || key_neg) begin cnt <=20'd0;end
else if(cnt < 20'd999_999) begin cnt <= cnt + 1'b1;end
else begin cnt <= 20'd0;end
end
reg[1:0] key_value;
always @(posedge clk )
begin
if (!rst_n) begin key_value[0] <= 1'b1;end
else if(cnt == 20'd999_999)
begin
key_value[0] <= keyr[3];
end
end
always @(posedge clk )
begin
if (!rst_n) begin key_value[1] <= 1'b1;end
else begin key_value[1] <= key_value[0];end
end
wire led_ctrl = ~key_value[0] & key_value[1];
//-------------------------------------
always @ (posedge clk )
begin
if (!rst_n) begin led <= 1'b0;end
else if(led_ctrl) begin led <= ~led;end
end
endmodule