You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
3.9 KiB
Coq

8 months ago
`timescale 1ns/1ns
module tb_lm();
8 months ago
8 months ago
reg k_1; // 1
reg k_2; // 2
reg key; // , ,
reg key_1; //
reg key_2; //
reg is_show; //
8 months ago
reg [4:0] flag_time;
8 months ago
8 months ago
reg flag; // 500,
8 months ago
reg sys_clk;
reg sys_rst;
8 months ago
reg [7:0]x;
reg [7:0]y;
8 months ago
always #10 sys_clk = ~sys_clk;
initial begin
sys_clk <= 1'b0;
sys_rst <= 1'b0;
#200
sys_rst <= 1'b1;
// 2000, x 0
#2000
8 months ago
8 months ago
key <= 1'b1;
8 months ago
#120
8 months ago
key <= 1'b0;
8 months ago
#20
key <= 1'b1;
#80
key <= 1'b0;
#20
key <= 1'b1;
#90
key <= 1'b0;
#20
8 months ago
// 4000
{k_2, k_1} <= 2'b10;
#3900
{k_2, k_1} <= 2'b01;
#3800
8 months ago
key <= 1'b1;
#20
key <= 1'b0;
#20
8 months ago
key <= 1'b1;
8 months ago
#20
8 months ago
key <= 1'b0;
8 months ago
#20
key <= 1'b1;
#90
key <= 1'b0;
#200
key <= 1'b1;
#120
key <= 1'b0;
#20
key <= 1'b1;
#120
key <= 1'b0;
#20
key <= 1'b1;
#150
key <= 1'b0;
8 months ago
end
8 months ago
//
8 months ago
always @(posedge sys_clk or negedge sys_rst) begin
if (sys_rst == 1'b0) begin
8 months ago
flag_time <= 5'd0;
8 months ago
end
8 months ago
else if (flag_time < (5'd25 - 5'd1) && is_show) begin
flag_time <= flag_time + 5'd1;
8 months ago
end
else begin
8 months ago
flag_time <= 5'b0;
8 months ago
end
end
always @(posedge sys_clk or negedge sys_rst) begin
if (sys_rst == 1'b0) begin
{k_2, k_1} <= 2'b11;
x <= 8'b00000000;
y <= 8'b11111111; //
end
else if ({k_2, k_1} == 2'b10 && is_show) begin
case (flag)
1'b0: x <= 8'b1010_1010;
1'b1: x <= 8'b0101_0101;
endcase
end
else if ({k_2, k_1} == 2'b01 && is_show) begin
case (flag)
1'b0: x <= 8'b1111_0000;
1'b1: x <= 8'b0000_1111;
endcase
end
else begin
x <= 8'b00000000;
end
end
8 months ago
// 500ns
8 months ago
always @(posedge sys_clk or negedge sys_rst) begin
if (sys_rst == 1'b0) begin
flag <= 1'b0;
end
8 months ago
else if (flag_time == (5'd25 - 5'd1)) begin
8 months ago
flag <= !flag;
end
else begin
end
end
// ,
8 months ago
always @(posedge sys_clk or negedge sys_rst) begin
if (sys_rst == 1'b0) begin
key <= 1'b0;
key_1 <= 1'b0;
key_2 <= 1'b0;
end
else begin
key_1 <= key;
key_2 <= key_1;
end
end
// 沿,
assign is_click = key_1 && !key_2;
8 months ago
// , 20, 10,
reg [4:0] down_time; // max: 10
reg [4:0] click_time; // max: 20
reg is_lock = 1'b0; //
8 months ago
// 使
always @(posedge sys_clk or negedge sys_rst) begin
if (sys_rst == 1'b0) begin
is_show <= 1'b0;
8 months ago
down_time <= 5'd0;
click_time <= 5'd0;
8 months ago
end
8 months ago
//
8 months ago
else if (is_click) begin
8 months ago
is_lock <= 1'b1;
end
else begin
end
// , ,
if (is_lock && click_time == 5'd20 - 5'd1) begin
is_lock <= 1'b0;
click_time <= 5'd0;
down_time <= 5'd0;
//
if (down_time > 5'd10 - 5'd1) begin
is_show <= !is_show;
end
else begin
end
end
//
else if (is_lock && click_time < 5'd20 - 5'd1) begin
click_time <= click_time + 5'd1;
//
if (key_1) begin
down_time <= down_time + 1'd1;
end
else begin
end
8 months ago
end
else begin
end
end
lm u_lm(
.x (x),
.y (y)
);
endmodule