module keypadscan(reset,
clk,
row,
column,
out);
// program for 4x3 keypad
input reset, clk;
output [3:0] row;
input [2:0] column; //pullup to vcc
output [3:0] out; //decoded output
reg [3:0] row;
reg [3:0] out;
wire scan_en = &column;
//scanning keypad
always @(posedge clk or posedge reset)
if (reset)
row <= 4'b1110;
else if (scan_en)
row <= {row[2:0], row[3]};
always @(row or column) begin
out = 4'b0000;
case ({row,column})
7'b1110_110 : out = 4'b0001;
7'b1110_101 : out = 4'b0010;
7'b1110_011 : out = 4'b0011;
7'b1101_110 : out = 4'b0100;
7'b1101_101 : out = 4'b0101;
7'b1101_011 : out = 4'b0110;
7'b1011_110 : out = 4'b0111;
7'b1011_101 : out = 4'b1000;
7'b1011_011 : out = 4'b1001;
7'b0111_110 : out = 4'b1110; // decode as E
7'b0111_101 : out = 4'b0000;
7'b0111_011 : out = 4'b1111; // decode as F
endcase // case({row,column})
end // always @ (row or column)
endmodule // keypadscan