module digital1 (clk,res,sm_cs1,sm_cs2,out);
input clk,res;
output sm_cs1,sm_cs2;
output [6:0] out;
wire [6:0] out;
reg [24:0] cnt;
always @ (posedge clk or negedge res)
if(!res) cnt <= 25'b0;
else cnt <= cnt + 1'b1;
reg [3:0] shi,ge;
always @ (posedge clk or negedge res)
if(!res)
begin
shi <= 4'd1;
ge <= 4'd0;
end
else if(cnt == 25'h1ffffff)
begin
//shi <= shi + 1'b1;
ge <= ge + 1'b1;
if(ge == 4'h9)
begin
ge <= 4'd0;
shi <= shi + 1'b1;
if(shi == 4'h9)
begin
shi <= 4'd0;
end
end
end
parameter result0 = 7'h3f,
result1 = 7'h06,
result2 = 7'h5b,
result3 = 7'h4f,
result4 = 7'h66,
result5 = 7'h6d,
result6 = 7'h7d,
result7 = 7'h07,
result8 = 7'h7f,
result9 = 7'h6f;
// result10 = 7'hf7,
// result11 = 7'hfc,
// result12 = 7'h39,
// result13 = 7'h5e,
// result14 = 7'h79,
// result15 = 7'h71;
reg [3:0] num;
reg [6:0] outr;
always @ (num)
case(num)
4'h0 utr<=result0;
4'h1 utr<=result1;
4'h2 utr<=result2;
4'h3 utr<=result3;
4'h4 utr<=result4;
4'h5 utr<=result5;
4'h6 utr<=result6;
4'h7 utr<=result7;
4'h8 utr<=result8;
4'h9 utr<=result9;
// 4'hA:outr<=result10;
// 4'hB:outr<=result11;
// 4'hC:outr<=result12;
// 4'hD:outr<=result13;
// 4'hE:outr<=result14;
// 4'hF:outr<=result15;
default: outr <= result0;
endcase
assign out = outr;
reg sm_cs2_r,sm_cs1_r;
//----------------------------两个数码管之间的扫描
always @(clk or shi or ge)
begin
if(cnt[19])
begin
sm_cs2_r = 0;
sm_cs1_r = 1;
num = shi;
end
else
begin
sm_cs2_r = 1;
sm_cs1_r = 0;
num = ge;
end
end
assign sm_cs2 = sm_cs2_r;
assign sm_cs1 = sm_cs1_r;
endmodule
|