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