我寫的一個十進位制計數,可以復位,置數,使能,雙向計數,請參考
`timescale 1ns/100ps
module count(
clk,
nrst,
ncs,
s,
load,
load_data,
q
);
input clk;
input nrst;
input ncs;
input s;
input load;
input [3:0] load_data;
output [3:0] q;
reg [3:0] q;
always @(posedge clk or negedge nrst) begin
if(!nrst) begin
end else if(!ncs) begin
end else if(load==1"b1) begin
end else if(s==1"b1) begin
if(q==4"b1001) begin
end else begin
end
end else if(s==1"b0) begin
if(q==4"b0000) begin
endmodule
我寫的一個十進位制計數,可以復位,置數,使能,雙向計數,請參考
`timescale 1ns/100ps
module count(
clk,
nrst,
ncs,
s,
load,
load_data,
q
);
input clk;
input nrst;
input ncs;
input s;
input load;
input [3:0] load_data;
output [3:0] q;
reg [3:0] q;
always @(posedge clk or negedge nrst) begin
if(!nrst) begin
q
end else if(!ncs) begin
q
end else if(load==1"b1) begin
q
end else if(s==1"b1) begin
if(q==4"b1001) begin
q
end else begin
q
end
end else if(s==1"b0) begin
if(q==4"b0000) begin
q
end else begin
q
end
end
end
endmodule