module LedWater(CLOCK_50,SW, KEY, LEDR, LEDG );
input [17:0] SW; // toggle switches
input [7:0] KEY;
input CLOCK_50; //Clock 50MHZ
output [17:0] LEDR; // red LEDs
output [7:0] LEDG; // green LEDs
/*
input clk;
input rst;
output [7:0] dataout;
*/
wire clk;
wire rst;
reg [7:0] dataout;
reg [22:0] cnt;
//assign to DE2-70 hardware
assign LEDR = SW;
assign clk = CLOCK_50;
assign rst = KEY[0];
always@(posedge clk or negedge rst)
begin
if(!rst) begin
cnt<=0;
dataout<=8'b1110_0111;//0->Led on, 1->Led off
end
else begin
cnt<=cnt+1;
if(cnt==23'h7fffff) begin
dataout[2:0]<=dataout[3:1];
dataout[3]<=dataout[0];
dataout[6:4]<=dataout[7:5];
dataout[7]<=dataout[4];
end
end
end
assign LEDG=dataout;
endmodule
沒有留言:
張貼留言