<?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: ASM Register vs. C Array</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182851#M6267</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;GPREG = bitpattern;&lt;/P&gt;&lt;P&gt;for(i = 0; i &amp;lt; 8; i++)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(GPREG &amp;amp; 0x80) bit_is_set();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPREG &amp;lt;&amp;lt;= 1;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jul 2012 14:26:24 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2012-07-25T14:26:24Z</dc:date>
    <item>
      <title>ASM Register vs. C Array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182850#M6266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;wasnt sure where to post this so i stuck with my 8 &amp;amp; 16 bit forum, always good answers &lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif"&gt;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In assembly I have an 8 bit register, GPREG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LDA #$6D &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; which is decimal 109&lt;/P&gt;&lt;P&gt;STA GPREG&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gives me 01101101&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets say i want an LED to turn on off according to that pattern&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LSR GPREG&lt;/P&gt;&lt;P&gt;(check carry bit set LED on/off etc. for 8 bits)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now the led blinks in an order unique to "decimal 109"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how would i accomlpish this in C?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have "decemial 109" or even "hex 6D"&lt;/P&gt;&lt;P&gt;i have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;byte b;&lt;/P&gt;&lt;P&gt;b = 109; &amp;nbsp;// my variable type in this case is a byte, and i CANT change that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i have to right an algorith creating an array?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for i = 0 to 7 {&lt;/P&gt;&lt;P&gt;if b divided by whatever*i has a remander or not theh&amp;nbsp;pattern[i] = 0 or 1&lt;/P&gt;&lt;P&gt;} // sorry for ugly pseudo code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so now my "pattern[]" has 8 ints 0 and 1s, and matches my GPREG,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But is there an easier way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;byte b = 109;&lt;/P&gt;&lt;P&gt;if b.0&lt;/P&gt;&lt;P&gt;if b.1&lt;/P&gt;&lt;P&gt;if b.2 (bit 2 "third bit") is 0 then LED off&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or something like that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance for the help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 00:46:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182850#M6266</guid>
      <dc:creator>LiveMike</dc:creator>
      <dc:date>2012-07-25T00:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: ASM Register vs. C Array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182851#M6267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;GPREG = bitpattern;&lt;/P&gt;&lt;P&gt;for(i = 0; i &amp;lt; 8; i++)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(GPREG &amp;amp; 0x80) bit_is_set();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPREG &amp;lt;&amp;lt;= 1;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 14:26:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182851#M6267</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2012-07-25T14:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: ASM Register vs. C Array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182852#M6268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mike,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no need to use an array - you can also use a shift operation in C.&amp;nbsp; The primary difference is that you do not have direct access to the carry flag (without use of a special "intrinsic" function), so the usual approach is to test the (LS) bit prior to doing the right shift.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following&amp;nbsp;assembly sub-routine&amp;nbsp;will generate the LED sequence, and&amp;nbsp;is what&amp;nbsp;might be used in practice.&amp;nbsp; I have made&amp;nbsp;use of&amp;nbsp;the&amp;nbsp;stack&amp;nbsp;for temporary storage, which is akin to using local variables in C.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EQU&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; PTAD0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;; LED SEQUENCE OUTPUT&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;; On entry, ACC = LED pattern&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; X = bit period (multiples of 10 ms)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LED_SEQ:&amp;nbsp; PSHA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Blink pattern&amp;nbsp;(1,SP)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LDA&amp;nbsp;&amp;nbsp;&amp;nbsp; #8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Bit counter&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;LS1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LSR&amp;nbsp;&amp;nbsp;&amp;nbsp; 1,SP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; CF is current bit state&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BCC&amp;nbsp;&amp;nbsp;&amp;nbsp; LS2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Branch if off state&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BSET&amp;nbsp;&amp;nbsp; LED,PTAD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Turn LED on&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BRA&amp;nbsp;&amp;nbsp;&amp;nbsp; *+4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Skip next always&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;LS2:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BCLR&amp;nbsp;&amp;nbsp; LED,PTAD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Turn LED off&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JSR&amp;nbsp;&amp;nbsp;&amp;nbsp; WAIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; X = multiples of 10 ms&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBNZA&amp;nbsp; LS1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Loop for next state&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AIS&amp;nbsp;&amp;nbsp;&amp;nbsp; #1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Adjust stack pointer&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RTS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following C function should operate similarly to the above code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define LED&amp;nbsp; PTAD_PTAD0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Would usually be in a header file&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;void LED_seq( byte pattern, byte bit_time)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; byte i;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Bit counter&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; for (i = 0; i &amp;lt;&amp;lt; 8; i++) {&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (pattern &amp;amp; 1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Test bit-0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LED = 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Turn LED on&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LED = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Turn LED off&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pattern &amp;gt;&amp;gt;= 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Shift right&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wait( bit_time);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Multiples of 10 ms&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you were to use a global variable for the bit pattern, rather than the function parameter, it is likely that the function would occupy more bytes, unless the global variable is explicitly placed within zero page RAM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jul 2012 15:05:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182852#M6268</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2012-07-25T15:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: ASM Register vs. C Array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182853#M6269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#define LED  PTAD_PTAD0         // Would usually be in a header filevoid LED_seq( byte pattern, byte bit_time){   byte i;                      // Bit counter   for (i = 0; i &amp;lt;&amp;lt; 8; i++) {      if (pattern &amp;amp; 1)          // Test bit-0         LED = 1;               // Turn LED on      else         LED = 0;               // Turn LED off      pattern &amp;gt;&amp;gt;= 1;            // Shift right      wait( bit_time);          // Multiples of 10 ms   }}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this looks great mac, but (of course) i have a few questions...&lt;/P&gt;&lt;P&gt;so the "byte" type in C is like a register? &amp;nbsp;as opposed to maybe int? you cant shift ints correct?&lt;/P&gt;&lt;PRE&gt;int foo;foo &amp;gt;&amp;gt;=1;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;that wouldnt work right?&lt;/P&gt;&lt;P&gt;but we can operate on bytes like ints correct?&lt;/P&gt;&lt;PRE&gt;byte bar;bar = 50;bar = bar - 48;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;this would make bar 2 correct? &amp;nbsp;then it still stored as 0000010 correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;next question is...&lt;/P&gt;&lt;P&gt;"pattern &amp;amp; 1" will always give you 1 or 0 correct? &amp;nbsp;so why have the if statement?&lt;/P&gt;&lt;P&gt;cant you just do LED = pattern &amp;amp; 1; ???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;last question...&lt;/P&gt;&lt;P&gt;i had been looking for somethign to "wait", so i see you have wait(7); that would wait 70ms correct??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a wait for microseconds (us)? &amp;nbsp;in assembly i use subroutines with NOP.&lt;/P&gt;&lt;P&gt;in C though this has been more difficult. sometimes it seems i to a for loop or while loop and try to fill it with "asm (NOP);" but it seems that i can get the right amount of loops.&lt;/P&gt;&lt;P&gt;right now I use:&lt;/P&gt;&lt;PRE&gt;int a;a = 0;while (a &amp;lt; 565){  a++;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;to get a 500us delay. &amp;nbsp;i know this is based off of the JM16's speed and clock settings, but it works, I just wandering if there is a wait() for microsecond intervals??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and of course THANK YOU THANK YOU for all of your help!!! &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:33:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182853#M6269</guid>
      <dc:creator>LiveMike</dc:creator>
      <dc:date>2020-10-29T09:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: ASM Register vs. C Array</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182854#M6270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mike,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Within the header file for the MCU derivative, you should find the following entries -&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;typedef unsigned char byte;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;typedef unsigned int word;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;What this means is that you can use the &lt;FONT face="courier new,courier"&gt;byte&lt;/FONT&gt; data type in lieu of the standard data type of &lt;FONT face="courier new,courier"&gt;unsigned char&lt;/FONT&gt;.&amp;nbsp; Similarly with using &lt;FONT face="courier new,courier"&gt;word&lt;/FONT&gt; in lieu of &lt;FONT face="courier new,courier"&gt;unsigned int&lt;/FONT&gt;.&amp;nbsp; With C we refer to a "variable" as having a specific data type.&amp;nbsp; The word "register" has a very specific meaning in C.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The first example that you give would require that variable foo be initialised prior to the shift operation.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;foo &amp;gt;&amp;gt;= 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This is short-hand for&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;foo = foo &amp;gt;&amp;gt; 1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Yes, you could use -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;LED = pattern &amp;amp; 1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Good observation!&amp;nbsp; That is one I missed in attempting to demonstrate the equivalence of the assembly and C snippets.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;I was not specific about the wait function, but you will obviously need one.&amp;nbsp; While the looping method can be calibrated to produce the right amount of delay for a specific bus frequency, a better method is to make use of a timer module.&amp;nbsp; An approach that is often used is to generate "tick" interrupts at regular intervals, typically 1 to 10 milliseconds.&amp;nbsp; This can be used for general delay&amp;nbsp;timing, provided you can tolerate a timing uncertainty of one tick interval - if&amp;nbsp;the required&amp;nbsp;timing parameter is N intervals, the actual delay will&amp;nbsp;fall somewhere between N-1 and N intervals.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The chosen tick interval should not be too short, where the frequent execution of the ISR code would occupy a significant percentage of the processing time.&amp;nbsp; With say, 500 microsecond interval and a 10MHz bus frequency, the number of cycles between interrupts would be 5000 - probably acceptable with short ISR code.&amp;nbsp; However, a tick period of 50 microseconds would appear unacceptable in most instances.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The following code snippet assumes use of a TPM channel, using software compare mode, although there are other possible alteratives.&amp;nbsp;Assume a 10 MHz bus frequency, and a TPM prescale factor of 4, the following ISR code is a possibility for a tick interval of 5ms.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define INCRVAL&amp;nbsp;12500&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 5ms interval&amp;nbsp;with 10MHz bus, TPM prescale 4&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;volatile&amp;nbsp;word delay_cnt = 0; // volatile modifier is required for this global variable&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;__interrupt 9 void ISR_TPM1C0( void)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM1C0V += INCRVAL;&amp;nbsp; // Next compare value&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM1C0_CH0F = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear flag&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; if (delay_cnt)&amp;nbsp; delay_cnt--;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The&amp;nbsp;delay function -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;void wait(&amp;nbsp;word delay)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; delay_cnt = delay;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; while (delay_cnt)&amp;nbsp;&amp;nbsp;&amp;nbsp; // Wait for timeout&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __RESET_WATCHDOG();&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2012 01:54:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/ASM-Register-vs-C-Array/m-p/182854#M6270</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2012-07-26T01:54:56Z</dc:date>
    </item>
  </channel>
</rss>

