分频器功能module fenpin(key,clk0,clk1,clk2);
input key;
input clk0;
output clk1;
output clk2;
reg clk1;
reg clk2;
integer i=0;
integer k=0;
integer j=0;
integer flag=1;
always @(posedge clk0)
begin
if(key==1)
begin
if(i<500000)
begin
i=i+1;
clk1<=1;
end
else if(i<1000000)
begin
i=i+1;
clk1<=0;
end
else
begin
flag=flag+1;
i=0;
end
if(flag<4&&k<250000)
begin
k=k+1;
clk2<=1;
end
else if(flag<4&&k<500000)
begin
k=k+1;
clk2<=0;
end
else if(flag<4&&k>=500000)
begin
k=0;
end
if(flag>=4&& flag <7&&j<125000)
begin
j=j+1;
clk2<=1;
end
else if(flag>=4&& flag <7&&j<250000)
begin
j=j+1;
clk2<=0;
end
else if(flag>=4&&flag <7&&j>=250000)
begin
j=0;
end
if(flag >=7)
begin
clk2<=1;
end
end
else
begin
clk1=0;
clk2=0;
end
end
endmodule