<?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 Problem with implementing c code on HC908qb8 in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Problem-with-implementing-c-code-on-HC908qb8/m-p/231612#M19406</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm currently working on simple memory game. I have code, which was working correctly on Atmega8. But when i've portet it onto HC908qb i have issues. &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;When i run it, the MCU jumps into odczyt_klaw() but don't wait for my respond and puts some different data into my tab_kop[] and all diodes start to flash (game over)...&lt;BR /&gt;&lt;/SPAN&gt;Anyone could help?&lt;BR /&gt;I've attached code to this post&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 May 2013 14:19:55 GMT</pubDate>
    <dc:creator>mateuszjagocha</dc:creator>
    <dc:date>2013-05-09T14:19:55Z</dc:date>
    <item>
      <title>Problem with implementing c code on HC908qb8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Problem-with-implementing-c-code-on-HC908qb8/m-p/231612#M19406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm currently working on simple memory game. I have code, which was working correctly on Atmega8. But when i've portet it onto HC908qb i have issues. &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;When i run it, the MCU jumps into odczyt_klaw() but don't wait for my respond and puts some different data into my tab_kop[] and all diodes start to flash (game over)...&lt;BR /&gt;&lt;/SPAN&gt;Anyone could help?&lt;BR /&gt;I've attached code to this post&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 May 2013 14:19:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Problem-with-implementing-c-code-on-HC908qb8/m-p/231612#M19406</guid>
      <dc:creator>mateuszjagocha</dc:creator>
      <dc:date>2013-05-09T14:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with implementing c code on HC908qb8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Problem-with-implementing-c-code-on-HC908qb8/m-p/231613#M19407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firstly, your attempted macros will not work as you intend.&amp;nbsp; The following macros should work correctly.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define KEY1&amp;nbsp; PTA_PTA0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define KEY2&amp;nbsp; PTA_PTA1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define KEY3&amp;nbsp; PTA_PTA2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define KEY4&amp;nbsp; PTA_PTA3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define LED1&amp;nbsp; PTB_PTB0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define LED2&amp;nbsp; PTB_PTB1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define LED3&amp;nbsp; PTB_PTB2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define LED4&amp;nbsp; PTB_PTB3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LED1 = 1;&amp;nbsp; // Turn the LED on (presumably)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Additionally, the &lt;SPAN style="font-family: courier new,courier;"&gt;tab_oryg[] &lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;array will reside in RAM.&amp;nbsp; Flash memory may be more appropriate for this table.&amp;nbsp; You may also want to consider whether the variable should be an unsigned 8-bit type, rather than a signed 16-bit type, as you currently have.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #ff0000;"&gt;const &lt;/SPAN&gt;int tab_oryg[] = { &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; 4, 2, 4, 8, 1, 2, 4, 2, 8, 1 , 2, 4, 2, 8, 1, 8, 2, 4, 1, 8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;The primary problem with your code would seem to be that the &lt;SPAN style="font-family: courier new,courier; color: #3366ff;"&gt;odczyt_klaw()&lt;/SPAN&gt; function does not exit, because of the presence of the &lt;SPAN style="font-family: courier new,courier; color: #ff0000;"&gt;&lt;SPAN style="color: #ff0000;"&gt;while&lt;/SPAN&gt;(1)&lt;/SPAN&gt; loop, and the absence of a &lt;SPAN style="color: #000000;"&gt;&lt;SPAN style="font-family: courier new,courier; color: #ff0000;"&gt;break;&lt;/SPAN&gt; .&amp;nbsp; &lt;SPAN style="color: #003366;"&gt;Eventually, COP timeout and reset will occur.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #003366; font-family: arial,helvetica,sans-serif;"&gt;Here is part of the code, re-written to make use of the above macros -&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void odczyt_klaw( void)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; a = 10;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; //PTA = 0xFF;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; while (1) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!key_lock &amp;amp;&amp;amp; !KEY1) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key_lock = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LED1 = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (key_lock &amp;amp;&amp;amp; KEY1) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key_lock++;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!key_lock) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTB = 0x00;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #003366; font-family: arial,helvetica,sans-serif;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #003366; font-family: arial,helvetica,sans-serif;"&gt;Since key_lock is a 16-bit variable, the "else" part of the statement would need to execute 65535 times before the variable again reaches zero, and the LEDs are turned off.&amp;nbsp; Since the while loop is not "paced" by using a delay function, the total period will be compiler dependent, and will also depend on which of the remaining code, within the while loop, is being executed.&amp;nbsp; Presumably, this is not what you had intended.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #003366; font-family: arial,helvetica,sans-serif;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #003366; font-family: arial,helvetica,sans-serif;"&gt;Mac&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 May 2013 11:34:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Problem-with-implementing-c-code-on-HC908qb8/m-p/231613#M19407</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-05-12T11:34:14Z</dc:date>
    </item>
  </channel>
</rss>

