<?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>LPC MicrocontrollersのトピックRe: Consecutive bit assignments in the same register</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521686#M4324</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by nerd herd on Tue Mar 31 07:26:00 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Mohannad,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OldManVimes gave a clear proof of why your two bit assignments are not the same. In case you were interested in delving deeper, the formal reason why the two bit assignments are not equal is due to De Morgan's Law. Essentially, when you NOT a statement such as ~(1 &amp;lt;&amp;lt; 16 | 1 &amp;lt;&amp;lt; 17), the NOT will flip the OR into a AND, making the equivalent statement of ~(1 &amp;lt;&amp;lt; 16) &amp;amp; ~(1 &amp;lt;&amp;lt; 17). For more information:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDe_Morgan%2527s_laws" rel="nofollow" target="_blank"&gt;http://en.wikipedia.org/wiki/De_Morgan%27s_laws&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 17:50:22 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T17:50:22Z</dc:date>
    <item>
      <title>Consecutive bit assignments in the same register</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521684#M4322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Mohannad on Tue Mar 31 03:42:54 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm having a problem regarding assigning bit consecutively in the same register on LPC1769.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, to display number 5 on 7 segment display I write this statement and it works perfectly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN = ~(1&amp;lt;&amp;lt;16 | 1&amp;lt;&amp;lt;17 | 1&amp;lt;&amp;lt;7 | 1&amp;lt;&amp;lt;1 | 1&amp;lt;&amp;lt;18);&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, if I have written consecutive statements to assign the same bits, it doesn't work. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN |= ~(1&amp;lt;&amp;lt;16) ;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN |= ~(1&amp;lt;&amp;lt;17) ;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN |= ~(1&amp;lt;&amp;lt;7) ;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN |= ~(1&amp;lt;&amp;lt;1) ;&lt;BR /&gt;LPC_GPIO0-&amp;gt;FIOPIN |= ~(1&amp;lt;&amp;lt;18) ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was just curious, why the consecutive bit assignment doesn't work?!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your help is appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:50:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521684#M4322</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive bit assignments in the same register</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521685#M4323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by OldManVimes on Tue Mar 31 04:16:32 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Boolean logic, that's why.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Simpler example in binary where integers are 3 bits wide.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;0b001&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0b010&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0b100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-------- | (i.e OR them together)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0b111&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Take 3 values (1, 2 and 4) and OR them. Result: 7&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Now take the inverse of 7: ~0b111 = 0b000&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next section:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN |= ~0b001 is equal to FIOPIN |= 0b110&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN |= ~0b010 is equal to FIOPIN |= 0b101&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN |= ~0b100 is equal to FIOPIN |= 0b011&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After these 3 operations, what is the value of FIOPIN (assuming that the start value was zero)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN |= 0b110;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN |= 0b101;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN |= 0b011;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Result: FIOPIN = 0b111;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So because of the change in behavior, the value of FIOPIN is the inverse of what you expected. In conclusion: the two pieces of code do not apply the same operation. You can make it right though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN = 0b111;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN &amp;amp;= ~0b001; // Set bit 0 to 0, leave the rest unchanged&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FIOPIN &amp;amp;= ~0b100; // Set bit 2 to 0, leave the rest unchanged&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Result: FIOPIN = 0b010; // Great.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Vimes&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:50:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521685#M4323</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive bit assignments in the same register</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521686#M4324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by nerd herd on Tue Mar 31 07:26:00 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Mohannad,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OldManVimes gave a clear proof of why your two bit assignments are not the same. In case you were interested in delving deeper, the formal reason why the two bit assignments are not equal is due to De Morgan's Law. Essentially, when you NOT a statement such as ~(1 &amp;lt;&amp;lt; 16 | 1 &amp;lt;&amp;lt; 17), the NOT will flip the OR into a AND, making the equivalent statement of ~(1 &amp;lt;&amp;lt; 16) &amp;amp; ~(1 &amp;lt;&amp;lt; 17). For more information:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDe_Morgan%2527s_laws" rel="nofollow" target="_blank"&gt;http://en.wikipedia.org/wiki/De_Morgan%27s_laws&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:50:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Consecutive-bit-assignments-in-the-same-register/m-p/521686#M4324</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:50:22Z</dc:date>
    </item>
  </channel>
</rss>

