<?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 Re: Flag Clearing methods with codewarrior in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162230#M2780</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Yes set the whole byte. When writing to the HCS(X)12 flag&amp;nbsp;registers all bits that are 0 are ignored and only the bit(s) that are 1 clear the flag for that bit position.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For all other registers, memory locations all bit values are written.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Nov 2007 23:06:32 GMT</pubDate>
    <dc:creator>Technoman64</dc:creator>
    <dc:date>2007-11-09T23:06:32Z</dc:date>
    <item>
      <title>Flag Clearing methods with codewarrior</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162227#M2777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;I am trying to use PIT module in MC9S12XDT512. I found S12PIT24B4CV1 document about it. But I couldn't understand that how to do flag clearing (without BSET) by codewarrior. When I looked at disassambled code I see that always BSET instructions for clear commands. Is&amp;nbsp;there any way for clearing flag with MOV instruction (but without writing assembly).&lt;STRONG&gt;&lt;/STRONG&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 5;"&gt;(S12PIT24B4CV1)&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 5;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-size: 3;"&gt;13.5.3 Flag Clearing&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;A flag is cleared by writing a one to the flag bit. Always use store or move instructions to write a one in&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;certain bit positions. Do not use the BSET instructions. Do not use any C-constructs that compile to BSET&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;instructions. “BSET flag_register, #mask” must not be used for flag clearing because BSET is a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;read-modify-write instruction which writes back the “bit-wise or” of the flag_register and the mask into&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;the flag_register. BSET would clear all flag bits that were set, independent from the mask.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 2;"&gt;For example, to clear flag bit 0 use: MOVB #$01,PITTF.&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2007 15:42:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162227#M2777</guid>
      <dc:creator>sfb</dc:creator>
      <dc:date>2007-11-09T15:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Flag Clearing methods with codewarrior</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162228#M2778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Just use assigment instructions with c code and avoid&amp;nbsp;logical operations.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For example&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Correct&amp;nbsp;method, this&amp;nbsp;writes value&amp;nbsp;directly to the register&amp;nbsp;*/&lt;/DIV&gt;&lt;DIV&gt;PITTF = 0x01;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Incorrect metoid, this will generate a bset instruction&amp;nbsp;*/&lt;/DIV&gt;&lt;DIV&gt;PITTF |= 0x01&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2007 22:16:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162228#M2778</guid>
      <dc:creator>Technoman64</dc:creator>
      <dc:date>2007-11-09T22:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Flag Clearing methods with codewarrior</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162229#M2779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Thanks. For example if I changed PORTB_B4 pin status BSET used but when I changed all of PORTB BSET didn't used.&amp;nbsp;So when changing status flags&amp;nbsp;should I change all byte instead of bit wise?&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2007 22:29:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162229#M2779</guid>
      <dc:creator>sfb</dc:creator>
      <dc:date>2007-11-09T22:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flag Clearing methods with codewarrior</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162230#M2780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Yes set the whole byte. When writing to the HCS(X)12 flag&amp;nbsp;registers all bits that are 0 are ignored and only the bit(s) that are 1 clear the flag for that bit position.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For all other registers, memory locations all bit values are written.&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2007 23:06:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162230#M2780</guid>
      <dc:creator>Technoman64</dc:creator>
      <dc:date>2007-11-09T23:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Flag Clearing methods with codewarrior</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162231#M2781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;DIV&gt;sfb,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I don't know why you asked about PORTB. PORTB is like regular RAM variable, you can BCLR and BSET, do anything with PORTB. But flags that reset&amp;nbsp;to zero when you write ones to them, they are just a little complicated. Technoman64 advices are good, but you may wish to bust some myths and get familiar with these flags..&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Suppose you are using two ECT channels. One IC/OC channel is logically connected to bit1 of TFLG1, and another one to bit0 of TFLG1.&lt;/DIV&gt;&lt;DIV&gt;-&amp;nbsp;Suppose both bits are set, TFLG1 reads as 0x03.&lt;/DIV&gt;&lt;DIV&gt;-&amp;nbsp;You want to clear bit0. You do (bad code just for excercise&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt; TFLG1 |= 0x01;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;- We had 0x03; we bit-OR it with 0x01; we get 0x03; we write 0x03 to TFLG1. OOPS, it will clear both bits instead of just&amp;nbsp;one bit! Is it clear? I hope it is.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CodeWarrior has macros and bitfield #defines for all registers, all register bits and&amp;nbsp;flags. Be careful with flag bits defines. You can read from flag bits (flags bitfields actually), but you shouldn't use flag bitfields&amp;nbsp;to clear flags. For example TFLG1_C0F bit. It expands to _TFLG1.Bits.C0F. You may read TFLG1_C0F&amp;nbsp;as many times as you wish without any side effect. But, you can't write to TFLG1_C0F without affecting other TFLG1 bits. Let's see how:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1)&amp;nbsp;Wrong line TFLG1_C5F=1 would make CPU read TFLG1 register; bit-OR it with (1&amp;lt;&amp;lt;5)=0x20; and finally&amp;nbsp;write result of bit-ORing back to TFLG1. Of course this will clear all flags that were set at the time CPU read TFLG1.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;2) Wrong line TFLG1_C5F=0 would make CPU read TFLG1 register; bit-AND it with ~(1&amp;lt;&amp;lt;5)=0xBF, then write result of bit-ANDing back to TFLG1. Funny result. TFLG1_C5F won't clear, but all other TFLG1 bits,&amp;nbsp;that were set, will reset to zero.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I recommend reading M68HC11 Microcontrollers Reference Manual chapter 10.4.4 Tips for clearing Timer Flags&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC11RM.pdf?fpsp=1" rel="nofollow" target="_blank"&gt;http://www.freescale.com/files/microcontrollers/doc/ref_manual/M68HC11RM.pdf?fpsp=1&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;HC11 manual suggests clearing timer flags using two ways:&lt;/DIV&gt;&lt;DIV&gt;1) use load bit-mask to accumulator, then store accumulator&amp;nbsp;to flag register. This corresponds to C&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TFLG1=(1&amp;lt;&amp;lt;N); //where N is&amp;nbsp;bit number.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2) use BCLR instruction with *inverse* bit-mask.&amp;nbsp; To clear bit5 you would need to BCLR&amp;nbsp; TFLG1,#$BF. In C this corresponds to&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TFLG1 &amp;amp;= (1&amp;lt;&amp;lt;N);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Let's try to decifier it.&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;-&amp;nbsp;Suppose both bits are set, TFLG1 reads as 0x03.&lt;/DIV&gt;&lt;DIV&gt;-&amp;nbsp;You want to clear bit0. You do&amp;nbsp;TFLG1 &amp;amp;= 0x01;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;- We had 0x03; we bit-AND it with 0x01; we get 0x01; we write 0x01 to TFLG1. Bingo, TFLG1 &amp;amp;= 0x01&amp;nbsp; will clear only bit we specified.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hope it helps&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Nov 2007 04:13:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Flag-Clearing-methods-with-codewarrior/m-p/162231#M2781</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2007-11-10T04:13:17Z</dc:date>
    </item>
  </channel>
</rss>

