Professional Documents
Culture Documents
Lab 12 Keypad
Lab 12 Keypad
EXPERIMENT 12:
Keypad
Keypad Controller for Keypad Scanning is a digital circuit designed to interface with a keypad,
scan its matrix of keys, and detect when a key is pressed. This type of controller is commonly
used in various electronic devices that require user input, such as calculators, security systems,
and electronic locks.
WORKINHG:
The Anvyl keypad has 16 labeled keys (0-F). It is set up as a matrix in which each row of buttons
from left to right are tied to a row pin, and each column from top to bottom is tied to a column
pin. This gives the user four row pins and four column pins to address a button push. When a
button is pressed, the pins corresponding to that button’s row and column are connected.
To read a button’s state, the column pin in which the button resides must be driven low while the
other three column pins are driven high. This enables all of the buttons in that column. When a
button in that column is pushed, the corresponding row pin will read logic low.
The state of all 16 buttons can be determined in a four-step process by enabling each of the four
columns one at a time. This can be accomplished by rotating an “1110” pattern through the
column pins. During each step, the logic levels of the row pins correspond to the state of the
buttons in that column. To allow simultaneous button presses in the same row, instead configure
the column pins as bi-directional with internal pull-up resistors and keep the columns not
currently being read at high impedance.
NATIONAL UNIVERSITY OF TECHNOLOGY (NUTECH)
Main IJP Road, Sector I-12, Islamabad
Telephone: 051-5476768/4576809, Fax: 051-
5476769 Website: www.nutech.edu.pk
DEPARTMENT OF ELECTRICAL ENGINEERING
VERILOG CODE:
module keypad(
input clk,
);
begin
AN =1;
end
initial
cscan = 4'b0010;
begin
case(cscan)
4'b0001:
begin
end
4'b0010:
begin
end
4'b0100:
begin
end
4'b1000:
begin
end
endcase
cscan = {cscan[2:0],cscan[3]};
end
endmodule
TEST bENCH:
`timescale 1ns / 1ps
module keypad_controller_tb;
// Define parameters
parameter CLK_PERIOD = 10; // Clock period in ns
// Declare signals
reg clk;
reg rst;
reg [3:0] row;
wire [3:0] col;
wire [7:0] seg;
Keypad_Controller dut (
.clk(clk),
.rst(rst),
.row(row),
.col(col),
.seg(seg)
);
// Clock generation
always #((CLK_PERIOD)/2) clk = ~clk;
// Reset generation
initial begin
clk = 0;
rst = 1;
#10;
rst = 0;
#1000;
$finish;
end
// Stimulus
initial begin
// Press Key 1
row = 4'b1110;
#50;
row = 4'b1111;
#50;
row = 4'b1110;
#50;
row = 4'b1111;
#50;
// Press Key 2
row = 4'b1101;
#50;
row = 4'b1111;
#50;
row = 4'b1101;
#50;
NATIONAL UNIVERSITY OF TECHNOLOGY (NUTECH)
Main IJP Road, Sector I-12, Islamabad
Telephone: 051-5476768/4576809, Fax: 051-
5476769 Website: www.nutech.edu.pk
DEPARTMENT OF ELECTRICAL ENGINEERING
row = 4'b1111;
#50;
// Press Key 3
row = 4'b1011;
#50;
row = 4'b1111;
#50;
row = 4'b1011;
#50;
row = 4'b1111;
#50;
// Press Key 4
row = 4'b0111;
#50;
row = 4'b1111;
#50;
row = 4'b0111;
#50;
row = 4'b1111;
#50;
end
endmodule
NATIONAL UNIVERSITY OF TECHNOLOGY (NUTECH)
Main IJP Road, Sector I-12, Islamabad
Telephone: 051-5476768/4576809, Fax: 051-
5476769 Website: www.nutech.edu.pk
DEPARTMENT OF ELECTRICAL ENGINEERING
##Switches
NET "read_1_in[0]" LOC= V5 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L13N_3, Sch name = SW0
NET "read_1_in[1]" LOC= U4 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L18P_3, Sch name = SW1
NET "read_1_in[2]" LOC= V3 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L18N_3, Sch name = SW2
NET "read_1_in[3]" LOC= P4 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L21P_3, Sch name = SW3
#NET "SW[4]" LOC= R4 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L21N_3, Sch name = SW4
#NET "SW[5]" LOC= P6 | IOSTANDARD=LVCMOS18;
NATIONAL UNIVERSITY OF TECHNOLOGY (NUTECH)
Main IJP Road, Sector I-12, Islamabad
Telephone: 051-5476768/4576809, Fax: 051-
5476769 Website: www.nutech.edu.pk
DEPARTMENT OF ELECTRICAL ENGINEERING
## Buttons
#NET "BTN[0]" LOC = E6 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L82P_3, Sch name = BTN0
#NET "BTN[1]" LOC = D5 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L82N_3, Sch name = BTN1
#NET "BTN[2]" LOC = A3 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L83P_3, Sch name = BTN2
#NET "BTN[3]" LOC = AB9 | IOSTANDARD=LVCMOS33;
## 7 Segment Display
NET "disp[0]" LOC=AA21 | IOSTANDARD=LVCMOS33;
#Bank = 1, pin name = IO_L63P_1, Sch name = 7SD-AA
NET "disp[1]" LOC=AA22 | IOSTANDARD=LVCMOS33;
#Bank = 1, pin name = IO_L63N_1, Sch name = 7SD-AB
NET "disp[2]" LOC=Y22 | IOSTANDARD=LVCMOS33;
#Bank = 1, pin name = IO_L59N_1, Sch name = 7SD-AC
NET "disp[3]" LOC=N15 | IOSTANDARD=LVCMOS33;
#Bank = 1, pin name = IO_L60P_1, Sch name = 7SD-AD
NET "disp[4]" LOC=AB19 | IOSTANDARD=LVCMOS33;
#Bank = 1, pin name = IO_L65P_1, Sch name = 7SD-AE
NET "disp[5]" LOC=P20 | IOSTANDARD=LVCMOS33;
NATIONAL UNIVERSITY OF TECHNOLOGY (NUTECH)
Main IJP Road, Sector I-12, Islamabad
Telephone: 051-5476768/4576809, Fax: 051-
5476769 Website: www.nutech.edu.pk
DEPARTMENT OF ELECTRICAL ENGINEERING
## Keypad
NET "cscan[0]" LOC = H8 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L58P_3, Sch name = COL1
NET "cscan[1]" LOC = J7 | IOSTANDARD=LVCMOS18;
#Bank = 3, pin name = IO_L58N_3, Sch name = COL2
NATIONAL UNIVERSITY OF TECHNOLOGY (NUTECH)
Main IJP Road, Sector I-12, Islamabad
Telephone: 051-5476768/4576809, Fax: 051-
5476769 Website: www.nutech.edu.pk
DEPARTMENT OF ELECTRICAL ENGINEERING