实现流水灯 50MHZ 分频成1HZ 斯巴达3 小弟的错误很多 求改啊
module main(CLK,RST,EN,led,DIVOUT);
input CLK,RST;
input EN;
output [2:0] DIVOUT;
output [7:0] led;
wire CLK,RST;
reg [7:0] led;
wire EN;
wire [2:0] DIVOUT;
// always @(posedge CLK)
initial
begin
led = 8'b00000001;
end
// div50 div5050(.CLK(CLK),.RST(RST),.EN(EN),.div(DIVOUT[0]));
// div50 #(1000) div501000(.CLK(CLK),.RST(RST),.EN(DIVOUT[0]),.div(DIVOUT[1]));
// div50 #(1000) div502000(.CLK(CLK),.RST(RST),.EN(DIVOUT[1]),.div(DIVOUT[2]));
div50 div5050(CLK,RST,EN,DIVOUT[0]);
div50 #(1000) div501000(CLK,RST,DIVOUT[0],DIVOUT[1]);
div50 #(1000) div502000(CLK,RST,DIVOUT[1],DIVOUT[2]);
always @ (posedge CLK or posedge RST )
if(RST == 1'b1)
begin
led = 8'b00000001;
end
else
if( DIVOUT[2]==1'b1)
begin
if(led == 8'b10000000 )
led = 8'b00000001;
else
led=led<<1;
end
endmodule
module div50(CLK,RST,EN,div
);
input RST,CLK,EN;
reg DIVOUT;
output wire div;
parameter MAX_VALUE=50;
wire [9:0]cnt;
reg [9:0] cnt_q;
assign cnt=(EN==1'b1)?(cnt_q+1'b1):cnt_q;
always@(posedge CLK or negedge RST)
if(!RST)
cnt_q<='b0;
else
if(cnt_q>=MAX_VALUE-1)
cnt_q<='b0;
else
cnt_q<=cnt;
always@(posedge CLK or negedge RST)
if(!RST)
DIVOUT<=1'b0;
else
if(cnt_q>=MAX_VALUE-1)
DIVOUT<=1'b1;
else
DIVOUT<=1'b0;
assign div=DIVOUT;
endmodule |