module myclock(key,clk,segdat1,segdat2,segdat3,segdat4);
input key,clk;
output [6:0] segdat1,segdat2,segdat3,segdat4;
reg [24:0] count;
reg [7:0] sec,min;
reg [6:0] segdat1,segdat2,segdat3,segdat4;
reg [3:0] dispdat1,dispdat2,dispdat3,dispdat4;
reg second;
reg cn;
////////////////////fen ping///////////////////////////
always @(posedge clk)
begin
count=count+1;
if(count==25'd25000000)
begin
count=25'b0000000000000000000000000;
second=~second;
end
end
////////////////////display////////////////////////////
always @(count[11:10])
begin
case(count[11:10])
2'b00: dispdat1=sec[3:0]; // miao de ge wei
2'b01: dispdat2=sec[7:4]; //miao de shi wei
2'b10: dispdat3=min[3:0]; //fen de ge wei
2'b11: dispdat4=min[7:4]; //fen de shi wei
endcase
end
/////////////////////////miao de ge wei///////////////////////////////////////
always @(dispdat1)
begin
case(dispdat1)
4'h0: segdat1=7'b1000000;//0
4'h1: segdat1=7'b1111001;//1
4'h2: segdat1=7'b0100100;//2
4'h3: segdat1=7'b0110000;//3
4'h4: segdat1=7'b0011001;//4
4'h5: segdat1=7'b0010010;//5
4'h6: segdat1=7'b0000010;//6
4'h7: segdat1=7'b1111000;//7
4'h8: segdat1=7'b0000000;//8
4'h9: segdat1=7'b0010000;//9
endcase
end
/////////////////////////miao de shi wei///////////////////////////////////////
always @(dispdat2)
begin
case(dispdat2)
4'h0: segdat2=7'b1000000;//0
4'h1: segdat2=7'b1111001;//1
4'h2: segdat2=7'b0100100;//2
4'h3: segdat2=7'b0110000;//3
4'h4: segdat2=7'b0011001;//4
4'h5: segdat2=7'b0010010;//5
4'h6: segdat2=7'b0000010;//6
4'h7: segdat2=7'b1111000;//7
4'h8: segdat2=7'b0000000;//8
4'h9: segdat2=7'b0010000;//9
endcase
end
/////////////////////////fen de ge wei///////////////////////////////////////
always @(dispdat3)
begin
case(dispdat3)
4'h0: segdat3=7'b1000000;//0
4'h1: segdat3=7'b1111001;//1
4'h2: segdat3=7'b0100100;//2
4'h3: segdat3=7'b0110000;//3
4'h4: segdat3=7'b0011001;//4
4'h5: segdat3=7'b0010010;//5
4'h6: segdat3=7'b0000010;//6
4'h7: segdat3=7'b1111000;//7
|
文件: |
myclock.rar |
大小: |
473KB |
下载: |
下载 | |
4'h8: segdat3=7'b0000000;//8
4'h9: segdat3=7'b0010000;//9
endcase
end
/////////////////////////miao de shi wei///////////////////////////////////////
always @(dispdat4)
begin
case(dispdat4)
4'h0: segdat4=7'b1000000;//0
4'h1: segdat4=7'b1111001;//1
4'h2: segdat4=7'b0100100;//2
4'h3: segdat4=7'b0110000;//3
4'h4: segdat4=7'b0011001;//4
4'h5: segdat4=7'b0010010;//5
4'h6: segdat4=7'b0000010;//6
4'h7: segdat4=7'b1111000;//7
4'h8: segdat4=7'b0000000;//8
4'h9: segdat4=7'b0010000;//9
endcase
end
//////////////////////////////ji shi chu li////////////////////////////////
always @(posedge second)
begin
if(!key)
begin
sec[7:0]=8'h0;
cn=0;
end
else
begin
cn=0;
sec[3:0]=sec[3:0]+1;
if(sec[3:0]==4'd10)
begin
sec[3:0]=4'd0;
sec[7:4]=sec[7:4]+1;
if(sec[7:4]==4'd6)
begin
sec[7:4]=4'd0;
cn=1;
end
end
end
end
always @(posedge cn)
begin
if(!key)
begin
min[7:0]=8'h0;
end
else
begin
min[3:0]=min[3:0]+1;
if(min[3:0]==4'd10)
begin
min[3:0]=4'd0;
min[7:4]=min[7:4]+1;
if(min[7:4]==4'd6)
begin
min[7:4]=4'd0;
end
end
end
end
endmodule
阅读(904) | 评论(0) | 转发(0) |