<?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>Classic/Legacy CodeWarriorのトピックRe: hint for a code organization</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211047#M5930</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thank you very much Ludin!&lt;/DIV&gt;&lt;DIV&gt;I will try that and see If I got it right.&lt;/DIV&gt;&lt;DIV&gt;B&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 11 Apr 2008 00:44:42 GMT</pubDate>
    <dc:creator>Halom</dc:creator>
    <dc:date>2008-04-11T00:44:42Z</dc:date>
    <item>
      <title>hint for a code organization</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211045#M5928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I am starting interrupt&amp;nbsp; (with MC9S12C32) and I need some help in the organiztion of one of mu program.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have a program that is doing some function. Then when &lt;STRONG&gt;I press and realease a button&lt;/STRONG&gt; (set up at PTAD0) the program stops and the LED's are supposed to flash every second using timer interrupt.When we &lt;STRONG&gt;press and release the button again&lt;/STRONG&gt; the LEDs stop flashing and the main program continues.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Our teacher want us to us the following when dealing with interrupt:&lt;/DIV&gt;&lt;DIV&gt;- have a LED thread_begin function that start the thread( intialization of the device here&amp;nbsp; timer)&lt;/DIV&gt;&lt;DIV&gt;- have the ISR - doing the work&lt;/DIV&gt;&lt;DIV&gt;- have a thread " end" that stop the LED thread&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I have&amp;nbsp;one issue here:&lt;/DIV&gt;&lt;DIV&gt;One is how to implement the part when the button is pressed and released.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My&amp;nbsp; code organization is something like this:&lt;/DIV&gt;&lt;DIV&gt;...main program working...&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;Check if&amp;nbsp; button pressed and released&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF yes&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call LED thread_begin&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;In the ISR function&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Does 1 second passed?&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF yes&amp;nbsp; flash the LED&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE wait&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;Check if button is pressed and released&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;If yes&amp;nbsp;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;&amp;nbsp; Call LED thread_stop&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG style=": ; color: #FF0033;"&gt;(return to main program)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;Also wher should I place my 'check button' code?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Please can I have some help with the button and my program&amp;nbsp;organization?&lt;/DIV&gt;&lt;DIV&gt;thank you&lt;/DIV&gt;&lt;DIV&gt;B&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 02:31:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211045#M5928</guid>
      <dc:creator>Halom</dc:creator>
      <dc:date>2008-04-10T02:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: hint for a code organization</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211046#M5929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The way of implementing that makes most sense to me is to let the thread handle the button scanning, which is actually the only real work as such.&lt;BR /&gt;&lt;BR /&gt;You will need to read the button status, then read it again after some miliseconds to check if it is the same. This is known as "debouncing" and the purpose is to take care of signal bounces caused by the button mechanics as well as possible EMI glitches etc. When you have made clear that the button is stable, you have to save its position (pressed/not pressed) into a variable.&lt;BR /&gt;&lt;BR /&gt;This variable can be polled from another thread or the main program. If it changed status from pressed to not pressed, the button was released and another timer which controlls the led can be started. And similar, if the button was pressed again, stop the timer.&lt;BR /&gt;&lt;BR /&gt;It is very important to make all variables shared between threads/ISRs volatile, and possibly also protect them with semaphores/muticies etc. If this isn't done, you might get several kinds of very hard-to-find runtime bugs.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 15:09:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211046#M5929</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2008-04-10T15:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: hint for a code organization</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211047#M5930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thank you very much Ludin!&lt;/DIV&gt;&lt;DIV&gt;I will try that and see If I got it right.&lt;/DIV&gt;&lt;DIV&gt;B&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Apr 2008 00:44:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/hint-for-a-code-organization/m-p/211047#M5930</guid>
      <dc:creator>Halom</dc:creator>
      <dc:date>2008-04-11T00:44:42Z</dc:date>
    </item>
  </channel>
</rss>

