电子表代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一、module myclock(RSTn,CLK,FLAG4,UP,DN,WD,H,M,S,MS);
input RSTn,CLK,UP,DN;
output [7:0]WD,H,M,S;
output [7:0]MS;
input [2:0]FLAG4;
reg [2:0]m_WD;
reg [5:0]m_H,m_M,m_S;
reg [6:0]m_MS;
assign WD=m_WD;
assign H=m_H;
assign M=m_M;
assign S=m_S;
assign MS=m_MS;
always@(posedge CLK)
if(~RSTn)
begin //同步复位
m_WD<=8'd4;
m_H<=8'd15;
m_M<=8'd10;
m_S<=8'b000000;
m_MS<=8'b0000000;
end
else if(FLAG4==3'b001)
begin //调星期状态
if(UP)
begin
m_WD<=m_WD+1'b1;
if(m_WD==8'd7)
m_WD<=8'd1;
end
else if(DN)
begin
m_WD<=m_WD-1'b1;
if(m_WD==8'h01)
m_WD<=8'd7;
end
end
else if(FLAG4==3'b010)
begin //调时状态
if(UP)
begin
m_H<=m_H+1'b1;
if(m_H==8'd23)
m_H<=8'd0;
end
else if(DN)
begin
m_H<=m_H-1'b1;
if(m_H==8'h00)
m_H<=8'd23;
end
end
else if(FLAG4==3'b011)
begin //调分状态
if(UP)
begin
m_M<=m_M+1'b1;
if(m_M==8'd59)
m_M<=8'd0;
end
else if(DN)
begin
m_M<=m_M-1'b1;
if(m_M==8'h00)
m_M<=8'd59;
end
end
else if(FLAG4==3'b100)
begin //调秒状态
if(UP)
begin
m_S<=m_S+1'b1;
if(m_S==8'd59)
m_S<=8'b0;
end
else if(DN)
begin
m_S<=m_S-1'b1;
if(m_S==8'h00)
m_S<=8'd59;
end
end
else
begin //正常显示
m_MS<=m_MS+1'b1;
if(m_MS==8'd100)
begin
m_MS<=8'd0;
m_S<=m_S+1'd1;
end
if(m_S==8'd60)
begin
m_S<=8'd0;
m_M<=m_M+8'd1;
end
if(m_M==8'd60)
begin
m_M<=8'd0;
m_H<=m_H+8'd1;
end
if(m_H==8'd24)
begin
m_H<=8'd0;
end
end
endmodule
二、module date(RSTn,CLK,FLAG_DT,UP,DN,MON,DT,YH,YL);
input RSTn,CLK,UP,DN;
output [7:0]YH,YL;
output [7:0]MON,DT;
input [1:0]FLAG_DT;
reg [4:0]m_MON,m_DT;//0~31,5 wei er jin zhi
reg [6:0]m_YH,m_YL;//0~99,7 wei er jin zhi
assign YH=m_YH;
assign YL=m_YL;
assign MON=m_MON;
assign DT=m_DT;
always@(posedge CLK)
if(~RSTn)
begin //同步复位
m_YH<=7'd20; //nian fen de gao liang wei
m_YL<=7'd13; //nian fen de di liang wei
m_MON<=5'd07;
m_DT<=5'd11;
end
else if(FLAG_DT==2'b01) //调节年
if(UP)
begin
m_YL<=m_YL+1'b1;
if (m_YL==7'd100)
begin
m_YL<=7'd0;
m_YH<=m_YH+1'b1;
end
end
else if(DN)
begin
m_YL<=m_YL-1'b1;
if (m_YL==7'd0)
begin
m_YL<=7'd99;
m_YH<=m_YH-1'b1;
end
end
end
else if(FLAG_DT==2'b10) //调节月
begin
if(UP)
begin
m_MON<=m_MON+1'b1;
if(m_MON==8'd12)
m_MON<=8'd1;
end
else if(DN)
begin
m_MON<=m_MON-1'b1;
if(m_MON==8'd1)
m_MON<=8'd12;
end
end
else
if(FLAG_DT==2'b11&&m_MON==8'd1||m_MON==8'd3||m_MON==8'd5||m_MON==8'd7||m_ MON==8'd8||m_MON==8'd10||m_MON==8'd12)//调节日,分不同的月份
begin
if(UP)
begin
m_DT<=m_DT+1'b1;
if(m_DT==8'd31)
m_DT<=8'd1;