1.软件版本
quartusii12.1
2.系统描述
系统的整个结构框图:

然后,设置控制输入有5个脚,分析功能如下所示:
i_Function_Controller=0;显示年月日
i_sel:选择需要调整的某位数字。
i_set:计数器,调整需要调整的位置的数字。
具体调整的时候,首先选择i_sel,按键按一下,需要调整的位置会移动一次,然后移动到需要调整的位置上,然后松开i_sel,然后按下i_set,调整显示的数字。
i_run:不使用
i_Function_Controller=1;显示时间,小时,分,秒
i_sel:
i_set:
i_run:
正常工作的时候,上面三个设置分别输入0,0,1
当需要调整时间的时候,设置i_run=0,然后设置i_sel,选择对应的需要调整的数字位,然后设置i_set,设置具体的值,其中秒位置,如果设置i_set。那么秒直接清零。
注意,因为时间部分计数到24小时的时候,年月日才被加1,所以在年月日这里i_run不使用,他是靠日期模块来驱动的。
i_Function_Controller=2;闹钟设置模块
i_sel:
i_set:
i_run:不使用,
通过设置i_sel,选择需要被设置的数字位,然后通过i_set进行闹钟的设置。
i_Function_Controller=3;秒表的控制
i_sel:清零
i_set:暂停
i_run:开始秒表计时
整体的结构如下所示:
3.部分源码
[code]`timescale 1ns / 1psmodule tops( i_clk, i_rst, i_Function_Controller, i_sel, i_set, i_run, o_Num1, o_Num2, o_Num3, o_Num4, o_Num5, o_Num6, o_Num7, o_Num8, o_digit, o_en );input i_clk;input i_rst;input[1:0] i_Function_Controller;input i_sel;input i_set;input i_run;output[3:0]o_Num1;output[3:0]o_Num2;output[3:0]o_Num3;output[3:0]o_Num4; output[3:0]o_Num5;output[3:0]o_Num6;output[3:0]o_Num7;output[3:0]o_Num8; output[7:0]o_digit;output[7:0]o_en;wire Clock_mb;wire Clock;clock_div clock_div_u( .i_clk (i_clk), .i_rst (i_rst), .i_sel (1'b0), .o_clock1 (Clock_mb), .o_clock2 (Clock) );//======================================================================wire CLK_Year;wire[3:0]ym_Num1;wire[3:0]ym_Num2;wire[3:0]ym_Num3;wire[3:0]ym_Num4; wire[3:0]ym_Num5;wire[3:0]ym_Num6;wire[3:0]ym_Num7;wire[3:0]ym_Num8;year_month year_month_u( .i_clk (CLK_Year), .i_rst (i_rst), .i_sel (i_sel), .i_set (i_set), .o_Num1 (ym_Num1), .o_Num2 (ym_Num2), .o_Num3 (ym_Num3), .o_Num4 (ym_Num4), .o_Num5 (ym_Num5), .o_Num6 (ym_Num6), .o_Num7 (ym_Num7), .o_Num8 (ym_Num8) );//======================================================================wire[3:0]tm_Num1;wire[3:0]tm_Num2;wire[3:0]tm_Num3;wire[3:0]tm_Num4; wire[3:0]tm_Num5;wire[3:0]tm_Num6;wire[3:0]tm_Num7;wire[3:0]tm_Num8;times times_u( .i_clk (Clock), .i_rst (i_rst), .i_run (i_run), .i_sel (i_sel), .i_set (i_set), .o_Num1 (tm_Num1), .o_Num2 (tm_Num2), .o_Num3 (tm_Num3), .o_Num4 (tm_Num4), .o_Num5 (tm_Num5), .o_Num6 (tm_Num6), .o_CLK_Year (CLK_Year), .CNT () ); assign tm_Num7 = 4'd0;assign tm_Num8 = 4'd0;//======================================================================wire[3:0]be_Num1;wire[3:0]be_Num2;wire[3:0]be_Num3;wire[3:0]be_Num4; wire[3:0]be_Num5;wire[3:0]be_Num6;wire[3:0]be_Num7;wire[3:0]be_Num8;beer beer_u( .i_clk (Clock), .i_rst (i_rst), .i_sel (i_sel), .i_set (i_set), .i_N1 (tm_Num3), .i_N2 (tm_Num4), .i_N3 (tm_Num5), .i_N4 (tm_Num6), .o_N1 (be_Num3), .o_N2 (be_Num4), .o_N3 (be_Num5), .o_N4 (be_Num6), .o_bear (o_bear) );assign be_Num1 = 4'd0;assign be_Num2 = 4'd0;assign be_Num7 = 4'd0;assign be_Num8 = 4'd0;//======================================================================wire[3:0]mb_Num1;wire[3:0]mb_Num2;wire[3:0]mb_Num3;wire[3:0]mb_Num4; wire[3:0]mb_Num5;wire[3:0]mb_Num6;wire[3:0]mb_Num7;wire[3:0]mb_Num8;miaobiao miaobiao_u( .i_clk (Clock_mb), .i_rst (i_rst), .i_run (i_run), .i_pause (i_set), .i_clear (i_sel), .o_Num1 (mb_Num1), .o_Num2 (mb_Num2), .o_Num3 (mb_Num3), .o_Num4 (mb_Num4), .o_Num5 (mb_Num5), .o_Num6 (mb_Num6) );assign mb_Num7 = 4'd0;assign mb_Num8 = 4'd0;//=====================================================================reg[3:0]o_Num1;reg[3:0]o_Num2;reg[3:0]o_Num3;reg[3:0]o_Num4; reg[3:0]o_Num5;reg[3:0]o_Num6;reg[3:0]o_Num7;reg[3:0]o_Num8; always @(posedge i_clk or posedge i_rst)begin if(i_rst) begin o_Num1 |