avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] inline'ing sbi/cbi...


From: Dave Hansen
Subject: RE: [avr-gcc-list] inline'ing sbi/cbi...
Date: Mon, 12 Jan 2004 13:08:12 -0500

From: Herb Peyerl <address@hidden>
[...]
I/O port usage.  To make the code readable, I was hoping to do something
like:

        // from sfr_defs.h
        #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
        #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

        #define FOO (PORTB,4)
        sbi(FOO);
        cbi(FOO);

Obviously I can't do that.  So to work around that, I did:

Why "obviously?" Because of the preprocessor? If so, try something like this:

  #define Do_The_Work(p, m) p |= m
  #define Turn_On(pm)       Do_The_Work(pm)
  #define MY_BIT            PORTB, 0x04

  unsigned char PORTB;  /* Dummy to allow compile */

  void try_it()
  {
     Turn_On(MY_BIT);  /* preprocessor produces "PORTB |= 0x04;" */
  }

I'm fairly sure you can adapt this to your needs.

Nearly all problems in Computer Science can be solved by an additional level of indirection. ;-)

Regards,
  -=Dave

_________________________________________________________________
Learn how to choose, serve, and enjoy wine at Wine @ MSN. http://wine.msn.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]