<?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>CodeWarrior for MCU中的主题 Re: Bit compare using PTXD_PTAXX</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162924#M4573</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Thanks for clearing up the mistake in my logic!&lt;BR /&gt;&lt;BR /&gt;I really though what i was doing made sense, and the compilier looked like it was 'trying' to do (what i thought was) the right thing.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Carl&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by CarlFST60L_3rd on &lt;SPAN class="date_text"&gt;2008-06-11&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:57 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jun 2008 08:57:22 GMT</pubDate>
    <dc:creator>CarlFST60L_3rd</dc:creator>
    <dc:date>2008-06-11T08:57:22Z</dc:date>
    <item>
      <title>Bit compare using PTXD_PTAXX</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162920#M4569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;SPAN&gt;Sorry if this is very obvious, but why cant I do this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please note, this is just illistrating the exor compare, nothing more. Using S08 processors, 5.9.0 codewarrior.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;if(PTAD_PTAD1 ^ PTAD_PTAD2) dothis();&amp;nbsp; //If both the same dothis()else dothis1();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //If one bit is different dothis1()&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;If i do somthing like this, it works (dont use the predefined PTAD_PTAD1 directly):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;uchar Temp1, Temp2;if(PTAD_PTAD1) Temp1 = 1;else Temp1 = 0if(PTAD_PTAD2) Temp2 = 1;else Temp2 = 0if(Temp1 ^ Temp2) dothis();else dothis1();&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;I am guessing its due to the way the PTAD_PTAD1 is setup in the header files? Whats the best way to do this without it getting so ugly?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again, sorry if this is a simple lesson that I should already know.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Carl&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by CarlFST60L_3rd on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2008-06-10&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;11:38 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:08:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162920#M4569</guid>
      <dc:creator>CarlFST60L_3rd</dc:creator>
      <dc:date>2020-10-29T09:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Bit compare using PTXD_PTAXX</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162921#M4570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;CarlFST60L_3rd wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;Sorry if this is very obvious, but why cant I do this&lt;BR /&gt;&lt;BR /&gt;Please note, this is just illistrating the exor compare, nothing more. Using S08 processors, 5.9.0 codewarrior.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;if(PTAD_PTAD1 ^ PTAD_PTAD2) dothis();  //If both the same dothis()else dothis1();          //If one bit is different dothis1()&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;The compiler seems to generate assembly that works correctly for this.&amp;nbsp; Your comments are backwards, if the bits are the same then XOR is false so the else condition will run.&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:08:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162921#M4570</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2020-10-29T09:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Bit compare using PTXD_PTAXX</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162922#M4571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Ah, yes, the comments are backwards, was just writing freehand.&lt;BR /&gt;&lt;BR /&gt;I have looked at the code more to narrow it down, my orginal thoughts of the issue were clearly off. the above examples both work, it was the bit I left out causing the problem:&lt;BR /&gt;&lt;BR /&gt;This is the code (Writen free hand to show the idea)&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;//main.c//Some global register used for bit flagsbyte FlagsRegister#define MaskSomeFlag 2main{    byte Temp1,Temp2;                             if(FlagsRegister &amp;amp; MaskSomeFlag) Temp1 = 1;    else Temp1 = 0;    if(Temp1 ^ PTAD_PTAD2){...}        //THIS LINE WORKS AS EXPECTED    if((FlagsRegister &amp;amp; MaskSomeFlag) ^ PTAD_PTAD2){...}  //THIS LINE DOES NOT WORK}&lt;/PRE&gt;&lt;/DIV&gt;Note, when I compilied and tested this, it was strictly one of the other, I just combined them to illistrate.&lt;BR /&gt;&lt;BR /&gt;Now, here is where I see the issue in the non working code:&lt;BR /&gt;&lt;BR /&gt;lda&amp;nbsp;&amp;nbsp; PTAD&amp;nbsp;&lt;BR /&gt;and&amp;nbsp;&amp;nbsp; 0x04&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Mask out PTA2&lt;BR /&gt;lsra&lt;BR /&gt;lsra&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; //move it into position bit 0? This should be at bit 1 for the compare to work!&lt;BR /&gt;psha&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; //Save on stack&lt;BR /&gt;lda&amp;nbsp;&amp;nbsp; FlagsRegister&lt;BR /&gt;and&amp;nbsp;&amp;nbsp; 0x02&amp;nbsp;&amp;nbsp; //Mask out the correct bit from FlagsRegister&lt;BR /&gt;tsx&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;&lt;BR /&gt;eor&amp;nbsp;&amp;nbsp; ,x&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Do the compare with the wrong bit!&lt;BR /&gt;pulh&lt;BR /&gt;beq&amp;nbsp;&amp;nbsp; *+54&lt;BR /&gt;...&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;So, is it my code causing it to be out by one? or?&lt;BR /&gt;&lt;BR /&gt;I am pretty sure my code is 'ok' as it works when each bit is tested seperately.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:08:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162922#M4571</guid>
      <dc:creator>CarlFST60L_3rd</dc:creator>
      <dc:date>2020-10-29T09:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Bit compare using PTXD_PTAXX</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162923#M4572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Sorry, the compiler is correct and the code contains the bug &lt;IMG alt="Smiley Wink" class="emoticon emoticon-smileywink" id="smileywink" src="https://community.nxp.com/i/smilies/16x16_smiley-wink.png" title="Smiley Wink" /&gt;.&lt;BR /&gt;&lt;BR /&gt;Using ^ as you intend it only works if both sides have a value of 0 or 1.&lt;BR /&gt;Obviously an expression like (x &amp;amp; 2) has a value of 0 or 2, and never 1.&lt;BR /&gt;So if you really want to do this, code it like&lt;BR /&gt;&lt;PRE&gt;if (((FlagsRegister &amp;amp; MaskSomeFlag) != 0) ^ PTAD_PTAD2)

Note that if you only use the XOR for this, then I would use a != instead,
as this more clearly shows that you intend to do something if the two sides differ.

I usually do not mix booleans and ints, although this of course works as long as the int's happen to
be 0 and 1's only. So in order to test if the second bit of a register has a different value
than the PTAD_PTAD2 bit, I would write something like:
if (((FlagsRegister &amp;amp; 2) != 0) != (PTAD_PTAD2 != 0))

(although I don't think such patterns are that often)

Daniel


&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:09:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162923#M4572</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2020-10-29T09:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Bit compare using PTXD_PTAXX</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162924#M4573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Thanks for clearing up the mistake in my logic!&lt;BR /&gt;&lt;BR /&gt;I really though what i was doing made sense, and the compilier looked like it was 'trying' to do (what i thought was) the right thing.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Carl&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by CarlFST60L_3rd on &lt;SPAN class="date_text"&gt;2008-06-11&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:57 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jun 2008 08:57:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Bit-compare-using-PTXD-PTAXX/m-p/162924#M4573</guid>
      <dc:creator>CarlFST60L_3rd</dc:creator>
      <dc:date>2008-06-11T08:57:22Z</dc:date>
    </item>
  </channel>
</rss>

