?? keypadscan.v
字號:
/* The following is example code that is described in the associated application note, XAPPxxx.
This code can be implemented in the smallest 32 macrocell CPLD. The application involves an 8x8
keypad (with 16 IO) that connects to the CPLD. Eight of these 16 IO are CPLD outputs that
drive the keypad rows, and the other 8 are CPLD inputs coming from the keypads columns.
This design scans the keypad rows and monitors the columns. When a key on the keypad is
pressed a connection between a row and column is made. This design deduces which key is being
pressed and generates a six bit encoded word representing that key (which is output from the CPLD).
Each key is identified by a different six bit encoded value. An 8x8 keypad can have up to 64 keys.
With a six bit encoded word, up to 63 different keys can be uniquely identified. One
state must be reserved for when no keys are pressed. This example design does not reserve a state
since this condition is beyond the scope of this reference design and can be accomplished
a variety of ways that are design dependent.
Only minimal simulations have been run on this code as it is intended to be used for
reference purposes only.
Mike Gulotta
3/3/05
*/
module KeypadScan(clk,out,row,column);
input clk;
output [5:0] out;
output [7:0] row;
input [7:0] column;
reg [7:0] shiftreg = 8'b11111110;
wire [7:0] column, row;
reg [5:0] outreg = 6'b111110;
// scan_en = 1 when all column inputs are high (ie, no keys pushed).
// In this state enable barrel shifter to shift (ie, scan rows).
assign scan_en = &column;
// Barrel shifter
// Initialized as "11111110" in the UCF.
always @(posedge clk) begin
if (scan_en) begin
shiftreg[7:0] <= {shiftreg[6:0], shiftreg[7]};
end
end
assign row = shiftreg;
// Column inputs all have internal pullups which is done in the UCF.
// Column encoder.
always @(column)
case (column)
8'b11111110: outreg[2:0] = 3'b000;
8'b11111101: outreg[2:0] = 3'b001;
8'b11111011: outreg[2:0] = 3'b010;
8'b11110111: outreg[2:0] = 3'b011;
8'b11101111: outreg[2:0] = 3'b100;
8'b11011111: outreg[2:0] = 3'b101;
8'b10111111: outreg[2:0] = 3'b110;
8'b01111111: outreg[2:0] = 3'b111;
endcase
// Row encoder.
always @(row)
case (row)
8'b11111110: outreg[5:3] = 3'b000;
8'b11111101: outreg[5:3] = 3'b001;
8'b11111011: outreg[5:3] = 3'b010;
8'b11110111: outreg[5:3] = 3'b011;
8'b11101111: outreg[5:3] = 3'b100;
8'b11011111: outreg[5:3] = 3'b101;
8'b10111111: outreg[5:3] = 3'b110;
8'b01111111: outreg[5:3] = 3'b111;
endcase
// If no keys pressed, output all 1s.
assign out = !scan_en ? outreg : 6'b111111;
endmodule
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -