<?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: BASIC SWITCH USAGE</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198592#M7397</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes your logic is wrong, you need to study how to correctly use the bitwise operators in C.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding standard C, Freescale provides a default register map which is implemented using non-standard bit fields. Your code is trying to write more than 1 bit to a single bit location in their bit-field. What happens when you do that, nobody can tell, since Freescale's register maps aren't standard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally I generate my own register maps using a little parser program I've written, which goes through the MCU manual pdf and fetches every register name and bit mask from there, then generates code which is 100% conforming with the C standard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it is sad that Freescale can't deliver libraries that are compliant with standard C and MISRA-C. Instead they focus on providing buggy Eclipse IDEs that nobody asked for. Apparently their new target customers are hobbyist PC programmers, rather than professional car manufacturers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Dec 2012 09:42:51 GMT</pubDate>
    <dc:creator>Lundin</dc:creator>
    <dc:date>2012-12-12T09:42:51Z</dc:date>
    <item>
      <title>BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198587#M7392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi! I am new to microcontroller programming so please be patient. the following will seem like a stupid question.&lt;/P&gt;&lt;P&gt;I am using DEMO9S08AW60E and using Codewarrior(Version: 5.9) with PE.&lt;/P&gt;&lt;P&gt;-------------Code Begins.&lt;/P&gt;&lt;P&gt;PTFDD = 0x00;&amp;nbsp; // to activate/intialize the port F and D&lt;/P&gt;&lt;P&gt;PTDDD = 0x00;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ((PTDD_PTDD2 |= 0x02))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PTFD_PTFD0 |=0x01;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;PTFD_PTFD0 &amp;amp;=0x01;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;-------------Code Ends. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;link for DEMO9S08AW60E: &lt;A _jive_internal="true" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fcache.freescale.com%2Ffiles%2Fmicrocontrollers%2Fhardware_tools%2Fschematics%2FDEMO9S08AW60_SCH.pdf" rel="nofollow" target="_blank"&gt;http://cache.freescale.com/files/microcontrollers/hardware_tools/schematics/DEMO9S08AW60_SCH.pdf&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;According to the schematic of the board, Switch 4 is connected to PortD/Pin2. And the set of LED are connected to the PortF/Pin(0-7). I have used a pull up resistor with the help of PE. The idea is to switch on the Led when the swtich is pressed.&amp;nbsp; Logically i feel my code is fine but there doesnt seem to be any effect. I would like to know where i am going wrong and hope you will able to help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;And also it will be great if someone could tell me how to add delay in a loop for example when i am using if else loop.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;THANKS in advance!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 09:59:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198587#M7392</guid>
      <dc:creator>sheetanshkaushi</dc:creator>
      <dc:date>2012-12-05T09:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198588#M7393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The PortD needs to be initilised to output ports:&amp;nbsp;&amp;nbsp; PTDDD bits should be set to 'ones'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 20:27:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198588#M7393</guid>
      <dc:creator>donw</dc:creator>
      <dc:date>2012-12-05T20:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198589#M7394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you DON Wood, i realised my mistake and corrected but the problem still remains. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 13:57:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198589#M7394</guid>
      <dc:creator>sheetanshkaushi</dc:creator>
      <dc:date>2012-12-06T13:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198590#M7395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How to enable pull resistors in HCS08 is pretty much undocumented in the manual. What you have to do is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Write to PTnPS to enable interrupts. Yes, it doesn't make sense. But it will enable the next register, PTnES.&lt;/P&gt;&lt;P&gt;- Write to PTnES to select interrupt edge trigger. Yes, it doesn't make sense. But it will at the same time set the pull resistor polarity: pull-up or pull-down.&lt;/P&gt;&lt;P&gt;- Write to PTnPE to enable the pull resistor.&lt;/P&gt;&lt;P&gt;- Write zero to PTnDD to set the pin as input.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That being said, your code has the following problems:&lt;/P&gt;&lt;P&gt;- You aren't using any contact de-bouncing. You need some form of simple contact de-bouncing algorithm, or your program will read random inputs from the switch.&lt;/P&gt;&lt;P&gt;- You are using the bitwise operators incorrectly. To check if a port input is set, you should have written PTDD_PTDD2 &amp;amp; 0x02, meaning "if the port AND the value 0x02 gives me 0x02 rather than 0x00 as result, then...". Similarly you are setting the output incorrectly, it should have been PTFD_PTFD0 |= 0x01; // set to pin to 1, or PTFD_PTFD0 &amp;amp;=~0x01; // set pin to 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you seem to be using Freescale's default register map with non-standard bit-fields. Since that crappy register map isn't written in standard C, nobody knows what will happen when you write 0x02 to a single bit, the C standard doesn't document or specify it. I would personally stick to C instead of using Freescale non-standard features.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 14:24:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198590#M7395</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2012-12-06T14:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198591#M7396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THANKS A LOT, DON WOOD.&amp;nbsp; That was truly the help i needed.&lt;BR /&gt;Just one question, SO my Logic is wrong? i should always use Masks to access the ports, right??&lt;/P&gt;&lt;P&gt;Also, would you explain a little more about the Last paragraph of your's; specially what do you mean by " ... I would personally stick to C instead of using Freescale non-standard features."&lt;BR /&gt;Thanks again!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 15:29:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198591#M7396</guid>
      <dc:creator>sheetanshkaushi</dc:creator>
      <dc:date>2012-12-06T15:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198592#M7397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes your logic is wrong, you need to study how to correctly use the bitwise operators in C.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding standard C, Freescale provides a default register map which is implemented using non-standard bit fields. Your code is trying to write more than 1 bit to a single bit location in their bit-field. What happens when you do that, nobody can tell, since Freescale's register maps aren't standard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally I generate my own register maps using a little parser program I've written, which goes through the MCU manual pdf and fetches every register name and bit mask from there, then generates code which is 100% conforming with the C standard.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it is sad that Freescale can't deliver libraries that are compliant with standard C and MISRA-C. Instead they focus on providing buggy Eclipse IDEs that nobody asked for. Apparently their new target customers are hobbyist PC programmers, rather than professional car manufacturers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Dec 2012 09:42:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198592#M7397</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2012-12-12T09:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: BASIC SWITCH USAGE</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198593#M7398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have learned about my mistake. thank you for tat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Dec 2012 11:35:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/BASIC-SWITCH-USAGE/m-p/198593#M7398</guid>
      <dc:creator>sheetanshkaushi</dc:creator>
      <dc:date>2012-12-12T11:35:03Z</dc:date>
    </item>
  </channel>
</rss>

