赞题库-背景图
问答题

28.写出一个同步可预制数计数器代码

【参考答案】

module cnt(clk,rst,en,load,din,cnt);
input  clk,rst,en,load;
input [3:0]din;
output [3:0]cnt;
reg  [3:0]cnt;
always@(posedge clk)
 begin
    if(rst==1'b0)
      cnt<=4'b0000;
      else if(en==1'b1)begin
   if(load==1'b1)
    cnt<=din;
    else cnt<=cnt+1'b1;
    end
   else;
   end
   endmodule