always@(posedge clk or posedeg rst or count_en)
begin
if(rst) begin
count_en<=0;
count<=0;
end
else if(!count_en)
count<=0;
elseif(count=9)
count<=0;
else
count<=count+1;
end
也可以分成控制部分跟数据部分。
module johnson(clk,clr,out);
input clk,clr;
output out;
reg out;
always @(posedge clk or posedge clr)
begin
if (clr) out<= 1'h0;
else
begin out<= out+1;
end
end
endmodule