verilog 写一个数码管闪烁,一旦按键摁到第三个摁键时,数码管开始从9到0倒计时,倒计时结束后数码管闪烁
时间: 2023-05-25 20:03:21 浏览: 95
module led_disp(
input clk,
input [2:0] key,
output reg [6:0] led
);
reg [3:0] cnt;
reg [3:0] cnt2;
reg [3:0] counter;
reg [3:0] countdown;
parameter MAX_COUNT = 15;
parameter MAX_COUNT2 = 10;
always @ (posedge clk) begin
if (key == 3'b011) begin
if (countdown == 4'b0000) begin
led = 7'b1111110;
end else if (counter == MAX_COUNT) begin
if (cnt2 == MAX_COUNT2) begin
if (cnt == 4'b0000) begin
led = 7'b1111111;
end else if (cnt == 4'b0001) begin
led = 7'b0110000;
end else if (cnt == 4'b0010) begin
led = 7'b1101101;
end else if (cnt == 4'b0011) begin
led = 7'b1111001;
end else if (cnt == 4'b0100) begin
led = 7'b0110011;
end else if (cnt == 4'b0101) begin
led = 7'b1011011;
end else if (cnt == 4'b0110) begin
led = 7'b1011111;
end else if (cnt == 4'b0111) begin
led = 7'b1110000;
end else if (cnt == 4'b1000) begin
led = 7'b1111111;
end else if (cnt == 4'b1001) begin
led = 7'b1111011;
end
cnt <= cnt + 1;
cnt2 <= 0;
end else begin
cnt2 <= cnt2 + 1;
end
counter <= 0;
end else begin
counter <= counter + 1;
end
countdown <= countdown + 1;
end else begin
countdown <= 4'b0000;
if (counter == MAX_COUNT) begin
if (cnt2 == MAX_COUNT2) begin
if (cnt == 4'b0000) begin
led = 7'b1111111;
end else if (cnt == 4'b0001) begin
led = 7'b0110000;
end else if (cnt == 4'b0010) begin
led = 7'b1101101;
end else if (cnt == 4'b0011) begin
led = 7'b1111001;
end else if (cnt == 4'b0100) begin
led = 7'b0110011;
end else if (cnt == 4'b0101) begin
led = 7'b1011011;
end else if (cnt == 4'b0110) begin
led = 7'b1011111;
end else if (cnt == 4'b0111) begin
led = 7'b1110000;
end else if (cnt == 4'b1000) begin
led = 7'b1111111;
end else if (cnt == 4'b1001) begin
led = 7'b1111011;
end
cnt <= cnt + 1;
cnt2 <= 0;
end else begin
cnt2 <= cnt2 + 1;
end
counter <= 0;
end else begin
counter <= counter + 1;
end
end
end
endmodule
阅读全文