{"id":8640,"date":"2014-05-17T13:42:57","date_gmt":"2014-05-17T17:42:57","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=8640"},"modified":"2014-05-17T13:56:22","modified_gmt":"2014-05-17T17:56:22","slug":"mm74c922n-based-encoded-matrix-keypad","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/mm74c922n-based-encoded-matrix-keypad\/","title":{"rendered":"MM74C922N-based encoded matrix keypad"},"content":{"rendered":"<p>Matrix keypads are an excellent way of providing user input data into microcontroller-based systems. Keypads find applications in remote controls, standalone data-loggers, security systems, door entry systems, calculators, microwave ovens, etc. They are usually implemented as pushbutton switches arranged in a row and column matrix format to reduce the number of I\/O connections. For example, a 16-switch keypad is arranged in a 4 X 4 matrix format requiring 8 I\/O connections. A pressed key is detected and identified by scanning the keypad to look for a short circuit condition between a row and a column wire. The keypad scanning can be done either by polling or by means of an interrupt routine. In the polling approach, the scanning process is repeated in a continuous loop, which results in waste of CPU time. The interrupt-approach is more efficient and it notifies the processor when there is a keystroke. Another approach of interfacing a keypad to the microcontroller is by using a dedicated keypad encoder IC, which further reduces the I\/O connections and makes the interface much simpler. In this project, we are building a simplified 16-switch keypad using the MM74C922 encoder chip, which converts a key switch closure to a 4-bit nibble output.<\/p>\n<div id=\"attachment_8676\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8676\" rel=\"attachment wp-att-8676\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8676\" class=\"size-full wp-image-8676\" alt=\"MM74C22N based encoded keypad\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoderTitle.jpg\" width=\"580\" height=\"462\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoderTitle.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoderTitle-550x438.jpg 550w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-8676\" class=\"wp-caption-text\">MM74C922N based encoded keypad<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Theory<\/strong><\/p>\n<p>The <a href=\"http:\/\/www.fairchildsemi.com\/ds\/MM\/MM74C922.pdf\" target=\"_blank\"><strong>MM74C922<\/strong><\/a>\u00a0chip is available in 18-pin DIP and 20-pin SOIC packages. This project uses the DIP version, which has the pin configuration as shown below.<\/p>\n<div id=\"attachment_8693\" style=\"width: 452px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8693\" rel=\"attachment wp-att-8693\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8693\" class=\"size-full wp-image-8693\" alt=\"Pin diagram of MM74C922 DIP \" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/PinDiagram.png\" width=\"442\" height=\"411\" \/><\/a><p id=\"caption-attachment-8693\" class=\"wp-caption-text\">Pin diagram of MM74C922 DIP<\/p><\/div>\n<p>The\u00a0<a href=\"http:\/\/www.fairchildsemi.com\/ds\/MM\/MM74C922.pdf\" target=\"_blank\"><strong>MM74C922<\/strong><\/a>\u00a0encoder\u00a0implements all the logic necessary to interface a 16-key switch matrix to a digital system. The encoder chip continuously scans the keypad waiting for a key press. When a switch is pressed, it provides a 4-bit nibble corresponding to the pressed switch at its output pins D, B, C, and A (14-17).\u00a0 The chip has a built-in debounce circuit, which requires a single external capacitor to be connected to Keybounce Mask pin (6) to operate. The value of the capacitor depends on the required debounce time. When a valid key press is detected and the key bounce circuit times out, the encoded data is latched to the output port and the Data Available (DAV) pin (11) goes high. The DAV pin falls back low when the pressed key is released. The DAV output can be thus used as an interrupt signal for the processor when there is a keystroke. The latched output remains active at pins A through D even after the key is lifted. New data will be available at a new keystroke. The chip also has the two-key rollover feature, which disregards any second key press during an active keystroke. The keypad scanning rate is also configurable through an external capacitor connected to the Oscillator pin (5). The graphs below show the dependency of debounce time and scan rate on the respective capacitor values.<\/p>\n<div id=\"attachment_8689\" style=\"width: 595px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8689\" rel=\"attachment wp-att-8689\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8689\" class=\"size-full wp-image-8689\" alt=\"Recomment\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/capvalues.png\" width=\"585\" height=\"310\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/capvalues.png 585w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/capvalues-550x291.png 550w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><\/a><p id=\"caption-attachment-8689\" class=\"wp-caption-text\">Debounce time and scan rate as functions of capacitors<\/p><\/div>\n<p><strong>Circuit diagram<\/strong><\/p>\n<p>The circuit diagram of this project is shown below. The capacitor values selected for Debounce Mask and Oscillator pins are 1uF and 0.1uF, respectively. This sets the debounce time to approximately 10 ms and the keypad scan rate to about 600 Hz (from the above graphs). An LED connected to the DAV pin serves as a visual indicator when a valid key press is detected.<\/p>\n<div id=\"attachment_8697\" style=\"width: 589px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8697\" rel=\"attachment wp-att-8697\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8697\" class=\"size-full wp-image-8697 \" alt=\"aa\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/Circuit_Encoder21.png\" width=\"579\" height=\"489\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/Circuit_Encoder21.png 579w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/Circuit_Encoder21-550x464.png 550w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/a><p id=\"caption-attachment-8697\" class=\"wp-caption-text\">16-switch encoded keypad circuit diagram<\/p><\/div>\n<p>The 16 switches in the above arrangement are named 0-9, *, #, and A-D. The following table shows the HEX values of the output nibble corresponding to each key presses.<\/p>\n<div id=\"attachment_8650\" style=\"width: 565px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8650\" rel=\"attachment wp-att-8650\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8650\" class=\"size-full wp-image-8650\" alt=\"asas\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/LookUpTable.png\" width=\"555\" height=\"681\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/LookUpTable.png 555w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/LookUpTable-529x650.png 529w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/a><p id=\"caption-attachment-8650\" class=\"wp-caption-text\">Table showing the nibble output for each individual key press on the matrix<\/p><\/div>\n<p>The following pictures show assembled circuit board of this project. I am using 12mm x 12mm tact switches with plastic caps and transparent covers on top.<\/p>\n<div style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8645\" rel=\"attachment wp-att-8645\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder4-550x394.jpg\" width=\"550\" height=\"394\" \/><\/a><p class=\"wp-caption-text\">Assembled encoded matrix keypad uses 12mm x 12mm tact switches<\/p><\/div>\n<div id=\"attachment_8644\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8644\" rel=\"attachment wp-att-8644\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8644\" class=\"size-medium wp-image-8644 \" alt=\"sasas\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder3-550x402.jpg\" width=\"550\" height=\"402\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder3-550x402.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder3.jpg 800w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-8644\" class=\"wp-caption-text\">Assembled encoded matrix keypad with caps and plastic covers on top of switches<\/p><\/div>\n<p>We can put small paper cuts between the yellow cap and top plastic cover to label the keys like shown below.<\/p>\n<div id=\"attachment_8679\" style=\"width: 497px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8679\" rel=\"attachment wp-att-8679\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8679\" class=\"size-medium wp-image-8679\" alt=\"Key labeling\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncodersetup-487x650.jpg\" width=\"487\" height=\"650\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncodersetup-487x650.jpg 487w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncodersetup-767x1024.jpg 767w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncodersetup.jpg 800w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/a><p id=\"caption-attachment-8679\" class=\"wp-caption-text\">Keypad labeling<\/p><\/div>\n<p><strong>Interfacing example<\/strong><\/p>\n<p>In this section, I will demonstrate how to interface this matrix keypad to a host microcontroller. I am using Arduino platform here but the same logic can be extended to any other microcontroller platform. The keypad is powered with 5V supply from the Arduino board. The DAV output pin goes to INT0 (digital I\/O pin 2) pin of the Arduino board. This means that whenever a keystroke is detected, the Arduino will be interrupted to read the pressed key value. The encoder output pins A, B, C, and D are connected to Arduino digital I\/O pins 7, 6, 5, and 4, respectively. The following picture shows the complete setup of this demo project. The detected keystroke is displayed on Serial Monitor window on PC.<\/p>\n<div id=\"attachment_8678\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8678\" rel=\"attachment wp-att-8678\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8678\" class=\"size-full wp-image-8678\" alt=\"Interfacing with Arduino\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoderArduino.jpg\" width=\"580\" height=\"457\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoderArduino.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoderArduino-550x433.jpg 550w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-8678\" class=\"wp-caption-text\">Interfacing with Arduino board<\/p><\/div>\n<p>The Arduino sketch for this demo project is very simple. An interrupt service routine is written to read the encoder output (A-D) when a keystroke is detected (at the falling edge of the DAV pulse). The encoded nibble are mapped to the key names on the matrix through a look-up table.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/uploads\/Misc\/MM74C922N_Demo.zip\"><strong>Download Arduino Demo Sketch \u00a0\u00a0<\/strong><\/a><\/p>\n<p>The following screenshot is of the serial monitor window on my PC that shows the detected keystrokes and their names and hex values, as discussed before.<\/p>\n<div id=\"attachment_8680\" style=\"width: 363px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8680\" rel=\"attachment wp-att-8680\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8680\" class=\"size-full wp-image-8680\" alt=\"Pressed keys displayed on Serial Monitor window\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/UARTterm.png\" width=\"353\" height=\"651\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/UARTterm.png 353w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/UARTterm-352x650.png 352w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/a><p id=\"caption-attachment-8680\" class=\"wp-caption-text\">Pressed keys displayed on Serial Monitor window<\/p><\/div>\n<div id=\"attachment_8677\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8677\" rel=\"attachment wp-att-8677\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8677\" class=\"size-full wp-image-8677\" alt=\"Led turns on when a key is pressed\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder7.jpg\" width=\"580\" height=\"453\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder7.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder7-550x429.jpg 550w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-8677\" class=\"wp-caption-text\">Led turns on when a key is pressed<\/p><\/div>\n<p>You can also buy the 4 x 4 encoded keypad from our <a href=\"https:\/\/www.tindie.com\/stores\/rajbex\/\" target=\"_blank\"><strong>Tindie store<\/strong><\/a>. You will receive an assembled and tested board with 16 sets of free plastic caps and transparent covers.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/encoded-matrix-keypad-16-switch\/\" target=\"_blank\"><strong>Buy 16-switch encoded keypad<\/strong><\/a><\/p>\n<div id=\"attachment_8646\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8646\" rel=\"attachment wp-att-8646\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8646\" class=\"size-medium wp-image-8646\" alt=\"asasa\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder5-550x323.jpg\" width=\"550\" height=\"323\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder5-550x323.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/KeyPadEncoder5.jpg 800w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-8646\" class=\"wp-caption-text\">16-switch encoded keypad kit<\/p><\/div>\n<div id=\"attachment_8725\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/?attachment_id=8725\" rel=\"attachment wp-att-8725\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-8725\" class=\"size-medium wp-image-8725\" alt=\"Quick reference sheet\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/ReferenceSheetEncodedKeypad-550x399.jpg\" width=\"550\" height=\"399\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/ReferenceSheetEncodedKeypad-550x399.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/05\/ReferenceSheetEncodedKeypad.jpg 787w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-8725\" class=\"wp-caption-text\">Quick reference sheet<\/p><\/div>\n<p style=\"text-align: center;\">\u00a0<a href=\"https:\/\/www.tindie.com\/products\/rajbex\/encoded-matrix-keypad-16-switch\/\" target=\"_blank\"><strong>Buy 16-switch encoded keypad<\/strong><\/a><\/p>\n<p style=\"text-align: center;\">\n","protected":false},"excerpt":{"rendered":"<p>Matrix keypads are an excellent way of providing user input data into microcontroller-based systems. Keypads find applications in remote controls, standalone data-loggers, security systems, door entry systems, calculators, microwave ovens, etc. They are usually implemented as pushbutton switches arranged in a row and column matrix format to reduce the number of I\/O connections. For example, a 16-switch keypad is arranged in a 4 X 4 matrix format requiring 8 I\/O connections. A pressed key is detected and identified by scanning the keypad to look for a short circuit condition between a row and a column wire. The keypad scanning can<\/p>\n","protected":false},"author":1,"featured_media":8642,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[437],"tags":[769,323,768],"class_list":["post-8640","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-products","tag-encoder","tag-matrix-keypad","tag-mm74c922"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=8640"}],"version-history":[{"count":18,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8640\/revisions"}],"predecessor-version":[{"id":8726,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8640\/revisions\/8726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/8642"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=8640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=8640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=8640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}