[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Question about gcc preprocessing and port/pinassignme
From: |
Ben Mann |
Subject: |
RE: [avr-gcc-list] Question about gcc preprocessing and port/pinassignments |
Date: |
Mon, 6 Dec 2004 16:05:46 +0800 |
I ran into some problems when I last tried an all-#define solution.
In the end I used something along the lines of
/***** header file stuff ******/
#define P_MODE &PORTB,_BV(PB0)
#define P_ROW &PORTB,_BV(PB1)
#define P_COL &PORTB,_BV(PB2)
//Read the value of a port pin
extern inline unsigned char PIN(volatile unsigned char *PORTNAME,unsigned
char PINS) {
return *PORTNAME & (unsigned char)PINS;
};
//Set the value of an output port to 1 (hi)
extern inline void PSET(volatile unsigned char *PORTNAME,unsigned char PINS)
{
*PORTNAME |= (unsigned char)PINS;
};
//Set the value of an output port to 0 (lo)
extern inline void PCLR(volatile unsigned char *PORTNAME,unsigned char PINS)
{
*PORTNAME &= (unsigned char)(~PINS);
};
/******************************/
And then use in .c file as
/******************************/
PSET(P_MODE); //sets portb pb0 high
PCLR(P_ROW); //sets portb pb1 low
a = PIN(P_COL); //reads portb pb2
/******************************/
(btw I suspect that "#define switch ..." would cause problems simply because
switch is a c statement...?)
Ben Mann
mailto:address@hidden
-----Original Message-----
From: address@hidden [mailto:address@hidden
On Behalf Of James Washer
Sent: Monday, 6 December 2004 2:19 PM
To: address@hidden
Subject: [avr-gcc-list] Question about gcc preprocessing and
port/pinassignments
I'd like to be able to say something like
#define switch PB7
.
.
.
setpin(PB7)
and have the following code generated
PORTB |= 1<<7
What I'm hoping for is the ability to change the definition of "switch" at
any time, and have everything work
For example
if I change switch to PD2, the preprocessor would (auto)magically arrange
for the following code
PORTD |= 1<<2
Any ideas?
- jim
_______________________________________________
avr-gcc-list mailing list
address@hidden http://www.avr1.org/mailman/listinfo/avr-gcc-list