{"id":12453,"date":"2022-11-23T12:21:40","date_gmt":"2022-11-23T06:51:40","guid":{"rendered":"https:\/\/fastbitlab.com\/?p=12453"},"modified":"2023-08-22T14:45:08","modified_gmt":"2023-08-22T09:15:08","slug":"microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 134| IO pin read exercise 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: 31px; border-width: 0px; line-height: 45px;\"><strong><span style=\"color: #000080;\">IO pin read exercise implementation<\/span><\/strong><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\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: 16px; line-height: 31px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In this article, let\u2019s implement the below exercise.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: Merriweather; font-weight: 400; font-size: 20px; line-height: 30px;\" data-font-family=\"Merriweather\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><b>Exercise:<\/b><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<ul class=\"\" style=\"border-width: 0px; font-size: 17px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Write a program which reads the status of the pin PA0. If the status of PA0 is LOW, then turn off the onboard LED(PD12) and if the status of the PA0 is HIGH, then turn on the LED.&nbsp;<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Change the status of PA0 pin manually by connecting between GND and VDD points of the board.<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 17px; line-height: 30px;\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Code<\/strong><\/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;\">#include<\/span>&lt;stdint.h&gt;\r\n\r\n<span style=\"color: #ff99cc;\">int<\/span> main(<span style=\"color: #ff99cc;\">void<\/span>)\r\n{\r\n    <span style=\"color: #008000;\">uint32_t<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pClkCtrlReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)0x40023830;\r\n <span style=\"color: #008000;\">   uint32_t&nbsp;<\/span> *<span style=\"color: #ff99cc;\">const<\/span> pPortDModeReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)0x40020C00;\r\n    <span style=\"color: #008000;\">uint32_t<\/span>&nbsp; *<span style=\"color: #ff99cc;\">const<\/span> pPortDOutReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)0x40020C14;\r\n   <span style=\"color: #008000;\"> uint32_t<\/span>&nbsp; *<span style=\"color: #ff99cc;\">const<\/span> pPortAModeReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)0x40020000;\r\n    <span style=\"color: #008000;\">uint32_t<\/span>  *<span style=\"color: #ff99cc;\">const<\/span> pPortAInReg = (<span style=\"color: #008000;\">uint32_t<\/span>*)0x40020010;\r\n\r\n<span style=\"color: #008000;\">\/\/1.enable the clock for GPOID , GPIOA peripherals in the AHB1ENR<\/span>\r\n    *pClkCtrlReg |= ( 1 &lt;&lt; 3);\r\n    *pClkCtrlReg |= ( 1 &lt;&lt; 0);\r\n\r\n<span style=\"color: #008000;\">\/\/2.configuring PD12 as output<\/span>\r\n    *pPortDModeReg &amp;= ~( 3 &lt;&lt; 24);\r\n<span style=\"color: #008000;\">\/\/3.make 24th bit position as 1 (SET)<\/span>\r\n    *pPortDModeReg |= ( 1 &lt;&lt; 24);\r\n\r\n<span style=\"color: #008000;\">\/\/4.Configure PA0 as input mode (GPIOA MODE REGISTER)<\/span>\r\n    *pPortAModeReg &amp;= ~(3 &lt;&lt; 0);\r\n\r\n  <span style=\"color: #ff99cc;\">while<\/span>(1)\r\n  {\r\n    <span style=\"color: #008000;\">\/\/5.read the pin status of the pin PA0 (GPIOA INPUT DATA REGISTER)<\/span>\r\n     <span style=\"color: #008000;\"> uint8_t<\/span> pinStatus = (<span style=\"color: #008000;\">uint8_t<\/span>)(*pPortAInReg &amp; 0x1); <span style=\"color: #008000;\">\/\/zero out all other bits except bit 0<\/span>\r\n\r\n <span style=\"color: #ff99cc;\"> if<\/span>(pinStatus){\r\n    <span style=\"color: #008000;\">\/\/turn on the LED<\/span>\r\n    *pPortDOutReg |= ( 1 &lt;&lt; 12);\r\n  }<span style=\"color: #ff99cc;\">else<\/span>{\r\n   <span style=\"color: #008000;\"> \/\/turn off the LED<\/span>\r\n    *pPortDOutReg &amp;= ~( 1 &lt;&lt; 12);\r\n }\r\n}\r\n}<\/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=\"\"><strong><span style=\"color: #000000;\">1. Enable the clock for GPIOD, GPIOA peripherals in the AHB1ENR.<\/span><\/strong><\/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;\">First, turn on the clock for that. This register will be the same because all these GPIO peripherals are hanging on the AHB1 bus. So, the register will be the same but the bit fields may be different.<\/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 explore what we should do for GPIOD and GPIOA peripherals.&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;\">Look at the reference manual of the microcontroller to understand the AHB1ENR register, as shown in Figure 1. The bit position 3 was for GPIOD, the bit position 0 is for GPIOA.<\/span><\/p>\n<figure id=\"attachment_12459\" aria-describedby=\"caption-attachment-12459\" style=\"width: 654px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-12459\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/11\/Figure-2-6.png\" alt=\"IO pin read exercise implementation\" width=\"654\" height=\"249\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.png 1165w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6-300x114.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6-1024x389.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6-768x292.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6-600x228.png 600w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/><figcaption id=\"caption-attachment-12459\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. User manual<\/span><\/figcaption><\/figure>\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;\">*pClkCtrlReg |= (1 &lt;&lt; 3) is for GPIOD and *pClkCtrlReg |= (1 &lt;&lt; 0) is for GPIOA.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>2. Configure PD12 as output<\/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;\">pPortDModeReg &amp;= ~(3 &lt;&lt; 24);&nbsp;&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>3. Make the 24th bit position as 1(SET)<\/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;\">pPortDModeReg |= (1 &lt;&lt; 24);<\/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;\">These codes are for Port D pin number 12. That is for our LED. This code is for configuring PD12 as output.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 25px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>4. Configure PA0 as input mode (GPIOA MODE REGISTER)<\/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;\">Now, let&#8217;s implement the code to configuring PA0 as input.<\/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 this, we have to explore the GPIOA mode register. So, let&#8217;s create a variable to store the address of the GPIOA mode 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=\"font-weight: 400; color: #000000;\">Here, 0x40020C00 is an address of the GPIOD mode register. We have to create another pointer to store the address of the GPIOA mode register. That&#8217;s why let&#8217;s create one variable.<\/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;\">uint32_t *pPortAModeReg = (uint32_t*)0x40020000;<\/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;\">The address of the mode register of GPIO Port A is 0x40020000.&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;\">For the GPIO Port A mode register address we have to refer to the reference manual of the microcontroller. Here we have to first go and explore the Memory map to understand the base address of the GPIOA peripheral registers.<\/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 go to the Memory and bus architecture, Memory map, and let&#8217;s see where exactly GPIOA is placed, as shown in Figure 2.&nbsp;<\/span><\/p>\n<figure id=\"attachment_12461\" aria-describedby=\"caption-attachment-12461\" style=\"width: 648px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-12461\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/11\/Figure-4-3.png\" alt=\"IO pin read exercise implementation\" width=\"648\" height=\"355\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-4-3.png 1863w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-4-3-300x164.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-4-3-1024x560.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-4-3-768x420.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-4-3-600x328.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-4-3-1536x840.png 1536w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><figcaption id=\"caption-attachment-12461\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. User manual <\/span><\/figcaption><\/figure>\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=\"color: #ff0000;\"><strong>What is the offset of the mode register?&nbsp;<\/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;\">The mode register is always at offset 00. So, for every GPIO peripheral, the mode register is at the offset 0 but from different base addresses( Figure 3).<\/span><\/p>\n<figure id=\"attachment_12462\" aria-describedby=\"caption-attachment-12462\" style=\"width: 677px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-12462\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/11\/Figure-5-2.png\" alt=\"IO pin read exercise implementation\" width=\"677\" height=\"335\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-5-2.png 1243w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-5-2-300x148.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-5-2-1024x507.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-5-2-768x380.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-5-2-600x297.png 600w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><figcaption id=\"caption-attachment-12462\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Offset of the mode register<\/span><\/figcaption><\/figure>\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;\">That&#8217;s why the offset is 0.&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;\">MODER0[1:0] is the place for configuring mode for pin number 0. You have to keep these two bits(0 1) cleared to set the pin mode to input.&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;\">Let&#8217;s use * pPortAModeReg &amp;=&nbsp; ~(3 &lt;&lt; 0);<\/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;\">That clears the first two positions of the Port A mode register.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 25px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><b>5. Read the pin status of the pin PA0( GPIOA INPUT DATA REGISTER)<\/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;\">After that, you have to read the pin status of the pin PA0.&nbsp;&nbsp;<\/span><\/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;\">For this, you have to refer to the GPIOA INPUT DATA REGISTER.<\/span><\/p>\n<figure id=\"attachment_12464\" aria-describedby=\"caption-attachment-12464\" style=\"width: 1591px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-12464 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/11\/Figure-6-1.png\" alt=\"GPIO port input data register\" width=\"1591\" height=\"915\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-6-1.png 1591w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-6-1-300x173.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-6-1-1024x589.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-6-1-768x442.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-6-1-600x345.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-6-1-1536x883.png 1536w\" sizes=\"(max-width: 1591px) 100vw, 1591px\" \/><figcaption id=\"caption-attachment-12464\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. GPIO port input data register<\/span><\/figcaption><\/figure>\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;\">Now let&#8217;s explore the input data register. Let&#8217;s go to the GPIO section in the reference manual of the microcontroller and in the GPIO section you get the input data register, as shown in Figure 4. You can see that this is a read-only register, you cannot write into this 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=\"font-weight: 400; color: #000000;\">Let\u2019s say Whenever you connect the pin PA0 to high voltage(that is VDD), then the corresponding bit position in this register will be set.&nbsp; In this case, the bit position 0 will be set because we are dealing with pin PA0.&nbsp;&nbsp;<\/span><\/p>\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;\">If it is PA1, then bit position 1 will be set if the pin is connected to +VDD.&nbsp; And if you connect the pin to GND, then the corresponding position will be reset.<\/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 first, we have to find out the address of the Port A input data register.&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;\">So, let&#8217;s create one more variable GPIOA InReg.<\/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;\">uint32_t *pPortAInReg = (uint32_t*)0x40020010;<\/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;\">The offset is 0x10. That&#8217;s why let me put 10 at the end.&nbsp;<\/span><\/p>\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;\">After that, create a variable uint8_t pinStatus = (uint8_t)(*pPortAInReg &amp; 0x1)<\/span><\/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;\">we have to read this pPortInReg.<\/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;\">When you do this you get 32 bits of data, but what we want is just 1 bit the status of bit position 0. So, we can do masking to 0 out of all other bits except the bit position 0. That&#8217;s why we write &amp; 0x1.&nbsp; This will 0 out all the bits except the bit position 0.&nbsp; And after that let me just typecast this to uint8_t.<\/span><\/p>\n<figure id=\"attachment_12465\" aria-describedby=\"caption-attachment-12465\" style=\"width: 710px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-12465\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/11\/Figure-7.png\" alt=\"IO pin read exercise implementation\" width=\"710\" height=\"304\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-7.png 1473w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-7-300x129.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-7-1024x439.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-7-768x329.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-7-600x257.png 600w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><figcaption id=\"caption-attachment-12465\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Code <\/span><\/figcaption><\/figure>\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;\">After that, let&#8217;s implement decision-making. If pin status is non-zero, then turn on the LED else turn off the LED.<\/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;\">To turn on the LED, we have *pPortDOutReg |= (1 &lt;&lt; 12) and to turn off the LED we have this code *pPortDOutReg &amp;= ~( 1 &lt;&lt; 12 ).<\/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;\">This should work forever. That&#8217;s why let&#8217;s keep while(1) in a super loop.<\/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;\">This should happen again and again, you have to read the pin status and take the decision. This should happen forever. So, let&#8217;s implement the infinite while loop.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 19px; border-width: 0px;\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"font-size: 17px;\"><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; IO pin read exercise implementation &nbsp; &nbsp; In this article, let\u2019s implement the below exercise.&nbsp; &nbsp; Exercise:&nbsp; Write a program which reads the status of the pin PA0. If the status of PA0 is LOW, then turn off the onboard LED(PD12) and if the status of the PA0 is HIGH, then turn on the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12459,"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":"IO pin read exercise implementation","ocean_post_subheading":"","ocean_post_title_style":"solid-color","ocean_post_title_background_color":"#00c6c9","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-12453","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>IO pin read exercise implementation<\/title>\n<meta name=\"description\" content=\"IO pin read exercise implementation. This tutorial guides you through reading the status of a GPIO pin, controlling an onboard LED based on\" \/>\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-134-io-pin-read-exercise-implementation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"IO pin read exercise implementation\" \/>\n<meta property=\"og:description\" content=\"IO pin read exercise implementation. This tutorial guides you through reading the status of a GPIO pin, controlling an onboard LED based on\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-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=\"2022-11-23T06:51:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-22T09:15:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1165\" \/>\n\t<meta property=\"og:image:height\" content=\"443\" \/>\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-134-io-pin-read-exercise-implementation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 134| IO pin read exercise implementation\",\"datePublished\":\"2022-11-23T06:51:40+00:00\",\"dateModified\":\"2023-08-22T09:15:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/\"},\"wordCount\":964,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Figure-2-6.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-134-io-pin-read-exercise-implementation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/\",\"name\":\"IO pin read exercise implementation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Figure-2-6.png\",\"datePublished\":\"2022-11-23T06:51:40+00:00\",\"dateModified\":\"2023-08-22T09:15:08+00:00\",\"description\":\"IO pin read exercise implementation. This tutorial guides you through reading the status of a GPIO pin, controlling an onboard LED based on\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Figure-2-6.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Figure-2-6.png\",\"width\":1165,\"height\":443,\"caption\":\"Figure 2. User manual\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 134| IO pin read exercise 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":"IO pin read exercise implementation","description":"IO pin read exercise implementation. This tutorial guides you through reading the status of a GPIO pin, controlling an onboard LED based on","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-134-io-pin-read-exercise-implementation\/","og_locale":"en_US","og_type":"article","og_title":"IO pin read exercise implementation","og_description":"IO pin read exercise implementation. This tutorial guides you through reading the status of a GPIO pin, controlling an onboard LED based on","og_url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-11-23T06:51:40+00:00","article_modified_time":"2023-08-22T09:15:08+00:00","og_image":[{"width":1165,"height":443,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.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-134-io-pin-read-exercise-implementation\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 134| IO pin read exercise implementation","datePublished":"2022-11-23T06:51:40+00:00","dateModified":"2023-08-22T09:15:08+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/"},"wordCount":964,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.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-134-io-pin-read-exercise-implementation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/","url":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/","name":"IO pin read exercise implementation","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.png","datePublished":"2022-11-23T06:51:40+00:00","dateModified":"2023-08-22T09:15:08+00:00","description":"IO pin read exercise implementation. This tutorial guides you through reading the status of a GPIO pin, controlling an onboard LED based on","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/11\/Figure-2-6.png","width":1165,"height":443,"caption":"Figure 2. User manual"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/microcontroller-embedded-c-programming-lecture-134-io-pin-read-exercise-implementation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 134| IO pin read exercise 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\/12453","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=12453"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/12453\/revisions"}],"predecessor-version":[{"id":15562,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/12453\/revisions\/15562"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/12459"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=12453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=12453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=12453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}