2012年10月18日 星期四

8個LED 的流水燈(跑馬燈) --(2)

8個LED 的流水燈(跑馬燈)





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

沒有留言:

張貼留言

習題解答 (5/6)

  第五章 習題解答 一、 錯誤偵測技術 1. 何謂循環冗餘檢查法 (CRC)? 是一種根據傳輸資料產生簡短固定位數校驗碼的演算法。發送端將資料除以一個特定的多項式,得到的「餘數」即為 CRC 碼並隨資料發送;接收端以同樣多項式除之,若餘數為 0 則代表資料傳輸正確。 2. 何...