Verilog数字系统设计——10进制计数器,具有异步复位功能

这篇博客介绍了如何使用Verilog语言设计一个10进制计数器,该计数器具有异步复位功能,并使用8421BCD码表示十位和个位。在模块`Decimal_counter`中,作者实现了根据时钟边沿和复位信号更新计数器值的逻辑,并在`Decimal_counter_test`模块中进行了测试,通过仿真波形展示了计数器的正确工作。此外,代码还包含了错误处理和优化,如处理进位条件。
摘要由CSDN通过智能技术生成

Verilog数字系统设计——10进制计数器,具有异步复位功能

题目

  1. 编程实现10进制计数器,具有异步复位功能,十位和个位用8421BCD码表示,各端口定义如下图所示:
  2. 仔细考虑端口定义中每个端口的含义;
  3. 要求完成程序编辑、编译、时序仿真;
  4. 实验提交Verilog设计文件(.v文件)、仿真波形截图以及对于第3个步骤所提出问题的回答,文件打包,压缩包以自己的学号+姓名命名;
    i_clk时钟
    I_rest复位
    i_load置位
    i_datin置位的数
    o_cout10进制的进位端
    o_count 计数值
    下面展示一些 内联代码片
module Decimal_counter(c_count,cout,i_datin,i_load,i_cin,i_rest,i_clk);
	output [7:0]c_count;
	output cout;
	input [7:0]i_datin;
	input i_load,i_cin,i_rest,i_clk;
	reg [7:0]c_count;
      // reg cout;
	always @(posedge i_clk or negedge i_rest)
		begin
			if (!i_rest)
				c_count=0;
                        else if (i_load)
				c_count=i_datin;
			else if (i_cin)
			begin
				if(c_count[3:0]==9)
				begin
					//cout=1;
					c_count[3:0]=0;
					if(c_count[7:4]==9)
						c_count[7:4]=0;
					else
						c_count[7:4]=c_count[7:4]+1;

				end
				else 
					begin
					c_count[3:0]=c_count[3:0]+1;
					//cout=0;
					end
			end
		end
assign cout=((c_count[7:0]==8'b10011001)&i_cin)?1:0;

endmodule

下面展示一些 内联代码片

module Decimal_counter_test();
reg [7:0]i_datin_t;
reg i_cin_t,i_load_t;
reg i_rest_t,i_clk_t;
wire [7:0]c_count_t;
wire cout;
   Decimal_counter Decimal_counter1(.c_count(c_count_t),.cout(cout_t),.i_datin(i_datin_t),.i_load(i_load_t),.i_cin(i_cin_t),.i_rest(i_rest_t),.i_clk(i_clk_t));
	initial
	begin
		i_rest_t=1;
		i_clk_t=0;
		i_load_t=0;
		i_cin_t=0;
		i_datin_t[7:0]=8'd3;
                #20 i_rest_t=0;
		#40 i_rest_t=1;


 		#100 i_load_t=1;
                #120 i_load_t=0;

	end
	always #10 i_cin_t=~i_cin_t;
	always #5 i_clk_t=~i_clk_t;
	


endmodule 

下面展示一些 内联代码片

// A code block
var foo = 'bar';
module Decimal_counter(c_count,cout,i_datin,i_load,i_cin,i_rest,i_clk);
	output [7:0]c_count;
	output cout;
	input [7:0]i_datin;
	input i_load,i_cin,i_rest,i_clk;
	reg [7:0]c_count;
       reg cout;
	always @(posedge i_clk or negedge i_rest)
		begin
			if (!i_rest)
				c_count=0;
                        else if (i_load)
				c_count=i_datin;
			else if (i_cin)
			begin
				if(c_count[3:0]==9)
				begin
					cout=1;
					c_count[3:0]=0;
					if(c_count[7:4]==9)
						c_count[7:4]=0;
					else
						c_count[7:4]=c_count[7:4]+1;

				end
				else 
					begin
					c_count[3:0]=c_count[3:0]+1;
					cout=0;
					end
			end
		end
//assign cout=((c_count[3:0]==9)&i_cin)?1:0;

Endmodule

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值