<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Push buttons using assembly language in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Push-buttons-using-assembly-language/m-p/153587#M3814</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;H&lt;SPAN&gt;&lt;SPAN&gt;ow&lt;/SPAN&gt; &lt;SPAN&gt;can I&lt;/SPAN&gt; &lt;SPAN&gt;know what&lt;/SPAN&gt; &lt;SPAN&gt;push button&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;was pressed&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN&gt;by the user in assembly language, i.e.&lt;/SPAN&gt; &lt;SPAN&gt;how can I&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;know if&amp;nbsp; the user pressed the&lt;/SPAN&gt; &lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;button&lt;/SPAN&gt;&lt;/SPAN&gt; PTA2&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;PTA3&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;PTD2&lt;/SPAN&gt; &lt;SPAN&gt;or&lt;/SPAN&gt; &lt;SPAN&gt;PTD3&lt;/SPAN&gt;&lt;SPAN&gt;?&lt;/SPAN&gt; &lt;SPAN&gt;Because I&lt;/SPAN&gt; &lt;SPAN&gt;created a code (an interruption) that&lt;/SPAN&gt; &lt;SPAN&gt;detects&lt;/SPAN&gt; &lt;SPAN&gt;when&lt;/SPAN&gt; &lt;SPAN&gt;any push&lt;/SPAN&gt; &lt;SPAN&gt;button&lt;/SPAN&gt; &lt;SPAN&gt;was pressed&lt;/SPAN&gt; &lt;SPAN&gt;but I need&lt;/SPAN&gt; &lt;SPAN&gt;to validate&lt;/SPAN&gt; &lt;SPAN&gt;what was the&lt;/SPAN&gt; &lt;SPAN&gt;button pressed&lt;/SPAN&gt; &lt;SPAN&gt;by the user.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I'm using the microcontroller &lt;SPAN&gt;MC9S08QE128.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thank you for your help.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Apr 2012 12:34:09 GMT</pubDate>
    <dc:creator>MindMond</dc:creator>
    <dc:date>2012-04-12T12:34:09Z</dc:date>
    <item>
      <title>Push buttons using assembly language</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Push-buttons-using-assembly-language/m-p/153587#M3814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;H&lt;SPAN&gt;&lt;SPAN&gt;ow&lt;/SPAN&gt; &lt;SPAN&gt;can I&lt;/SPAN&gt; &lt;SPAN&gt;know what&lt;/SPAN&gt; &lt;SPAN&gt;push button&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;was pressed&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN&gt;by the user in assembly language, i.e.&lt;/SPAN&gt; &lt;SPAN&gt;how can I&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;know if&amp;nbsp; the user pressed the&lt;/SPAN&gt; &lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;button&lt;/SPAN&gt;&lt;/SPAN&gt; PTA2&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;PTA3&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;PTD2&lt;/SPAN&gt; &lt;SPAN&gt;or&lt;/SPAN&gt; &lt;SPAN&gt;PTD3&lt;/SPAN&gt;&lt;SPAN&gt;?&lt;/SPAN&gt; &lt;SPAN&gt;Because I&lt;/SPAN&gt; &lt;SPAN&gt;created a code (an interruption) that&lt;/SPAN&gt; &lt;SPAN&gt;detects&lt;/SPAN&gt; &lt;SPAN&gt;when&lt;/SPAN&gt; &lt;SPAN&gt;any push&lt;/SPAN&gt; &lt;SPAN&gt;button&lt;/SPAN&gt; &lt;SPAN&gt;was pressed&lt;/SPAN&gt; &lt;SPAN&gt;but I need&lt;/SPAN&gt; &lt;SPAN&gt;to validate&lt;/SPAN&gt; &lt;SPAN&gt;what was the&lt;/SPAN&gt; &lt;SPAN&gt;button pressed&lt;/SPAN&gt; &lt;SPAN&gt;by the user.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I'm using the microcontroller &lt;SPAN&gt;MC9S08QE128.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Thank you for your help.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Apr 2012 12:34:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Push-buttons-using-assembly-language/m-p/153587#M3814</guid>
      <dc:creator>MindMond</dc:creator>
      <dc:date>2012-04-12T12:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: Push buttons using assembly language</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Push-buttons-using-assembly-language/m-p/153588#M3815</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As quickly as possible, after the interrupt occurs, you should read&amp;nbsp;the port to which the switches are connected.&amp;nbsp;&lt;BR /&gt;This should be before any mechanical contact bounce has an opportunity to occur.&amp;nbsp; To prevent subsequent bounce from&lt;BR /&gt;causing additional interrupts, the KB interrupt should be disabled for a sufficient de-bounce period of say 50ms, or greater.&amp;nbsp; I would suggest that this timing might be done using the TPM1 overflow interrupt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will cater for the switch closure.&amp;nbsp; However, the switch will&amp;nbsp;usually be released after the debounce period has expired.&amp;nbsp; Here, there is also the possibility of bounce occurring, and causing false interrupts during the turn-off bounce.&amp;nbsp; I can think of two solutions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While the switch is active,you could alter the next interrupt from negative edge to positive edge.&amp;nbsp; Since the internal pullup would become a pulldown, this is not appropriate for the switch connection, and the internal pullup/pulldown would need to remain disabled.&amp;nbsp; This would require that external pullup resistors to be fitted.&amp;nbsp; This may not be readily feasible if you are using an existing board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another solution would be to temporarily disable the active switch pin from the KBI module.&amp;nbsp; The release of the switch would need to be ascertained by polling, to determine when the pin should be re-enabled for the KBI module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a further issue for the 'QE128 device, and the pins that you mention.&amp;nbsp; There are two KBI modules, and each pair of pins is associated with a different module. This means that you will require separate ISR code for each module.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following untested code snippet attempts to demonstrate the first method, where the polarity of the edge is changed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ISR_KBI1: LDA    PTAD  COMA                  ; Invert - switches have common ground          AND    #$0C           ; Mask switch inputs  STA    SWSTAT1        ; Save current switch status  LDA    KBI1ES         ; Edge select register  AND    #$F3           ; Clear bits 2 &amp;amp; 3  ORA    SWSTAT1  STA    KBI1ES         ; Update active edge  MOV    #2,DEBOUNCE1   ; Set debounce delay (1-2 TPM overflows)  MOV    #$04,KBI1SC    ; Clear flag, disable interrupts  RTI  &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You would need a similar ISR for KBI2 interrupts.&amp;nbsp; The following code is for the debounce timing for both KBI modules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ISR_TPM1OVF:           TST    DEBOUNCE1   BEQ    ITP1           ; Branch if already zero   DEC    DEBOUNCE1   BNE    ITP1           ; Branch if not timeout     MOV    #$06,KBI1SC    ; Re-enable KB interrupt   ITP1:      TST    DEBOUNCE2   BEQ    ITP2           ; Branch if already zero   DEC    DEBOUNCE2   BNE    ITP2           ; Branch if not timeout           MOV    #$06,KBI2SC    ; Re-enable KB interrupt   ITP2:   BCLR   TPM1SC_TOF,TPM1SC ; Clear timer flag   RTI&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:56:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Push-buttons-using-assembly-language/m-p/153588#M3815</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T08:56:52Z</dc:date>
    </item>
  </channel>
</rss>

