{"id":501,"date":"2021-08-21T17:45:12","date_gmt":"2021-08-21T15:45:12","guid":{"rendered":"https:\/\/automatico.freevar.com\/?page_id=501"},"modified":"2021-09-28T11:49:55","modified_gmt":"2021-09-28T09:49:55","slug":"mcp-23017-gpio","status":"publish","type":"page","link":"https:\/\/automatico.freevar.com\/index.php\/z80-mbc2\/mcp-23017-gpio\/","title":{"rendered":"MCP 23017 GPIO"},"content":{"rendered":"<p><span style=\"font-size: 14pt;\">The MCP23017 integrated circuit is a micro-controller manufactured by PIC and is a digital port expander with i\u00a0<sup>2<\/sup> c communication protocol (Philips 1982). Allows you to control 16 individually configurable inputs \/ outputs. The I \/ O terminals are divided into two groups of ports of 8 bits each (GPIOA and GPIOB). Let&#8217;s see the technical characteristics that this micro-controller has:<\/span><\/p>\n<ul>\n<li class=\"western\"><span style=\"font-size: 14pt;\">Power supply from 1.8V to 5.5V<\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">Each pin can handle up to 25 mA in both output and input<\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">Maximum global current of 150 mA towards ground and 125 mA\u00a0<span lang=\"it-IT\">towards the power supply positive.<\/span><\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">V\u00a0<sub>IL<\/sub>\u00a0\u00a0= 0.2 *\u00a0<sub>Vdc<\/sub>\u00a0(1V with 5V of\u00a0<sub>Vdc<\/sub>\u00a0)<\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">V\u00a0<sub>IH<\/sub>\u00a0\u00a0= 0.8 *\u00a0<sub>Vdc<\/sub>\u00a0(4V with 5V of\u00a0<sub>Vdc<\/sub>\u00a0)<\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">V\u00a0<sub>OL<\/sub>\u00a0\u00a0= 0.6V<\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">V\u00a0<sub>OH<\/sub>\u00a0\u00a0=\u00a0<sub>Vdc<\/sub>\u00a0-0.7 (4.3V with 5V of\u00a0<sub>Vdc<\/sub>\u00a0)<\/span><\/li>\n<li class=\"western\"><span style=\"font-size: 14pt;\">4 kV ESD protection<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 14pt;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-502 size-medium\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-21_172856-300x244.png\" alt=\"\" width=\"300\" height=\"244\" srcset=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-21_172856-300x244.png 300w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-21_172856-768x624.png 768w, https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/immagine_2021-08-21_172856.png 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><span class=\"\">In the drawing beside we see the group A and B of the General Purpuse, Serial CLock and Serial DAta pins, two Interrupt pins and the A0-A1-A2 addressing.<\/span><\/span><\/p>\n<p><span class=\"VIiyi\" lang=\"it\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"it\" data-language-to-translate-into=\"en\" data-phrase-index=\"0\">The interrupts detected by two pins INTA and INTB, can be associated with the respective ports or can be logically linked so that both pins are activated if one of the ports causes an interruption.<\/span><\/span><\/p>\n<p><span class=\"VIiyi\" lang=\"it\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"it\" data-language-to-translate-into=\"en\" data-phrase-index=\"0\">The interrupt output can be configured to activate in two conditions (mutually exclusive):<\/span><\/span><\/p>\n<ul>\n<li><span style=\"font-size: 14pt;\">When an input status differs from the corresponding input port register status.\u00a0It is used to indicate to the system master that an input status has changed.<\/span><\/li>\n<li><span class=\"VIiyi\" lang=\"it\" style=\"font-size: 14pt;\"><span class=\"JLqJ4b\" data-language-for-alternatives=\"it\" data-language-to-translate-into=\"en\" data-phrase-index=\"0\">When an input state differs from a preconfigured register value (DEFVAL register).\u00a0The Interrupt Capture register captures the port values \u200b\u200bat the time of the interrupt, thereby saving the condition that caused the interrupt.\u00a0Power-on Reset (POR) sets registers to default values \u200b\u200band initializes machine status.\u00a0<\/span><\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 14pt;\">Let&#8217;s see now how the Z80-mbc2 card uses this micro-controller.<\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-size: 14pt;\">The software of the micro-controller of the Z809-MBC2 board defines, as indicated in the following table, the peripheral management number. The values \u200b\u200bare indicated in hexadecimal base and these are the values \u200b\u200bto be used with the peripheral output instruction in the chosen programming language. The accompanying examples are written in MBASIC but are easily translate into other languages. For writing operations we have:<\/span><\/p>\n<table style=\"width: 62.1895%;\" width=\"643\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\" align=\"center\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\"><b>Peripheral<\/b><\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\" align=\"center\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\"><b>Port<\/b><\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\" align=\"center\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\"><b>Length<\/b><\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">USER LED<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x00<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">GPIOA<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x03<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">GPIOB<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x04<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">IODIRA<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x05<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">IODIRB<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x06<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">GPPUA<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x07<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td style=\"width: 26.8634%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">GPPUB<\/span><\/p>\n<\/td>\n<td style=\"width: 27.0379%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">0x08<\/span><\/p>\n<\/td>\n<td style=\"width: 28.0509%;\" width=\"214\">\n<p class=\"western\"><span style=\"font-family: georgia, palatino, serif; font-size: 14pt;\">1 byte<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"western\"><span style=\"font-size: 14pt;\"><span class=\"\">Now let&#8217;s see what the registers of the MCP23017 indicated in the table mean.<\/span><\/span><\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\">The\u00a0<b>IODIRx<\/b>\u00a0register\u00a0programs the pins corresponding to bits D [7..0] as input or output: 1 &#8211; input;\u00a00 &#8211; exit.\u00a0So IODIRB = 10001000\u00a0<sub>b<\/sub>\u00a0means that the pins GPB7 and GPB3 are input, the remaining are output.<\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-size: 14pt;\">The\u00a0<b>GPIOx<\/b>\u00a0register\u00a0contains the value of the logic status of the pins corresponding to the bits D [7..0] of the micro-controller.\u00a0For example, during the writing phase, it brings the output of the GPIOA pins [7..0] to the logical state as indicated by the byte passed.\u00a0On the other hand, during the reading phase, it copies the logic state of the GPIOA pins [7..0] into the peripheral input variable of the program.<\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-size: 14pt;\">The\u00a0<b>GPPUx<\/b> register enables or disables the internal pull-up. If the pin is marked as input and the corresponding bit of GPPUx is at 1, then the <\/span><span style=\"font-size: 18.6667px;\">pull-up <\/span><span style=\"font-size: 14pt;\">100 k\u03a9 resistor\u00a0 is applied.<\/span><\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\"><span lang=\"it-IT\"><span class=\"\">Operationally,<\/span><\/span><span class=\"\">\u00a0to activate a register, a<\/span><span class=\"\">\u00a0&#8220;1&#8221;<\/span><span class=\"\"> must be sent\u00a0<\/span><span class=\"\">to the corresponding address, then to write a<\/span><span class=\"\">\u00a0&#8220;0&#8221;<\/span><span class=\"\"> followed by the byte\u00a0<\/span><span class=\"\">must be sent<\/span><span class=\"\">, for example:<\/span><\/span><\/p>\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">OUT (1, register)<\/span><\/p>\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">OUT (0, byte)<\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-size: 14pt;\">Instead to read the log:<\/span><\/p>\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">OUT (1, register)<\/span><\/p>\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">byte = INP (0)<\/span><\/p>\n<p class=\"western\" align=\"justify\"><span style=\"font-size: 14pt;\">Let&#8217;s now look at the RTC.\u00a0From the previous table we see that RTC has as peripheral address 84\u00a0<sub>16<\/sub>\u00a0(132\u00a0<sub>10<\/sub>\u00a0).\u00a0Then we activate the RTC registers with<\/span><\/p>\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">OUT 1, 132<\/span><\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\">Recall that RTC contains 8 registers: seconds, minutes, hours, days, months, year, temperature. These can be read sequentially via the input instruction:<\/span><\/p>\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">INP (0)<\/span><\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\">Seconds and minutes range from 0 to 59; hours from 0 to 23; days from 0 to 31; month from 1 to 12; year from 0 to 99; temperature in degrees centigrade from -128 to 127. Let&#8217;s see the example attached to the Z80-MBC2 that allows you to read date and time from the RTC:<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n10 REM ***************************************\r\n11 REM\r\n12 REM ORARIO e DATA da RTC\r\n13 REM\r\n14 REM ****************************************\r\n15 OUT 1,132 : REM Invia il comando 0x84 per leggere i registri dell\u2019RTC\r\n20 SECONDI = INP(0) : REM legge il numero di secondi\r\n30 MINUTI  = INP(0) : REM legge il numero di minuti\r\n40 ORE     = INP(0) : REM legge il numero delle ore\r\n50 GIORNI  = INP(0) : REM legge il numero dei giorni\r\n60 MESI    = INP(0) : REM legge il numero dei mesi\r\n70 ANNO    = INP(0) : REM legge il numero degli anni\r\n80 TEMP    = INP(0) : REM legge il valore della temperatura\r\n83 IF TEMP &lt; 128 THEN 90 : REM se la temperatura \u00e8 inferiore a 128 \u00e8 corretta\r\n85 TEMP = TEMP \u2013 256 : REM complemento a 2 per ricondurla tra -128 e 127\r\n90 PRINT\r\n100 PRINT &quot;L\u2019orario \u00e8: &quot;\r\n110 PRINT ORE; : PRINT &quot;:&quot;; : PRINT MINUTI; : PRINT &quot;:&quot;; : PRINT SECONDI\r\n120 PRINT &quot;La data \u00e8: &quot;\r\n125 ANNO = ANNO+ 2000\r\n130 PRINT GIORNI; : PRINT &quot;\/&quot;; : PRINT MESI; : PRINT &quot;\/&quot;; : PRINT ANNO\r\n135 PRINT &quot;La temperatura: &quot;;\r\n140 PRINT TEMP; : PRINT &quot;gradi Centigradi&quot;\r\n145 PRINT\r\n<\/pre>\n<p class=\"western\" align=\"justify\"><span style=\"font-size: 14pt;\">From the A0640618-2 diagram of the Z80-MBC2 motherboard we see the correspondence between the pins of the GPIO registers A and B of the MCP23017 and the J7 socket.<\/span><\/p>\n<table width=\"279\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA0<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">18<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB0<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">3<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA1<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">16<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB1<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">5<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA2<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">14<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB2<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">7<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA3<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">12<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB3<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">9<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA4<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">10<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB4<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">11<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA5<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">8<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB5<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">13<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA6<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">6<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB6<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">15<\/span><\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td width=\"76\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPA7<\/span><\/p>\n<\/td>\n<td width=\"68\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">4<\/span><\/p>\n<\/td>\n<td width=\"71\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">GPB7<\/span><\/p>\n<\/td>\n<td width=\"64\">\n<p class=\"western\" align=\"center\"><span style=\"font-size: 14pt;\">17<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-531 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/gpio1.bmp\" alt=\"\" width=\"238\" height=\"211\" \/><\/p>\n<p>&nbsp;<\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\">If we\u00a0want a LED connected to pin 8 of J7 to be lit, we would have to act on GPA5.<\/span><\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\">As indicated in the diagram, we connect the cathode of the LED to pin 8 (GPA5) and the anode to a 680 \u03a9 resistor\u00a0which in turn is connected to ground.<\/span><\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\">We\u00a0activate the IODIRA register, which in the table is 0x05 and then we impose that GPIOA.5 is an output:<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOUT 1,5\r\nOUT 0,11011111b\r\n<\/pre>\n<p class=\"western\"><span style=\"font-size: 14pt;\">Now we turn on the LED by addressing the GPIOA register first and then we set the pin of GPIOA to 1.<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOUT 1, 3\r\nOUT 0, 0000000b \r\n<\/pre>\n<p class=\"western\">To turn off the LED:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOUT 1, 3\r\nOUT 0, 00000000b\r\n<\/pre>\n<p class=\"western\"><span style=\"font-size: 14pt;\">If we wanted to intercept the pressure on the USER button of the Z80-MBC2 we can operate as follows:<\/span><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nFLOP = 1\r\nWHILE FLOP\r\n      OUT 1, 128 : REM 0x80 = 128 decimale\r\n      IF INP(0) = 1 THEN FLOP = 0\r\nWEND\r\n<\/pre>\n<p class=\"western\"><a href=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/gpioswitch.bmp\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-541 alignleft\" src=\"https:\/\/automatico.freevar.com\/wp-content\/uploads\/2021\/08\/gpioswitch.bmp\" alt=\"\" width=\"229\" height=\"241\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p class=\"western\"><span style=\"font-size: 14pt;\"><span class=\"\">If instead the button were connected to pin\u00a0<\/span><span lang=\"it-IT\"><span class=\"\">4<\/span><\/span><span class=\"\">\u00a0of J7, which corresponds to GPA7, we must also mount a pull-up resistor.<\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nGPPUA = 7: REM 0x07\r\nGPIOA = 3: REM 0x03\r\nOUT 1, GPPUA\r\nOUT 0, 100000b : REM 0x80 = 128\r\nOUT 1, GPIOA\r\nOUT 0, 1000000b : REM 0x80 = 128\r\nFLOP = 1\r\nWHILE FLOP\r\n OUT 1, GPIOA\r\n IF INP(0) = 128 THEN FLOP = 0\r\nWEND\r\n<\/pre>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_501\" class=\"pvc_stats all  \" data-element-id=\"501\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/automatico.freevar.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The MCP23017 integrated circuit is a micro-controller manufactured by PIC and is a digital port expander with i\u00a02 c communication protocol (Philips 1982). Allows you to control 16 individually configurable inputs \/ outputs. The I \/ O terminals are divided into two groups of ports of 8 bits each (GPIOA and GPIOB). Let&#8217;s see the [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_501\" class=\"pvc_stats all  \" data-element-id=\"501\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/automatico.freevar.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"parent":82,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-501","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/501"}],"collection":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/comments?post=501"}],"version-history":[{"count":45,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/501\/revisions"}],"predecessor-version":[{"id":750,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/501\/revisions\/750"}],"up":[{"embeddable":true,"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/pages\/82"}],"wp:attachment":[{"href":"https:\/\/automatico.freevar.com\/index.php\/wp-json\/wp\/v2\/media?parent=501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}