2012年10月18日 星期四

//8 LED 流水燈 (3) 適用於DE2-70

//8 LED 流水燈

超連結影片
http://www.youtube.com/embed/clpfmwGbP3A



module LED_Water8(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 sys_clk,rst_n;
output [7:0] led;
*/
wire  sys_clk;
wire  rst_n;
reg  [7:0] led;

//assign to DE2-70 hardware     
assign LEDR = SW;
    assign sys_clk = CLOCK_50;
    assign rst_n = KEY[0];
    

    reg [25:0] count;
    reg [4:0] flag;

always @(posedge sys_clk,negedge rst_n)

if(!rst_n) 
begin
flag <= 5'b0;
count <= 26'b0;
end
else 
begin
if( count == 26'b00_0011_1111_1111_1111_1111_1110 )
begin 
count <= 26'b0; 
flag <= flag+2'b01;

if(flag == 5'b1_0000) 
flag <= 5'b0;
end
else
count <= count + 1; 
end


always @(posedge sys_clk)
begin
case(flag) 
5'b0_0000: led <= 8'b1111_1110;  //0
5'b0_0001: led <= 8'b1111_1101;  //1
5'b0_0010: led <= 8'b1111_1011;  //2
5'b0_0011: led <= 8'b1111_0111;  //3
5'b0_0100: led <= 8'b1110_1111;  //4
5'b0_0101: led <= 8'b1101_1111;  //5
5'b0_0110: led <= 8'b1011_1111;  //6
5'b0_0111: led <= 8'b0111_1111;  //7
5'b0_1000: led <= 8'b0111_1111;  //8
5'b0_1001: led <= 8'b1011_1111;  //9
5'b0_1010: led <= 8'b1101_1111;  //10
5'b0_1011: led <= 8'b1110_1111;  //11
5'b0_1100: led <= 8'b1111_0111;  //12
5'b0_1101: led <= 8'b1111_1011;  //13
5'b0_1110: led <= 8'b1111_1101;  //14
default:led <= 8'b1111_1110;     //15
endcase
end

assign LEDG =led;

endmodule

沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...