|
module shifenmiao(clk,seg,wei,key_in);
input clk;
input[3:0]key_in;
output[7:0] wei;
output[7:0] seg;
reg[23:0] hour;
reg[7:0] seg_r;
reg[7:0] wei_r;
reg[3:0] deg_r;
reg[24:0] 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[17:15])
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[17:15])
3'b000:deg_r=hour[3:0];
3'b001:deg_r=hour[7:4];
3'b010:deg_r=4'hF;
3'b011:deg_r=hour[11:8];
3'b100:deg_r=hour[15:12];
3'b101:deg_r=4'hF;
3'b110:deg_r=hour[19:16];
3'b111:deg_r=hour[23:20];
default:deg_r=4'hF;
endcase
end
always@(posedge sec)
begin
if(key_in[0]==0)
hour=24'd0;
else if(key_in[1]==0)
begin
hour[3:0]=hour[3:0]+4'd1;//秒的个位数
if(hour[3:0]==10)
begin
hour[3:0]=0;
hour[7:4]=hour[7:4]+4'd1;
if(hour[7:4]==6)hour[7:0]=8'd0;
end
end
else if(key_in[2]==0)
begin
hour[11:8]=hour[11:8]+4'd1;//分的个位数
if(hour[11:8]==10)
begin
hour[11:8]=0;
hour[15:12]=hour[15:12]+4'd1;
if(hour[15:12]==6)hour[15:8]=8'd0;
end
end
else if(key_in[3]==0)
begin
hour[19:16]=hour[19:16]+4'd1;//小时的个位数
if(hour[19:16]==10)
begin
hour[19:16]=0;
hour[23:20]=hour[23:20]+4'd1;
if(hour[23:20]==2 && hour[19:16]==4)hour[23:0]=24'd0;
end
end
else
begin
hour[3:0]=hour[3:0]+4'd1;//秒的个位数
if(hour[3:0]==4'ha)
begin
hour[3:0]=4'd0;
hour[7:4]=hour[7:4]+4'd1;//秒的十位数
if(hour[7:4]==4'h6)
begin
hour[7:4]=4'd0;
hour[11:8]=hour[11:8]+4'd1;//分的个位数
if(hour[11:8]==4'ha)
begin
hour[11:8]=4'd0;
hour[15:12]=hour[15:12]+4'd1;//分的十位数
if(hour[15:12]==4'h6)
begin
hour[15:12]=4'd0;
hour[19:16]=hour[19:16]+4'd1;//小时的个位数
if(hour[19:16]==4'd10)
begin
hour[19:16]=4'd0;
hour[23:20]=hour[23:20]+4'd1;//小时的十位数
if(hour[23:20]==4'd2 && hour[19:16]==4'd4)hour[23:16]=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 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|