分频模块
module time1Hz(clk1Hz, clk_20M);
input clk_20M;
output clk1Hz;
reg[24:0] temp_count;
initial
temp_count <= 25'b0;
always @ (posedge clk_20M)
if (temp_count == 25'b1_0011_0001_0010_1101_0000_0000)
temp_count <= 25'b0;
else
temp_count <= temp_count + 1;
assign clk1Hz = temp_count[25];
endmodule
倒计时模块
module BCD_cnt59(qout,cin,clk,reset);
output[7:0] qout;
reg[7:0]qout;
input cin,clk,reset;
always@(posedge clk )
begin
if(reset)
qout<=0;
else if(cin)
begin
if(qout[3:0]==4'd0)
begin
qout[3:0]<=9;
if(qout[7:4]==0)
qout[7:4]<=5;
else
qout[7:4]=qout[7:4]-1'b1;
end
else qout[3:0]<=qout[3:0]-1'b1;
end
end
endmodule
译码器模块
module BCD(in,out);
output[6:0]out;
input[3:0]in;
reg[6:0]out;
always@(in)
begin
case(in)
4'd0ut=7'b1111110;
4'd1ut=7'b0110000;
4'd2ut=7'b1101101;
4'd3:out=7'b1111001;
4'd4:out=7'b0110011;
4'd5:out=7'b1011011;
4'd6:out=7'b1011111;
4'd7:out=7'b1110000;
4'd8:out=7'b1111111;
4'd9:out=7'b1111011;
default:out=7'bx;
endcase
end
endmodule
这几个模块写好了,不知道有没有错,另外顶层调用模块不会写,求指点 |