{"id":13729,"date":"2023-01-27T10:45:38","date_gmt":"2023-01-27T05:15:38","guid":{"rendered":"https:\/\/fastbitlab.com\/?p=13729"},"modified":"2023-08-19T14:24:56","modified_gmt":"2023-08-19T08:54:56","slug":"microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 168| Keypad key read code implementation"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 35px; border-width: 0px; line-height: 50px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #000080;\">Keypad key read code implementation<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: 0px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this article, let\u2019s code for the keypad exercise.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here I have a new project, the 011keypad, and here I have all peripheral register addresses definition, as shown below.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #ff99cc;\">int<\/span> main(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\n<span style=\"color: #008000;\">\/\/peripheral register addresses<\/span>\r\n<span style=\"color: #008000;\">uint32_t<\/span> <span style=\"color: #ff99cc;\">volatile<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pGPIODModeReg  = (<span style=\"color: #008000;\">uint32_t<\/span>*)(0x40020C00);\r\n<span style=\"color: #008000;\">uint32_t<\/span> <span style=\"color: #ff99cc;\">volatile<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pInPutDataReg  = (<span style=\"color: #008000;\">uint32_t<\/span>*)(0x40020C00+0x10);\r\n<span style=\"color: #008000;\">uint32_t<\/span> <span style=\"color: #ff99cc;\">volatile<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pOutPutDataReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)(0x40020C00+0x14);\r\n<span style=\"color: #008000;\">uint32_t<\/span> <span style=\"color: #ff99cc;\">volatile<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pClockCtrlReg  = (<span style=\"color: #008000;\">uint32_t<\/span>*)(0x40023800+0x30);\r\n<span style=\"color: #008000;\">uint32_t<\/span> <span style=\"color: #ff99cc;\">volatile<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pPullupDownReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)(0x40020C00 + 0x0C);\r\n\r\n<span style=\"color: #008000;\">\/\/1.Enable the peripheral clock of GPIOD peripheral<\/span><\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I have created a couple of pointer variables. The pointer for pull up\/pull down register is the new one. And since these are memory-mapped register access, so I have made data as volatile.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Keep all row GPIOs in OUTPUT Mode and column GPIOs in INPUT Mode<\/b><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #008000;\">\/\/1.Enable the peripheral clock of GPIOD peripheral<\/span>\r\n*pClockCtrlReg |= ( 1 &lt;&lt; 3);\r\n\r\n\r\n<span style=\"color: #008000;\">\/\/ 2.configure PD0,PD1,PD2,PD3 as output (rows)<\/span>\r\n*pGPIODModeReg &amp;= ~(0xFF); <span style=\"color: #008000;\">\/\/clear<\/span>\r\n*pGPIODModeReg |= 0x55; <span style=\"color: #008000;\">\/\/set<\/span>\r\n\r\n\r\n<span style=\"color: #008000;\">\/\/ 3. configure PD8 , PD9, PD10, PD11 as input (columns)<\/span>\r\n*pGPIODModeReg &amp;= ~(0xFF &lt;&lt; 16);\r\n\r\n<span style=\"color: #008000;\">\/\/ 4.Enable internal pull-up resistors for PD8 PD9 PD10 PD11<\/span>\r\n*pPullupDownReg &amp;= ~(0xFF &lt;&lt; 16);\r\n*pPullupDownReg |= (0x55 &lt;&lt; 16);<\/pre>\n<ol class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"font-weight: 400; color: #000000;\"> The first step is to enable the peripheral clock for GPIOD peripheral. For that, we have to refer to the clock register.&nbsp;<\/span><\/li>\n<\/ol>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>*pClockCtrlReg |= (1 &lt;&lt; 3);<\/strong><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<ol class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" start=\"2\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"font-weight: 400; color: #000000;\"> The next one is configure PD0, PD1, PD2, PD3 as output. These are our rows.&nbsp;<\/span><\/li>\n<\/ol>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, let&#8217;s refer to the mode register.<\/span><\/p>\n<figure id=\"attachment_13733\" aria-describedby=\"caption-attachment-13733\" style=\"width: 547px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-13733\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/01\/Figure-3-10.png\" alt=\"Keypad key read code implementation\" width=\"547\" height=\"303\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png 1809w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10-300x166.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10-1024x567.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10-768x425.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10-600x332.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10-1536x850.png 1536w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><figcaption id=\"caption-attachment-13733\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. GPIO Port mode register<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here MODER0 is PD0, MODER1 is PD1, MODER2 is PD2, MODER3 is PD3. We have to keep all these 01. MODER0 and MODER1 are 5 and&nbsp; MODER2 and MODER3 are 5.&nbsp; This value turns out to be 0x55. So, we have to program 0x55.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We refer to the ModeReg.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"><span style=\"color: #000080;\"><strong>*pGPIODModeReg |= 0x55;<\/strong><\/span> \/\/ This is set<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Before that, you can also clear those fields. So, it&#8217;s better if we clear those fields first.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"><span style=\"color: #000080;\"><strong>*pGPIODModeReg &amp;= ~(0xFF);<\/strong><\/span> \/\/ This is clear&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<ol class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" start=\"3\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"font-weight: 400; color: #000000;\"> After that configure PD8, PD9, PD10, PD11 as inputs( columns).&nbsp;<\/span><\/li>\n<\/ol>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For that, you have to clear all those bits.<\/span><\/p>\n<figure id=\"attachment_13734\" aria-describedby=\"caption-attachment-13734\" style=\"width: 591px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-13734\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/01\/Figure-4-7.png\" alt=\"Keypad key read code implementation\" width=\"591\" height=\"334\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-4-7.png 1741w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-4-7-300x170.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-4-7-1024x579.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-4-7-768x435.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-4-7-600x339.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-4-7-1536x869.png 1536w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><figcaption id=\"caption-attachment-13734\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. GPIO port mode register<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">PD8 starts from MODER8. MODER9 is PD9, MODER10 is PD10, MODER11 is PD11. So, all these should be zeros. That is the input mode. That means you have to clear 8 bits from the 16th-bit position onwards.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In the mode register, we are going to clear 8 consecutive bit positions, which appear 16th-bit position onwards. That&#8217;s why let&#8217;s use&nbsp; ~(0xFF &lt;&lt; 16).&nbsp; Why 16?&nbsp; Because the bit position for the 8th pin is at the 16th.&nbsp;&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>*pGPIODModeReg &amp;= ~(0xFF &lt;&lt; 16);<\/strong><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">4. Enable internal pull-up resistors for PD8, PD9, PD10, and PD11.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">Let&#8217;s refer to the GPIO port pull-up\/pull-down register.<\/span>&nbsp;<\/span><\/p>\n<figure id=\"attachment_13735\" aria-describedby=\"caption-attachment-13735\" style=\"width: 586px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-13735\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2023\/01\/Figure-5-4.png\" alt=\"Keypad key read code implementation\" width=\"586\" height=\"332\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-5-4.png 1641w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-5-4-300x170.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-5-4-1024x581.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-5-4-768x436.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-5-4-600x340.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-5-4-1536x871.png 1536w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><figcaption id=\"caption-attachment-13735\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. GPIO port pull-up\/pull-down register<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">PD8 starts from PUPDR8, PUPDR9 is PD9, PUPDR10 is PD10, PUPDR11 is PD11. And it has to be pull up, so 01. So, I had to keep all these 01 here. This happens to be 0x55, but shifted by 16.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s start with a pull-up\/pull-down register.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First, let&#8217;s clear those bit positions before setting.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"><span style=\"color: #000080;\"><strong>*pPullupDownReg &amp;= ~(0xFF &lt;&lt; 16);<\/strong><\/span> \/\/ Clear<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"><span style=\"color: #000080;\"><strong>*pPullupDownReg |= (0x55 &lt;&lt; 16);<\/strong> <\/span>\/\/Set<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px; padding-left: 40px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, that completes the initialization phase.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #db4b0d;\"><b>Make all row GPIOs high state<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">For that, I use ODR (output data register).<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>*pOutPutDataReg |= 0x0f;&nbsp;<\/strong><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #db4b0d;\"><b>Make R1 low(PD0)<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this case, R1 is PD0. Again let&#8217;s make use of the output data register we have to clear. Low means clear.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>*pOutPutDataReg &amp;= ~(1&lt;&lt;0);<\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">&amp;= ~( 1 &lt;&lt; 0) or you can simply write 1, no problem. So, that 0 has no effect.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #008000;\">\/\/make all rows HIGH<\/span>\r\n*pOutPutDataReg |= 0x0f;\r\n\r\n<span style=\"color: #008000;\">\/\/make R1 LOW(PD0)<\/span>\r\n*pOutPutDataReg &amp;= ~( 1 &lt;&lt; 0);<\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #db4b0d;\"><b>Read C1<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s scan the columns.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You have to check C1(PD8) is low or high.<\/span><\/p>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>if(!(*pInPutDataReg &amp; (1&lt;&lt;8))) {<\/strong><\/span><\/p>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>delay();<\/strong><\/span><\/p>\n<p class=\"\" style=\"padding-left: 40px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>printf(\u201c1\\n\u201d);<\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, use the if condition and dereference the input data register. And we have to test.&nbsp; Test whether the 8th-bit position is high or low. For that, we have to use bitwise &amp;(1 &lt;&lt; 8).<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">According to the flowchart we have to give a small amount of delay before printing. So, let&#8217;s give that delay here.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, if(*pInputDataReg &amp; (1&lt;&lt;8))evaluation returns 1, then C1 is high. That is PD8 high, which means the key is not pressed.&nbsp; If this expression returns 0, then you can conclude that C1 is 0. That means a key is pressed, which key? key number 1.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now we can use the not(!) operator here. If this expression is false, then this expression will be true. So, then we can conclude key is pressed.&nbsp; After that print 1 here, because the key press detected is 1.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that proceed to the next one. Check for C2. That is PD9. Let&#8217;s use the same code for C3 and C4, as shown below.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\"><span style=\"color: #008000;\">\/\/scan the columns<\/span>\r\n<span style=\"color: #008000;\">\/\/check C1(PD8) low or high<\/span>\r\n<span style=\"color: #ff99cc;\">if<\/span>(!(*pInPutDataReg &amp; ( 1 &lt;&lt; 8))){\r\n<span style=\"color: #008000;\">\/\/key is pressed<\/span>\r\ndelay();\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"1\\n\");\r\n}\r\n\r\n<span style=\"color: #008000;\">\/\/check C2(PD9) low or high<\/span>\r\n<span style=\"color: #ff99cc;\">if<\/span>(!(*pInPutDataReg &amp; ( 1 &lt;&lt; 9))){\r\n<span style=\"color: #008000;\">\/\/key is pressed<\/span>\r\ndelay();\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"2\\n\");\r\n}\r\n\r\n<span style=\"color: #008000;\">\/\/check C3(PD10) low or high<\/span>\r\n<span style=\"color: #ff99cc;\">if<\/span>(!(*pInPutDataReg &amp; ( 1 &lt;&lt; 10))){\r\n<span style=\"color: #008000;\">\/\/key is pressed<\/span>\r\ndelay();\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"3\\n\");\r\n}\r\n\r\n<span style=\"color: #008000;\">\/\/check C4(PD11) low or high<\/span>\r\n<span style=\"color: #ff99cc;\">if<\/span>(!(*pInPutDataReg &amp; ( 1 &lt;&lt; 11))){\r\n<span style=\"color: #008000;\">\/\/key is pressed<\/span>\r\ndelay();\r\n<span style=\"color: #ff00ff;\">printf<\/span>(\"A\\n\");\r\n}<\/pre>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #db4b0d;\"><b>Make R2 low(PD1)<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">R2 is PD1. So, here I have to give 1. But before that, make sure that all other rows are high. That is important.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #008000;\">\/\/make all rows HIGH<\/span>\r\n*pOutPutDataReg |= 0x0f;\r\n<span style=\"color: #008000;\">\/\/make R2 LOW(PD1)<\/span>\r\n*pOutPutDataReg &amp;= ~( 1 &lt;&lt; 1);<\/pre>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First, make all rows high, then make R2 low. And after that, you have to repeat the same logic.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">So, use the same scan the column&#8217;s logic(Figure 7). Here, again we scan C1, C2, C3, and C4. And in the printf statement, the key will be 4, 5, 6, B.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #db4b0d;\"><span style=\"text-decoration: underline;\"><b>Ma<\/b><\/span><span style=\"text-decoration: underline;\"><b>ke R3 low(PD2)<\/b><\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here in the printf statement, the key will be 7, 8, 9, C.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #db4b0d;\"><b>Make R4 low(PD3)<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px; font-size: 17px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here in the printf statement, the key will be&nbsp; *, 0, #, D.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, it should loop back. Once it loops back to the top, which is right here it has to make all rows high again. So, that&#8217;s why, I would give a while loop here while(1), as shown below.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\"><span style=\"color: #008000;\">    \/\/ 4.Enable internal pull-up resistors for PD8 PD9 PD10 PD11<\/span>\r\n    *pPullupDownReg &amp;= ~(0xFF &lt;&lt; 16);\r\n    *pPullupDownReg |= (0x55 &lt;&lt; 16);\r\n\r\n<span style=\"color: #ff99cc;\">while<\/span>(1)\r\n{\r\n    <span style=\"color: #008000;\">\/\/make all rows HIGH<\/span>\r\n   *pOutPutDataReg |= 0x0f;<\/pre>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I use the header file #include &lt;stdint.h&gt; , #include&lt;stdio.h&gt;. And use void delay(void) for the delay function.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And in the following article, let&#8217;s implement this delay.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 23px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px; border-width: 0px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span><span style=\"color: #0000ff;\">&nbsp;<\/span><\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Keypad key read code implementation &nbsp; In this article, let\u2019s code for the keypad exercise.&nbsp; Here I have a new project, the 011keypad, and here I have all peripheral register addresses definition, as shown below. int main(void) { \/\/peripheral register addresses uint32_t volatile *const pGPIODModeReg = (uint32_t*)(0x40020C00); uint32_t volatile *const pInPutDataReg = (uint32_t*)(0x40020C00+0x10); uint32_t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13733,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"enable","ocean_disable_heading":"default","ocean_post_title":"Keypad key read code implementation","ocean_post_subheading":"","ocean_post_title_style":"solid-color","ocean_post_title_background_color":"#00458e","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-13729","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Keypad Key Read Code Implementation: Step-by-Step Guide<\/title>\n<meta name=\"description\" content=\"Keypad key read code using C programming. Follow this step-by-step guide to configure GPIOs, read keypad input, and detect key presses. Get\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keypad Key Read Code Implementation: Step-by-Step Guide\" \/>\n<meta property=\"og:description\" content=\"Keypad key read code using C programming. Follow this step-by-step guide to configure GPIOs, read keypad input, and detect key presses. Get\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-27T05:15:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-19T08:54:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1809\" \/>\n\t<meta property=\"og:image:height\" content=\"1001\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 168| Keypad key read code implementation\",\"datePublished\":\"2023-01-27T05:15:38+00:00\",\"dateModified\":\"2023-08-19T08:54:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/\"},\"wordCount\":939,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/Figure-3-10.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/\",\"name\":\"Keypad Key Read Code Implementation: Step-by-Step Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/Figure-3-10.png\",\"datePublished\":\"2023-01-27T05:15:38+00:00\",\"dateModified\":\"2023-08-19T08:54:56+00:00\",\"description\":\"Keypad key read code using C programming. Follow this step-by-step guide to configure GPIOs, read keypad input, and detect key presses. Get\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/Figure-3-10.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/Figure-3-10.png\",\"width\":1809,\"height\":1001,\"caption\":\"Figure 3. GPIO Port mode register\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 168| Keypad key read code implementation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Keypad Key Read Code Implementation: Step-by-Step Guide","description":"Keypad key read code using C programming. Follow this step-by-step guide to configure GPIOs, read keypad input, and detect key presses. Get","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/","og_locale":"en_US","og_type":"article","og_title":"Keypad Key Read Code Implementation: Step-by-Step Guide","og_description":"Keypad key read code using C programming. Follow this step-by-step guide to configure GPIOs, read keypad input, and detect key presses. Get","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2023-01-27T05:15:38+00:00","article_modified_time":"2023-08-19T08:54:56+00:00","og_image":[{"width":1809,"height":1001,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 168| Keypad key read code implementation","datePublished":"2023-01-27T05:15:38+00:00","dateModified":"2023-08-19T08:54:56+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/"},"wordCount":939,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/","name":"Keypad Key Read Code Implementation: Step-by-Step Guide","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png","datePublished":"2023-01-27T05:15:38+00:00","dateModified":"2023-08-19T08:54:56+00:00","description":"Keypad key read code using C programming. Follow this step-by-step guide to configure GPIOs, read keypad input, and detect key presses. Get","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2023\/01\/Figure-3-10.png","width":1809,"height":1001,"caption":"Figure 3. GPIO Port mode register"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-168-keypad-key-read-code-implementation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 168| Keypad key read code implementation"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/13729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=13729"}],"version-history":[{"count":4,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/13729\/revisions"}],"predecessor-version":[{"id":15296,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/13729\/revisions\/15296"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/13733"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=13729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=13729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=13729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}