2015-10-06 69 views
0

我已經問過關於此代碼的上一個問題,但那是在「工作」之前。這裏是代碼:連接到GPIO引腳的LED閃爍而不是持續閃爍

module MatrixInput(CLOCK_50,MOutput, MInput, LEDR); 
//10 -> 16 Cols INPUTS 
//24 -> 18 rows OUTPUTS 
input [16:10] MInput; 
output reg [24:18] MOutput; 
output [7:0] LEDR; 
integer counter = 0; 
input CLOCK_50; //50Mhz 
reg [3:0] ButtonFlag; 

initial counter = 0; 


assign LEDR[7] = ~MInput[10]; //Assign Cols to Leds 7 to 4 
assign LEDR[6] = ~MInput[12]; 
assign LEDR[5] = ~MInput[14]; 
assign LEDR[4] = ~MInput[16]; 
assign LEDR[3] = ButtonFlag[3]; //assign LED Rows to button Flag indicator 
assign LEDR[2] = ButtonFlag[2]; 
assign LEDR[1] = ButtonFlag[1]; 
assign LEDR[0] = ButtonFlag[0]; 


[email protected](posedge CLOCK_50) begin 

    if (counter > 3) //if counter is larger than amount of cases. reset to 0 
     counter = 0; 

    case(counter) //go through and set every row except one high which we will compare against columns 
     0: MOutput[24:18] = 7'b1x0x1x1; //dont care about GPIO 23, 21 or 19 
     1: MOutput[24:18] = 7'b1x1x0x1; 
     2: MOutput[24:18] = 7'b1x1x1x0; 
     3: MOutput[24:18] = 7'b0x1x1x1; 
     default: counter = 0; //ideally shouldn't be needing a default case 
    endcase 


    if (MInput[10] == 1 && MInput[12] == 1 && MInput[14] == 1 && MInput[16] == 1) begin 
     ButtonFlag[counter] = 0; 
    end else 
     ButtonFlag[counter] = 1; 

    counter = counter + 1; 

end 
endmodule 

眼下的LED 7到4不上的「滿」的亮度時,相關的列按鈕被按下,表明它實際上是閃爍時速度極快。 MOutput和Minput分配給GPIO引腳。

我的問題是如何解決這個問題,並讓他們在他們的列中的按鈕被按下時不斷地開着。

+0

看起來這可能是一個很好的問題,但只看當前的代碼和描述並不能說明您使用的GPIO之間的關係。我建議你編輯你的問題來解釋'MInput'是如何由MOutput驅動的,這取決於任何按鈕按壓。另外,重組您的代碼(可能將與按鈕相關的代碼移到子模塊中)以獲取更有意義的信號/端口名稱可能會有所幫助。 – FriendFX

+0

好的歡呼聲,其實你的評論讓我意識到什麼答案是對我自己的問題哈哈。 –

+0

是的,我認爲這是沿着這些線。從你提供的代碼和描述中就不太清楚。很高興我的評論是有幫助的! – FriendFX

回答

0

我剛剛意識到,這是因爲我正在騎自行車的MOutput,並且只有當MOutput處於正確的週期時,Minput纔會亮起,因此LED列閃爍。