用verilog设计一数字钟系统

二.设计一数字钟系统,要求如下:

1. 有基础的实时数字钟功能,即时,分,秒的正常显示模式。(24小时制)

2. 可对系统用手动方式校准,设计两个按键,按动校时键,时计数器加一,按动校分键,则电路处于校分状态。

3. 整点报时,要求在5950秒,52秒,54秒,56秒和58秒发出一个低音信号,0000秒发出一个高音信号。


源程序如下:

module clock (clk,reset,hour_g,hour_d,minute_g,minute_d,second_g,second_d,add_s,add_f,lowalarm,highalarm);  
input         clk,reset,add_s,add_f;
output[3:0]   hour_g,hour_d,minute_g,minute_d,second_g,second_d;
reg[3:0]      hour_g,hour_d,minute_g,minute_d,second_g,second_d;
wire          cout_s,cout_m;
reg[3:0] jishi;
output lowalarm,highalarm;//低音和高音信号
reg lowalarm;
wire highalarm;
always @(posedge clk)
begin
  if(!reset) second_d<=0;
  else if(second_d==9)
    second_d<=0;
  else
    second_d<=second_d+1;
end

always @(posedge clk)
begin
  if(!reset) second_g<=0;
  else if(second_d==9)
    begin
      if(second_g==5)
        second_g<=0;
      else
        second_g<=second_g+1;
    end
  end
assign cout_s=((second_d==9)&&(second_g==5))?1:0;

always @(posedge clk)
begin
  if(!reset)
        minute_d <= 0;
  else if(cout_s)
    begin
     if(minute_d==9)
        minute_d <= 0;
     else 
        minute_d <=minute_d+1;
    end
end

always @(posedge clk)
begin
  if(!reset)
    minute_g <= 0;
  else if(cout_s)
    begin
    if(minute_d==9)
      begin
      if(minute_g==5)
        minute_g <= 0;
      else 
        minute_g<= minute_g+1;
      end
    end
end

assign cout_m = ((minute_d==9)&&(minute_g==5))?1:0;

always @(posedge clk)
begin
  if(!reset)
        hour_d <= 0;
  else if(cout_m&&cout_s)
  begin
    if((hour_d==3)&&(hour_g==2))
      hour_d<=0;
    else
       if(hour_d==9)
        hour_d <=0;
       else
        hour_d <= hour_d + 1;
  end
end

always @(posedge clk)
begin
  if(!reset)
        hour_g <= 0;
  else if(cout_m&&cout_s)
  begin
      if((hour_d==3)&&(hour_g==2))
        hour_g <= 0;
      else if(hour_d==9)
        hour_g<=hour_g+1;
  end
end

always @(posedge clk)
begin
    if(add_s)
      begin
        if((hour_d==3)&&(hour_g==2))
          begin
            hour_g<=0;
            hour_d<=0;
          end
        else
          if(hour_d==9)
            begin
              hour_d<=0;
              hour_g<=hour_g+1;
            end
          else
            hour_d<=hour_d+1;
      end
    end
    
    always @(posedge clk)
    begin
     if(add_f)
        begin
          if((minute_d==9)&&(minute_g==5))
            begin
              minute_d<=0;
              minute_g<=0;
            end
          else 
            if(minute_d==9)
              begin
                minute_d<=0;
                minute_g<=minute_g+1;
              end
            else
              minute_d<=minute_d+1;
        end
      end
      
      always @(posedge clk)
      begin
        if(!reset) 
        begin
        lowalarm<=0;
        jishi<=1;
        end
        else
          if((minute_g==5)&&(minute_d==9))
            begin
              if(second_g==5)
                begin
                  if((second_d==1)||(second_d==3)||(second_d==5)||(second_d==7))
                    lowalarm<=1;
                  else
                    begin
                    lowalarm<=0;
                    jishi<=jishi+1;
                    end
                end
          if(second_g==4&&second_d==9)
            lowalarm<=1;
            end  
      end
        
        assign highalarm=((minute_g==0)&&(minute_d==0)&&(second_g==0)&&(second_d==0))?1:0;
  
endmodule



测试程序如下:
`timescale 1ns/1ns
module clock_tb();
  reg clk,reset;
  wire[3:0] hour_g,hour_d,minute_g,minute_d,second_g,second_d;
  wire lowalarm,highalarm;
  reg add_s,add_f;
  clock u1(.clk(clk),.reset(reset),.hour_g(hour_g),.hour_d(hour_d),.minute_g(minute_g),
            .minute_d(minute_d),.second_g(second_g),.second_d(second_d),.add_s(add_s),.add_f(add_f),.lowalarm(lowalarm),.highalarm(highalarm));
  parameter DELY=100;
  always #(DELY/2) clk=~clk;
  initial
  begin
    clk=0;add_s=0;add_f=0;reset=0;
    #150 reset=1;
    #(DELY*100000) add_s=1;
    #DELY add_s=0;
    #(DELY*5) add_f=1;
    #DELY add_f=0;
    #DELY $finish;
  end
endmodule



  • 26
    点赞
  • 168
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
摘 要:Verilog是广泛应用的硬件描述语言,可以用在硬件设计流程的建模、综合和模拟等多个阶段。随着硬件设计规模的不断扩大,应用硬件描述语言进行描述的CPLD结构,成为设计专用集成电路和其他集成电路的主流。通过应用Verilog HDL对多功能电子钟的设计,达到对Verilog HDL的理解,同时对CPLD器件进行简要了解。 本文的研究内容包括: 对Altera公司Flex 10K系列的EPF10K 10简要介绍,Altera公司软件Max+plusⅡ简要介绍和应用Verilog HDL对多功能电子钟进行设计。 关键词:多功能电子钟;硬件描述语言 Abstract:Verilog is the most widely used hardware description language.It can be used to the modeling, synthesis, and simulation stages of the hardware system design flow. With the scale of hardware design continually enlarging, describing the CPLD with HDL become the mainstream of designing ASIC and other IC.To comprehend Verilog HDL and get some knowledge of CPLD device, we design a block with several functions with Verilog HDL. This thesis is about to discuss the above there aspects: Introduce the EPF10K 10 of Flex 10K series producted by Altera Corporation simply. the software Max+plusⅡ,Design the block with several functions with Verilog HDL. Keywords: block with several functions; hardware description language ******************************************* 目  录 1 引言 2 1.1课题的背景、目的 2 1.2 课题设计环境 2 2 EPF10K 10相关说明及VERILOG HDL简介 2 2.1 EPF10K 10相关说明 2 2.2 VERILOG HDL硬件描述语言简介 4 3应用VERILOG HDL描述的多功能电子钟 5 3.1功能描述 5 3.2 源程序 6 3.3模块仿真 13 4 应用VERILOG HDL描述的多功能电子钟功能模块及仿真 15 4.1 计时模块 15 4.2 闹铃设置模块 17 4.3 校时模块 19 4.4 秒表功能模块 22 4.5 整点报时模块 25 4.6 闹铃屏蔽及响铃功能 27 4.7 秒表提示铃声功能 28 5结束语 30 6致谢 30 参考文献 31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值