写在最前:
纸上得来终觉浅,绝知此事要编程!
一、实验目的
用 EDA 技术设计多功能数字钟
能够实现任意设定闹铃时间,到达闹钟时间时闹钟持续响一分钟
能够对小时进行12/24进制切换,并用LED指示AM和PM
整点报时,从整点零分一秒开始,奇数秒亮LED,偶数秒熄灭,几点钟LED闪烁几下。如果是12小时进制的显示情况下,需要按照24小时进制下面的计数进行报时,零点或者下午12点都需要报时24下,报时完毕LED熄灭
利用ISE软件对其进行仿真,并给出各功能实现关键点的截图和解释
二、实验代码
//******************* my_Clock.v ***********************
module my_Clock(
input CLK_50, // 50MHz clock
input nCR, EN, // reset, enable
input Adj_Min, Adj_Hour, // adjust signal of minute and hour
input Set_Alarm, // decide whether to set alarm clock
input Set_Min, Set_Hour, // set signal of alarm clock
output Clock, // alarm control signal
output [5:0] Second_B, // binary code of second
output [3:0] Bit, // position
output [7:0] Seg, // number
input Set_count, // decide 12 counting or 24 counting
output AP, // AM or PM
output Int_time // integral time accounce
);
//============ Parameters =========================
wire [7:0] Hour, Minute, Second; // time
supply1 Vdd; // logical true
wire MinL_EN, MinH_EN, Hour_EN; // enable signal
wire CP_1Hz; // freq 1Hz
wire CP_200Hz; // freq 100Hz
wire [7:0] HEX2, HEX3, HEX4, HEX5;
wire [7:0] C_Hour, C_Minute; // clock time
wire C_MinL_EN, C_MinH_EN;
wire C_Hour_EN;
wire [7:0] B_Hour; // 12 counting
wire [7:0] CB_Hour; // 12 counting for clock time
wire [5:0] Hour_B; // binary code of 12 counting hour
wire [5:0] Hour_24;
//============ Divider50MHz ========================
// divide 50MHz to 1Hz
Divider50MHz U0 (.CLK_50M(CLK_50),
.nCLR(nCR),
.CLK_1Hzout(CP_1Hz));
defparam U0.N = 25,
U0.CLK_Freq = 50000000,
U0.OUT_Freq = 1;
// divide 50MHz to 100Hz
Divider50MHzto100Hz X0 (.CLK_50M(CLK_50),
.nCLR(nCR),
.CLK_200Hzout(CP_200Hz));
defparam X0.N = 25,
X0.CLK_Freq = 50000000,
X0.OUT_Freq = 200;
//========== Hour & Minute & Second counter ========
// Second counter
counter10 S0 (Second[3:0], nCR, EN, CP_1Hz);
counter6 S1 (Second[7:4], nCR, (Second[3:0] == 4'h9), CP_1Hz);
// Change Second to binary code
change_B S2 (Second[7:0], Second_B[5:0]);
// Minute counter
counter10 M0 (Minute[3:0], nCR, MinL_EN, CP_1Hz);
counter6 M1 (Minute[7:4], nCR, MinH_EN, CP_1Hz);
// assign enable signal
assign MinL_EN = Adj_Min?Vdd:(Second == 8'h59); // we can adjust M0 by using Adj_Min
assign MinH_EN = (Adj_Min && (Minute[3:0] == 4'h9)) // the conditions which add 1 to M1
|| ((Minute[3:0] == 4'h9) && (Second == 8'h59));
// Hour counter (24 counting)
counter24 H0(Hour[7:4], Hour[3:0], nCR, Hour_EN, CP_1Hz);
// Hour counter (12 counting)
counter12 P0(B_Hour[7:4], B_Hour[3:0], nCR, Hour_EN, CP_1Hz);
// assign enable signal
assign Hour_EN = Adj_Hour?Vdd:((Minute == 8'h59) && (Second == 8'h59));
// AM or PM
// initial AP = 0;
change_B S3 (Hour[7:0], Hour_B[5:0]); // change hour to be binary code
assign AP = (Hour_B > 5'b01011)?0:1; // AM: AP = 1 PM: AP = 0
//============ Set Alarm clock ======================
// Minute counter
counter10 M2 (C_Minute[3:0], nCR, C_MinL_EN, CP_1Hz);
counter6 M3 (C_Minute[7:4], nCR, C_MinH_EN, CP_1Hz);
// assign enable signal
assign C_MinL_EN = (Set_Min && Set_Alarm);
assign C_MinH_EN = (Set_Min && (C_Minute[3:0] == 4'h9) && Set_Alarm);
// Hour counter (24 counting)
counter24 H1(C_Hour[7:4], C_Hour[3:0], nCR, C_Hour_EN, CP_1Hz);
// Hour counter (12 counting)
counter12 P1(CB_Hour[7:4], CB_Hour[3:0], nCR, C_Hour_EN, CP_1Hz);
// assign enable signal
assign C_Hour_EN =