<?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>S12 / MagniV Microcontrollers中的主题 How to clear MCZF flag？</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161869#M5111</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;MCU:9s12xep100.&lt;/P&gt;&lt;P&gt;I want to clear MCZF flag in ISR,just like here:&lt;/P&gt;&lt;P&gt;#pragma TRAP_PROC&lt;BR /&gt;void&amp;nbsp;&amp;nbsp;&lt;BR /&gt;CPU_Modulus_Counter_ISR(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ECT_MCFLG_MCZF = 1;//The first way to clear MCZF flag.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ECT_MCFLG &amp;amp;= 0x80;&amp;nbsp; //The second way to clear MCZF flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; //ECT_MCCNT = 0x30;//The third way to clear MCZF flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ECT_MCCTL = 0x00;&lt;BR /&gt;}&lt;BR /&gt;I find that the first and the second can not clear MCZF flag,&lt;SPAN style="color: #00ff00;"&gt;but only the third way can clear MCZF flag.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;According to the datasheet,&lt;/P&gt;&lt;P&gt;"The flag indicates when interrupt conditions have occurred. The flag can be cleared via the normal flag clearing&lt;BR /&gt;mechanism (writing a one to the flag) or via the fast flag clearing mechanism (Reference TFFCA bit in&lt;BR /&gt;Section 14.3.2.6, “Timer System Control Register 1 (TSCR1)”).",this is to say we can clear it by&amp;nbsp;&lt;SPAN style="color: #00ff00;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #FF6600;"&gt;ECT_MCFLG_MCZF = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333;"&gt;I am&amp;nbsp;&amp;nbsp;puzzled here,how to understand it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333;"&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Nov 2010 13:00:07 GMT</pubDate>
    <dc:creator>100asong</dc:creator>
    <dc:date>2010-11-10T13:00:07Z</dc:date>
    <item>
      <title>How to clear MCZF flag？</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161869#M5111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;MCU:9s12xep100.&lt;/P&gt;&lt;P&gt;I want to clear MCZF flag in ISR,just like here:&lt;/P&gt;&lt;P&gt;#pragma TRAP_PROC&lt;BR /&gt;void&amp;nbsp;&amp;nbsp;&lt;BR /&gt;CPU_Modulus_Counter_ISR(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ECT_MCFLG_MCZF = 1;//The first way to clear MCZF flag.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// ECT_MCFLG &amp;amp;= 0x80;&amp;nbsp; //The second way to clear MCZF flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; //ECT_MCCNT = 0x30;//The third way to clear MCZF flag.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ECT_MCCTL = 0x00;&lt;BR /&gt;}&lt;BR /&gt;I find that the first and the second can not clear MCZF flag,&lt;SPAN style="color: #00ff00;"&gt;but only the third way can clear MCZF flag.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;According to the datasheet,&lt;/P&gt;&lt;P&gt;"The flag indicates when interrupt conditions have occurred. The flag can be cleared via the normal flag clearing&lt;BR /&gt;mechanism (writing a one to the flag) or via the fast flag clearing mechanism (Reference TFFCA bit in&lt;BR /&gt;Section 14.3.2.6, “Timer System Control Register 1 (TSCR1)”).",this is to say we can clear it by&amp;nbsp;&lt;SPAN style="color: #00ff00;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #FF6600;"&gt;ECT_MCFLG_MCZF = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333;"&gt;I am&amp;nbsp;&amp;nbsp;puzzled here,how to understand it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333;"&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Nov 2010 13:00:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161869#M5111</guid>
      <dc:creator>100asong</dc:creator>
      <dc:date>2010-11-10T13:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to clear MCZF flag？</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161870#M5112</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This means&lt;/P&gt;&lt;P&gt;if&amp;nbsp; TFFC = 0&amp;nbsp; then MCZF can only be cleared by writing a "1" to it&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (e.g. ECT_MCFLG_MCZF = 1&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if&amp;nbsp; TFFC =1 then MCZF can only be cleared by the fast flag clearing mechanism&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (e.g. ECT_MCCNT = 0x30&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This corresponds to the behavior that you have observed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DPB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Nov 2010 17:21:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161870#M5112</guid>
      <dc:creator>DPB</dc:creator>
      <dc:date>2010-11-10T17:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to clear MCZF flag？</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161871#M5113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Generally, clearing interrupt source flags from C code is dangerous, it is very easy to get unintended side effects. I strong encourage the practice of always disassembling such code to see what it actually does behind the lines. That will save you from many dangerous, hard-to-find bugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this specific case: when setting timer flags with plain, portable bit-wise operators, you will typically get a problem in CW if you write something like:&lt;/P&gt;&lt;P&gt;REG |= 0x01;&lt;/P&gt;&lt;P&gt;This results in a read-modify-write sequence, that destroys all adjacent flags. The work-around is to write REG = 0x01 instead, which results in a bit set instruction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whether the bit field write in your code results in read-modify-write or bit set, I don't know. Whether accessing a bit in a bit field destroys adjacent bits in the same register, I don't know either. The only way to know how they work is to read the compiler docs in detail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the fun thing with bit fields: the C standard guarantees that bit fields are implemented in completely inpredictable ways, and a programmer can never tell what a bit field access actually does between the lines from reading the C code - the behavior isn't specified by the standard.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Nov 2010 17:42:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/How-to-clear-MCZF-flag/m-p/161871#M5113</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-11-10T17:42:00Z</dc:date>
    </item>
  </channel>
</rss>

