上传了VHDL以来,陆续接到一些挑战,网友们的设计方案真是个有千秋,而且平台不同,语言也不同。下面是Verilog的时钟模板部分仅供参考。
EDA电子时钟程序 (verilog HDL)
module wyptime(cp,con, oth,otm,ots,ch,cm );
input con,cp,ch,cm;
output[5:0] oth,otm,ots;
reg[5:0] oth,otm,ots,oth1,otm1;
reg cp1,c;
/*仿真赋初值*/
initial
begin
oth="0";otm=0;ots=0;oth1=0;otm1=0;cp1=0;c=0;
end
/*分频功能*/
always@(posedge cp)
begin
c="c"+1;if(c==1)cp1=~cp1;
end
/*完成计时功能*/
always @(posedge cp1 or negedge con )
begin
if(~con) begin oth="oth1";otm=otm1;end //若控制端有效,完成校时功能
else begin ots="ots"+1;
if(ots==60) begin ots="0";otm =otm +1; end
if(otm==60) begin otm="0";oth =oth +1;end
if(oth==12) begin oth="0"; end
end
end
/*对小时和分进行校准*/
always@(posedge ch )
begin
oth1=oth1+1;if(oth1==12) oth1=0;
end
always@(posedge cm )
begin
otm1=otm1+1; if(otm1==60) otm1=0;
end
endmodule
电子时钟(EDA)
module wyptime(cp,con, othg,otmg,otsg,oths,otms,otss,ch,cm );
input con,cp,ch,cm;
output[3:0] othg,otmg,otsg,oths,otms,otss;
integer oth,otm,ots,oth1,otm1 ;
reg[3:0] othg,otmg,otsg,oths,otms,otss;
reg cp1 ;
reg[32:0] c;
/*仿真赋初值*/
initial
begin
oth="0";otm=0;ots=0;oth1=0;otm1=0;cp1=0;c=0;
end
/*分频功能*/
begin
c="c"+1;if(c==10000000)begin cp1=~cp1;c=0; end
end
/*完成计时功能*/
always @(posedge cp1 or negedge con )
begin
if(~con) begin oth="oth1";otm=otm1;end //若控制端有效,完成校时功能
else begin ots="ots"+1;
if(ots==60) begin ots="0";otm =otm +1; end
if(otm==60) begin otm="0";oth =oth +1;end
if(oth==24) begin oth="0"; end
end
end
/*对小时和分进行校准*/
begin
oth1=oth1+1;if(oth1==24) oth1=0;
end
begin
otm1=otm1+1; if(otm1==60) otm1=0;
end
always
begin
oths =oth/10; othg="oth-10"*oths;
otms="otm/10"; otmg="otm-10"*otms;
otss =ots/10; otsg =ots-10*otss;
end
endmodule
文章评论(0条评论)
登录后参与讨论