Hi,
----- Original Message ----- 
From: "Helvécio Lopes Teixeira" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, 09 January, 2008 9:50 PM
Subject: [Sdcc-user] SET instruction


> Hello,
>
> I wrote this code:
>
> #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);
> }
>
-------------------------------------------------------------------------
I have been using this in AVR-GCC, but it will work here too.
//-------------------------------------------------------------------------
#define setb(port, bitno)  port |= 1<< bitno
#define clrb(port, bitno)  port &= ~(1<< bitno)
#define test(port, bitno) ((port & (1<< bitno)) > 0)
#define cplb(port, bitno) port ^= 1<< bitno

#define BVAL(p,b)              (b)
#define IO(p,b)                     (p)

#define SETB(io)                  setb(IO(io),BVAL(io))       //set the bit
#define CLRB(io)                  clrb(IO(io), BVAL(io))      //clear the 
bit
#define TEST(io)                  test(IO(io), BVAL(io))       //test the 
bit whether 0 or 1.
#define CPLB(io)                   cplb(IO(io), BVAL(io))       //invert the 
bit

/*   Once you have done this, you can say: */

#define      LED                PORTA, 2

/* And in your code say:  */

SETB(LED);           //led on
//or,
//setb(PORTA, 2);

CLRB(LED);           //led off

TEST(LED)            //check whether ON or OFF

CPLB(LED)            //toggle led.
//---------------------------------------------------
// Hope this helpd.

--Royce.




-------------------------------------------------------------------------
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