You are currently viewing Matrix Keypad interfacing with CPLD Development Kit

Matrix Keypad interfacing with CPLD Development Kit

Spread the love

Matrix Keypad

Keypad is most commonly used input device in electronics. To Simply number of input keypad lines to controller device leads to formation of matrix keypad. Matrix keyboard consist of NxN number of push button arranged in rows and column. 2N is the number of lines required to get the input of NxN Push Button.

Matrix keypad consists of a set of buttons similar to an alphanumeric keyboard provided with keys usually marked with letters or numbers and various extra keys. Embedded systems which require user interaction must be interfaced with devices that accept user input such as a keypad.

Interfacing Keypad with CPLD Development Kit

The CPLD board has 4×4 Matrix Keypad, indicated as in Figure. Keypads arranged by matrix format, each row and column section pulled by high, all row lines and column lines connected directly by the I/O pins.

Matrix Keypad Placement in CPLD Development Kit

VHDL Code Description for Matrix Keypad to LED Interface

The CPLD Scan continuously for key press. Once the NxN key pressed the following key press will be represented in 4- bit binary value and displayed in the LED’s.

VHDL Code for Matrix Keypad to LED Interface

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating

---- any Xilinx primitives in this code. --library UNISIM;

--use UNISIM.VComponents.all;

LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL;

USE IEEE.STD_LOGIC_ARITH.ALL;

USE IEEE.STD_LOGIC_UNSIGNED.ALL;

entity matrix_keypad is port( clock,rst : in std_logic;

col_line : in std_logic_vector(3 downto 0);

row_line : out std_logic_vector(3 downto 0);

led : out std_logic_vector(15 downto 0) );

end matrix_keypad;

architecture Behavioral of matrix_keypad is signal temp : std_logic_vector(29 downto 0);

begin test: process(clock,rst) is begin if(rst='0')

then led <= "1111111111111111";

elsif rising_edge(clock) then temp <= temp + 1;

case temp(10 downto 8) is when "000" => row_line <= "0111";

--first row when "001" => if col_line = "0111" then led <= "0011001100110011";

-- 3 elsif col_line = "1011" then led <= "0010001000100010";

-- 2 elsif col_line = "1101" then led <= "0001000100010001";

-- 1 elsif col_line = "1110" then led <= "0000000000000000";

-- 0 end if; when "010" => row_line <= "1011";

--second row when "011" => if col_line = "1110" then led <= "0100010001000100";

-- 4 elsif col_line = "1101" then led <= "0101010101010101";

-- 5 elsif col_line = "1011" then led <= "0110011001100110";

-- 6 elsif col_line = "0111" then led <= "0111011101110111";

-- 7 end if; when "100" => row_line <= "1101";

--third row when "101" => if col_line = "1110" then led <= "1000100010001000";

-- 8 elsif col_line = "1101" then led <= "1001100110011001";

-- 9 elsif col_line = "1011" then led <= "1010101010101010";

-- a elsif col_line = "0111" then led <= "1011101110111011";

-- b end if; when "110" => row_line <= "1110";

--fourth row when "111" => if col_line = "1110" then led <= "1100110011001100";

-- C elsif col_line = "1101" then led <= "1101110111011101";

-- d elsif col_line = "1011" then led <= "1110111011101110";

-- e elsif col_line = "0111" then led <= "1111111111111111";

-- f end if; when others => led <= "0000000000000000";

end case;

end if;

end process;

end Behavioral; 

User Constraint File

NET "row_line(0)" LOC = "p113";

NET "row_line(1)" LOC = "p112";

NET "row_line(2)" LOC = "p111";

NET "row_line(3)" LOC = "p110";

NET "clock" LOC = "p3" ;

NET "col_line(0)" LOC = "p109" ;

NET "col_line(1)" LOC = "p107" ;

NET "col_line(2)" LOC = "p106" ;

NET "col_line(3)" LOC = "p103" ;

NET "led[0]" LOC = P35;

NET "led[1]" LOC = P36;

NET "led[2]" LOC = P37;

NET "led[3]" LOC = P38;

NET "led[4]" LOC = P39;

NET "led[5]" LOC = P40;

NET "led[6]" LOC = P41;

NET "led[7]" LOC = P43;

NET "led[8]" LOC = P54;

NET "led[9]" LOC = P55;

NET "led[10]" LOC = P56;

NET "led[11]" LOC = P57;

NET "led[12]" LOC = P58;

NET "led[13]" LOC = P60;

NET "led[14]" LOC = P61;

NET "led[15]" LOC = P62;

NET "rst" LOC = p44 ;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.