Helmut Schaefer wrote:
[...]
>
> 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.
A simple solution is to pass the _address_ of the
PxOUT register to your function, instead of the
port _number_.
void impulse(byte volatile *pxout_addr, byte pbit, word cnt)
#define BLINK40(x) (impulse(&P4OUT, 0, x))
Otherwise you can use a lookup table inside your
impulse() function to translate a port number
into the address of the PxOUT register.
void impulse(byte portnr, byte pbit, word cnt) {
const byte volatile *pxoutaddrs[7] =
{P1OUT, P1OUT, P2OUT, P3OUT, P4OUT, P5OUT, P6OUT};
byte volatile *pxout_addr;
if (portnr == 0 || portnr > 6)
return;
pxout_addr = pxoutaddrs[portnr];
...
}
Ports are numbered from 1, not 0, so there is a
dummy entry at the start of pxoutaddrs[] that
corresponds to portnr == 0 and is never used.
The array of addresses is needed because there
is no simple pattern to the locations of the
PxOUT registers using calculations.
Disclaimer: I'm not sure about the syntax for the
"volatile" keyword, it might be in the wrong
place, and I haven't compiled this code.
Kris
--
Kris Heidenstrom Embedded systems designer / programmer
[email protected] Abbey Systems Ltd - Telemetry Specialists
Wellington NEW ZEALAND Voice +64-4-385-6611 Fax +64-4-385-6848