练习
设计一个10进制计数器电路,把10进制计数器的计数结果送到一位数码管显示,要求计数器的计数频率为1Hz。
系统时钟为25MHz,要求系统同步复位,高电平有效。
完成电路设计框图,各模块仿真以及系统功能仿真和下载编程。
分频器:
module fenpin25(clk,rst,clk_1hz);
input clk;
input rst;
output clk_1hz;
reg clk_1hz;
reg [23:0] cnt;
always@(posedge clk or posedge rst)
begin
if(rst==1'b1)
cnt<=24'd0;
else if(cnt==13107119)begin
cnt<=24'd0;
clk_1hz<=~clk_1hz;
end
else
cnt<=cnt+1;
end
endmodule
十进制计数器:
module cnt10(rst,clk,cnt);
input rst,clk;
output [3:0] c nt;
reg [3:0] c nt;
always@(posedge clk)
begin
if(rst==1'b0)
cnt<=4'b000;
else if(cnt==4'd9)
cnt<=4'b000;
else
cnt<=cnt+1;
end
endmodule
十进制计数器仿真波形图:
LED译码器:
module qiduan(cnt,led,scan); input [3:0] c nt;
output [6:0] l ed;
output [3:0] s can;
reg [6:0] l ed;
wire [3:0] s can;
assign scan=4'b0001;
always@(cnt)
begin
case(cnt)
4'b0001:led=7'b0000110;
4'b0010:led=7'b1011011;
4'b0011:led=7'b1001111;
4'b0100:led=7'b1100110;
4'b0101:led=7'b1101101;
4'b0110:led=7'b1111100;
4'b0111:led=7'b0000111;
4'b1000:led=7'b1111111;
4'b1001:led=7'b1101111;
4'b1010:led=7'b1110111;
default:led=7'b0111111;
endcase
end
endmodule
LED译码器仿真波形图:
顶层电路Verilog HDL代码:
module cnt10led(rst,clk,led,scan);
input rst;
input clk;
output [6:0] l ed;
output [3:0] s can;
wire [3:0] c nt;
wire [6:0] l ed;
wire [3:0] s can;
fenpin25 u0(.clk(clk),.rst(rst),.clk_1hz(clk_1hz)); cnt10 u1(.clk(clk_1hz),.rst(rst),.cnt(cnt)); qiduan u2(.cnt(cnt),.led(led),.scan(scan));
endmodule
框图:。