新聞中心

EEPW首頁 > EDA/PCB > 設(shè)計應(yīng)用 > 基于PLD的矩陣鍵盤狀態(tài)機控制

基于PLD的矩陣鍵盤狀態(tài)機控制

作者: 時間:2012-03-12 來源:網(wǎng)絡(luò) 收藏

parameter SCAN_IDLE = 3'b000;

parameter SCAN_JITTER= 3'b001;

parameter SCAN_COL0 = 3'b011;

parameter SCAN_COL1 = 3'b010;

parameter SCAN_COL2 = 3'b110;

parameter SCAN_COL3 = 3'b100;

parameter SCAN_READ = 3'b101;

parameter SCAN_JTTTER2= 3'b111;

reg [2:0] current_state;

reg [2:0] next_state;

always@(posedge clk or negedge rst_n)

begin

if(!rst_n)

current_state = SCAN_IDLE;

else if(cnt == 20'hfffff)

current_state = next_state;

end

always@*

begin

case(current_state)

SCAN_IDLE : //init

if(col_data != 4'b1111) next_state = SCAN_JITTER;

else next_state = SCAN_IDLE;

SCAN_JITTER: //escape the jitter

if(col_data != 4'b1111) next_state = SCAN_COL0;

else next_state = SCAN_IDLE;

SCAN_COL0 : //1th row

if(col_data != 4'b1111) next_state = SCAN_READ;

else next_state = SCAN_COL1;

SCAN_COL1 : //2th row

if(col_data != 4'b1111) next_state = SCAN_READ;

else next_state = SCAN_COL2;

SCAN_COL2 : //3th row

if(col_data != 4'b1111) next_state = SCAN_READ;

else next_state = SCAN_COL3;

SCAN_COL3 : //4th row

if(col_data != 4'b1111) next_state = SCAN_READ;

else next_state = SCAN_IDLE;

SCAN_READ : //lock the vaule

if(col_data != 4'b1111) next_state = SCAN_JTTTER2;

else next_state = SCAN_IDLE;

SCAN_JTTTER2: //when your hand is gone

if(col_data != 4'b1111) next_state = SCAN_JTTTER2;

else next_state = SCAN_IDLE;

endcase

end



關(guān)鍵詞: PLD 矩陣鍵盤

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