<?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>Kinetis Microcontrollers中的主题 Re: FRDM-K22F:  Working with arrays</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773884#M47063</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am sorry but I don't follow your code:&lt;/P&gt;&lt;P&gt;1. data[] has a size of 8 ints but your loop is using 16 entries and so over-running the end of the array.&lt;BR /&gt;2. data[i] (when i is in valid range) can be either 1 or 0 so the &lt;STRONG&gt;if (data[i] == 8)&lt;/STRONG&gt; can never be true.&lt;BR /&gt;3. &lt;STRONG&gt;Data_GetRawVal() == data[i]&lt;/STRONG&gt; is comparing the function's return value with the array entry but the compare is useless.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the console output when you compile this since I would expect the compiler to already generate one or two warnings due to this.&lt;BR /&gt;Run lint over the program and it will probably give half a dozen warnings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 07 Apr 2018 01:27:28 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2018-04-07T01:27:28Z</dc:date>
    <item>
      <title>FRDM-K22F:  Working with arrays</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773881#M47060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I'm looking for an example of how to use arrays in my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I currently have is a CD4094 8-bit shift register connected to the FRDM-K22.&lt;/P&gt;&lt;P&gt;I'm using PTE0 as a clock, and PTE1&amp;nbsp;as my Data pin.&lt;/P&gt;&lt;P&gt;All the outputs of the shift register are tied to leds so I can confirm it works.&lt;/P&gt;&lt;P&gt;Below is a picture of the shift register if anyone's interested.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is more of a fun project for me.&amp;nbsp; I'm using KDS 3.2.0 and PE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/20329i44757839DE4804AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below this statement is how it would be connected, IF, I was using an ATtiny 13.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also included is the code for the ATtiny below that.&amp;nbsp; The syntax used to create the array I assume is different than in KDS.&amp;nbsp; My biggest problem is correctly writing the code PRIOR to "int main(void) {...", i.e. initializing the array,&lt;/P&gt;&lt;P&gt;followed by what to write&amp;nbsp;within&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;"int main(void) {...}" in order to use the array.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did try, however, I haven't been successful.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Brian&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/19131i9BDF283091A8033B/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_3.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/19798i4BC5864E3D81DE38/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_3.png" alt="pastedImage_3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2018 21:49:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773881#M47060</guid>
      <dc:creator>briancavanagh</dc:creator>
      <dc:date>2018-04-06T21:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K22F:  Working with arrays</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773882#M47061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may be an issue with the compiler C programming language standard dialect (eg. C90, C99, C11) used by KDS (it may also be configurable if you play with it) that will not allow you to declare variables in a routine after code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do this instead it may build:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;int main(void) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;int i;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;int data[] = {1,0,1,1,0,0,0,1};&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;DDRB |= ((1&amp;lt;&amp;lt;DDB0)|(1&amp;lt;&amp;lt;DDB4));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or if you put the second part in brackets it may also be OK:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;int main(void) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;DDRB |= ((1&amp;lt;&amp;lt;DDB0)|(1&amp;lt;&amp;lt;DDB4));&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;...&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int data[] = {1,0,1,1,0,0,0,1};&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (....&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would also make int data[]&lt;BR /&gt;&lt;STRONG&gt;static const int data[]&lt;/STRONG&gt;&lt;BR /&gt;to keep it in flash.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Also, the array looks to be a bit overkill in this case whereby&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;static const data = 0xb1;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;for (i=0x80;i!=0;i&amp;gt;&amp;gt;=1) {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((data &amp;amp; i) == 0) {PORTB = 0;}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {PORTB = (1&amp;lt;&amp;lt;DATA);}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTB |= (1&amp;lt;&amp;lt;REG_CLK);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;is both more efficient and more logical "when thinking in the byte value" to be sent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;uTasker developer and supporter (&lt;EM&gt;+5'000 hours experience on +60 Kinetis derivatives in +80 product developments&lt;/EM&gt;)&lt;BR /&gt;&lt;SPAN&gt;Kinetis: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Apr 2018 23:07:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773882#M47061</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2018-04-06T23:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K22F:  Working with arrays</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773883#M47062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, that's put on the correct track.&lt;/P&gt;&lt;P&gt;I now see me clock signal that I created.&lt;/P&gt;&lt;P&gt;I would like to output each value in the array on PT1 but I'm not sure how to do that.&lt;/P&gt;&lt;P&gt;Here's what I have so far in my code, I'm not comfortable with my choice taking data[i] and passing it to Data_GetRawVal().&lt;/P&gt;&lt;P&gt;I've tried others but still not sucess.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/20752i0BCF73A68964AA69/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.png" alt="pastedImage_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/21081i28CB39F84573FFFB/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2018 01:07:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773883#M47062</guid>
      <dc:creator>briancavanagh</dc:creator>
      <dc:date>2018-04-07T01:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-K22F:  Working with arrays</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773884#M47063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Brian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am sorry but I don't follow your code:&lt;/P&gt;&lt;P&gt;1. data[] has a size of 8 ints but your loop is using 16 entries and so over-running the end of the array.&lt;BR /&gt;2. data[i] (when i is in valid range) can be either 1 or 0 so the &lt;STRONG&gt;if (data[i] == 8)&lt;/STRONG&gt; can never be true.&lt;BR /&gt;3. &lt;STRONG&gt;Data_GetRawVal() == data[i]&lt;/STRONG&gt; is comparing the function's return value with the array entry but the compare is useless.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the console output when you compile this since I would expect the compiler to already generate one or two warnings due to this.&lt;BR /&gt;Run lint over the program and it will probably give half a dozen warnings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Apr 2018 01:27:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-K22F-Working-with-arrays/m-p/773884#M47063</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2018-04-07T01:27:28Z</dc:date>
    </item>
  </channel>
</rss>

