<?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 Re: Stupid question on define pin in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168498#M5077</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks but...With variable it's impossible?&lt;/P&gt;&lt;P&gt;I used 3 pin for i2c (manual i2c not with dedicated function).&lt;/P&gt;&lt;P&gt;I have make generic Start, Stop,Write, Read. Before I use this function I set my port, example:&lt;/P&gt;&lt;P&gt;char SdaPin;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SdaPin= PTCD_PTCD2;&lt;/P&gt;&lt;P&gt;Start();&lt;/P&gt;&lt;P&gt;Write();&lt;/P&gt;&lt;P&gt;Stop();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//other pin&lt;/P&gt;&lt;P&gt;SdaPin= PTCD_PTCD3;&lt;/P&gt;&lt;P&gt;Start();&lt;/P&gt;&lt;P&gt;Write();&lt;/P&gt;&lt;P&gt;Stop();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is impossible if I must use a DEFINE.&lt;/P&gt;&lt;P&gt;I must re-write my function, one for each pin? Example:&lt;/P&gt;&lt;P&gt;Start_Pin2();&lt;/P&gt;&lt;P&gt;Write_Pin2();&lt;/P&gt;&lt;P&gt;Stop_Pin2();&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;Start_Pin3();&lt;/P&gt;&lt;P&gt;Write_Pin3();&lt;/P&gt;&lt;P&gt;Stop_Pin3();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 01 Apr 2009 13:33:38 GMT</pubDate>
    <dc:creator>cicciounico</dc:creator>
    <dc:date>2009-04-01T13:33:38Z</dc:date>
    <item>
      <title>Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168496#M5075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a stupid question on define pin.&lt;/P&gt;&lt;P&gt;I want define the name of pin, example:&lt;/P&gt;&lt;P&gt;char SdaPin;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SdaPin= PTCD_PTCD2;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;but when I write:&lt;/P&gt;&lt;P&gt;SdaPin= 1;&lt;/P&gt;&lt;P&gt;this not work!!!&lt;/P&gt;&lt;P&gt;Sorry for stupid question, I don't understand!!!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Apr 2009 00:34:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168496#M5075</guid>
      <dc:creator>cicciounico</dc:creator>
      <dc:date>2009-04-01T00:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168497#M5076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the preprocessor macro -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define&amp;nbsp; SdaPin&amp;nbsp; PTCD_PTCD2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;should permit SdaPin = 1; to be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Whenever the symbol SdaPin is encountered, the preprocessor will substitute PTCD_PTCD2.&amp;nbsp; As it happens, this is also a macro (defined in the derivative header file), so a further substitution will actually take place.&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, 01 Apr 2009 03:11:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168497#M5076</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-04-01T03:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168498#M5077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks but...With variable it's impossible?&lt;/P&gt;&lt;P&gt;I used 3 pin for i2c (manual i2c not with dedicated function).&lt;/P&gt;&lt;P&gt;I have make generic Start, Stop,Write, Read. Before I use this function I set my port, example:&lt;/P&gt;&lt;P&gt;char SdaPin;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SdaPin= PTCD_PTCD2;&lt;/P&gt;&lt;P&gt;Start();&lt;/P&gt;&lt;P&gt;Write();&lt;/P&gt;&lt;P&gt;Stop();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//other pin&lt;/P&gt;&lt;P&gt;SdaPin= PTCD_PTCD3;&lt;/P&gt;&lt;P&gt;Start();&lt;/P&gt;&lt;P&gt;Write();&lt;/P&gt;&lt;P&gt;Stop();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is impossible if I must use a DEFINE.&lt;/P&gt;&lt;P&gt;I must re-write my function, one for each pin? Example:&lt;/P&gt;&lt;P&gt;Start_Pin2();&lt;/P&gt;&lt;P&gt;Write_Pin2();&lt;/P&gt;&lt;P&gt;Stop_Pin2();&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;Start_Pin3();&lt;/P&gt;&lt;P&gt;Write_Pin3();&lt;/P&gt;&lt;P&gt;Stop_Pin3();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Apr 2009 13:33:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168498#M5077</guid>
      <dc:creator>cicciounico</dc:creator>
      <dc:date>2009-04-01T13:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168499#M5078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, it is possible to use it as a variable, but it's not as efficient as macro that generates just single bit set/clear instruction. On the other hand you can reuse the functions easily:&lt;/P&gt;&lt;P&gt;e.g.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
#define PIN_ON(x) *##x##.reg |= ##x##.mask
#define PIN_OFF(x) *##x##.reg &amp;amp;= ~##x##.mask

typedef struct {
 char *reg;    // poitner to the register
 char mask;    // bit mask
} tReg;

