<?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 S12ZVC functions like BitRead BitSet BitClear in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVC-functions-like-BitRead-BitSet-BitClear/m-p/1253202#M17783</link>
    <description>&lt;P&gt;Hello Everyone.&lt;/P&gt;&lt;P&gt;First timer here. I have not been able to find a way of setting bits for booleans the same way you can do so on Arduino. Commands like bitRead(), bitSet() and bitClear().&lt;BR /&gt;&lt;BR /&gt;Are there similar commands for this processor?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sun, 28 Mar 2021 22:37:29 GMT</pubDate>
    <dc:creator>highlander</dc:creator>
    <dc:date>2021-03-28T22:37:29Z</dc:date>
    <item>
      <title>S12ZVC functions like BitRead BitSet BitClear</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVC-functions-like-BitRead-BitSet-BitClear/m-p/1253202#M17783</link>
      <description>&lt;P&gt;Hello Everyone.&lt;/P&gt;&lt;P&gt;First timer here. I have not been able to find a way of setting bits for booleans the same way you can do so on Arduino. Commands like bitRead(), bitSet() and bitClear().&lt;BR /&gt;&lt;BR /&gt;Are there similar commands for this processor?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 28 Mar 2021 22:37:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVC-functions-like-BitRead-BitSet-BitClear/m-p/1253202#M17783</guid>
      <dc:creator>highlander</dc:creator>
      <dc:date>2021-03-28T22:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: S12ZVC functions like BitRead BitSet BitClear</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVC-functions-like-BitRead-BitSet-BitClear/m-p/1253697#M17787</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are an assembler player then you have instructions:&lt;BR /&gt;( for more info please read the S12ZCPU_RM )&lt;/P&gt;
&lt;P&gt;BSET Di,#opr5i&lt;BR /&gt;BSET.bwl oprmemreg,#opr5i&lt;BR /&gt;BSET.bwl oprmemreg,Dn&lt;/P&gt;
&lt;P&gt;BCLR Di,#opr5i&lt;BR /&gt;BCLR.bwl oprmemreg,#opr5i&lt;BR /&gt;BCLR.bwl oprmemreg,Dn&lt;/P&gt;
&lt;P&gt;(Note; all of them are read-modify-write instructions. It is necassary to think about it in the case of interupt flags clearing when you can acccidentaly clear all flags except required. x = mask; is not the same as x = x | mask; The first one is correct for flags learing. The second one clears all flags which are set even it uses bit instruction in the assembler code after compiling and building. )&lt;/P&gt;
&lt;P&gt;If you use C then you can use following approaches to set or clear bit(s):&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Let rm is register or memory&lt;/P&gt;
&lt;P&gt;rm |= mask; // set bits defined by mask&lt;BR /&gt;rm &amp;amp;= ~mask; // clear bits defined by mask&lt;BR /&gt;rm ^= mask; // flip bits defined by mask&lt;BR /&gt;rm &amp;amp;= mask; // test bits defined by mask&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;#define bytesetmask(rm,mask) (rm |= mask) // set bits defined by mask &lt;BR /&gt;#define byteclearmask(rm,mask) (rm &amp;amp;= ~mask) // clear bits defined by mask&lt;BR /&gt;#define byteflipmask(rm,mask) (rm ^= mask) // flips bits defined by mask&lt;BR /&gt;#define bytetestmask(rm,mask) (rm &amp;amp;= mask) // flips bits defined by mask&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;#define bitset(rm,nbit) (rm |= (1&amp;lt;&amp;lt;(nbit))) // set just one bit &lt;BR /&gt;#define bitclear(rm,nbit) (rm &amp;amp;= ~(1&amp;lt;&amp;lt;(nbit))) // clear just one bit&lt;BR /&gt;#define bitflip(rm,nbit) (rm ^= (1&amp;lt;&amp;lt;(nbit))) // flip just one bit&lt;BR /&gt;#define bitcheck(rm,nbit) (rm &amp;amp; (1&amp;lt;&amp;lt;(nbit))) // test just one bit&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I hope I have not made a mistake. I wrote it in one breath.&lt;/P&gt;
&lt;P&gt;BTW; Processor Expert, if you use it…from the help:&lt;BR /&gt;Processor Expert defines a set of C macros providing an effective access to a specified register or its part. The definitions of all these macros are in the file PE_Types.h.&lt;/P&gt;
&lt;P&gt;Only short example from the PE_types.h file:&lt;BR /&gt;/**************************************************/&lt;BR /&gt;/* PE register access macros */&lt;BR /&gt;/**************************************************/&lt;BR /&gt;#define setRegBit(reg, bit) (reg |= reg##_##bit##_##MASK)&lt;BR /&gt;#define clrRegBit(reg, bit) (reg &amp;amp;= ~reg##_##bit##_##MASK)&lt;BR /&gt;#define getRegBit(reg, bit) (reg &amp;amp; reg##_##bit##_##MASK)&lt;BR /&gt;#define setReg(reg, val) (reg = (word)(val))&lt;BR /&gt;#define getReg(reg) (reg)&lt;BR /&gt;#define setRegBits(reg, mask) (reg |= (word)(mask))&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Ladislav&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 15:17:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12ZVC-functions-like-BitRead-BitSet-BitClear/m-p/1253697#M17787</guid>
      <dc:creator>lama</dc:creator>
      <dc:date>2021-03-29T15:17:17Z</dc:date>
    </item>
  </channel>
</rss>

