sys_rstn,
key_in,
led,
sm_bit);
input sys_clk;
input sys_rstn;
input key_in;
output [6:0] led;
output [7:0] sm_bit;
reg [7:0] sm_bit;
reg [3:0] num;
reg [6:0] led_out;
reg [6:0] led;
always@(posedge sys_clk or negedge sys_rstn)
begin
if(!sys_rstn)
num<=4'd1;
else if(!key_in)
num<=num+4'd1;
else if(num==4'd10)
num<=4'd0;
else
num<=num;
end
always@(num)
begin
case (num)
4'd0 :led_out=7'hc0;
4'd1 :led_out=7'hf9;
4'd2 :led_out=7'ha4;
4'd3 :led_out=7'hb0;
4'd4 :led_out=7'h99;
4'd5 :led_out=7'h92;
4'd6 :led_out=7'h82;
4'd7 :led_out=7'hf8;
4'd8 :led_out=7'h80;
4'd9 :led_out=7'h90;
default:led_out=7'h90;
endcase
end
always@(posedge sys_clk )
begin
led<=led_out;
sm_bit<=8'b00000000;
end
endmodule
按键控制一位数码管显示0-9 因为没有进行消抖 所以数字显示很不稳定