可置位计数器
题目描述
请编写一个十六进制计数器模块,计数器输出信号递增每次到达0,给出指示信号zero,当置位信号set 有效时,将当前输出置为输入的数值set_num。
模块的接口信号图如下:
`timescale 1ns/1nsmodule count_module(input clk,input rst_n,input set,input [3:0] set_num,output reg [3:0]number,output reg zero);reg [3:0] num;always@(posedge clk or negedge rst_n)beginif(!rst_n)num <= 4'b0;else if(num == 4'd15)num <= 4'b0;else if(set == 1'b1)num <= set_num;elsenum <= num + 1'b1;endalways@(posedge clk or negedge rst_n)beginif(!rst_n)number <= 4'b0;elsenumber <= num;endalways@(posedge clk or negedge rst_n)beginif(!rst_n)zero <= 1'b0;else if(num == 4'd0)zero <= 1'b1;elsezero <= 1'b0;end
endmodule