<?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 Conditional tests in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1746168#M15938</link>
    <description>&lt;P&gt;I am using CodeWarrior 11.1 with a MC9S08SH MCU and the project uses Processor Expert. There are 3 buttons attached to the MCU via on-chip pull-ups.I.E. while a button is pressed the input pin returns a "0" , otherwise it returns a "1". The idea is that if the button is pressed for less than 1 second the first section &amp;nbsp;the code runs to (3) and then exits. If the button is held down the code jumps to (3) and then loops until the button is released. This section works correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if(!MODE_GetVal()) 	    //mode switch pressed            (1)
   {
   NewSetPoint=1;
   DelayX1ms(1000);         // 1 second delay
   key_mode = 1;
   if(MODE_GetVal()==1)	    // was the key released?        (2)
        {                   // if so - change the mode
        if(Mode==0) 
	     {
	     Mode = 1;	    //switch between functions
	     StartupTime = Time_1;		
	     }
         else
	    {
	    Mode = 0;
	    dt();
	    }
     }
   else          // repeat this loop untilkey is released
      while(!MODE_GetVal())                 (3)
           {
           ..............&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;While stepping through the code, when the MODE button is pressed execution correctly arrives at (1) and code is executed correctly up to (2). The execution then jumps to (3) irrespective of the state of the MODE button.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;On examination of the assembly code there is nothing between (2) and (3). A&lt;/SPAN&gt;&lt;SPAN class=""&gt;pparently the code between these two points has been removed as "DEAD CODE"&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;because the test at point (2) is "always false" which is, of course, incorrect if the button has been released.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The component Mode is configured as a BitIO with method GetVal()&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Oct 2023 17:22:06 GMT</pubDate>
    <dc:creator>juliancox</dc:creator>
    <dc:date>2023-10-25T17:22:06Z</dc:date>
    <item>
      <title>Conditional tests</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1746168#M15938</link>
      <description>&lt;P&gt;I am using CodeWarrior 11.1 with a MC9S08SH MCU and the project uses Processor Expert. There are 3 buttons attached to the MCU via on-chip pull-ups.I.E. while a button is pressed the input pin returns a "0" , otherwise it returns a "1". The idea is that if the button is pressed for less than 1 second the first section &amp;nbsp;the code runs to (3) and then exits. If the button is held down the code jumps to (3) and then loops until the button is released. This section works correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if(!MODE_GetVal()) 	    //mode switch pressed            (1)
   {
   NewSetPoint=1;
   DelayX1ms(1000);         // 1 second delay
   key_mode = 1;
   if(MODE_GetVal()==1)	    // was the key released?        (2)
        {                   // if so - change the mode
        if(Mode==0) 
	     {
	     Mode = 1;	    //switch between functions
	     StartupTime = Time_1;		
	     }
         else
	    {
	    Mode = 0;
	    dt();
	    }
     }
   else          // repeat this loop untilkey is released
      while(!MODE_GetVal())                 (3)
           {
           ..............&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp;While stepping through the code, when the MODE button is pressed execution correctly arrives at (1) and code is executed correctly up to (2). The execution then jumps to (3) irrespective of the state of the MODE button.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;On examination of the assembly code there is nothing between (2) and (3). A&lt;/SPAN&gt;&lt;SPAN class=""&gt;pparently the code between these two points has been removed as "DEAD CODE"&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;because the test at point (2) is "always false" which is, of course, incorrect if the button has been released.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;The component Mode is configured as a BitIO with method GetVal()&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 17:22:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1746168#M15938</guid>
      <dc:creator>juliancox</dc:creator>
      <dc:date>2023-10-25T17:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional tests</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1746921#M15939</link>
      <description>&lt;P&gt;A further anomaly:&lt;/P&gt;&lt;P&gt;According to The CodeWarrior documentation, if set as an input the function MODE_GetVal() should read THE PIN and return a BOOLEAN value. However, in this case it returns either 0 or 0x08. Noting that this particular input is on Port C, bit 3 - which has a value of 0x08. Furthermore, I solved the problem by changing the statement&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if(MODE_GetVal()==1) &amp;nbsp;&lt;/STRONG&gt;to &amp;nbsp;&lt;STRONG&gt;if(MODE_GetVal()!=0)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I also tried&amp;nbsp;if(MODE_GetVal())&lt;/STRONG&gt; but it did not work.&lt;/P&gt;&lt;P&gt;why does this function not return a boolean value as it should?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 10:12:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1746921#M15939</guid>
      <dc:creator>juliancox</dc:creator>
      <dc:date>2023-10-26T10:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional tests</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1747115#M15940</link>
      <description>&lt;P&gt;Hi&amp;nbsp;juliancox&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please create a demo project to show the issue. Thus we can run the demo to see problem directly.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Jun Zhang&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 13:27:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Conditional-tests/m-p/1747115#M15940</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2023-10-26T13:27:00Z</dc:date>
    </item>
  </channel>
</rss>

