FPGA——60进制计数器的设计(LED显示)

实验内容要求:
1、能够实现60进制的加法计数,计数速度每秒1次:

2、具有低电平异步复位功能;

3、能够随时暂停计数,暂停后能够继续技术(选做)

4、在暂停时可以进行置数,控制计数器增减;(选做)5、通过开发板进行板级调试。

代码:

module count60(clk, clr, ld, sw, data_a, data_b, q_a, q_b);
input clk, clr, ld, sw;
input[3:0] data_a,data_b;
output [3:0] q_a, q_b;
reg [26:0] cnt;
reg [3:0] temp_a,temp_b;
always @(posedge clk or negedge clr)
begin
if(!clr) cnt = 0;
   else if(cnt < 27'd50)
    begin
        cnt = cnt + 1;
   end          
         else if (cnt == 27'd50)
           begin
            cnt = 0;
            end
end
always @(posedge clk or negedge clr)
begin
if(!clr) {temp_a,temp_b} = 0;
 else if(sw == 1)
    {temp_a,temp_b} = {temp_a,temp_b};
 else begin 
     if(cnt< 27'd50)
         {temp_a,temp_b} = {temp_a,temp_b};
         else if(ld == 1) {temp_a,temp_b} = {data_a,data_b}; 
             else begin
                 if({temp_a,temp_b} == 8'h59)  {temp_a,temp_b} = 0;
                 else if(temp_b == 9)
                     begin
                        temp_b = 0;
                        temp_a = temp_a + 1;
                     end
                 else temp_b = temp_b + 1; 
          end
     end
end
assign {q_a,q_b}={temp_a,temp_b};
endmodule

测试文件:

`timescale 1ns/1ns
module count60_tb;
reg clk,clr,ld,sw;
reg[3:0] data_a,data_b;
wire [3:0]q_a,q_b;
count60 count60_u(
               .clk(clk),
                    .clr(clr),
                    .sw(sw),
                    .ld(ld),
                    .data_a(data_a),
                    .data_b(data_b),
                    .q_a(q_a),
                    .q_b(q_b)
                    );
                    
                    
initial clk = 1;
always #10
clk = ~clk;

initial begin
clr = 0; 
#100;
clr = 1;
ld = 1;
data_a = 1;
data_b = 6;
#200;
ld = 0;
#30000;
sw = 1;
#20000;
sw = 0;
#60000;
$stop;
end
endmodule 

波形图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值