tReg SDA1 = {&amp;amp;PTADD, PTADD_PTADD0_MASK};   // define register address and particular bit(s)
tReg SDA2 = {&amp;amp;PTADD, PTADD_PTADD1_MASK};

void main(void)
{
  PIN_ON(SDA1);
  PIN_OFF(SDA1);

  PIN_ON(SDA2);
  PIN_OFF(SDA2);
}&lt;/PRE&gt;&lt;P&gt;Disassembly listing:&lt;/P&gt;&lt;PRE&gt;
  21:  PIN_ON(SDA1);
  0001 c60002   [4]             LDA   SDA1:2
  0004 320000   [5]             LDHX  SDA1
  0007 fa       [3]             ORA   ,X
  0008 f7       [2]             STA   ,X
   22:  PIN_OFF(SDA1);
  0009 c60002   [4]             LDA   SDA1:2
  000c 43       [1]             COMA 
  000d 320000   [5]             LDHX  SDA1
  0010 f4       [3]             AND   ,X
  0011 f7       [2]             STA   ,X
   23: 
   24:  PIN_ON(SDA2);
  0012 c60002   [4]             LDA   SDA2:2
  0015 320000   [5]             LDHX  SDA2
  0018 fa       [3]             ORA   ,X
  0019 f7       [2]             STA   ,X
   25:  PIN_OFF(SDA2);
  001a c60002   [4]             LDA   SDA2:2
  001d 43       [1]             COMA 
  001e 320000   [5]             LDHX  SDA2
  0021 f4       [3]             AND   ,X
  0022 f7       [2]             STA   ,X&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Using register macros will generate more efficient code:&lt;/P&gt;&lt;PRE&gt;

void main(void)
{
  PTADD_PTADD0 = 1;
  PTADD_PTADD0 = 0;

  PTADD_PTADD1 = 1;
  PTADD_PTADD1 = 0;
}&lt;/PRE&gt;&lt;P&gt;Disassembly listing:&lt;/P&gt;&lt;PRE&gt;
  27:  PTADD_PTADD0 = 1;
  0001 1000     [5]             BSET  0,_PTADD
   28:  PTADD_PTADD0 = 0;
  0003 1100     [5]             BCLR  0,_PTADD
   29: 
   30:  PTADD_PTADD1 = 1;
  0005 1200     [5]             BSET  1,_PTADD
   31:  PTADD_PTADD1 = 0;
  0007 1300     [5]             BCLR  1,_PTADD&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stanish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:16:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168499#M5078</guid>
      <dc:creator>stanish</dc:creator>
      <dc:date>2020-10-29T09:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168500#M5079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks again!&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Apr 2009 18:53:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168500#M5079</guid>
      <dc:creator>cicciounico</dc:creator>
      <dc:date>2009-04-01T18:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168501#M5080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you require that each function make use of a choice of SDA pins, you will need to pass this choice to&amp;nbsp; each of the functions.&amp;nbsp; Assuming that all the pins are allocated to PTCD, you might have something like the following -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define SDA2&amp;nbsp; 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;#define SDA3&amp;nbsp; 3&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;// Bit manipulation macros:&lt;BR /&gt;#define&amp;nbsp; bset(n,reg)&amp;nbsp;&amp;nbsp; (reg) |= (1 &amp;lt;&amp;lt; (n))&lt;BR /&gt;#define&amp;nbsp; bclr(n,reg)&amp;nbsp;&amp;nbsp; (reg) &amp;amp;= ~(1 &amp;lt;&amp;lt; (n))&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 Start( byte bitnum)&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; bset( bitnum, PTCD);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ...&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; ...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; bclr( bitnum, PTCD);&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="courier new,courier"&gt;void main( 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; for ( ; ; );&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Start( SDA2);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; ...&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;&amp;nbsp; Start( SDA3);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;BR /&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; }&amp;nbsp;&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;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>Thu, 02 Apr 2009 12:43:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168501#M5080</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-04-02T12:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Stupid question on define pin</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168502#M5081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;stanish wrote: Using register macros will generate more efficient code:&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;I believe there is an optimizer setting somewhere making bitwise operators equally efficient. They usually generate BSET / BCLR in my code... although I don't know how I managed to get it that way. They -should- generate equally efficient code, even when they are declared properly with "volatile".&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You can't use the "register macros" in a C program anyway, since they don't follow standard C. Even if you find another non-standard compiler allowing 8-bit bitfields, the code would still not be portable, since bitfields aren't portable in the first place.&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2009 19:46:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Stupid-question-on-define-pin/m-p/168502#M5081</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2009-04-02T19:46:58Z</dc:date>
    </item>
  </channel>
</rss>

