代码拉取完成,页面将自动刷新
module digitalclock(SW,CLOCK_50,KEY,LEDR,LEDG,HEX7,HEX6,HEX5,HEX4,HEX3,HEX2,HEX1,HEX0,LCD_EN,LCD_RW,LCD_RS,LCD_DATA,LCD_ON,LCD_BLON);
input[17:0] SW;
input CLOCK_50;
input[3:0] KEY;
inout[7:0] LCD_DATA;
output[17:0] LEDR;
output[7:0] LEDG;
output[6:0] HEX7,HEX6,HEX5,HEX4,HEX3,HEX2,HEX1,HEX0;
output LCD_EN,LCD_RW,LCD_RS,LCD_ON,LCD_BLON;
integer alarm_times,z_times,stop,flag_a,flag_z,sti;
wire flaga,flagz;
reg start=0,begin_t=0;
reg [17:0]saveclock;
reg[9:0]mday;
reg[8:0]y1,y2,y3,y4,m1,m2,d1,d2,h1,h2,min1,min2,s1,s2;
reg[7:0] min,sec,mil,hour;
reg[5:0] min0,sec0,hour0=8;
reg[5:0] min11,sec11,hour11;
reg[5:0] min12,sec12,hour12;
reg[7:0] min13,sec13,mil13;
reg[7:0] min130,sec130,mil130;
reg[7:0] min131,sec131,mil131;
reg[7:0] min132,sec132,mil132;
reg[7:0] mins,secs,mils;
reg[5:0] times=0,stimes=0;
reg[9:0] year1,year2,month,day;
reg[9:0] year10=20,year20=15,month0=8,day0=22;
reg[5:0] m;
assign flaga=flag_a;
assign flagz=flag_z;
///////////////分频/////////
div_clock_1hz dc1(CLOCK_50,clock_1);
trans trans1(CLOCK_50,clock_2);
////////////LCD显示///////////
LCD lcd1(y1,y2,y3,y4,m1,m2,d1,d2,h1,h2,min1,min2,s1,s2,CLOCK_50,LCD_ON, LCD_BLON, LCD_RW, LCD_EN, LCD_RS, LCD_DATA );
////////////////跑马灯////////////
LED l(flaga,flagz,KEY[0],KEY[1],LEDR,LEDG,CLOCK_50);
////////////////////七段管显示//////////////
BCDto7 a3(sec/(4'd10),HEX3); BCDto7 a2(sec%(4'd10),HEX2);
BCDto7 a5(min/(4'd10),HEX5); BCDto7 a4(min%(4'd10),HEX4);
BCDto7 a7(hour/(4'd10),HEX7); BCDto7 a6(hour%(4'd10),HEX6);
BCDto7 a1(6'b111111,HEX1); BCDto7 a0(m,HEX0);
function [9:0] num;
input[3:0] x;
case(x)
4'd0:num=9'h30; 4'd1:num=9'h31;
4'd2:num=9'h32; 4'd3:num=9'h33;
4'd4:num=9'h34; 4'd5:num=9'h35;
4'd6:num=9'h36; 4'd7:num=9'h37;
4'd8:num=9'h38; 4'd9:num=9'h39;
default:num=9'h20;
endcase
endfunction
/////////////////////////////判断月份天数//////////////////////////////////////////
function [9:0] maxday;
input[3:0] month;
input[7:0] year1,year2;
reg[14:0] year;
year={year1,year2};
case(month)
4'd1:maxday=5'd31;
4'd2:begin
if((year%400)==0) maxday=29;
else if((year%400)!=0)
begin if((year%100)!=0&&(year%4)==0) maxday=29;
else maxday=28;
end
end
4'd3:maxday=5'd31; 4'd4:maxday=5'd30;
4'd5:maxday=5'd31; 4'd6:maxday=5'd30;
4'd7:maxday=5'd31; 4'd8:maxday=5'd31;
4'd9:maxday=5'd30; 4'd10:maxday=5'd31;
4'd11:maxday=5'd30; 4'd12:maxday=5'd31;
default:maxday=5'd31;
endcase
endfunction
always@*
begin
y1=num(year1/10); y2=num(year1%10);
y3=num(year2/10); y4=num(year2%10);
m1=num(month/10); m2=num(month%10);
d1=num(day/10); d2=num(day%10);
h1=num(hour/10); h2=num(hour%10);
min1=num(min/10); min2=num(min%10);
s1=num(sec/10); s2=num(sec%10);
end
always@(posedge clock_2)
begin
mday=maxday(month,year1,year2);
end
//////////////////////////////////计数:m次数-----KEY[3]///////////////////////////////////////////
always@(negedge KEY[3])
begin
if(m<4) m=m+1;
else m=0;
end
//////功能选择------0.设置显示日历时间-----1.计时器-----2.闹钟----3.跑表----4.显示跑表计时//////////////////
always@(*)
begin
case(m)
6'b000000:begin year1=year10; year2=year20; month=month0; day=day0; hour=hour0; min=min0; sec=sec0; end
6'b000001:begin hour=hour11; min=min11; sec=sec11; end
6'b000010:begin hour=hour12; min=min12; sec=sec12; end
6'b000011:begin hour=min13; min=sec13; sec=mil13; end
6'b000100:begin hour=mins; min=secs; sec=mils; end
default :begin year1=year10; year2=year20; month=month0; day=day0; hour=hour0; min=min0; sec=sec0;end
endcase
end
///////显示日期及调整:KEY[0]设置时间---KEY[1]设置月日---KEY[2]设置年///////////////////////////////////
always@(posedge clock_1)
begin
if(m==0&&!KEY[0]&&KEY[1]&&KEY[2])//KEY[0]设置时间
begin
saveclock=SW;
if(saveclock[17:12]<=23) hour0=saveclock[17:12]; else hour0=23;
if(saveclock[11:6]<=59) min0=saveclock[11:6]; else min0=59;
if(saveclock[5:0]<=59) sec0=saveclock[5:0]; else sec0=59;
end
else if(m==0&&!KEY[1]&&KEY[0]&&KEY[2])//设置月日
begin
if(SW[8:5]<=12&&SW[8:5]!=0) month0=SW[8:5]; else if(SW[8:5]==0) month0=1; else month0=12;
if(SW[4:0]<=mday&&SW[4:0]!=0) day0=SW[4:0]; else if(SW[4:0]==0) day0=1; else day0=1;
end
else if(m==0&&!KEY[2]&&KEY[0]&&KEY[1])//设置年
begin
if(SW[17:11]<=99) year10=SW[17:11]; else year10=99;
if(SW[10:4]<=99) year20=SW[10:4]; else year20=99;
end
else begin
if(sec0<6'd59) sec0<=sec0+1;
else begin sec0<=6'd0;
if(min0<6'd59) min0<=min0+1;
else begin min0<=6'd0;
if(hour0<5'd23)hour0<=hour0+1;
else begin hour0<=6'd0;
if(day0<mday) day0<=day0+1;
else begin day0<=5'd1;
if(month0<4'd11) month0<=month0+1;
else begin month0<=4'd1;
if(year20<7'd99) year20<=year20+1;
else begin year20<=7'd0;
if(year10<7'd99) year10<=year10+1;
else begin year10<=7'd0;year20<=7'd0;month0<=4'd1;day0<=5'd1;
hour0<=6'd0;min0<=6'd0;sec0<=6'd0;
end
end
end
end
end
end
end
end
end
/*
//////计时功能:KEY[0]计时开始---KEY[1]计时暂停---KEY[2]计时清零////////////////////////
always@(posedge clock_1)
begin
if(m==1)
begin
if(begin_t==1)
begin
if(sec11<6'd59) sec11<=sec11+1;
else begin sec11<=6'd0;
if(min11<6'd59) min11<=min11+1;
else begin min11<=6'd0;
if(hour11<5'd23)hour11<=hour0+1;
else begin hour11<=6'd0;min11<=6'd0;sec11<=6'd0;
end
end
end
end
end
if(m==1&&!KEY[0]&&KEY[1]&&KEY[2]) begin_t=1;
else if(m==1&&!KEY[1]&&KEY[0]&&KEY[2])begin_t=0;
else if(m==1&&!KEY[2]&&KEY[0]&&KEY[1])
begin hour11<=0; min11<=0; sec11<=0; end
else if(m!=1)
begin begin_t=0; hour11<=0; min11<=0; sec11<=0; end
end
////////////////闹钟设置:KEY[0]设置闹钟时分-----闹钟“贪睡功能”//////////////////////////////////////////
always@(posedge clock_1)
begin
if(m==2&&!KEY[0]&&KEY[1]&&KEY[2])
begin
if(SW[11:6]<=23) hour12=SW[11:6];
else hour12<=23;
if(SW[5:0]<=59) min12=SW[5:0];
else min12<=59;
end
else if (flag_a==1&&!KEY[0]&&!KEY[2])
begin
if(min12<=57) min12=min12+3;
else begin min12=min12+3-60;hour12=hour12+1;end
end
else if(hour0==hour12&& min0==min12 &&sec0<=5&&flag_a==0)
begin
if(min12<=59) min12=min12+1;
else begin min12=0;hour12=hour12+1;end
end
end
///////////////////////////////////闹钟响//////////////////////////////////////////////
always@(posedge clock_1)
begin
if(flag_a==0)
begin
if(hour0==hour12&& min0==min12 && sec0==0)
begin flag_a<=1'b1;alarm_times<=0;end
end
else //flag_a==1;
begin
alarm_times<=alarm_times+1;
if(alarm_times==6) flag_a<=0;
end
end
////////////////////////////////////整点报时//////////////////////////////////////////
always@(posedge clock_1)
begin
if(flag_z==0)
begin
if(sec0==0&&min0==0)
begin flag_z<=1'b1;z_times<=0;end
end
else //flag_z==1;
begin
z_times<=z_times+1;
if(z_times==6) flag_z<=0;
end
end
/////////////////跑表:KEY[0]开始------KEY[1]清零--KEY[2]时间录入/////////////////////////////////////////
always@(posedge clock_2)
begin
if(m==3)
begin
if(start==1)
begin
if(mil13==99) begin mil13<=0; sec13<=sec13+1; end
else mil13<=mil13+1;
if(sec13==59) begin sec13<=0; min13<=min13+1; end
if(min13==59) min13<=0; end
if(m==2'b11&&!KEY[0]&&KEY[1]&&KEY[2]) start<=1;
else if(m==2'b11&&!KEY[1]&&KEY[0]&&KEY[2]) begin min13<=0; sec13<=0;mil13<=0;end
end
else if(m!=3) begin start<=0; min13<=0; sec13<=0; mil13<=0; end
end
///////////////////////////////////录入时间选择 KEY[2]//////////////////////////////////
always@(negedge KEY[2])
begin
if(m==3)
begin
if(times<2) times=times+1;
else times=0;
end
end
/////////////////////////////录入时间显示KEY[1]////////////////////////////
always@(negedge KEY[1])
begin
if(m==4)
begin
if(stimes<2) stimes=stimes+1;
else stimes=0;
end
end
////////////////////////////////时间录入 OR 录入时间清零 KEY[2]////////////////////////////////////////
always@(negedge KEY[2])
begin
if(m==3)
begin
case (times)
6'b000000:begin min130<=min13;sec130<=sec13;mil130<=mil13;end
6'b000001:begin min131<=min13;sec131<=sec13;mil131<=mil13;end
6'b000010:begin min132<=min13;sec132<=sec13;mil132<=mil13;end
default :begin end
endcase
end
else if(m==4)
begin
min130<=0;sec130<=0;mil130<=0;
min131<=0;sec131<=0;mil131<=0;
min132<=0;sec132<=0;mil132<=0;
end
end
///////////////////////////////显示时间//////////////////////////////////////
always@(posedge clock_2)
begin
if(m==4)
begin
case(stimes)
6'b000000:begin secs<=sec130;mins<=min130;mils<=mil130; end
6'b000001:begin secs<=sec131;mins<=min131;mils<=mil131; end
6'b000010:begin secs<=sec132;mins<=min132;mils<=mil132; end
default :begin secs<=0;mins<=0;mils<=0; end
endcase
end
end
////////////////////////////////////////////////////////////////
*/
endmodule
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。