You have to write your own macros.
For example:
#define BIT0 0x0001
#define BIT1 0x0002
#define setRegBit(reg, bit) reg |= bit
#define clrRegBit(reg, bit) reg &= ~bit
Now you can write setRegBit(porta,BIT1)
Maik Schormann
________________________________
Von: motoroladsp@moto... [mailto:motoroladsp@moto...] Im
Auftrag von Ko Ihara
Gesendet: Sonntag, 16. Oktober 2005 21:58
An: motoroladsp@moto...
Betreff: [motoroladsp] bitwise operation in simple C
Does anyone know how to set or clear individual bits without resorting
to something like:
porta = porta | 0x0001; // set 0th bit
porta = porta & 0xFFFE; // clear 0th bit
I come from assembly background, which provided handy operations like
setb and clrb.
* <http://docs.yahoo.com/info/terms/> .
________________________________
AW: bitwise operation in simple C
Started by ●October 17, 2005
Reply by ●October 17, 20052005-10-17
It is a good practice to parenthesize macro arguments, so it is better
to define the macros like this:
#define setRegBit(reg, bit) ((reg) |= (bit))
#define clrRegBit(reg, bit) ((reg) &= ~(bit)) Roberto Bonacina
-----Messaggio originale-----
Da: motoroladsp@moto... [mailto:motoroladsp@moto...] Per
conto di maik.schormann@maik...
Inviato: luned17 ottobre 2005 9.21
A: kihara@kiha...; motoroladsp@moto...
Oggetto: AW: [motoroladsp] bitwise operation in simple C You have to write your own macros.
For example:
#define BIT0 0x0001
#define BIT1 0x0002
#define setRegBit(reg, bit) reg |= bit
#define clrRegBit(reg, bit) reg &= ~bit
Now you can write setRegBit(porta,BIT1)
Maik Schormann
________________________________
Von: motoroladsp@moto... [mailto:motoroladsp@moto...] Im
Auftrag von Ko Ihara
Gesendet: Sonntag, 16. Oktober 2005 21:58
An: motoroladsp@moto...
Betreff: [motoroladsp] bitwise operation in simple C
Does anyone know how to set or clear individual bits without resorting
to something like:
porta = porta | 0x0001; // set 0th bit
porta = porta & 0xFFFE; // clear 0th bit
I come from assembly background, which provided handy operations like
setb and clrb.
* <http://docs.yahoo.com/info/terms/> .
________________________________
to define the macros like this:
#define setRegBit(reg, bit) ((reg) |= (bit))
#define clrRegBit(reg, bit) ((reg) &= ~(bit)) Roberto Bonacina
-----Messaggio originale-----
Da: motoroladsp@moto... [mailto:motoroladsp@moto...] Per
conto di maik.schormann@maik...
Inviato: luned17 ottobre 2005 9.21
A: kihara@kiha...; motoroladsp@moto...
Oggetto: AW: [motoroladsp] bitwise operation in simple C You have to write your own macros.
For example:
#define BIT0 0x0001
#define BIT1 0x0002
#define setRegBit(reg, bit) reg |= bit
#define clrRegBit(reg, bit) reg &= ~bit
Now you can write setRegBit(porta,BIT1)
Maik Schormann
________________________________
Von: motoroladsp@moto... [mailto:motoroladsp@moto...] Im
Auftrag von Ko Ihara
Gesendet: Sonntag, 16. Oktober 2005 21:58
An: motoroladsp@moto...
Betreff: [motoroladsp] bitwise operation in simple C
Does anyone know how to set or clear individual bits without resorting
to something like:
porta = porta | 0x0001; // set 0th bit
porta = porta & 0xFFFE; // clear 0th bit
I come from assembly background, which provided handy operations like
setb and clrb.
* <http://docs.yahoo.com/info/terms/> .
________________________________