This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Pass Port to function

Hi,

I'm trying to write a function that takes the port it should output to as a parameter. I can of course pass pointers like P1OUT but how to I get the other registers of the corresponding port like P1SEL as well?

Btw, the function itself is written in asm and called from C

Regards,

Max

  • You shall check datasheet of the chip, "Peripheral File Map". This possibly will give you an idea.

  • Max said:
    I can of course pass pointers like P1OUT but how to I get the other registers of the corresponding port like P1SEL as well?

    You can pass a base address and the funciton then uses offsets (adding the offset to the base address).

    As mentioned, the peripheral file map gives you the addresses. Or the users guide register description. Look which register is first in memory. It is the same in all ports of this MSP and also in all MSPs of the same family.The other port registers are 2, 4, 6,8 bytes after the base address, so simply add 2,4,6,8 to the passed base pointer to access them.

    Example (untested)

    setPortOutputHigh (&P1IN, BIT0);

    setPortBitHigh: MOV R15, R12 ; R15 = &P1IN, R14 = BIT0), R12 and R13 are considered clobbered by the compiler and can be used freely)
    ADD #2, R12 ; R12 now points to P1OUT
    BIS.B R14, 0(R12); switch P1.0 output level to high
    ADD #2, R12 ; R12 now points to P1DIR
    BIS.B R14, 0(R12) ; switch P1.0 to output
    RET

**Attention** This is a public forum