【FPGA代码】模为60 的BCD 码加法计数器
[复制链接]
module count60(qout,cout,data,load,cin,reset,clk); output[7:0] qout; output cout; input[7:0] data; input load,cin,clk,reset; reg[7:0] qout; always @(posedge clk) //clk 上升沿时刻计数 begin if (reset) qout<=0; //同步复位 else if(load) qout<=data; //同步置数 else if(cin) begin if(qout[3:0]==9) //低位是否为9,是则 begin qout[3:0]<=0; //回0,并判断高位是否为5 if (qout[7:4]==5) qout[7:4]<=0; else qout[7:4]<=qout[7:4]+1; //高位不为5,则加1 end else //低位不为9,则加1 qout[3:0]<=qout[3:0]+1; end end assign cout=((qout==8'h59)&cin)?1:0; //产生进位输出信号
endmodule
|