这是39进制计数器,可进行加减操作,为0时减操作输出38,为38是加操作输出0.你改一下就成9进制了
module counter_39{
add,
dec,
counter
};
input add; //为1时加操作
input dec; //为1时减操作
output [5:0] counter;
reg [5:0] counter;
always @(add and dec) begin
if(add && !dec) begin
if(counter == 6'd38) begin
counter <= 6'd0;
end
else begin
counter <= counter + 1'b1;
end
end
if(!add and dec) begin
if(counter == 6'd0) begin
counter <= 6'd38;
end
else begin
counter <= counter - 1'b1;
end
end
end
endmodule