module smg(clk,Rst_n,dig,sel,led);
input clk; //50m晶振
input Rst_n; //复位键
output reg [7:0] dig; //数码管abcdefgh
output reg [5:0] sel; //6位数码管位选
reg [23:0]data;//要显示的数
reg [3:0] num=0;
[email protected](posedge clk_1k or negedge Rst_n)
if(!Rst_n)begin
sel<=6'b111111;//复位按下,全都不亮
end
else begin
case(sel)
6'b011111:begin
sel<=6'b111110;num<=data[3:0];
end
6'b111110:begin
sel<=6'b111101;num<=data[7:4];
end
6'b111101:begin
sel<=6'b111011;num<=data[11:8];
end
6'b111011:begin
sel<=6'b110111;num<=data[15:12];
end
6'b110111:begin
sel<=6'b101111;num<=data[19:16];
end
6'b101111:begin
sel<=6'b011111;num<=data[23:20];
end
default:begin
sel<=6'b111110;num<=data[3:0];
end
endcase
end
//数码管显示,数码管hgfedcba
[email protected](posedge clk)
case(num)
4'h0:dig=8'b11000000;
4'h1:dig=8'b11111001;
4'h2:dig=8'b10100100;
4'h3:dig=8'b10110000;
4'h4:dig=8'b10011001;
4'h5:dig=8'b10010010;
4'h6:dig=8'b10000010;
4'h7:dig=8'b11111000;
4'h8:dig=8'b10000000;
4'h9:dig=8'b10010000;
default:dig=8'b11111111;
endcase
endmodule