always @(posedge clk or negedge rst_n)begin
if(rst_n==1'b0)begin
seg_ment <= 7'h01;
end
else if(cnt1==0)begin
seg_ment <= 7'h01;
end
else if(cnt1==1)begin
seg_ment <= 7'h4f;
end
else if(cnt1==2)begin
seg_ment <= 7'h12;
end
else if(cnt1==3)begin
seg_ment <= 7'h06;
end
else if(cnt1==4)begin
seg_ment <= 7'h4c;
end
else if(cnt1==5)begin
seg_ment <= 7'h24;
end
else if(cnt1==6)begin
seg_ment <= 7'h20;
end
else if(cnt1==7)begin
seg_ment <= 7'h0f;
end
else if(cnt1==8)begin
seg_ment <= 7'h00;
end
else if(cnt1==9)begin
seg_ment <= 7'h04;
end
end
然后,用组合逻辑把x的值确定下来。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
always @(*)begin
if(cnt1==0)begin
x = 50_000_000;
end
else if(cnt1==1)begin
x = 100_000_000;
end
else if(cnt1==2)begin
x = 150_000_000;
end
else if(cnt1==3)begin
x = 200_000_000;
end
else if(cnt1==4)begin
x = 250_000_000;
end
else if(cnt1==5)begin
x = 300_000_000;
end
else if(cnt1==6)begin
x = 350_000_000;
end
else if(cnt1==7)begin
x = 400_000_000;
end
else if(cnt1==8)begin
x = 450_000_000;
end
else if(cnt1==9)begin
x = 500_000_000;
end
end
always @(posedge clk or negedge rst_n)begin
if(!rst_n)begin
cnt1 <= 0;
end
else if(add_cnt1)begin
if(end_cnt1)
cnt1 <= 0;
else
cnt1 <= cnt1 + 1;
end
end
assign add_cnt1 = end_cnt0;
assign end_cnt1 = add_cnt1 && cnt1==10-1 ;
assign seg_sel = 8'hfe;
always @(posedge clk or negedge rst_n)begin
if(rst_n==1'b0)begin
seg_ment <= 7'h01;
end
else if(cnt1==0)begin
seg_ment <= 7'h01;
end
else if(cnt1==1)begin
seg_ment <= 7'h4f;
end
else if(cnt1==2)begin
seg_ment <= 7'h12;
end
else if(cnt1==3)begin
seg_ment <= 7'h06;
end
else if(cnt1==4)begin
seg_ment <= 7'h4c;
end
else if(cnt1==5)begin
seg_ment <= 7'h24;
end
else if(cnt1==6)begin
seg_ment <= 7'h20;
end
else if(cnt1==7)begin
seg_ment <= 7'h0f;
end
else if(cnt1==8)begin
seg_ment <= 7'h00;
end
else if(cnt1==9)begin
seg_ment <= 7'h04;
end
end
always @(*)begin
if(cnt1==0)begin
x = 50_000_000;
end
else if(cnt1==1)begin
x = 100_000_000;
end
else if(cnt1==2)begin
x = 150_000_000;
end
else if(cnt1==3)begin
x = 200_000_000;
end
else if(cnt1==4)begin
x = 250_000_000;
end
else if(cnt1==5)begin
x = 300_000_000;
end
else if(cnt1==6)begin
x = 350_000_000;
end
else if(cnt1==7)begin
x = 400_000_000;
end
else if(cnt1==8)begin
x = 450_000_000;
end
else if(cnt1==9)begin
x = 500_000_000;
end
end
endmodule