• 方案介绍
  • 附件下载
  • 相关推荐
申请入驻 产业图谱

基于FPGA的电子万年历显示年月日设计Verilog代码VIVADO仿真

08/01 08:04
665
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

2-24060G53911W3.doc

共1个文件

名称:基于FPGA的电子万年历显示年月日设计Verilog代码VIVADO仿真

软件:VIVADO

语言:Verilog

代码功能:电子万年历显示年月日

FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com

演示视频:

设计文档:

1. 工程文件

2. 程序文件

3. 程序编译

4. RTL图

5. Testbench

6. 仿真图

部分代码展示:

/*
--万年历
*/
`timescale  1ns/100ps
module wannianli
(
input sysclk,//1s时钟
input reset_n,//低电平复位
//输出年月日,时分秒
output [7:0]   year_high_dis,//
output [7:0]   year_low_dis,//
output [7:0]   month_dis,//
output [7:0]   day_dis,//
output [7:0]   hour_dis,//
output [7:0]   minute_dis,//
output [7:0]   second_dis//
);
//定义计数常数
parameter   second_cnt   = 60;//60秒
parameter   minute_cnt   = 60;//60分
parameter   hour_cnt   = 24;//24时
//定义计数器
reg [7:0]   year_high  =  8'd0;
reg [7:0]   year_low   =  8'd0;
reg [3:0]   month     =  4'd0;
reg [4:0]   day       =  5'd0;
reg [4:0]   hour      =  5'd0;
reg [5:0]   minute    =  6'd0;
reg [5:0]   second    =  6'd0;
//闰年控制2月时间及大月小月控制------------------------------------------------------------------------------
wire  month_flag = (day == 28)&!(year_low[1:0] == 0 & year_low !=0 | year_high[1:0] ==0 & year_low ==0)&(month == 2)|
                   (day == 29)& (year_low[1:0] == 0 & year_low !=0 | year_high[1:0] ==0 & year_low ==0)&(month == 2)|
                   (day == 30)& ((month == 4)|(month == 6)|(month == 9)|(month == 11))|
                   (day == 31)& ((month == 1)|(month == 3)|(month == 5)|(month == 7)|(month == 8)|(month == 10)|(month == 12));
//------------------------------------------------------------------------------
always@(posedge sysclk or negedge reset_n)
begin
  if (!reset_n)//复位,修改该处可以修改起始时间,目前设置为2019.12.31日22:10:00
  begin
    second  <= 6'd0;
    minute  <= 6'd10;
    hour    <= 5'd22;
    day     <= 5'd30;
    month   <= 4'd12;
    year_low  <= 8'd19;
    year_high  <= 8'd20;
  end
  else begin
          if ((second == second_cnt - 1'b1)) //秒计时到59
          begin
            second <= 6'd0;//秒回0
            if (minute == minute_cnt - 1'b1)  //分计时到59
            begin
              minute <= 6'd0;//分回0
              if (hour == hour_cnt - 1'b1)  //时计时到23
              begin
                hour <= 5'd0;//时回0
                if (month_flag) //month_flag指示当月最后一天,根据闰年及大小月判断,闰年2月为29,否则28;大月31,小月30
                begin
                  day <= 5'd1;//回到1号
                  if (month == 12) //12月
                  begin
                    month <= 5'd1;//回到1月
                    if (year_low == 100 -1'b1)//年低位最大到99
                    begin
                      year_low <= 8'd0;//回0
                      if (year_high == 100 -1'b1)//年高位最大到99
                      begin
                        year_high <= 8'd0;//回0
                      end
                      else if (year_low == 100 -1'b1)//计数到99年,年高位加1
                      begin
                        year_high <= year_high + 1'b1;
                      end

点击链接获取代码文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=842

  • 2-24060G53911W3.doc
    下载

相关推荐