例14.模为60的BCD码加法计数器
module count60(
input [7:0] data,
input clk,
input reset,
input cin,//计数使能
output [7:0] qout,
output cout
);
always@( posedge clk)begin
if(reset)
qout <= 0;
else if(load)
qout <= data;
else if(cin) begin
if(qout[3:0] == 4'd9)begin
qout[3:0] <= 4'd0
if(qout[7:4] == 4'd5)
qout[7:4] <= 4'd0;
else
qout[7:4] <= qout[7:4] +4'd1;
else
qout[3:0] <= qout[3:0] + 4'd1;
end
end
assign cout = (qout == 8'h59 & cin)?1:0;
endmodule
BCD码(Binary-Coded Decimal)亦称二进码十进数或二-十进制代码。用4位