module
KeyPadEncoder
// Encodes the ten keypad lines into a four-bit binary value.
// NOTES:
// 1. Higher digits have higher priority on multiple keypress
// 2. 'KeyValue' should not be used unless 'KeyIsPressed' is asserted
(
// Data inputs:
iD$KeyPad, // Keypad lines (10-bit bus)
// Condition signals to controller:
oS$KeyIsPressed, // Asserted when any key is pressed
// Data outputs:
oD$KeyValue // Value of key that is pressed; only valid
// when KeyIsPressed is asserted.
);
input [9:0] iD$KeyPad;
output oS$KeyIsPressed;
output [3:0] oD$KeyValue;
reg oS$KeyIsPressed;
reg [3:0] oD$KeyValue;
always @ (iD$KeyPad) begin
casez (iD$KeyPad)
10'b1????????? : oD$KeyValue <= 4'd9;
10'b01???????? : oD$KeyValue <= 4'd8;
10'b001??????? : oD$KeyValue <= 4'd7;
10'b0001?????? : oD$KeyValue <= 4'd6;
10'b00001????? : oD$KeyValue <= 4'd5;
10'b000001???? : oD$KeyValue <= 4'd4;
10'b0000001??? : oD$KeyValue <= 4'd3;
10'b00000001?? : oD$KeyValue <= 4'd2;
10'b000000001? : oD$KeyValue <= 4'd1;
10'b0000000001 : oD$KeyValue <= 4'd0;
default : oD$KeyValue <= 4'd0;
endcase
oS$KeyIsPressed <= iD$KeyPad != 0;
end
endmodule
This page: |
Created: | Thu Jan 16 14:38:01 2003 |
|
From: |
keypad_encoder.v |