>> Is there a indexable way to access the SFRs?
>>
>> like: value = PxIN(5);
>> which should do the same like value = P5IN;
[ From: amx <a...@me...> - 2008-01-29 06:43 ]
> Try this macro:
> #define PxIN(a) P##a##IN
.. is a nice usage of the ## operator, but it does not work
for me because my 'a' is defined much later in a function
call at runtime:
n = 5;
printf( "PxIN(1)=%d.\n", PxIN(1) );
printf( "PxIN(n)=%d.\n", PxIN(n) );
leads to:
main.c:189: `PnIN' undeclared (first use in this function)
But good old '?' operator seems to do what i expect from him:
printf( "PxIN(1)=%d.\n", PxIN(1) );
12d6: 5f 42 20 00 mov.b &0x0020,r15 ;0x0020
12da: 7f f3 and.b #-1, r15 ;r3 As==11
12dc: 0f 12 push r15 ;
12de: 30 12 0c 12 push #4620 ;#0x120c
12e2: 30 12 7e 22 push #8830 ;#0x227e
12e6: b0 12 b6 70 call #28854 ;#0x70b6
printf( "PxIN(5)=%d.\n", PxIN(5) );
12ea: 5f 42 30 00 mov.b &0x0030,r15 ;0x0030
12ee: 7f f3 and.b #-1, r15 ;r3 As==11
12f0: 0f 12 push r15 ;
12f2: 30 12 19 12 push #4633 ;#0x1219
12f6: 30 12 7e 22 push #8830 ;#0x227e
12fa: b0 12 b6 70 call #28854 ;#0x70b6
n = 3;
printf( "PxIN(n)=%d.\n", PxIN(n) );
12fe: 5f 42 18 00 mov.b &0x0018,r15 ;0x0018
1302: 7f f3 and.b #-1, r15 ;r3 As==11
1304: 0f 12 push r15 ;
1306: 30 12 26 12 push #4646 ;#0x1226
130a: 30 12 7e 22 push #8830 ;#0x227e
130e: b0 12 b6 70 call #28854 ;#0x70b6
with PxIN(x) made like this:
#define PxIN(x) ( (x) == 1 ? (P1IN) : \
(x) == 2 ? (P2IN) : \
(x) == 3 ? (P3IN) : \
(x) == 4 ? (P4IN) : \
(x) == 5 ? (P5IN) : \
(x) == 6 ? (P6IN) : 0 )
Haven't figured out a general solution for the default part '0'
esp. when it comes to PxOUT(x) stuff etc.
Ciao,
Helmut
PS:
why?
wanted to have a single function to perform N pulses on any
MSP430 portpin.
void Impulse( byte portnr, byte pbit, word cnt ) { ... }
plus a
#define BLINK40(x) (Impulse(4,0,x))
to have Port 4.0 pulse out some message with:
BLINK40(5);
BLINK33(2);
etc.