module jyh_4490_3_counter(Q,clk,clr,load,in,en,upd,co);
input[3:0] in;
input en,clk,clr,load,upd;
output reg [3:0] Q;
output reg co;
always@(posedge clk,negedge clr)
begin
//异步清零
if(!clr)
Q<=0;
else if(en)
//同步置数
if(load)
Q<=in;
co<=1'b1;
end
//正反计数
else if(upd)
if(Q>=4'd9)
Q<=4'd0;
else
Q <= Q+1;
co<=0;
if(Q<=4'd0)
Q<=4'd9;
Q <= Q-1;
endmodule