設計一計數器計數0~999_4A037052_蘇偉諺
=========================程式碼=======================
module cnt10(clk,reset,q,cin);
input clk,reset;
output [3:0] q;
output cin;
reg [3:0] q;
reg cin;
wire eq;
assign eq=(q==4'd9);
always@(posedge
clk or posedge reset)
if(reset)
begin
q=0;
cin=0;
end
else
if(q==4'd9) begin
cin= #1 1;
q= #1 0;
end
else begin
q= #1 q+1'b1;
cin= #1 0;
end
endmodule
module
cnt999(clk,reset,digit1,digit2,digit3);
input
clk,reset;
output [3:0]
digit1;
output [3:0]
digit2;
output [3:0]
digit3;
wire
cin1,cin2,cin3;
cnt10 U1(clk,reset,digit1,cin1);
cnt10 U2(cin1,reset,digit2,cin2);
cnt10 U3(cin2,reset,digit3,cin3);
endmodule
======================測試平台======================
`timescale 1ns/100ps
`include "cnt10.v"
module
testcnt10;
reg clk,reset;
wire [3:0] g,i,k;
cnt999
U1(clk,reset,g,i,k);
initial clk=0;
always #10 clk=~clk;
initial begin
#0 reset=1;
#10 reset=0;
#1000010 $finish;
end
initial begin
$dumpfile("testcnt10.vcd");
$dumpvars;
end
endmodule
=====================GTKWAVE之波形圖=================
真的很瓜張
回覆刪除怎麼編譯都是錯的pussylove
不好意思
刪除作者已經移除這則留言。
回覆刪除