可调节电子钟
module shifenmiao(clk,seg,wei,key_in);input clk;
inputkey_in;
output wei;
output seg;
reg hour;
reg seg_r;
reg wei_r;
reg deg_r;
reg FIV;reg sec;
assign seg=seg_r;
assign wei=wei_r;
always @(posedge clk)
begin
FIV=FIV+1'b1;
if(FIV==24000000)
begin
FIV=25'd0;
sec=~sec;
end
end
always@(posedge clk)
begin
case(FIV)
3'b000:wei_r=8'b11111110;
3'b001:wei_r=8'b11111101;
3'b010:wei_r=8'b11111011;
3'b011:wei_r=8'b11110111;
3'b100:wei_r=8'b11101111;
3'b101:wei_r=8'b11011111;
3'b110:wei_r=8'b10111111;
3'b111:wei_r=8'b01111111;
default:wei_r=4'h4;
endcase
case(FIV)
3'b000:deg_r=hour;
3'b001:deg_r=hour;
3'b010:deg_r=4'hF;
3'b011:deg_r=hour;
3'b100:deg_r=hour;
3'b101:deg_r=4'hF;
3'b110:deg_r=hour;
3'b111:deg_r=hour;
default:deg_r=4'hF;
endcase
end
always@(posedge sec)
begin
if(key_in==0)
hour=24'd0;
else if(key_in==0)
begin
hour=hour+4'd1;//秒的个位数
if(hour==10)
begin
hour=0;
hour=hour+4'd1;
if(hour==6)hour=8'd0;
end
end
else if(key_in==0)
begin
hour=hour+4'd1;//分的个位数
if(hour==10)
begin
hour=0;
hour=hour+4'd1;
if(hour==6)hour=8'd0;
end
end
else if(key_in==0)
begin
hour=hour+4'd1;//小时的个位数
if(hour==10)
begin
hour=0;
hour=hour+4'd1;
if(hour==2 && hour==4)hour=24'd0;
end
end
else
begin
hour=hour+4'd1;//秒的个位数
if(hour==4'ha)
begin
hour=4'd0;
hour=hour+4'd1;//秒的十位数
if(hour==4'h6)
begin
hour=4'd0;
hour=hour+4'd1;//分的个位数
if(hour==4'ha)
begin
hour=4'd0;
hour=hour+4'd1;//分的十位数
if(hour==4'h6)
begin
hour=4'd0;
hour=hour+4'd1;//小时的个位数
if(hour==4'd10)
begin
hour=4'd0;
hour=hour+4'd1;//小时的十位数
if(hour==4'd2 && hour==4'd4)hour=8'd0;
end
end
end
end
end
end
end
always@(deg_r)
begin
case(deg_r)
4'h0:seg_r=8'hc0;
4'h1:seg_r=8'hf9;
4'h2:seg_r=8'ha4;
4'h3:seg_r=8'hb0;
4'h4:seg_r=8'h99;
4'h5:seg_r=8'h92;
4'h6:seg_r=8'h82;
4'h7:seg_r=8'hf8;
4'h8:seg_r=8'h80;
4'h9:seg_r=8'h90;
default:seg_r=8'hbf;
endcase
end
endmodule {:smile:}{:smile:}{:smile:}{:smile:} 顶顶顶{:smile:}{:smile:}{:smile:}{:smile:}{:smile:} {:smile:}{:huffy:}{:huffy:}{:huffy:}{:huffy:}{:huffy:}{:huffy:} {:smile:}{:smile:}{:smile:}{:smile:}{:smile:}{:smile:}{:smile:} {:smile:}{:smile:}{:smile:}{:smile:}{:smile:}{:smile:}{:smile:}{:smile:} 同步时钟里一大堆=号,楼主想干嘛 wildone 发表于 2013-8-21 10:24 static/image/common/back.gif
同步时钟里一大堆=号,楼主想干嘛
有问题吗?这个我是验证通过的! 389704844 发表于 2013-8-21 15:26 static/image/common/back.gif
有问题吗?这个我是验证通过的!
一堆毛刺。 wildone 发表于 2013-8-21 15:43 static/image/common/back.gif
一堆毛刺。
谢谢您==== 来顶一个 加油! Fourier00 发表于 2013-8-25 15:42 static/image/common/back.gif
加油!
谢谢您!加油
页:
[1]