Hi,

> #include <pic16f877.h>
> #define SET(reg,bit) (reg) |= (1<<(bit))
> #define CLR(reg,bit) (reg) &= ~(1<<(bit))
> 
> #define LED1 PORTA,0
> #define LED2 PORTA,2
> 
> void main() {
>     SET(LED1);
> }

The problem is that LED1 is expanded too late, you need to insert a
level of indirection:

/* for demonstration only, #include <pic14regs.h> in real life */
unsigned PORTA;

/* requires two separate arguments */
#define SET2(reg,bit)    (reg) |= (1 << (bit))
#define CLR2(reg,bit)    (reg) &= ~(1 << (bit))

/* requires a single argument that expands to two */
#define SET(arg)       SET2(arg)
#define CLR(arg)       CLR2(arg)

/* macros to address single bits in a register */
#define LED1    PORTA, 0
#define LED2    PORTA, 2

void main(void) {
    SET(LED1);
    CLR(LED2);
    SET2(PORTA, 0);
}

> I'm using SDCC 2.7.4. Can anybody help me?

Actually this is a GNU C Preprocessor problem, we only use it ;-)

Regards,
Raphael

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to